diff --git a/docs/source/usage_projectformat.rst b/docs/source/usage_projectformat.rst index ea0b55b52..6a7c4c8ba 100644 --- a/docs/source/usage_projectformat.rst +++ b/docs/source/usage_projectformat.rst @@ -11,13 +11,32 @@ changes require minor actions from the user. The key changes in the formats are listed below, as well as the user actions required where applicable. +.. caution:: + + When you update a project from one format version to the next, the project can no longer be + opened by a version of novelWriter prior to the version where the new file format was + introduced. You will get a notification about any updates to your project file format and will + have the option to decline the upgrade. + + +.. _a_prjfmt_1_4: + +Format 1.4 Changes +================== + +This project format was introduced in novelWriter version 1.7. + +This format changes the way project items (folders, documents and notes) are stored. It is a more +compact format that is simpler and faster to parse, and easier to extend. The conversion is done +automatically the first time a project is loaded. No user action is required. + .. _a_prjfmt_1_3: Format 1.3 Changes ================== -This project format vas introduces in novelWriter version 1.5. +This project format was introduced in novelWriter version 1.5. With this format, the number of document layouts was reduced from 8 to 2. The conversion of document layouts is performed automatically when the project is opened. @@ -55,7 +74,7 @@ should be used only a few places in any given project. These are as follows: Format 1.2 Changes ================== -This project format was introduces in novelWriter version 0.10. +This project format was introduced in novelWriter version 0.10. With this format, the way auto-replace entries were stored in the main project XML file changed. Opening an old project automatically converts the storage format up to and including version 1.1.1. @@ -69,7 +88,7 @@ auto-replace is not being used, can still be opened in novelWriter as of version Format 1.1 Changes ================== -This project format was introduces in novelWriter version 0.7. +This project format was introduced in novelWriter version 0.7. With this format, the ``content`` folder was introduced in the project storage. Previously, all novelWriter documents were saved in a series of folders numbered from ``data_0`` to ``data_f``. diff --git a/novelwriter/__init__.py b/novelwriter/__init__.py index 98247c68f..740ed327d 100644 --- a/novelwriter/__init__.py +++ b/novelwriter/__init__.py @@ -60,8 +60,8 @@ __author__ = "Veronica Berglyd Olsen" __maintainer__ = "Veronica Berglyd Olsen" __email__ = "code@vkbo.net" -__version__ = "1.6" -__hexversion__ = "0x010600f0" +__version__ = "1.7-alpha0" +__hexversion__ = "0x010700a0" __date__ = "2022-02-20" __status__ = "Stable" __domain__ = "novelwriter.io" diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index 8c7b2ef44..07db4a411 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -139,24 +139,32 @@ def cursorPos(self): def packXML(self, xParent): """Pack all the data in the class instance into an XML object. """ - xPack = etree.SubElement(xParent, "item", attrib={ - "handle": str(self._handle), - "order": str(self._order), - "parent": str(self._parent), - }) - self._subPack(xPack, "name", text=str(self._name)) - self._subPack(xPack, "type", text=str(self._type.name)) - self._subPack(xPack, "class", text=str(self._class.name)) - self._subPack(xPack, "status", text=str(self._status)) + itemAttrib = {} + itemAttrib["handle"] = str(self._handle) + itemAttrib["parent"] = str(self._parent) + itemAttrib["order"] = str(self._order) + itemAttrib["type"] = str(self._type.name) + itemAttrib["class"] = str(self._class.name) if self._type == nwItemType.FILE: - self._subPack(xPack, "exported", text=str(self._exported)) - self._subPack(xPack, "layout", text=str(self._layout.name)) - self._subPack(xPack, "charCount", text=str(self._charCount), none=False) - self._subPack(xPack, "wordCount", text=str(self._wordCount), none=False) - self._subPack(xPack, "paraCount", text=str(self._paraCount), none=False) - self._subPack(xPack, "cursorPos", text=str(self._cursorPos), none=False) + itemAttrib["layout"] = str(self._layout.name) + + metaAttrib = {} + if self._type == nwItemType.FILE: + metaAttrib["charCount"] = str(self._charCount) + metaAttrib["wordCount"] = str(self._wordCount) + metaAttrib["paraCount"] = str(self._paraCount) + metaAttrib["cursorPos"] = str(self._cursorPos) else: - self._subPack(xPack, "expanded", text=str(self._expanded)) + metaAttrib["expanded"] = str(self._expanded) + + nameAttrib = {} + nameAttrib["status"] = str(self._status) + if self._type == nwItemType.FILE: + nameAttrib["exported"] = str(self._exported) + + xPack = etree.SubElement(xParent, "item", attrib=itemAttrib) + self._subPack(xPack, "meta", attrib=metaAttrib) + self._subPack(xPack, "name", text=str(self._name), attrib=nameAttrib) return @@ -175,19 +183,31 @@ def unpackXML(self, xItem): self.setParent(xItem.attrib.get("parent", None)) self.setOrder(xItem.attrib.get("order", 0)) + self.setType(xItem.attrib.get("type", None)) + self.setClass(xItem.attrib.get("class", None)) + self.setLayout(xItem.attrib.get("layout", None)) - tmpStatus = "" for xValue in xItem: - if xValue.tag == "name": + if xValue.tag == "meta": + self.setExpanded(xValue.attrib.get("expanded", False)) + self.setCharCount(xValue.attrib.get("charCount", 0)) + self.setWordCount(xValue.attrib.get("wordCount", 0)) + self.setParaCount(xValue.attrib.get("paraCount", 0)) + self.setCursorPos(xValue.attrib.get("cursorPos", 0)) + elif xValue.tag == "name": self.setName(xValue.text) + self.setStatus(xValue.attrib.get("status", None)) + self.setExported(xValue.attrib.get("exported", True)) + + # Legacy Format (1.3 and earlier) + elif xValue.tag == "status": + self.setStatus(xValue.text) elif xValue.tag == "type": self.setType(xValue.text) elif xValue.tag == "class": self.setClass(xValue.text) elif xValue.tag == "layout": self.setLayout(xValue.text) - elif xValue.tag == "status": - tmpStatus = xValue.text elif xValue.tag == "expanded": self.setExpanded(xValue.text) elif xValue.tag == "exported": @@ -206,9 +226,6 @@ def unpackXML(self, xItem): # version of novelWriter that doesn't know the tag logger.error("Unknown tag '%s'", xValue.tag) - # Guarantees that is parsed after - self.setStatus(tmpStatus) - return True @staticmethod diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 26d2c0985..556f6e183 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -53,7 +53,7 @@ class NWProject(): - FILE_VERSION = "1.3" + FILE_VERSION = "1.4" def __init__(self, theParent): @@ -479,8 +479,11 @@ def openProject(self, fileName, overrideLock=False): # 1.3 : Reduces the number of layouts to only two. One for novel # documents and one for project notes. Introduced in # version 1.5. + # 1.4 : Introduces a more compact format for storing items. All + # settings aside from name are now attributes. Introduced + # in version 1.7. - if fileVersion not in ("1.0", "1.1", "1.2", "1.3"): + if fileVersion not in ("1.0", "1.1", "1.2", "1.3", "1.4"): self.theParent.makeAlert(self.tr( "Unknown or unsupported novelWriter project file format. " "The project cannot be opened by this version of novelWriter. " diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 9e37d34ab..bf40e1eeb 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1299 + 1303 199 - 64923 + 64457 False @@ -49,265 +49,105 @@ - - Novel - ROOT - NOVEL - Started - True + + + Novel - - Title Page - FILE - NOVEL - Started - True - DOCUMENT - 93 - 19 - 2 - 2 + + + Title Page - - Page - FILE - NOVEL - New - True - DOCUMENT - 186 - 39 - 2 - 212 + + + Page - - Part One - FILE - NOVEL - New - True - DOCUMENT - 26 - 6 - 1 - 33 + + + Part One - - A Folder - FOLDER - NOVEL - 1st Draft - True + + + A Folder - - Chapter One - FILE - NOVEL - Notes - True - DOCUMENT - 75 - 14 - 1 - 279 + + + Chapter One - - Making a Scene - FILE - NOVEL - 1st Draft - True - DOCUMENT - 2429 - 432 - 14 - 219 + + + Making a Scene - - Another Scene - FILE - NOVEL - 1st Draft - True - DOCUMENT - 476 - 93 - 3 - 577 + + + Another Scene - - Interlude - FILE - NOVEL - New - True - DOCUMENT - 617 - 101 - 3 - 4 + + + Interlude - - A Note on Structure - FILE - NOVEL - 2nd Draft - False - NOTE - 1692 - 313 - 6 - 1110 + + + A Note on Structure - - Chapter Two - FILE - NOVEL - 1st Draft - True - DOCUMENT - 139 - 28 - 1 - 343 + + + Chapter Two - - We Found John! - FILE - NOVEL - 1st Draft - True - DOCUMENT - 189 - 37 - 1 - 224 + + + We Found John! - - Characters - ROOT - CHARACTER - None - True + + + Characters - - Main Characters - FOLDER - CHARACTER - None - True + + + Main Characters - - John Smith - FILE - CHARACTER - Minor - True - NOTE - 49 - 9 - 1 - 24 + + + John Smith - - Jane Smith - FILE - CHARACTER - Major - True - NOTE - 55 - 9 - 1 - 25 + + + Jane Smith - - Locations - ROOT - WORLD - None - True + + + Locations - - Earth - FILE - WORLD - Main - True - NOTE - 76 - 15 - 1 - 20 + + + Earth - - Space - FILE - WORLD - Minor - True - NOTE - 115 - 24 - 1 - 133 + + + Space - - Mars - FILE - WORLD - Major - True - NOTE - 28 - 6 - 1 - 45 + + + Mars - - Archive - ROOT - ARCHIVE - New - True + + + Archive - - Scenes - FOLDER - ARCHIVE - New - True + + + Scenes - - Old File - FILE - NOVEL - 1st Draft - True - DOCUMENT - 315 - 55 - 1 - 322 + + + Old File - - Trash - TRASH - TRASH - None - True + + + Trash - - Delete Me! - FILE - NOVEL - New - True - DOCUMENT - 30 - 6 - 1 - 36 + + + Delete Me! diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index 02803bbde..c6eab805b 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -1,12 +1,12 @@ - + Lorem Ipsum Lorem Ipsum lipsum.com - 17 + 21 24 - 1777 + 1847 False @@ -44,227 +44,89 @@ - - Novel - ROOT - NOVEL - New - True + + + Novel - - Lorem Ipsum - FILE - NOVEL - Finished - True - DOCUMENT - 230 - 40 - 3 - 148 + + + Lorem Ipsum - - Front Matter - FILE - NOVEL - Finished - True - DOCUMENT - 1058 - 176 - 2 - 43 + + + Front Matter - - Prologue - FILE - NOVEL - Draft - True - DOCUMENT - 584 - 92 - 1 - 4 + + + Prologue - - Act One - FILE - NOVEL - New - True - DOCUMENT - 35 - 6 - 1 - 42 + + + Act One - - Chapter One - FOLDER - NOVEL - Draft - True + + + Chapter One - - Chapter One - FILE - NOVEL - Draft - True - DOCUMENT - 419 - 67 - 1 - 56 + + + Chapter One - - Scene One - FILE - NOVEL - Finished - True - DOCUMENT - 2758 - 404 - 4 - 1528 + + + Scene One - - Scene Two - FILE - NOVEL - Finished - True - DOCUMENT - 4043 - 600 - 6 - 2335 + + + Scene Two - - Interlude - FILE - NOVEL - New - False - DOCUMENT - 631 - 109 - 3 - 376 + + + Interlude - - Chapter Two - FOLDER - NOVEL - Draft - True + + + Chapter Two - - Chapter Two - FILE - NOVEL - Draft - True - DOCUMENT - 477 - 70 - 1 - 56 + + + Chapter Two - - Scene Three - FILE - NOVEL - Finished - True - DOCUMENT - 3006 - 439 - 4 - 57 + + + Scene Three - - Scene Four - FILE - NOVEL - Finished - True - DOCUMENT - 3839 - 563 - 6 - 56 + + + Scene Four - - Scene Five - FILE - NOVEL - Finished - True - DOCUMENT - 3644 - 543 - 5 - 351 + + + Scene Five - - Characters - ROOT - CHARACTER - New - True + + + Characters - - Mr. Nobody - FILE - CHARACTER - Major - True - NOTE - 1864 - 284 - 3 - 1883 + + + Mr. Nobody - - Plot - ROOT - PLOT - New - True + + + Plot - - Main - FILE - PLOT - Main - True - NOTE - 1369 - 195 - 2 - 1387 + + + Main - - World - ROOT - WORLD - New - True + + + World - - Ancient Europe - FILE - WORLD - Minor - True - NOTE - 1770 - 259 - 3 - 1792 + + + Ancient Europe diff --git a/tests/minimal/nwProject.nwx b/tests/minimal/nwProject.nwx index c1f2a901d..991d8b681 100644 --- a/tests/minimal/nwProject.nwx +++ b/tests/minimal/nwProject.nwx @@ -1,13 +1,13 @@ - + Test Minimal Minimal Jane Doe John Doh - 9 + 12 2 - 113 + 129 True @@ -42,76 +42,37 @@ - - Novel - ROOT - NOVEL - New - True + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 28 - 6 - 1 - 33 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - True + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 16 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 9 - 2 - 0 - 15 + + + New Scene - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World diff --git a/tests/reference/coreProject_NewCustomA_nwProject.nwx b/tests/reference/coreProject_NewCustomA_nwProject.nwx index 3ba6a538d..4b8a67bf2 100644 --- a/tests/reference/coreProject_NewCustomA_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomA_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -42,231 +42,97 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - Locations - ROOT - WORLD - New - False + + + Locations - - Timeline - ROOT - TIMELINE - New - False + + + Timeline - - Objects - ROOT - OBJECT - New - False + + + Objects - - Entities - ROOT - ENTITY - New - False + + + Entities - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Title Page - - Chapter 1 - FOLDER - NOVEL - New - False + + + Chapter 1 - - Chapter 1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Chapter 1 - - Scene 1.1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 1.1 - - Scene 1.2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 1.2 - - Scene 1.3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 1.3 - - Chapter 2 - FOLDER - NOVEL - New - False + + + Chapter 2 - - Chapter 2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Chapter 2 - - Scene 2.1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 2.1 - - Scene 2.2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 2.2 - - Scene 2.3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 2.3 - - Chapter 3 - FOLDER - NOVEL - New - False + + + Chapter 3 - - Chapter 3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Chapter 3 - - Scene 3.1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 3.1 - - Scene 3.2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 3.2 - - Scene 3.3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 3.3 diff --git a/tests/reference/coreProject_NewCustomB_nwProject.nwx b/tests/reference/coreProject_NewCustomB_nwProject.nwx index 2afad85af..3f55663e1 100644 --- a/tests/reference/coreProject_NewCustomB_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomB_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -42,138 +42,61 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - Locations - ROOT - WORLD - New - False + + + Locations - - Timeline - ROOT - TIMELINE - New - False + + + Timeline - - Objects - ROOT - OBJECT - New - False + + + Objects - - Entities - ROOT - ENTITY - New - False + + + Entities - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Title Page - - Scene 1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 1 - - Scene 2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 2 - - Scene 3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 3 - - Scene 4 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 4 - - Scene 5 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 5 - - Scene 6 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 6 diff --git a/tests/reference/coreProject_NewFile_nwProject.nwx b/tests/reference/coreProject_NewFile_nwProject.nwx index 88c9aafbb..d623ee2d3 100644 --- a/tests/reference/coreProject_NewFile_nwProject.nwx +++ b/tests/reference/coreProject_NewFile_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -40,100 +40,45 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Scene - - Hello - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Hello - - Jane - FILE - CHARACTER - New - True - NOTE - 0 - 0 - 0 - 0 + + + Jane diff --git a/tests/reference/coreProject_NewMinimal_nwProject.nwx b/tests/reference/coreProject_NewMinimal_nwProject.nwx index d3702a07b..6becb112d 100644 --- a/tests/reference/coreProject_NewMinimal_nwProject.nwx +++ b/tests/reference/coreProject_NewMinimal_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -40,76 +40,37 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Scene diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx index 58344c12a..cf55336eb 100644 --- a/tests/reference/coreProject_NewRoot_nwProject.nwx +++ b/tests/reference/coreProject_NewRoot_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -40,104 +40,53 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Scene - - Timeline - ROOT - TIMELINE - New - False + + + Timeline - - Object - ROOT - OBJECT - New - False + + + Object - - Custom1 - ROOT - CUSTOM - New - False + + + Custom1 - - Custom2 - ROOT - CUSTOM - New - False + + + Custom2 diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index 1111c579d..4dd43b9ad 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,11 +1,11 @@ - + New Project 5 2 - 4 + 3 True @@ -40,119 +40,53 @@ - - Novel - ROOT - NOVEL - New - True + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - True + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 612 - 95 - 10 - 768 + + + New Scene - - Plot - ROOT - PLOT - New - True + + + Plot - - New File - FILE - PLOT - New - True - NOTE - 48 - 10 - 1 - 69 + + + New File - - Characters - ROOT - CHARACTER - New - True + + + Characters - - New File - FILE - CHARACTER - New - True - NOTE - 34 - 8 - 1 - 51 + + + New File - - World - ROOT - WORLD - New - True + + + World - - New File - FILE - WORLD - New - True - NOTE - 51 - 9 - 1 - 68 + + + New File - - Trash - TRASH - TRASH - None - True + + + Trash diff --git a/tests/reference/guiEditor_Main_Initial_nwProject.nwx b/tests/reference/guiEditor_Main_Initial_nwProject.nwx index 7d2cfe5ff..f1b177402 100644 --- a/tests/reference/guiEditor_Main_Initial_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Initial_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -40,76 +40,37 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 9 - 2 - 0 - 0 + + + New Scene - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World diff --git a/tests/reference/guiProjSettings_Dialog_nwProject.nwx b/tests/reference/guiProjSettings_Dialog_nwProject.nwx index 96334e168..b88e7f176 100644 --- a/tests/reference/guiProjSettings_Dialog_nwProject.nwx +++ b/tests/reference/guiProjSettings_Dialog_nwProject.nwx @@ -1,5 +1,5 @@ - + Project Name Project Title @@ -46,76 +46,37 @@ - - Novel - ROOT - NOVEL - New - False + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 9 - 2 - 0 - 0 + + + New Scene - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py index dea2b3c7c..368592f1f 100644 --- a/tests/test_core/test_core_item.py +++ b/tests/test_core/test_core_item.py @@ -306,22 +306,6 @@ def testCoreItem_LayoutSetter(mockGUI): theItem.setLayout("NOTE") assert theItem.itemLayout == nwItemLayout.NOTE - # Deprecated Layouts - theItem.setLayout("TITLE") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("PAGE") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("BOOK") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("PARTITION") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("UNNUMBERED") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("CHAPTER") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("SCENE") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - # Alternatives theItem.setLayout(nwItemLayout.NOTE) assert theItem.itemLayout == nwItemLayout.NOTE @@ -358,12 +342,9 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): xContent = etree.SubElement(nwXML, "content") theItem.packXML(xContent) assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( - b"" - b"" - b"A NameFILENOVELNew" - b"FalseNOTE7" - b"5311" - b"" + b'A Name' ) # Unpack @@ -404,11 +385,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): xContent = etree.SubElement(nwXML, "content") theItem.packXML(xContent) assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( - b"" - b"" - b"A NameFOLDERNOVELNew" - b"True" - b"" + b'A Name' ) # Unpack @@ -462,3 +440,107 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): ) # END Test testCoreItem_XMLPackUnpack + + +@pytest.mark.core +def testCoreItem_ConvertFromFmt12(mockGUI): + """Test the setter for all the nwItemLayout values for the NWItem + class using the class names that were present in file format 1.2. + """ + theProject = NWProject(mockGUI) + theItem = NWItem(theProject) + + # Deprecated Layouts + theItem.setLayout("TITLE") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("PAGE") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("BOOK") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("PARTITION") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("UNNUMBERED") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("CHAPTER") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("SCENE") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("MUMBOJUMBO") + assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + +# END Test testCoreItem_ConvertFromFmt12 + + +@pytest.mark.core +def testCoreItem_ConvertFromFmt13(mockGUI): + """Test packing and unpacking XML objects for the NWItem class from + format version 1.3 + """ + theProject = NWProject(mockGUI) + + # Make Version 1.3 XML + nwXML = etree.Element("novelWriterXML") + xContent = etree.SubElement(nwXML, "content") + + # Folder + xPack = etree.SubElement(xContent, "item", attrib={ + "handle": "a000000000001", + "order": "1", + "parent": "b000000000001", + }) + NWItem._subPack(xPack, "name", text="Folder") + NWItem._subPack(xPack, "type", text="FOLDER") + NWItem._subPack(xPack, "class", text="NOVEL") + NWItem._subPack(xPack, "status", text="New") + NWItem._subPack(xPack, "expanded", text="True") + + # Unpack Folder + theItem = NWItem(theProject) + theItem.unpackXML(xContent[0]) + assert theItem.itemHandle == "a000000000001" + assert theItem.itemParent == "b000000000001" + assert theItem.itemOrder == 1 + assert theItem.isExpanded is True + assert theItem.isExported is True + assert theItem.charCount == 0 + assert theItem.wordCount == 0 + assert theItem.paraCount == 0 + assert theItem.cursorPos == 0 + assert theItem.itemClass == nwItemClass.NOVEL + assert theItem.itemType == nwItemType.FOLDER + assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + + # File + xPack = etree.SubElement(xContent, "item", attrib={ + "handle": "c000000000001", + "order": "2", + "parent": "a000000000001", + }) + NWItem._subPack(xPack, "name", text="Scene") + NWItem._subPack(xPack, "type", text="FILE") + NWItem._subPack(xPack, "class", text="NOVEL") + NWItem._subPack(xPack, "status", text="New") + NWItem._subPack(xPack, "exported", text="True") + NWItem._subPack(xPack, "layout", text="DOCUMENT") + NWItem._subPack(xPack, "charCount", text="600") + NWItem._subPack(xPack, "wordCount", text="100") + NWItem._subPack(xPack, "paraCount", text="6") + NWItem._subPack(xPack, "cursorPos", text="50") + + # Unpack File + theItem = NWItem(theProject) + theItem.unpackXML(xContent[1]) + assert theItem.itemHandle == "c000000000001" + assert theItem.itemParent == "a000000000001" + assert theItem.itemOrder == 2 + assert theItem.isExpanded is False + assert theItem.isExported is True + assert theItem.charCount == 600 + assert theItem.wordCount == 100 + assert theItem.paraCount == 6 + assert theItem.cursorPos == 50 + assert theItem.itemClass == nwItemClass.NOVEL + assert theItem.itemType == nwItemType.FILE + assert theItem.itemLayout == nwItemLayout.DOCUMENT + +# END Test testCoreItem_ConvertFromFmt13 diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index dc49c41ab..e0e82f395 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -385,36 +385,29 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems): nwXML = etree.Element("novelWriterXML") theTree.packXML(nwXML) assert etree.tostring(nwXML, pretty_print=False, encoding="utf-8") == ( - b"" - b"" - b"" - b"NovelROOTNOVELNone" - b"True" - b"" - b"Act OneFOLDERNOVELNone" - b"True" - b"" - b"Chapter OneFILENOVELNone" - b"TrueDOCUMENT300" - b"5020" - b"" - b"Scene OneFILENOVELNone" - b"TrueDOCUMENT3000" - b"500200" - b"" - b"OuttakesROOTARCHIVENone" - b"False" - b"" - b"TrashTRASHTRASHNone" - b"False" - b"" - b"CharactersROOTCHARACTERNone" - b"True" - b"" - b"Jane DoeFILECHARACTERNone" - b"TrueNOTE2000" - b"400160" - b"" + b'' + b'' + b'' + b'Novel' + b'Act One' + b'' + b'Chapter One' + b'' + b'Scene One' + b'' + b'Outtakes' + b'' + b'Trash' + b'' + b'Characters' + b'Jane Doe' + b'' + b'' ) theTree.clear()