Remove the showStatus flag from document handling

This commit is contained in:
Veronica K. B. Olsen
2021-04-25 17:16:57 +02:00
parent d473615ccf
commit 45f726669e
7 changed files with 29 additions and 28 deletions
+1 -11
View File
@@ -68,7 +68,7 @@ class NWDoc():
self._docMeta = {} self._docMeta = {}
return return
def readDocument(self, tHandle, showStatus=True, isOrphan=False): def readDocument(self, tHandle, isOrphan=False):
"""Read a document from handle, capturing potential file system """Read a document from handle, capturing potential file system
errors and parse meta data. If the document doesn't exist on errors and parse meta data. If the document doesn't exist on
disk, return an empty string. If something went wrong, return disk, return an empty string. If something went wrong, return
@@ -127,11 +127,6 @@ class NWDoc():
logger.debug("The requested document does not exist.") logger.debug("The requested document does not exist.")
return "" return ""
if showStatus and not isOrphan:
self.theParent.setStatus(
self.tr("Opened Document: {0}").format(self._theItem.itemName)
)
return theText return theText
def writeDocument(self, docText): def writeDocument(self, docText):
@@ -173,11 +168,6 @@ class NWDoc():
os.unlink(docPath) os.unlink(docPath)
os.rename(docTemp, 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 return True
def deleteDocument(self, tHandle): def deleteDocument(self, tHandle):
+1 -1
View File
@@ -117,7 +117,7 @@ class NWIndex():
return False return False
theDoc = NWDoc(self.theProject, self.theParent) theDoc = NWDoc(self.theProject, self.theParent)
theText = theDoc.readDocument(tHandle, showStatus=False) theText = theDoc.readDocument(tHandle)
if theText: if theText:
self.scanText(tHandle, theText) self.scanText(tHandle, theText)
+8 -8
View File
@@ -284,15 +284,15 @@ class NWProject():
self.projTree.setFileItemLayout(xHandle[5], nwItemLayout.TITLE) self.projTree.setFileItemLayout(xHandle[5], nwItemLayout.TITLE)
self.projTree.setFileItemLayout(xHandle[7], nwItemLayout.CHAPTER) self.projTree.setFileItemLayout(xHandle[7], nwItemLayout.CHAPTER)
aDoc.readDocument(xHandle[5], showStatus=False) aDoc.readDocument(xHandle[5])
aDoc.writeDocument(titlePage) aDoc.writeDocument(titlePage)
aDoc.clearDocument() aDoc.clearDocument()
aDoc.readDocument(xHandle[7], showStatus=False) aDoc.readDocument(xHandle[7])
aDoc.writeDocument("## %s\n\n" % self.tr("New Chapter")) aDoc.writeDocument("## %s\n\n" % self.tr("New Chapter"))
aDoc.clearDocument() aDoc.clearDocument()
aDoc.readDocument(xHandle[8], showStatus=False) aDoc.readDocument(xHandle[8])
aDoc.writeDocument("### %s\n\n" % self.tr("New Scene")) aDoc.writeDocument("### %s\n\n" % self.tr("New Scene"))
aDoc.clearDocument() aDoc.clearDocument()
@@ -311,7 +311,7 @@ class NWProject():
tHandle = self.newFile(self.tr("Title Page"), nwItemClass.NOVEL, nHandle) tHandle = self.newFile(self.tr("Title Page"), nwItemClass.NOVEL, nHandle)
self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE)
aDoc.readDocument(tHandle, showStatus=False) aDoc.readDocument(tHandle)
aDoc.writeDocument(titlePage) aDoc.writeDocument(titlePage)
aDoc.clearDocument() aDoc.clearDocument()
@@ -331,7 +331,7 @@ class NWProject():
cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle) cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle)
self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER)
aDoc.readDocument(cHandle, showStatus=False) aDoc.readDocument(cHandle)
aDoc.writeDocument("## %s\n\n" % chTitle) aDoc.writeDocument("## %s\n\n" % chTitle)
aDoc.clearDocument() aDoc.clearDocument()
@@ -341,7 +341,7 @@ class NWProject():
scTitle = self.tr("Scene {0}").format(f"{ch+1:d}.{sc+1:d}") scTitle = self.tr("Scene {0}").format(f"{ch+1:d}.{sc+1:d}")
sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle) sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle)
aDoc.readDocument(sHandle, showStatus=False) aDoc.readDocument(sHandle)
aDoc.writeDocument("### %s\n\n" % scTitle) aDoc.writeDocument("### %s\n\n" % scTitle)
aDoc.clearDocument() aDoc.clearDocument()
@@ -351,7 +351,7 @@ class NWProject():
scTitle = self.tr("Scene {0}").format(f"{sc+1:d}") scTitle = self.tr("Scene {0}").format(f"{sc+1:d}")
sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle) sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle)
aDoc.readDocument(sHandle, showStatus=False) aDoc.readDocument(sHandle)
aDoc.writeDocument("### %s\n\n" % scTitle) aDoc.writeDocument("### %s\n\n" % scTitle)
aDoc.clearDocument() aDoc.clearDocument()
@@ -1404,7 +1404,7 @@ class NWProject():
oParent = None oParent = None
oClass = None oClass = None
oLayout = 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() oName, oParent, oClass, oLayout = aDoc.getMeta()
if oName: if oName:
+2 -2
View File
@@ -110,7 +110,7 @@ class GuiDocMerge(QDialog):
theDoc = NWDoc(self.theProject, self.theParent) theDoc = NWDoc(self.theProject, self.theParent)
theText = "" theText = ""
for tHandle in finalOrder: for tHandle in finalOrder:
docText = theDoc.readDocument(tHandle, False).rstrip("\n") docText = theDoc.readDocument(tHandle).rstrip("\n")
if docText: if docText:
theText += docText+"\n\n" theText += docText+"\n\n"
@@ -131,7 +131,7 @@ class GuiDocMerge(QDialog):
newItem = self.theProject.projTree[nHandle] newItem = self.theProject.projTree[nHandle]
newItem.setStatus(srcItem.itemStatus) newItem.setStatus(srcItem.itemStatus)
theDoc.readDocument(nHandle, False) theDoc.readDocument(nHandle)
theDoc.writeDocument(theText) theDoc.writeDocument(theText)
self.theParent.treeView.revealNewTreeItem(nHandle) self.theParent.treeView.revealNewTreeItem(nHandle)
self.theParent.openDocument(nHandle, doScroll=True) self.theParent.openDocument(nHandle, doScroll=True)
+3 -3
View File
@@ -128,7 +128,7 @@ class GuiDocSplit(QDialog):
return return
theDoc = NWDoc(self.theProject, self.theParent) theDoc = NWDoc(self.theProject, self.theParent)
theText = theDoc.readDocument(self.sourceItem, False) theText = theDoc.readDocument(self.sourceItem)
if theText is None: if theText is None:
theText = "" theText = ""
@@ -217,7 +217,7 @@ class GuiDocSplit(QDialog):
theText = "\n".join(theLines[iStart:iEnd]) theText = "\n".join(theLines[iStart:iEnd])
theText = theText.rstrip("\n") + "\n\n" theText = theText.rstrip("\n") + "\n\n"
theDoc.readDocument(nHandle, False) theDoc.readDocument(nHandle)
theDoc.writeDocument(theText) theDoc.writeDocument(theText)
theDoc.clearDocument() theDoc.clearDocument()
self.theParent.treeView.revealNewTreeItem(nHandle) self.theParent.treeView.revealNewTreeItem(nHandle)
@@ -260,7 +260,7 @@ class GuiDocSplit(QDialog):
self.listBox.clear() self.listBox.clear()
theDoc = NWDoc(self.theProject, self.theParent) theDoc = NWDoc(self.theProject, self.theParent)
theText = theDoc.readDocument(self.sourceItem, False) theText = theDoc.readDocument(self.sourceItem)
if theText is None: if theText is None:
theText = "" theText = ""
+13 -2
View File
@@ -288,7 +288,7 @@ class GuiDocEditor(QTextEdit):
return True 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 """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 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 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 document is new (empty string), we set up the editor for editing
the file. the file.
""" """
theDoc = self.nwDocument.readDocument(tHandle, showStatus=showStatus) theDoc = self.nwDocument.readDocument(tHandle)
if theDoc is None: if theDoc is None:
# There was an io error # There was an io error
self.clearEditor() self.clearEditor()
@@ -377,6 +377,12 @@ class GuiDocEditor(QTextEdit):
self.setPlainText("") self.setPlainText("")
self.setCursorPosition(0) 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 return True
def updateTagHighLighting(self, forceBigDoc=False): def updateTagHighLighting(self, forceBigDoc=False):
@@ -457,6 +463,11 @@ class GuiDocEditor(QTextEdit):
self.nwDocument.writeDocument(docText) self.nwDocument.writeDocument(docText)
self.docFooter.updateInfo() self.docFooter.updateInfo()
# Update the status bar
self.theParent.setStatus(
self.tr("Saved Document: {0}").format(theItem.itemName)
)
return True return True
def updateDocMargins(self): def updateDocMargins(self):
+1 -1
View File
@@ -287,7 +287,7 @@ class GuiProjectTree(QTreeWidget):
# This is a new files, so let's add some content # This is a new files, so let's add some content
newDoc = NWDoc(self.theProject, self.theParent) newDoc = NWDoc(self.theProject, self.theParent)
curTxt = newDoc.readDocument(tHandle, showStatus=False) curTxt = newDoc.readDocument(tHandle)
if curTxt is None: if curTxt is None:
curTxt = "" curTxt = ""