diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index 45ae9acc..9b8dd47c 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -30,7 +30,7 @@ import logging from time import time -from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout +from novelwriter.enum import nwItemType, nwItemLayout from novelwriter.error import logException from novelwriter.constants import nwFiles, nwKeyWords, nwUnicode from novelwriter.core.document import NWDoc @@ -227,11 +227,8 @@ class NWIndex(): if theItem.itemParent is None: logger.info("Not indexing orphaned item '%s'", tHandle) return False - if theItem.itemClass == nwItemClass.TRASH: - logger.debug("Not indexing trash item '%s'", tHandle) - return False - if theItem.itemClass == nwItemClass.ARCHIVE: - logger.debug("Not indexing archived item '%s'", tHandle) + if theItem.isInactive(): + logger.debug("Not indexing inactive item '%s'", tHandle) return False itemClass = theItem.itemClass diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index 0178c512..f6d93b36 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -35,9 +35,6 @@ from novelwriter.constants import nwLabels, trConst logger = logging.getLogger(__name__) -# Deprecated layout labels -DEP_LAYOUTS = ("TITLE", "PAGE", "BOOK", "PARTITION", "UNNUMBERED", "CHAPTER", "SCENE") - class NWItem(): @@ -365,33 +362,33 @@ class NWItem(): self._name = "" return - def setHandle(self, tHandle): + def setHandle(self, handle): """Set the item handle, and ensure it is valid. """ - if isHandle(tHandle): - self._handle = tHandle + if isHandle(handle): + self._handle = handle else: self._handle = None return - def setParent(self, pHandle): + def setParent(self, handle): """Set the parent handle, and ensure it is valid. """ - if pHandle is None: + if handle is None: self._parent = None - elif isHandle(pHandle): - self._parent = pHandle + elif isHandle(handle): + self._parent = handle else: self._parent = None return - def setRoot(self, rHandle): + def setRoot(self, handle): """Set the root handle, and ensure it is valid. """ - if rHandle is None: + if handle is None: self._root = None - elif isHandle(rHandle): - self._root = rHandle + elif isHandle(handle): + self._root = handle else: self._root = None return @@ -404,59 +401,59 @@ class NWItem(): self._order = checkInt(order, 0) return - def setType(self, itemType): + def setType(self, value): """Set the item type from either a proper nwItemType, or set it from a string representing an nwItemType. """ - if isinstance(itemType, nwItemType): - self._type = itemType - elif isItemType(itemType): - self._type = nwItemType[itemType] + if isinstance(value, nwItemType): + self._type = value + elif isItemType(value): + self._type = nwItemType[value] else: - logger.error("Unrecognised item type '%s'", itemType) + logger.error("Unrecognised item type '%s'", value) self._type = nwItemType.NO_TYPE return - def setClass(self, itemClass): + def setClass(self, value): """Set the item class from either a proper nwItemClass, or set it from a string representing an nwItemClass. """ - if isinstance(itemClass, nwItemClass): - self._class = itemClass - elif isItemClass(itemClass): - self._class = nwItemClass[itemClass] + if isinstance(value, nwItemClass): + self._class = value + elif isItemClass(value): + self._class = nwItemClass[value] else: - logger.error("Unrecognised item class '%s'", itemClass) + logger.error("Unrecognised item class '%s'", value) self._class = nwItemClass.NO_CLASS return - def setLayout(self, itemLayout): + def setLayout(self, value): """Set the item layout from either a proper nwItemLayout, or set it from a string representing an nwItemLayout. """ - if isinstance(itemLayout, nwItemLayout): - self._layout = itemLayout - elif isItemLayout(itemLayout): - self._layout = nwItemLayout[itemLayout] - elif itemLayout in DEP_LAYOUTS: + if isinstance(value, nwItemLayout): + self._layout = value + elif isItemLayout(value): + self._layout = nwItemLayout[value] + elif value in ("TITLE", "PAGE", "BOOK", "PARTITION", "UNNUMBERED", "CHAPTER", "SCENE"): self._layout = nwItemLayout.DOCUMENT else: - logger.error("Unrecognised item layout '%s'", itemLayout) + logger.error("Unrecognised item layout '%s'", value) self._layout = nwItemLayout.NO_LAYOUT return - def setStatus(self, itemStatus): + def setStatus(self, value): """Set the item status by looking it up in the valid status items of the current project. """ - self._status = self.theProject.statusItems.check(itemStatus) + self._status = self.theProject.statusItems.check(value) return - def setImport(self, itemImport): + def setImport(self, value): """Set the item importance by looking it up in the valid import items of the current project. """ - self._import = self.theProject.importItems.check(itemImport) + self._import = self.theProject.importItems.check(value) return def setExpanded(self, state): diff --git a/novelwriter/core/tree.py b/novelwriter/core/tree.py index 2983f88a..29532c7d 100644 --- a/novelwriter/core/tree.py +++ b/novelwriter/core/tree.py @@ -292,13 +292,6 @@ class NWTree(): return True return False - def isTrashRoot(self, tHandle): - """Check if a handle is the trash folder. - """ - if self._trashRoot is None: - return False - return tHandle == self._trashRoot - def trashRoot(self): """Returns the handle of the trash folder, or None if there isn't one. @@ -307,14 +300,6 @@ class NWTree(): return self._trashRoot return None - def archiveRoot(self): - """Returns the handle of the archive folder, or None if there - isn't one. - """ - if self._archRoot: - return self._archRoot - return None - def findRoot(self, theClass): """Find the first root item for a given class. """ diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index cce1c91b..23238b84 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -444,8 +444,7 @@ class GuiProjectTree(QTreeWidget): logger.error("Could not delete item") return False - pHandle = nwItemS.itemParent - if self.theProject.projTree.isTrashRoot(pHandle): + if self.theProject.projTree.isTrash(tHandle): # If the file is in the trash folder already, as the # user if they want to permanently delete the file. doPermanent = False diff --git a/novelwriter/tools/build.py b/novelwriter/tools/build.py index feb1662d..d84a0d4c 100644 --- a/novelwriter/tools/build.py +++ b/novelwriter/tools/build.py @@ -785,10 +785,7 @@ class GuiBuildNovel(QDialog): isNone = theItem.itemType != nwItemType.FILE isNone |= theItem.itemLayout == nwItemLayout.NO_LAYOUT - isNone |= theItem.itemClass == nwItemClass.NO_CLASS - isNone |= theItem.itemClass == nwItemClass.ARCHIVE - isNone |= theItem.itemClass == nwItemClass.TRASH - isNone |= theItem.itemParent == self.theProject.projTree.trashRoot() + isNone |= theItem.isInactive() isNone |= theItem.itemParent is None isNote = theItem.itemLayout == nwItemLayout.NOTE isNovel = not isNone and not isNote diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 002cea43..23660870 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1303 + 1306 199 - 65049 + 65149 False @@ -33,7 +33,7 @@
- New + New Notes Started 1st Draft @@ -42,110 +42,110 @@ Finished - None + None Minor Major Main
- + Novel - + Title Page - + Page - + Part One - + A Folder - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Archive - + Scenes - + Old File - + Trash - + Delete Me! diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index 3e8aeeca..3b35abd5 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -126,8 +126,6 @@ def testCoreTree_BuildTree(mockGUI, mockItems): # Check for archive and trash folders assert theTree.trashRoot() is None - assert theTree.archiveRoot() is None - assert theTree.isTrashRoot("a000000000003") is False aHandles = [] for tHandle, pHandle, nwItem in mockItems: @@ -152,8 +150,8 @@ def testCoreTree_BuildTree(mockGUI, mockItems): # Check that we have the correct archive and trash folders assert theTree.trashRoot() == "a000000000003" - assert theTree.archiveRoot() == "a000000000002" - assert theTree.isTrashRoot("a000000000003") is True + assert theTree.findRoot(nwItemClass.ARCHIVE) == "a000000000002" + assert theTree.isTrash("a000000000003") is True assert theTree.isRoot("a000000000002") is True # Check the isTrash function @@ -221,7 +219,6 @@ def testCoreTree_BuildTree(mockGUI, mockItems): del theTree["a000000000002"] assert len(theTree) == len(mockItems) - 2 assert "a000000000002" not in theTree - assert theTree.archiveRoot() is None del theTree["a000000000003"] assert len(theTree) == len(mockItems) - 3