diff --git a/nw/core/document.py b/nw/core/document.py index 52f1517b..560815e6 100644 --- a/nw/core/document.py +++ b/nw/core/document.py @@ -30,8 +30,10 @@ import nw from os import path, mkdir, rename, unlink +from nw.core.item import NWItem from nw.constants import nwAlert from nw.common import isHandle +from nw.constants import nwItemLayout, nwItemClass logger = logging.getLogger(__name__) @@ -139,8 +141,18 @@ class NWDoc(): docPath = path.join(self.theProject.projContent, docFile) docTemp = path.join(self.theProject.projContent, docFile+"~") - itemPath = self.theProject.projTree.getItemPath(self.docHandle) - docMeta = "%%~ "+":".join(itemPath)+":"+self.theItem.itemName+"\n" + if isinstance(self.theItem, NWItem): + itemPath = self.theProject.projTree.getItemPath(self.docHandle) + docMeta = ( + "%%~ {handlepath:s}:{itemclass:s}:{itemlayout:s}:{itemname:s}\n" + ).format( + handlepath = ":".join(itemPath), + itemclass = self.theItem.itemClass.name, + itemlayout = self.theItem.itemLayout.name, + itemname = self.theItem.itemName, + ) + else: + docMeta = "" try: with open(docTemp, mode="w", encoding="utf8") as outFile: @@ -194,7 +206,7 @@ class NWDoc(): """ if len(self.docMeta) < 14: # Not enough information - return "", [] + return "", [], None, None theMeta = self.docMeta @@ -213,6 +225,18 @@ class NWDoc(): else: break - return theMeta, thePath + theClass = nwItemClass.NO_CLASS + for aClass in nwItemClass: + if theMeta.startswith(aClass.name): + theClass = aClass + theMeta = theMeta.lstrip(aClass.name+":") + + theLayout = nwItemLayout.NO_LAYOUT + for aLayout in nwItemLayout: + if theMeta.startswith(aLayout.name): + theLayout = aLayout + theMeta = theMeta.lstrip(aLayout.name+":") + + return theMeta, thePath, theClass, theLayout # END Class NWDoc diff --git a/nw/core/index.py b/nw/core/index.py index 456b415c..632375a7 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -41,7 +41,7 @@ logger = logging.getLogger(__name__) class NWIndex(): - VALID_KEYS = set([ + VALID_KEYS = { nwKeyWords.TAG_KEY, nwKeyWords.PLOT_KEY, nwKeyWords.POV_KEY, @@ -51,7 +51,7 @@ class NWIndex(): nwKeyWords.OBJECT_KEY, nwKeyWords.ENTITY_KEY, nwKeyWords.CUSTOM_KEY - ]) + } TAG_CLASS = { nwKeyWords.CHAR_KEY : nwItemClass.CHARACTER, nwKeyWords.POV_KEY : nwItemClass.CHARACTER, diff --git a/nw/core/options.py b/nw/core/options.py index abab6a65..25bf1fb4 100644 --- a/nw/core/options.py +++ b/nw/core/options.py @@ -45,7 +45,7 @@ class OptionState(): self.theState = {} self.validMap = { - "GuiSession": set([ + "GuiSession": { "widthCol0", "widthCol1", "widthCol2", @@ -53,11 +53,11 @@ class OptionState(): "sortOrder", "hideZeros", "hideNegative", - ]), - "GuiDocSplit": set([ + }, + "GuiDocSplit": { "spLevel", - ]), - "GuiBuildNovel": set([ + }, + "GuiBuildNovel": { "winWidth", "winHeight", "addNovel", @@ -72,12 +72,12 @@ class OptionState(): "incComments", "incKeywords", "incBodyText", - ]), - "GuiOutline": set([ + }, + "GuiOutline": { "headerOrder", "columnWidth", "columnHidden", - ]), + }, } return diff --git a/nw/core/project.py b/nw/core/project.py index 0784fc7a..3db93bf2 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -1075,17 +1075,22 @@ class NWProject(): # Look for meta data oName = "" if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True): - oName, oPath = aDoc.getMeta() + oName, oPath, oClass, oLayout = aDoc.getMeta() if oName == "": nOrph += 1 oName = "Orphaned File %d" % nOrph + if oClass is None: + oClass = nwItemClass.NO_CLASS + if oLayout is None: + oLayout = nwItemLayout.NO_LAYOUT + orphItem = NWItem(self) orphItem.setName(oName) orphItem.setType(nwItemType.FILE) - orphItem.setClass(nwItemClass.NO_CLASS) - orphItem.setLayout(nwItemLayout.NO_LAYOUT) + orphItem.setClass(oClass) + orphItem.setLayout(oLayout) self.projTree.append(oHandle, None, orphItem) return diff --git a/sample/content/14298de4d9524.nwd b/sample/content/14298de4d9524.nwd index 106f640e..af6c4e50 100644 --- a/sample/content/14298de4d9524.nwd +++ b/sample/content/14298de4d9524.nwd @@ -1,4 +1,4 @@ -%%~ 14298de4d9524:f7e2d9f330615:f6622b4617424:John Smith +%%~ 14298de4d9524:f7e2d9f330615:f6622b4617424:CHARACTER:NOTE:John Smith # John Smith @tag: John diff --git a/sample/content/53b69b83cdafc.nwd b/sample/content/53b69b83cdafc.nwd index 51c7c8d9..b25ce403 100644 --- a/sample/content/53b69b83cdafc.nwd +++ b/sample/content/53b69b83cdafc.nwd @@ -1,4 +1,4 @@ -%%~ 53b69b83cdafc:7031beac91f75:Title Page +%%~ 53b69b83cdafc:7031beac91f75:NOVEL:TITLE:Title Page # My Novel **By Jane Doh** diff --git a/sample/content/5eaea4e8cdee8.nwd b/sample/content/5eaea4e8cdee8.nwd index ac8ce5dd..ba951a2b 100644 --- a/sample/content/5eaea4e8cdee8.nwd +++ b/sample/content/5eaea4e8cdee8.nwd @@ -1,4 +1,4 @@ -%%~ 5eaea4e8cdee8:15c4492bd5107:Mars +%%~ 5eaea4e8cdee8:15c4492bd5107:WORLD:NOTE:Mars # Mars @tag: Mars diff --git a/sample/content/636b6aa9b697b.nwd b/sample/content/636b6aa9b697b.nwd index ea69cd21..e93bbb57 100644 --- a/sample/content/636b6aa9b697b.nwd +++ b/sample/content/636b6aa9b697b.nwd @@ -1,4 +1,4 @@ -%%~ 636b6aa9b697b:e7ded148d6e4a:7031beac91f75:Making a Scene +%%~ 636b6aa9b697b:e7ded148d6e4a:7031beac91f75:NOVEL:SCENE:Making a Scene ### Making a Scene @pov: Jane diff --git a/sample/content/6a2d6d5f4f401.nwd b/sample/content/6a2d6d5f4f401.nwd index 5e5d8566..583f503f 100644 --- a/sample/content/6a2d6d5f4f401.nwd +++ b/sample/content/6a2d6d5f4f401.nwd @@ -1,4 +1,4 @@ -%%~ 6a2d6d5f4f401:e7ded148d6e4a:7031beac91f75:Chapter One +%%~ 6a2d6d5f4f401:e7ded148d6e4a:7031beac91f75:NOVEL:CHAPTER:Chapter One ## So it Begins @pov: Jane diff --git a/sample/content/88706ddc78b1b.nwd b/sample/content/88706ddc78b1b.nwd index 94b563cf..4f9a8d43 100644 --- a/sample/content/88706ddc78b1b.nwd +++ b/sample/content/88706ddc78b1b.nwd @@ -1,4 +1,4 @@ -%%~ 88706ddc78b1b:e7ded148d6e4a:7031beac91f75:Chapter Two +%%~ 88706ddc78b1b:e7ded148d6e4a:7031beac91f75:NOVEL:CHAPTER:Chapter Two ## Where has John Gone? @pov: Jane diff --git a/sample/content/96b68994dfa3d.nwd b/sample/content/96b68994dfa3d.nwd index 29818dc1..6ab833fd 100644 --- a/sample/content/96b68994dfa3d.nwd +++ b/sample/content/96b68994dfa3d.nwd @@ -1,4 +1,4 @@ -%%~ 96b68994dfa3d:e7ded148d6e4a:7031beac91f75:A Note on Structure +%%~ 96b68994dfa3d:e7ded148d6e4a:7031beac91f75:NOVEL:NOTE:A Note on Structure # A Note on Structure This file is just a note. You can save notes anywhere you like in the project tree. Notes can be filtered out when you export the project. diff --git a/sample/content/974e400180a99.nwd b/sample/content/974e400180a99.nwd index 303d5232..07ca7817 100644 --- a/sample/content/974e400180a99.nwd +++ b/sample/content/974e400180a99.nwd @@ -1,4 +1,4 @@ -%%~ 974e400180a99:7031beac91f75:Page +%%~ 974e400180a99:7031beac91f75:NOVEL:PAGE:Page This is a plain page with some text on it. This file should receive no special formatting, but the text will always be left aligned and the content will always start on a fresh page when the project is exported. diff --git a/sample/content/ae7339df26ded.nwd b/sample/content/ae7339df26ded.nwd index 05ed60d5..ea4bb9ce 100644 --- a/sample/content/ae7339df26ded.nwd +++ b/sample/content/ae7339df26ded.nwd @@ -1,4 +1,4 @@ -%%~ ae7339df26ded:e7ded148d6e4a:7031beac91f75:We Found John! +%%~ ae7339df26ded:e7ded148d6e4a:7031beac91f75:NOVEL:SCENE:We Found John! ### We Found John! @pov: John diff --git a/sample/content/b3e74dbc1f584.nwd b/sample/content/b3e74dbc1f584.nwd index 3f81b275..a7a8ba8a 100644 --- a/sample/content/b3e74dbc1f584.nwd +++ b/sample/content/b3e74dbc1f584.nwd @@ -1,4 +1,4 @@ -%%~ b3e74dbc1f584:15c4492bd5107:Earth +%%~ b3e74dbc1f584:15c4492bd5107:WORLD:NOTE:Earth # Earth @tag: Earth diff --git a/sample/content/b8136a5a774a0.nwd b/sample/content/b8136a5a774a0.nwd index 4e63373d..8c6ddb77 100644 --- a/sample/content/b8136a5a774a0.nwd +++ b/sample/content/b8136a5a774a0.nwd @@ -1,4 +1,4 @@ -%%~ b8136a5a774a0:98acd8c76c93a:Delete Me! +%%~ b8136a5a774a0:98acd8c76c93a:NOVEL:SCENE:Delete Me! ### Delete Me! This scene is trash. \ No newline at end of file diff --git a/sample/content/ba8a28a246524.nwd b/sample/content/ba8a28a246524.nwd index b30cb63b..8cc5ae6c 100644 --- a/sample/content/ba8a28a246524.nwd +++ b/sample/content/ba8a28a246524.nwd @@ -1,4 +1,4 @@ -%%~ ba8a28a246524:e7ded148d6e4a:7031beac91f75:Interlude +%%~ ba8a28a246524:e7ded148d6e4a:7031beac91f75:NOVEL:UNNUMBERED:Interlude ## Interlude % Notice that this is a file with the flag ‘N.Un’. The ‘N’ means it’s a novel file, and the ‘Un’ means it’s an unnumbered chapter. Unnumbered chapters can be treated separately from numbered chapters during export. Perfect for when you want to add an interlude, or for a prologue or epilogue. diff --git a/sample/content/bb2c23b3c42cc.nwd b/sample/content/bb2c23b3c42cc.nwd index 869118d7..126f549b 100644 --- a/sample/content/bb2c23b3c42cc.nwd +++ b/sample/content/bb2c23b3c42cc.nwd @@ -1,4 +1,4 @@ -%%~ bb2c23b3c42cc:f7e2d9f330615:f6622b4617424:Jane Smith +%%~ bb2c23b3c42cc:f7e2d9f330615:f6622b4617424:CHARACTER:NOTE:Jane Smith # Jane Smith @tag: Jane diff --git a/sample/content/bc0cbd2a407f3.nwd b/sample/content/bc0cbd2a407f3.nwd index 1fe75e50..94b036c0 100644 --- a/sample/content/bc0cbd2a407f3.nwd +++ b/sample/content/bc0cbd2a407f3.nwd @@ -1,4 +1,4 @@ -%%~ bc0cbd2a407f3:e7ded148d6e4a:7031beac91f75:Another Scene +%%~ bc0cbd2a407f3:e7ded148d6e4a:7031beac91f75:NOVEL:SCENE:Another Scene ### Another Scene @pov: John diff --git a/sample/content/edca4be2fcaf8.nwd b/sample/content/edca4be2fcaf8.nwd index 679e4e27..0200ab75 100644 --- a/sample/content/edca4be2fcaf8.nwd +++ b/sample/content/edca4be2fcaf8.nwd @@ -1,4 +1,4 @@ -%%~ edca4be2fcaf8:7031beac91f75:Part 1 +%%~ edca4be2fcaf8:7031beac91f75:NOVEL:PARTITION:Part One # Part One The first part. \ No newline at end of file diff --git a/sample/content/f1471bef9f2ae.nwd b/sample/content/f1471bef9f2ae.nwd index 9b2d9368..32db9cb0 100644 --- a/sample/content/f1471bef9f2ae.nwd +++ b/sample/content/f1471bef9f2ae.nwd @@ -1,4 +1,4 @@ -%%~ f1471bef9f2ae:15c4492bd5107:Space +%%~ f1471bef9f2ae:15c4492bd5107:WORLD:NOTE:Space # Space @tag: Space diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 88ce6d2f..cee9b2fa 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,21 +1,21 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 273 - 40 - 4125 + 280 + 41 + 4312 False True True - 636b6aa9b697b + bc0cbd2a407f3 b3e74dbc1f584 - 914 + 920 B E @@ -117,7 +117,7 @@ 1199 216 7 - 1266 + 950 Another Scene @@ -274,9 +274,9 @@ New True SCENE - 0 - 0 - 0 + 30 + 6 + 1 36 diff --git a/tests/reference/gui/1_0e17daca5f3e1.nwd b/tests/reference/gui/1_0e17daca5f3e1.nwd index 0d9e8ec4..ecfbf8ff 100644 --- a/tests/reference/gui/1_0e17daca5f3e1.nwd +++ b/tests/reference/gui/1_0e17daca5f3e1.nwd @@ -1,4 +1,4 @@ -%%~ 0e17daca5f3e1:71ee45a3c0db9:New File +%%~ 0e17daca5f3e1:71ee45a3c0db9:PLOT:NOTE:New File # Main Plot @tag: MainPlot diff --git a/tests/reference/gui/1_1a6562590ef19.nwd b/tests/reference/gui/1_1a6562590ef19.nwd index def80bfd..7c6d19a7 100644 --- a/tests/reference/gui/1_1a6562590ef19.nwd +++ b/tests/reference/gui/1_1a6562590ef19.nwd @@ -1,4 +1,4 @@ -%%~ 1a6562590ef19:811786ad1ae74:New File +%%~ 1a6562590ef19:811786ad1ae74:WORLD:NOTE:New File # Main Location @tag: Home diff --git a/tests/reference/gui/1_31489056e0916.nwd b/tests/reference/gui/1_31489056e0916.nwd index fba0c438..0a238e45 100644 --- a/tests/reference/gui/1_31489056e0916.nwd +++ b/tests/reference/gui/1_31489056e0916.nwd @@ -1,4 +1,4 @@ -%%~ 31489056e0916:25fc0e7096fc6:73475cb40a568:New Scene +%%~ 31489056e0916:25fc0e7096fc6:73475cb40a568:NOVEL:SCENE:New Scene # Novel ## Chapter diff --git a/tests/reference/gui/1_98010bd9270f9.nwd b/tests/reference/gui/1_98010bd9270f9.nwd index 3b0477ca..632f53cd 100644 --- a/tests/reference/gui/1_98010bd9270f9.nwd +++ b/tests/reference/gui/1_98010bd9270f9.nwd @@ -1,4 +1,4 @@ -%%~ 98010bd9270f9:44cb730c42048:New File +%%~ 98010bd9270f9:44cb730c42048:CHARACTER:NOTE:New File # Jane Doe @tag: Jane diff --git a/tests/reference/gui/4_73475cb40a568.nwd b/tests/reference/gui/4_73475cb40a568.nwd index cb8cf6ba..5d18b581 100644 --- a/tests/reference/gui/4_73475cb40a568.nwd +++ b/tests/reference/gui/4_73475cb40a568.nwd @@ -1,4 +1,4 @@ -%%~ 73475cb40a568:b3643d0f92e32:Chapter One +%%~ 73475cb40a568:b3643d0f92e32:NOVEL:SCENE:Chapter One ## Chapter One @pov: Bod diff --git a/tests/reference/gui/5_031b4af5197ec.nwd b/tests/reference/gui/5_031b4af5197ec.nwd index 8ef13aab..bc9d9f7d 100644 --- a/tests/reference/gui/5_031b4af5197ec.nwd +++ b/tests/reference/gui/5_031b4af5197ec.nwd @@ -1,4 +1,4 @@ -%%~ 031b4af5197ec:0e17daca5f3e1:b3643d0f92e32:Scene One +%%~ 031b4af5197ec:0e17daca5f3e1:b3643d0f92e32:NOVEL:SCENE:Scene One ### Scene One @pov: Bod diff --git a/tests/reference/gui/5_25fc0e7096fc6.nwd b/tests/reference/gui/5_25fc0e7096fc6.nwd index eb32f417..d84c563a 100644 --- a/tests/reference/gui/5_25fc0e7096fc6.nwd +++ b/tests/reference/gui/5_25fc0e7096fc6.nwd @@ -1,4 +1,4 @@ -%%~ 25fc0e7096fc6:811786ad1ae74:b3643d0f92e32:Chapter One +%%~ 25fc0e7096fc6:811786ad1ae74:b3643d0f92e32:NOVEL:CHAPTER:Chapter One ## Chapter One @pov: Bod diff --git a/tests/reference/gui/5_2858dcd1057d3.nwd b/tests/reference/gui/5_2858dcd1057d3.nwd index 3c3297f0..198fd30a 100644 --- a/tests/reference/gui/5_2858dcd1057d3.nwd +++ b/tests/reference/gui/5_2858dcd1057d3.nwd @@ -1,4 +1,4 @@ -%%~ 2858dcd1057d3:0e17daca5f3e1:b3643d0f92e32:Scene Two +%%~ 2858dcd1057d3:0e17daca5f3e1:b3643d0f92e32:NOVEL:SCENE:Scene Two ### Scene Two @pov: Bod diff --git a/tests/reference/gui/5_2fca346db6561.nwd b/tests/reference/gui/5_2fca346db6561.nwd index 538fa126..93d611ff 100644 --- a/tests/reference/gui/5_2fca346db6561.nwd +++ b/tests/reference/gui/5_2fca346db6561.nwd @@ -1,4 +1,4 @@ -%%~ 2fca346db6561:0e17daca5f3e1:b3643d0f92e32:Scene Two, Section Two +%%~ 2fca346db6561:0e17daca5f3e1:b3643d0f92e32:NOVEL:SCENE:Scene Two, Section Two #### Scene Two, Section Two Suspendisse potenti. Fusce tempus lorem nec laoreet suscipit. Fusce vulputate nisl ac diam tincidunt, nec malesuada quam pellentesque. Maecenas congue, tellus quis commodo rutrum, magna leo egestas arcu, quis suscipit ex risus id ligula. Suspendisse potenti. Morbi blandit lacus vitae laoreet vulputate. Donec vitae tellus eleifend, lobortis eros eu, tincidunt enim. Nullam et ullamcorper nisi. Vivamus tellus ex, lobortis quis rutrum ut, dapibus sit amet turpis. Phasellus pellentesque metus diam, commodo tristique ante commodo ac. Ut mollis ipsum nec diam blandit sollicitudin. Duis bibendum lacus nec commodo dapibus. Sed condimentum luctus ante, id ultricies urna varius nec. Nam convallis magna nec bibendum ultrices. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed auctor pharetra quam, vitae porta ex bibendum eu. diff --git a/tests/reference/gui/5_31489056e0916.nwd b/tests/reference/gui/5_31489056e0916.nwd index 53799705..7c26cdb5 100644 --- a/tests/reference/gui/5_31489056e0916.nwd +++ b/tests/reference/gui/5_31489056e0916.nwd @@ -1,4 +1,4 @@ -%%~ 31489056e0916:811786ad1ae74:b3643d0f92e32:Scene One +%%~ 31489056e0916:811786ad1ae74:b3643d0f92e32:NOVEL:SCENE:Scene One ### Scene One @pov: Bod diff --git a/tests/reference/gui/5_41cfc0d1f2d12.nwd b/tests/reference/gui/5_41cfc0d1f2d12.nwd index 1860ad52..a39fc1c1 100644 --- a/tests/reference/gui/5_41cfc0d1f2d12.nwd +++ b/tests/reference/gui/5_41cfc0d1f2d12.nwd @@ -1,4 +1,4 @@ -%%~ 41cfc0d1f2d12:0e17daca5f3e1:b3643d0f92e32:Scene One, Section Two +%%~ 41cfc0d1f2d12:0e17daca5f3e1:b3643d0f92e32:NOVEL:SCENE:Scene One, Section Two #### Scene One, Section Two Integer vel libero ipsum. Donec varius aliquam libero, sit amet commodo urna hendrerit non. Nullam quis erat mollis nunc viverra volutpat tincidunt in odio. Nam vitae quam sem. Aliquam suscipit nulla non lorem pharetra semper. Ut suscipit erat eu ligula accumsan ultrices. Phasellus nisl tellus, placerat sed laoreet id, consectetur nec dolor. Sed fringilla ipsum id dapibus posuere. Aenean finibus pharetra tincidunt. Ut molestie malesuada nulla, id posuere lorem tincidunt eu. Aliquam tempor eros a est vulputate, scelerisque pulvinar ipsum fermentum. In hac habitasse platea dictumst. diff --git a/tests/reference/gui/5_98010bd9270f9.nwd b/tests/reference/gui/5_98010bd9270f9.nwd index 116a3fb3..4afe14ea 100644 --- a/tests/reference/gui/5_98010bd9270f9.nwd +++ b/tests/reference/gui/5_98010bd9270f9.nwd @@ -1,4 +1,4 @@ -%%~ 98010bd9270f9:811786ad1ae74:b3643d0f92e32:Scene Two +%%~ 98010bd9270f9:811786ad1ae74:b3643d0f92e32:NOVEL:SCENE:Scene Two ### Scene Two @pov: Bod