From 8fe25d4b43e4237e20e0b5514ba1ca236bba6172 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 17 Oct 2022 20:15:45 +0200 Subject: [PATCH] Update classes and functions to use the item as source of main heading instead of index --- novelwriter/core/doctools.py | 2 +- novelwriter/core/item.py | 10 +++++----- novelwriter/dialogs/docmerge.py | 3 +-- novelwriter/gui/doceditor.py | 7 +++---- novelwriter/gui/itemdetails.py | 5 ++--- novelwriter/gui/outline.py | 3 +-- novelwriter/gui/projtree.py | 4 ++-- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/novelwriter/core/doctools.py b/novelwriter/core/doctools.py index e26f6681..54cb9d25 100644 --- a/novelwriter/core/doctools.py +++ b/novelwriter/core/doctools.py @@ -91,7 +91,7 @@ class DocMerger: docText = (inDoc.readDocument() or "").rstrip("\n") if addComment: - docInfo = srcItem.describeMe("H0") + docInfo = srcItem.describeMe() docSt, _ = srcItem.getImportStatus(incIcon=False) cmtLine = f"% {cmtPrefix} {docInfo}: {srcItem.itemName} [{docSt}]\n\n" docText = cmtLine + docText diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index 185d84fa..22f48cdd 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -276,7 +276,7 @@ class NWItem: # Lookup Methods ## - def describeMe(self, hLevel=None): + def describeMe(self): """Return a string description of the item. """ descKey = "none" @@ -286,13 +286,13 @@ class NWItem: descKey = "folder" elif self._type == nwItemType.FILE: if self._layout == nwItemLayout.DOCUMENT: - if hLevel == "H1": + if self._heading == "H1": descKey = "doc_h1" - elif hLevel == "H2": + elif self._heading == "H2": descKey = "doc_h2" - elif hLevel == "H3": + elif self._heading == "H3": descKey = "doc_h3" - elif hLevel == "H4": + elif self._heading == "H4": descKey = "doc_h4" else: descKey = "document" diff --git a/novelwriter/dialogs/docmerge.py b/novelwriter/dialogs/docmerge.py index fd9fcebe..9bc822d4 100644 --- a/novelwriter/dialogs/docmerge.py +++ b/novelwriter/dialogs/docmerge.py @@ -155,9 +155,8 @@ class GuiDocMerge(QDialog): if nwItem is None or not nwItem.isFileType(): continue - hLevel = self.theProject.index.getHandleHeaderLevel(tHandle) itemIcon = self.mainTheme.getItemIcon( - nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel + nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, nwItem.mainHeading ) newItem = QListWidgetItem() diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index cc96b9e9..6ae8bec7 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -508,9 +508,9 @@ class GuiDocEditor(QTextEdit): self.setDocumentChanged(False) - oldHeader = self.theProject.index.getHandleHeaderLevel(tHandle) + oldHeader = self._nwItem.mainHeading self.theProject.index.scanText(tHandle, docText) - newHeader = self.theProject.index.getHandleHeaderLevel(tHandle) + newHeader = self._nwItem.mainHeading # ToDo: This should be a signal if self._updateHeaders(checkLevel=True): @@ -2972,8 +2972,7 @@ class GuiDocEditFooter(QWidget): else: theStatus, theIcon = self._theItem.getImportStatus() sIcon = theIcon.pixmap(self.sPx, self.sPx) - hLevel = self.theProject.index.getHandleHeaderLevel(self._docHandle) - sText = f"{theStatus} / {self._theItem.describeMe(hLevel)}" + sText = f"{theStatus} / {self._theItem.describeMe()}" self.statusIcon.setPixmap(sIcon) self.statusText.setText(sText) diff --git a/novelwriter/gui/itemdetails.py b/novelwriter/gui/itemdetails.py index dbd2838c..56258667 100644 --- a/novelwriter/gui/itemdetails.py +++ b/novelwriter/gui/itemdetails.py @@ -273,12 +273,11 @@ class GuiItemDetails(QWidget): # Layout # ====== - hLevel = self.theProject.index.getHandleHeaderLevel(tHandle) usageIcon = self.mainTheme.getItemIcon( - nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel + nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, nwItem.mainHeading ) self.usageIcon.setPixmap(usageIcon.pixmap(iPx, iPx)) - self.usageData.setText(nwItem.describeMe(hLevel)) + self.usageData.setText(nwItem.describeMe()) # Counts # ====== diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index d0837360..ed18d64a 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -685,7 +685,6 @@ class GuiOutlineTree(QTreeWidget): for _, tHandle, sTitle, novIdx in novStruct: iLevel = nwHeaders.H_LEVEL.get(novIdx.level, 0) - dLevel = self.theProject.index.getHandleHeaderLevel(tHandle) if iLevel == 0: continue @@ -699,7 +698,7 @@ class GuiOutlineTree(QTreeWidget): trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle) trItem.setFont(self._colIdx[nwOutline.TITLE], self._hFonts[iLevel]) trItem.setText(self._colIdx[nwOutline.LEVEL], novIdx.level) - trItem.setIcon(self._colIdx[nwOutline.LABEL], self._dIcon[dLevel]) + trItem.setIcon(self._colIdx[nwOutline.LABEL], self._dIcon[nwItem.mainHeading]) trItem.setText(self._colIdx[nwOutline.LABEL], nwItem.itemName) trItem.setText(self._colIdx[nwOutline.LINE], sTitle[1:].lstrip("0")) trItem.setText(self._colIdx[nwOutline.SYNOP], novIdx.synopsis) diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 15bc7cbf..caa28602 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -516,7 +516,7 @@ class GuiProjectTree(QTreeWidget): # Collect some information about the selected item that pItem = self.theProject.tree[sHandle] qItem = self._getTreeItem(sHandle) - sLevel = nwHeaders.H_LEVEL.get(self.theProject.index.getHandleHeaderLevel(sHandle), 0) + sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0) sIsParent = False if qItem is None else qItem.childCount() > 0 if self.theProject.tree.isTrash(sHandle): @@ -897,7 +897,7 @@ class GuiProjectTree(QTreeWidget): return itemStatus, statusIcon = nwItem.getImportStatus() - hLevel = self.theProject.index.getHandleHeaderLevel(tHandle) + hLevel = nwItem.mainHeading itemIcon = self.mainTheme.getItemIcon( nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel )