From 96d6accbde799352fa284e7dd3a2ac24fff38e9d Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:55:38 +0100 Subject: [PATCH 1/2] Add layout and class info to editor footer bar --- nw/gui/doceditor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 31e77f0d..bc83719b 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -54,7 +54,7 @@ from nw.gui.dochighlight import GuiDocHighlighter from nw.common import transferCase from nw.constants import ( nwConst, nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass, - nwKeyWords + nwKeyWords, nwLabels ) logger = logging.getLogger(__name__) @@ -417,6 +417,7 @@ class GuiDocEditor(QTextEdit): if self.theProject.projTree.updateItemLayout(tHandle, hLevel): self.theParent.treeView.setTreeItemValues(tHandle) self.nwDocument.saveDocument(docText) + self.docFooter.updateInfo() return True @@ -2484,8 +2485,11 @@ class GuiDocEditFooter(QWidget): else: iStatus = self.theProject.importItems.checkEntry(iStatus) theIcon = self.theParent.importIcons[iStatus] + sIcon = theIcon.pixmap(self.sPx, self.sPx) - sText = self.theItem.itemStatus + sClass = nwLabels.CLASS_NAME[self.theItem.itemClass] + sLayout = nwLabels.LAYOUT_NAME[self.theItem.itemLayout] + sText = f"{self.theItem.itemStatus} / {sClass} / {sLayout}" self.statusIcon.setPixmap(sIcon) self.statusText.setText(sText) From 9e294529cf6db8f968dbe33836e4dea53707aa25 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 30 Jan 2021 23:31:19 +0100 Subject: [PATCH 2/2] When a new file is added, automatically add the title line --- nw/gui/projtree.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index ca4c11de..f2703445 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -269,10 +269,43 @@ class GuiProjectTree(QTreeWidget): logger.error("Failed to add new item") return False + # If there is no handle set, return here + if tHandle is None: + return True + # Add the new item to the tree - if tHandle is not None: - self.revealNewTreeItem(tHandle, nHandle) - self.theParent.editItem(tHandle) + self.revealNewTreeItem(tHandle, nHandle) + self.theParent.editItem(tHandle) + nwItem = self.theProject.projTree[tHandle] + + # If this is a folder, return here + if nwItem.itemType != nwItemType.FILE: + return True + + # This is a new files, so let's add some content + newDoc = NWDoc(self.theProject, self.theParent) + curTxt = newDoc.openDocument(tHandle, showStatus=False) + if curTxt == "": + if nwItem.itemLayout == nwItemLayout.CHAPTER: + newText = f"## {nwItem.itemName}\n\n" + elif nwItem.itemLayout == nwItemLayout.UNNUMBERED: + newText = f"## {nwItem.itemName}\n\n" + elif nwItem.itemLayout == nwItemLayout.SCENE: + newText = f"### {nwItem.itemName}\n\n" + else: + newText = f"# {nwItem.itemName}\n\n" + + # Save the text and index it + newDoc.saveDocument(newText) + self.theParent.theIndex.scanText(tHandle, newText) + + # Get Word Counts + cC, wC, pC = self.theParent.theIndex.getCounts(tHandle) + nwItem.setCharCount(cC) + nwItem.setWordCount(wC) + nwItem.setParaCount(pC) + self.propagateCount(tHandle, wC) + self.projectWordCount() return True