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