Added more checks on actions for project or document being open

This commit is contained in:
Veronica K. B. Olsen
2020-11-01 18:39:12 +01:00
parent 98be2bd5b4
commit 2a0be718d7
4 changed files with 37 additions and 12 deletions
+4
View File
@@ -781,6 +781,10 @@ class NWProject():
def zipIt(self, doNotify): def zipIt(self, doNotify):
"""Create a zip file of the entire project. """Create a zip file of the entire project.
""" """
if not self.theParent.hasProject:
logger.error("No project open")
return False
logger.info("Backing up project") logger.info("Backing up project")
self.theParent.setStatus("Backing up project ...") self.theParent.setStatus("Backing up project ...")
+19 -12
View File
@@ -620,9 +620,10 @@ class GuiDocEditor(QTextEdit):
this class when calling these actions from other classes. this class when calling these actions from other classes.
""" """
logger.verbose("Requesting action: %s" % theAction.name) logger.verbose("Requesting action: %s" % theAction.name)
if not self.theParent.hasProject: if self.theHandle is None:
logger.error("No project open") logger.error("No document open")
return False return False
self._allowAutoReplace(False) self._allowAutoReplace(False)
if theAction == nwDocAction.UNDO: if theAction == nwDocAction.UNDO:
self.undo() self.undo()
@@ -678,7 +679,9 @@ class GuiDocEditor(QTextEdit):
logger.debug("Unknown or unsupported document action %s" % str(theAction)) logger.debug("Unknown or unsupported document action %s" % str(theAction))
self._allowAutoReplace(True) self._allowAutoReplace(True)
return False return False
self._allowAutoReplace(True) self._allowAutoReplace(True)
return True return True
def isEmpty(self): def isEmpty(self):
@@ -690,16 +693,20 @@ class GuiDocEditor(QTextEdit):
"""Tell the user where on the file system the file in the editor """Tell the user where on the file system the file in the editor
is saved. is saved.
""" """
if self.theHandle is not None: if self.theHandle is None:
msgBox = QMessageBox() logger.error("No document open")
msgBox.information(self, "File Location", ( return False
"File details for the currently open file<br>"
"Handle: {handle:s}<br>" msgBox = QMessageBox()
"Location: {fileLoc:s}" msgBox.information(self, "File Location", (
).format( "File details for the currently open file<br>"
handle = self.theHandle, "Handle: {handle:s}<br>"
fileLoc = str(self.nwDocument.getFileLocation()) "Location: {fileLoc:s}"
)) ).format(
handle = self.theHandle,
fileLoc = str(self.nwDocument.getFileLocation())
))
return return
def insertText(self, theInsert): def insertText(self, theInsert):
+13
View File
@@ -163,6 +163,7 @@ class GuiProjectTree(QTreeWidget):
nHandle = None nHandle = None
if not self.theParent.hasProject: if not self.theParent.hasProject:
logger.error("No project open")
return False return False
# The item needs to be assigned an item class, so one must be # The item needs to be assigned an item class, so one must be
@@ -281,6 +282,10 @@ class GuiProjectTree(QTreeWidget):
"""Move an item up or down in the tree, but only if the treeView """Move an item up or down in the tree, but only if the treeView
has focus. This also applies when the menu is used. has focus. This also applies when the menu is used.
""" """
if not self.theParent.hasProject:
logger.error("No project open")
return False
hasFocus = qApp.focusWidget() == self or not self.mainConf.showGUI hasFocus = qApp.focusWidget() == self or not self.mainConf.showGUI
if hasFocus and self.theParent.hasProject: if hasFocus and self.theParent.hasProject:
@@ -364,6 +369,10 @@ class GuiProjectTree(QTreeWidget):
function only asks for confirmation once, and calls the regular function only asks for confirmation once, and calls the regular
deleteItem function for each document in the Trash folder. deleteItem function for each document in the Trash folder.
""" """
if not self.theParent.hasProject:
logger.error("No project open")
return False
trashHandle = self.theProject.projTree.trashRoot() trashHandle = self.theProject.projTree.trashRoot()
logger.debug("Emptying Trash folder") logger.debug("Emptying Trash folder")
@@ -409,6 +418,10 @@ class GuiProjectTree(QTreeWidget):
delete the files on disk. Folders are deleted if they're empty only, delete the files on disk. Folders are deleted if they're empty only,
and the deletion is always permanent. and the deletion is always permanent.
""" """
if not self.theParent.hasProject:
logger.error("No project open")
return False
if tHandle is None: if tHandle is None:
tHandle = self.getSelectedHandle() tHandle = self.getSelectedHandle()
+1
View File
@@ -1053,6 +1053,7 @@ class GuiMain(QMainWindow):
""" """
if self.docEditor.theHandle is None: if self.docEditor.theHandle is None:
logger.error("No document open, so not activating Focus Mode") logger.error("No document open, so not activating Focus Mode")
self.mainMenu.aFocusMode.setChecked(self.isFocusMode)
return False return False
self.isFocusMode = not self.isFocusMode self.isFocusMode = not self.isFocusMode