Have the new project function also set titles in files added

This commit is contained in:
Veronica K. B. Olsen
2020-08-10 22:16:46 +02:00
parent 7bc62db5e3
commit 72e4656a57
8 changed files with 106 additions and 58 deletions
+36 -4
View File
@@ -255,6 +255,8 @@ class NWProject():
self.setBookTitle(projTitle) self.setBookTitle(projTitle)
self.setBookAuthors(projAuthors) self.setBookAuthors(projAuthors)
aDoc = NWDoc(self, self.theParent)
if popMinimal: if popMinimal:
# Creating a minimal project with a few root folders and a # Creating a minimal project with a few root folders and a
# single chapter folder with a single file. # single chapter folder with a single file.
@@ -263,11 +265,24 @@ class NWProject():
xHandle = self.newRoot("Characters", nwItemClass.CHARACTER) xHandle = self.newRoot("Characters", nwItemClass.CHARACTER)
xHandle = self.newRoot("World", nwItemClass.WORLD) xHandle = self.newRoot("World", nwItemClass.WORLD)
tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle) tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle)
cHandle = self.newFolder("New Chapter", nwItemClass.NOVEL, nHandle) dHandle = self.newFolder("New Chapter", nwItemClass.NOVEL, nHandle)
fHandle = self.newFile("New Chapter", nwItemClass.NOVEL, cHandle) cHandle = self.newFile("New Chapter", nwItemClass.NOVEL, dHandle)
XHandle = self.newFile("New Scene", nwItemClass.NOVEL, cHandle) sHandle = self.newFile("New Scene", nwItemClass.NOVEL, dHandle)
self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE)
self.projTree.setFileItemLayout(fHandle, nwItemLayout.CHAPTER) self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER)
aDoc.openDocument(tHandle, showStatus=False)
aDoc.saveDocument("# %s\n\n" % projName)
aDoc.clearDocument()
aDoc.openDocument(cHandle, showStatus=False)
aDoc.saveDocument("## New Chapter\n\n")
aDoc.clearDocument()
aDoc.openDocument(sHandle, showStatus=False)
aDoc.saveDocument("### New Scene\n\n")
aDoc.clearDocument()
elif popCustom: elif popCustom:
# Create a project structure based on selected root folders # Create a project structure based on selected root folders
@@ -284,6 +299,10 @@ class NWProject():
tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle) tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle)
self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE)
aDoc.openDocument(tHandle, showStatus=False)
aDoc.saveDocument("# %s\n\n" % projName)
aDoc.clearDocument()
# Create chapters and scenes # Create chapters and scenes
numChapters = projData.get("numChapters", 0) numChapters = projData.get("numChapters", 0)
numScenes = projData.get("numScenes", 0) numScenes = projData.get("numScenes", 0)
@@ -296,21 +315,34 @@ class NWProject():
pHandle = nHandle pHandle = nHandle
if chFolders: if chFolders:
pHandle = self.newFolder(chTitle, nwItemClass.NOVEL, nHandle) pHandle = self.newFolder(chTitle, nwItemClass.NOVEL, nHandle)
cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle) cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle)
self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER)
aDoc.openDocument(cHandle, showStatus=False)
aDoc.saveDocument("## %s\n\n" % chTitle)
aDoc.clearDocument()
# Create chapter scenes # Create chapter scenes
if numScenes > 0: if numScenes > 0:
for sc in range(numScenes): for sc in range(numScenes):
scTitle = "Scene %d.%d" % (ch+1, sc+1) scTitle = "Scene %d.%d" % (ch+1, sc+1)
sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle) sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle)
aDoc.openDocument(sHandle, showStatus=False)
aDoc.saveDocument("### %s\n\n" % scTitle)
aDoc.clearDocument()
# Create scenes (no chapters) # Create scenes (no chapters)
elif numScenes > 0: elif numScenes > 0:
for sc in range(numScenes): for sc in range(numScenes):
scTitle = "Scene %d" % (sc+1) scTitle = "Scene %d" % (sc+1)
sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle) sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle)
aDoc.openDocument(sHandle, showStatus=False)
aDoc.saveDocument("### %s\n\n" % scTitle)
aDoc.clearDocument()
else: else:
# Fallback just in case. We shouldn't reach here. # Fallback just in case. We shouldn't reach here.
self.newRoot("Novel", nwItemClass.NOVEL) self.newRoot("Novel", nwItemClass.NOVEL)
+3 -2
View File
@@ -300,6 +300,7 @@ class GuiMain(QMainWindow):
self.saveProject() self.saveProject()
self.hasProject = True self.hasProject = True
self.statusBar.setRefTime(self.theProject.projOpened) self.statusBar.setRefTime(self.theProject.projOpened)
self.rebuildIndex(beQuiet=True)
else: else:
self.theProject.clearProject() self.theProject.clearProject()
return False return False
@@ -700,7 +701,7 @@ class GuiMain(QMainWindow):
self.treeView.buildTree() self.treeView.buildTree()
return return
def rebuildIndex(self): def rebuildIndex(self, beQuiet=False):
"""Rebuild the entire index. """Rebuild the entire index.
""" """
if not self.hasProject: if not self.hasProject:
@@ -743,7 +744,7 @@ class GuiMain(QMainWindow):
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
if self.mainConf.showGUI: if self.mainConf.showGUI and not beQuiet:
self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO) self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO)
return True return True
+11
View File
@@ -8,6 +8,7 @@ class DummyMain():
def __init__(self): def __init__(self):
self.mainConf = None self.mainConf = None
self.statusBar = StatusBar()
return return
def makeAlert(self, theMessage, theLevel): def makeAlert(self, theMessage, theLevel):
@@ -33,3 +34,13 @@ class DummyMain():
return return
# END Class GuiMain # END Class GuiMain
class StatusBar():
def __init__(self):
return
def setStatus(self, theText):
return
# END Class StatusBar
+9 -9
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 21:06:05"> <novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 21:55:04">
<project> <project>
<name>New Project</name> <name>New Project</name>
<title></title> <title></title>
@@ -13,8 +13,8 @@
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>None</lastEdited> <lastEdited>None</lastEdited>
<lastViewed>None</lastViewed> <lastViewed>None</lastViewed>
<lastWordCount>0</lastWordCount> <lastWordCount>6</lastWordCount>
<novelWordCount>0</novelWordCount> <novelWordCount>6</novelWordCount>
<notesWordCount>0</notesWordCount> <notesWordCount>0</notesWordCount>
<autoReplace/> <autoReplace/>
<titleFormat> <titleFormat>
@@ -52,8 +52,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>TITLE</layout> <layout>TITLE</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -71,8 +71,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>CHAPTER</layout> <layout>CHAPTER</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -83,8 +83,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>SCENE</layout> <layout>SCENE</layout>
<charCount>0</charCount> <charCount>9</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
+9 -9
View File
@@ -1,11 +1,11 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 21:15:06"> <novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 22:00:16">
<project> <project>
<name>New Project</name> <name>New Project</name>
<title></title> <title></title>
<saveCount>4</saveCount> <saveCount>5</saveCount>
<autoCount>1</autoCount> <autoCount>1</autoCount>
<editTime>13</editTime> <editTime>14</editTime>
</project> </project>
<settings> <settings>
<doBackup>True</doBackup> <doBackup>True</doBackup>
@@ -13,8 +13,8 @@
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>0e17daca5f3e1</lastEdited> <lastEdited>0e17daca5f3e1</lastEdited>
<lastViewed>None</lastViewed> <lastViewed>None</lastViewed>
<lastWordCount>86</lastWordCount> <lastWordCount>90</lastWordCount>
<novelWordCount>59</novelWordCount> <novelWordCount>63</novelWordCount>
<notesWordCount>27</notesWordCount> <notesWordCount>27</notesWordCount>
<autoReplace/> <autoReplace/>
<titleFormat> <titleFormat>
@@ -52,8 +52,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>TITLE</layout> <layout>TITLE</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -71,8 +71,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>CHAPTER</layout> <layout>CHAPTER</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
+11 -11
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 21:21:39"> <novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 22:01:52">
<project> <project>
<name>Project Name</name> <name>Project Name</name>
<title>Project Title</title> <title>Project Title</title>
<author>Jane Doe</author> <author>Jane Doe</author>
<author>John Doh</author> <author>John Doh</author>
<saveCount>1</saveCount> <saveCount>2</saveCount>
<autoCount>1</autoCount> <autoCount>1</autoCount>
<editTime>1</editTime> <editTime>0</editTime>
</project> </project>
<settings> <settings>
<doBackup>True</doBackup> <doBackup>True</doBackup>
@@ -15,8 +15,8 @@
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>None</lastEdited> <lastEdited>None</lastEdited>
<lastViewed>None</lastViewed> <lastViewed>None</lastViewed>
<lastWordCount>0</lastWordCount> <lastWordCount>6</lastWordCount>
<novelWordCount>0</novelWordCount> <novelWordCount>6</novelWordCount>
<notesWordCount>0</notesWordCount> <notesWordCount>0</notesWordCount>
<autoReplace> <autoReplace>
<entry key="This">With This Stuff </entry> <entry key="This">With This Stuff </entry>
@@ -56,8 +56,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>TITLE</layout> <layout>TITLE</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -75,8 +75,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>CHAPTER</layout> <layout>CHAPTER</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -87,8 +87,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>SCENE</layout> <layout>SCENE</layout>
<charCount>0</charCount> <charCount>9</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
+10 -10
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 21:24:22"> <novelWriterXML appVersion="0.11.1" hexVersion="0x001101f0" fileVersion="1.2" timeStamp="2020-08-10 22:03:19">
<project> <project>
<name>New Project</name> <name>New Project</name>
<title></title> <title></title>
@@ -13,8 +13,8 @@
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>0e17daca5f3e1</lastEdited> <lastEdited>0e17daca5f3e1</lastEdited>
<lastViewed>None</lastViewed> <lastViewed>None</lastViewed>
<lastWordCount>59</lastWordCount> <lastWordCount>6</lastWordCount>
<novelWordCount>59</novelWordCount> <novelWordCount>6</novelWordCount>
<notesWordCount>0</notesWordCount> <notesWordCount>0</notesWordCount>
<autoReplace/> <autoReplace/>
<titleFormat> <titleFormat>
@@ -52,8 +52,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>TITLE</layout> <layout>TITLE</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -71,8 +71,8 @@
<status>New</status> <status>New</status>
<exported>True</exported> <exported>True</exported>
<layout>CHAPTER</layout> <layout>CHAPTER</layout>
<charCount>0</charCount> <charCount>11</charCount>
<wordCount>0</wordCount> <wordCount>2</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
@@ -83,9 +83,9 @@
<status>Note</status> <status>Note</status>
<exported>False</exported> <exported>False</exported>
<layout>PAGE</layout> <layout>PAGE</layout>
<charCount>331</charCount> <charCount>9</charCount>
<wordCount>59</wordCount> <wordCount>2</wordCount>
<paraCount>2</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos> <cursorPos>0</cursorPos>
</item> </item>
<item handle="44cb730c42048" order="1" parent="None"> <item handle="44cb730c42048" order="1" parent="None">
+17 -13
View File
@@ -14,8 +14,8 @@ from nw.gui import (
) )
from nw.constants import * from nw.constants import *
keyDelay = 5 keyDelay = 2
stepDelay = 50 stepDelay = 20
@pytest.mark.gui @pytest.mark.gui
def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
@@ -89,6 +89,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
# Type something into the document # Type something into the document
nwGUI.setFocus(2) nwGUI.setFocus(2)
qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay)
for c in "# Jane Doe": for c in "# Jane Doe":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
@@ -110,6 +111,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
# Type something into the document # Type something into the document
nwGUI.setFocus(2) nwGUI.setFocus(2)
qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay)
for c in "# Main Plot": for c in "# Main Plot":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
@@ -136,6 +138,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
# Type something into the document # Type something into the document
nwGUI.setFocus(2) nwGUI.setFocus(2)
qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay)
for c in "# Main Location": for c in "# Main Location":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
@@ -158,6 +161,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
# Type something into the document # Type something into the document
nwGUI.setFocus(2) nwGUI.setFocus(2)
qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay)
for c in "# Novel": for c in "# Novel":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
@@ -399,7 +403,7 @@ def testItemEditor(qtbot, nwTempGUI, nwRef, nwTemp):
assert not nwGUI.docEditor.setCursorLine("where?") assert not nwGUI.docEditor.setCursorLine("where?")
assert nwGUI.docEditor.setCursorLine(2) assert nwGUI.docEditor.setCursorLine(2)
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
assert nwGUI.docEditor.getCursorPosition() == 9 assert nwGUI.docEditor.getCursorPosition() == 15
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
assert nwGUI.saveProject() assert nwGUI.saveProject()
@@ -438,10 +442,10 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp):
jsonData = json.loads(inFile.read()) jsonData = json.loads(inFile.read())
assert len(jsonData) == 3 assert len(jsonData) == 3
assert jsonData[0]["length"] > 0 assert jsonData[1]["length"] > 0
assert jsonData[0]["newWords"] == 86 assert jsonData[1]["newWords"] == 84
assert jsonData[0]["novelWords"] == 59 assert jsonData[1]["novelWords"] == 63
assert jsonData[0]["noteWords"] == 27 assert jsonData[1]["noteWords"] == 27
# No Novel Files # No Novel Files
qtbot.mouseClick(sessLog.incNovel, Qt.LeftButton) qtbot.mouseClick(sessLog.incNovel, Qt.LeftButton)
@@ -456,7 +460,7 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp):
assert len(jsonData) == 2 assert len(jsonData) == 2
assert jsonData[0]["length"] > 0 assert jsonData[0]["length"] > 0
assert jsonData[0]["newWords"] == 27 assert jsonData[0]["newWords"] == 27
assert jsonData[0]["novelWords"] == 59 assert jsonData[0]["novelWords"] == 63
assert jsonData[0]["noteWords"] == 27 assert jsonData[0]["noteWords"] == 27
# No Note Files # No Note Files
@@ -471,10 +475,10 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp):
jsonData = json.loads(inFile.read()) jsonData = json.loads(inFile.read())
assert len(jsonData) == 3 assert len(jsonData) == 3
assert jsonData[0]["length"] > 0 assert jsonData[1]["length"] > 0
assert jsonData[0]["newWords"] == 59 assert jsonData[1]["newWords"] == 57
assert jsonData[0]["novelWords"] == 59 assert jsonData[1]["novelWords"] == 63
assert jsonData[0]["noteWords"] == 27 assert jsonData[1]["noteWords"] == 27
# No Negative Entries # No Negative Entries
qtbot.mouseClick(sessLog.incNotes, Qt.LeftButton) qtbot.mouseClick(sessLog.incNotes, Qt.LeftButton)
@@ -487,7 +491,7 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp):
with open(jsonStats, mode="r", encoding="utf-8") as inFile: with open(jsonStats, mode="r", encoding="utf-8") as inFile:
jsonData = json.loads(inFile.read()) jsonData = json.loads(inFile.read())
assert len(jsonData) == 1 assert len(jsonData) == 2
# Un-hide Zero Entries # Un-hide Zero Entries
qtbot.mouseClick(sessLog.hideNegative, Qt.LeftButton) qtbot.mouseClick(sessLog.hideNegative, Qt.LeftButton)