Remove the showStatus flag from document handling
This commit is contained in:
+1
-11
@@ -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):
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
|
||||
+8
-8
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
|
||||
+13
-2
@@ -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):
|
||||
|
||||
+1
-1
@@ -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 = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user