Tighten up the use of item and nwdoc objects in editor class

This commit is contained in:
Veronica K. B. Olsen
2021-04-25 23:46:09 +02:00
parent e7102725bd
commit 5ee39d7ecc
3 changed files with 40 additions and 43 deletions
+8 -18
View File
@@ -40,26 +40,20 @@ class NWDoc():
# Internal Variables
self._docHandle = theHandle
self._theItem = self.theProject.projTree[theHandle]
self._theItem = None
self._fileLoc = None
self._docMeta = {}
self._docError = ""
if theHandle is not None:
self._theItem = self.theProject.projTree[theHandle]
return
##
# Class Methods
##
def clearDocument(self):
"""Clear the document contents.
"""
self._theItem = None
self._docHandle = None
self._fileLoc = None
self._docMeta = {}
return
def readDocument(self, isOrphan=False):
"""Read a document from set handle, capturing potential file
system errors and parse meta data. If the document doesn't exist
@@ -68,11 +62,11 @@ class NWDoc():
"""
self._docError = ""
if not isHandle(self._docHandle):
self._docError = "No document handle set."
logger.error("No document handle set")
return None
if self._theItem is None and not isOrphan:
self._docError = "Unknown novelWriter document."
logger.error("Unknown novelWriter document")
return None
docFile = self._docHandle+".nwd"
@@ -101,10 +95,6 @@ class NWDoc():
except Exception as e:
self._docError = str(e)
# Note: Document must be cleared in case of an io error,
# or else the auto-save or save will try to overwrite it
# with an empty file. Return None to alert the caller.
self.clearDocument()
return None
else:
@@ -121,7 +111,7 @@ class NWDoc():
"""
self._docError = ""
if not isHandle(self._docHandle):
self._docError = "No document handle set."
logger.error("No document handle set")
return False
self.theProject.ensureFolderStructure()
@@ -164,7 +154,7 @@ class NWDoc():
"""
self._docError = ""
if not isHandle(self._docHandle):
self._docError = "No document handle set."
logger.error("No document handle set")
return False
docFile = self._docHandle+".nwd"