From 45f726669ea4920720a4b165815930e5ef9257e9 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 25 Apr 2021 17:16:57 +0200 Subject: [PATCH] Remove the showStatus flag from document handling --- nw/core/document.py | 12 +----------- nw/core/index.py | 2 +- nw/core/project.py | 16 ++++++++-------- nw/dialogs/docmerge.py | 4 ++-- nw/dialogs/docsplit.py | 6 +++--- nw/gui/doceditor.py | 15 +++++++++++++-- nw/gui/projtree.py | 2 +- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/nw/core/document.py b/nw/core/document.py index d9fe3268..e158cf87 100644 --- a/nw/core/document.py +++ b/nw/core/document.py @@ -68,7 +68,7 @@ class NWDoc(): self._docMeta = {} return - def readDocument(self, tHandle, showStatus=True, isOrphan=False): + def readDocument(self, tHandle, isOrphan=False): """Read a document from handle, capturing potential file system errors and parse meta data. If the document doesn't exist on disk, return an empty string. If something went wrong, return @@ -127,11 +127,6 @@ class NWDoc(): logger.debug("The requested document does not exist.") return "" - if showStatus and not isOrphan: - self.theParent.setStatus( - self.tr("Opened Document: {0}").format(self._theItem.itemName) - ) - return theText def writeDocument(self, docText): @@ -173,11 +168,6 @@ class NWDoc(): os.unlink(docPath) os.rename(docTemp, docPath) - if self._theItem is not None: - self.theParent.setStatus( - self.tr("Saved Document: {0}").format(self._theItem.itemName) - ) - return True def deleteDocument(self, tHandle): diff --git a/nw/core/index.py b/nw/core/index.py index 6b8f53e3..8d6f04c3 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -117,7 +117,7 @@ class NWIndex(): return False theDoc = NWDoc(self.theProject, self.theParent) - theText = theDoc.readDocument(tHandle, showStatus=False) + theText = theDoc.readDocument(tHandle) if theText: self.scanText(tHandle, theText) diff --git a/nw/core/project.py b/nw/core/project.py index 832e9c9b..75aaafa9 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -284,15 +284,15 @@ class NWProject(): self.projTree.setFileItemLayout(xHandle[5], nwItemLayout.TITLE) self.projTree.setFileItemLayout(xHandle[7], nwItemLayout.CHAPTER) - aDoc.readDocument(xHandle[5], showStatus=False) + aDoc.readDocument(xHandle[5]) aDoc.writeDocument(titlePage) aDoc.clearDocument() - aDoc.readDocument(xHandle[7], showStatus=False) + aDoc.readDocument(xHandle[7]) aDoc.writeDocument("## %s\n\n" % self.tr("New Chapter")) aDoc.clearDocument() - aDoc.readDocument(xHandle[8], showStatus=False) + aDoc.readDocument(xHandle[8]) aDoc.writeDocument("### %s\n\n" % self.tr("New Scene")) aDoc.clearDocument() @@ -311,7 +311,7 @@ class NWProject(): tHandle = self.newFile(self.tr("Title Page"), nwItemClass.NOVEL, nHandle) self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) - aDoc.readDocument(tHandle, showStatus=False) + aDoc.readDocument(tHandle) aDoc.writeDocument(titlePage) aDoc.clearDocument() @@ -331,7 +331,7 @@ class NWProject(): cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle) self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) - aDoc.readDocument(cHandle, showStatus=False) + aDoc.readDocument(cHandle) aDoc.writeDocument("## %s\n\n" % chTitle) aDoc.clearDocument() @@ -341,7 +341,7 @@ class NWProject(): scTitle = self.tr("Scene {0}").format(f"{ch+1:d}.{sc+1:d}") sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle) - aDoc.readDocument(sHandle, showStatus=False) + aDoc.readDocument(sHandle) aDoc.writeDocument("### %s\n\n" % scTitle) aDoc.clearDocument() @@ -351,7 +351,7 @@ class NWProject(): scTitle = self.tr("Scene {0}").format(f"{sc+1:d}") sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle) - aDoc.readDocument(sHandle, showStatus=False) + aDoc.readDocument(sHandle) aDoc.writeDocument("### %s\n\n" % scTitle) aDoc.clearDocument() @@ -1404,7 +1404,7 @@ class NWProject(): oParent = None oClass = None oLayout = None - if aDoc.readDocument(oHandle, showStatus=False, isOrphan=True) is not None: + if aDoc.readDocument(oHandle, isOrphan=True) is not None: oName, oParent, oClass, oLayout = aDoc.getMeta() if oName: diff --git a/nw/dialogs/docmerge.py b/nw/dialogs/docmerge.py index 4dd397c5..8dbaaa98 100644 --- a/nw/dialogs/docmerge.py +++ b/nw/dialogs/docmerge.py @@ -110,7 +110,7 @@ class GuiDocMerge(QDialog): theDoc = NWDoc(self.theProject, self.theParent) theText = "" for tHandle in finalOrder: - docText = theDoc.readDocument(tHandle, False).rstrip("\n") + docText = theDoc.readDocument(tHandle).rstrip("\n") if docText: theText += docText+"\n\n" @@ -131,7 +131,7 @@ class GuiDocMerge(QDialog): newItem = self.theProject.projTree[nHandle] newItem.setStatus(srcItem.itemStatus) - theDoc.readDocument(nHandle, False) + theDoc.readDocument(nHandle) theDoc.writeDocument(theText) self.theParent.treeView.revealNewTreeItem(nHandle) self.theParent.openDocument(nHandle, doScroll=True) diff --git a/nw/dialogs/docsplit.py b/nw/dialogs/docsplit.py index 184e7089..bf5f2d1f 100644 --- a/nw/dialogs/docsplit.py +++ b/nw/dialogs/docsplit.py @@ -128,7 +128,7 @@ class GuiDocSplit(QDialog): return theDoc = NWDoc(self.theProject, self.theParent) - theText = theDoc.readDocument(self.sourceItem, False) + theText = theDoc.readDocument(self.sourceItem) if theText is None: theText = "" @@ -217,7 +217,7 @@ class GuiDocSplit(QDialog): theText = "\n".join(theLines[iStart:iEnd]) theText = theText.rstrip("\n") + "\n\n" - theDoc.readDocument(nHandle, False) + theDoc.readDocument(nHandle) theDoc.writeDocument(theText) theDoc.clearDocument() self.theParent.treeView.revealNewTreeItem(nHandle) @@ -260,7 +260,7 @@ class GuiDocSplit(QDialog): self.listBox.clear() theDoc = NWDoc(self.theProject, self.theParent) - theText = theDoc.readDocument(self.sourceItem, False) + theText = theDoc.readDocument(self.sourceItem) if theText is None: theText = "" diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 6e6f74c9..7cbb761e 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -288,7 +288,7 @@ class GuiDocEditor(QTextEdit): return True - def loadText(self, tHandle, tLine=None, showStatus=True): + def loadText(self, tHandle, tLine=None): """Load text from a document into the editor. If we have an io error, we must handle this and clear the editor so that we don't risk overwriting the file if it exists. This can for instance @@ -297,7 +297,7 @@ class GuiDocEditor(QTextEdit): document is new (empty string), we set up the editor for editing the file. """ - theDoc = self.nwDocument.readDocument(tHandle, showStatus=showStatus) + theDoc = self.nwDocument.readDocument(tHandle) if theDoc is None: # There was an io error self.clearEditor() @@ -377,6 +377,12 @@ class GuiDocEditor(QTextEdit): self.setPlainText("") self.setCursorPosition(0) + # Update the status bar + if theItem is not None: + self.theParent.setStatus( + self.tr("Opened Document: {0}").format(theItem.itemName) + ) + return True def updateTagHighLighting(self, forceBigDoc=False): @@ -457,6 +463,11 @@ class GuiDocEditor(QTextEdit): self.nwDocument.writeDocument(docText) self.docFooter.updateInfo() + # Update the status bar + self.theParent.setStatus( + self.tr("Saved Document: {0}").format(theItem.itemName) + ) + return True def updateDocMargins(self): diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index dfa71b67..005e4d2f 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -287,7 +287,7 @@ class GuiProjectTree(QTreeWidget): # This is a new files, so let's add some content newDoc = NWDoc(self.theProject, self.theParent) - curTxt = newDoc.readDocument(tHandle, showStatus=False) + curTxt = newDoc.readDocument(tHandle) if curTxt is None: curTxt = ""