Added more checks on actions for project or document being open
This commit is contained in:
@@ -781,6 +781,10 @@ class NWProject():
|
||||
def zipIt(self, doNotify):
|
||||
"""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")
|
||||
self.theParent.setStatus("Backing up project ...")
|
||||
|
||||
|
||||
+19
-12
@@ -620,9 +620,10 @@ class GuiDocEditor(QTextEdit):
|
||||
this class when calling these actions from other classes.
|
||||
"""
|
||||
logger.verbose("Requesting action: %s" % theAction.name)
|
||||
if not self.theParent.hasProject:
|
||||
logger.error("No project open")
|
||||
if self.theHandle is None:
|
||||
logger.error("No document open")
|
||||
return False
|
||||
|
||||
self._allowAutoReplace(False)
|
||||
if theAction == nwDocAction.UNDO:
|
||||
self.undo()
|
||||
@@ -678,7 +679,9 @@ class GuiDocEditor(QTextEdit):
|
||||
logger.debug("Unknown or unsupported document action %s" % str(theAction))
|
||||
self._allowAutoReplace(True)
|
||||
return False
|
||||
|
||||
self._allowAutoReplace(True)
|
||||
|
||||
return True
|
||||
|
||||
def isEmpty(self):
|
||||
@@ -690,16 +693,20 @@ class GuiDocEditor(QTextEdit):
|
||||
"""Tell the user where on the file system the file in the editor
|
||||
is saved.
|
||||
"""
|
||||
if self.theHandle is not None:
|
||||
msgBox = QMessageBox()
|
||||
msgBox.information(self, "File Location", (
|
||||
"File details for the currently open file<br>"
|
||||
"Handle: {handle:s}<br>"
|
||||
"Location: {fileLoc:s}"
|
||||
).format(
|
||||
handle = self.theHandle,
|
||||
fileLoc = str(self.nwDocument.getFileLocation())
|
||||
))
|
||||
if self.theHandle is None:
|
||||
logger.error("No document open")
|
||||
return False
|
||||
|
||||
msgBox = QMessageBox()
|
||||
msgBox.information(self, "File Location", (
|
||||
"File details for the currently open file<br>"
|
||||
"Handle: {handle:s}<br>"
|
||||
"Location: {fileLoc:s}"
|
||||
).format(
|
||||
handle = self.theHandle,
|
||||
fileLoc = str(self.nwDocument.getFileLocation())
|
||||
))
|
||||
|
||||
return
|
||||
|
||||
def insertText(self, theInsert):
|
||||
|
||||
@@ -163,6 +163,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
nHandle = None
|
||||
|
||||
if not self.theParent.hasProject:
|
||||
logger.error("No project open")
|
||||
return False
|
||||
|
||||
# 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
|
||||
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
|
||||
if hasFocus and self.theParent.hasProject:
|
||||
|
||||
@@ -364,6 +369,10 @@ class GuiProjectTree(QTreeWidget):
|
||||
function only asks for confirmation once, and calls the regular
|
||||
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()
|
||||
|
||||
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,
|
||||
and the deletion is always permanent.
|
||||
"""
|
||||
if not self.theParent.hasProject:
|
||||
logger.error("No project open")
|
||||
return False
|
||||
|
||||
if tHandle is None:
|
||||
tHandle = self.getSelectedHandle()
|
||||
|
||||
|
||||
@@ -1053,6 +1053,7 @@ class GuiMain(QMainWindow):
|
||||
"""
|
||||
if self.docEditor.theHandle is None:
|
||||
logger.error("No document open, so not activating Focus Mode")
|
||||
self.mainMenu.aFocusMode.setChecked(self.isFocusMode)
|
||||
return False
|
||||
|
||||
self.isFocusMode = not self.isFocusMode
|
||||
|
||||
Reference in New Issue
Block a user