From cf3fc2ef4f7591b31e93b6258b9070c84f6ff37b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 10 May 2020 15:57:50 +0200 Subject: [PATCH] Added title formatting settings to project file --- nw/core/project.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/nw/core/project.py b/nw/core/project.py index 7011a7da..c2ce2902 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -80,10 +80,9 @@ class NWProject(): self.bookTitle = "" # The final title; should only be used for exports self.bookAuthors = [] # A list of book authors - # Various - self.autoReplace = {} # Text to auto-replace on exports - # Project Settings + self.autoReplace = {} # Text to auto-replace on exports + self.titleFormat = {} # The formatting of titles for exports self.spellCheck = False # Controls the spellcheck-as-you-type feature self.autoOutline = True # If true, the Project Outline is updated automatically self.statusItems = None # Novel file progress status values @@ -200,6 +199,15 @@ class NWProject(): self.bookTitle = "" self.bookAuthors = [] self.autoReplace = {} + self.titleFormat = { + "title": "%title%", + "chapter": "Chapter %num%", + "chapterSub": "%title%", + "unnumbered": "%title%", + "scene": "", + "sceneSep": "* * *", + "section": "", + } self.spellCheck = False self.autoOutline = True self.statusItems = NWStatus() @@ -347,6 +355,11 @@ class NWProject(): elif xItem.tag == "autoReplace": for xEntry in xItem: self.autoReplace[xEntry.tag] = checkString(xEntry.text, None, False) + elif xItem.tag == "titleFormat": + titleFormat = self.titleFormat.copy() + for xEntry in xItem: + titleFormat[xEntry.tag] = checkString(xEntry.text, None, False) + self.setTitleFormat(titleFormat) elif xChild.tag == "content": logger.debug("Found project content") self.projTree.unpackXML(xChild) @@ -417,10 +430,16 @@ class NWProject(): self._packProjectValue(xSettings, "lastEdited", self.lastEdited) self._packProjectValue(xSettings, "lastViewed", self.lastViewed) self._packProjectValue(xSettings, "lastWordCount", self.currWCount) + xAutoRep = etree.SubElement(xSettings, "autoReplace") for aKey, aValue in self.autoReplace.items(): if len(aKey) > 0: - self._packProjectValue(xAutoRep,aKey,aValue) + self._packProjectValue(xAutoRep, aKey, aValue) + + xTitleFmt = etree.SubElement(xSettings, "titleFormat") + for aKey, aValue in self.titleFormat.items(): + if len(aKey) > 0: + self._packProjectValue(xTitleFmt, aKey, aValue) xStatus = etree.SubElement(xSettings,"status") self.statusItems.packEntries(xStatus) @@ -695,6 +714,14 @@ class NWProject(): self.autoReplace = autoReplace return + def setTitleFormat(self, titleFormat): + """Set the formatting of titles in the project. + """ + for valKey in titleFormat: + if valKey in self.titleFormat: + self.titleFormat[valKey] = titleFormat[valKey] + return + def setProjectChanged(self, bValue): """Toggle the project changed flag, and propagate the information to the GUI statusbar.