Block a bunch more main GUI actions when no project is open
This commit is contained in:
+88
-43
@@ -442,6 +442,7 @@ class GuiMain(QMainWindow):
|
|||||||
"""Save the current project.
|
"""Save the current project.
|
||||||
"""
|
"""
|
||||||
if not self.hasProject:
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If the project is new, it may not have a path, so we need one
|
# If the project is new, it may not have a path, so we need one
|
||||||
@@ -465,27 +466,33 @@ class GuiMain(QMainWindow):
|
|||||||
def closeDocument(self):
|
def closeDocument(self):
|
||||||
"""Close the document and clear the editor and title field.
|
"""Close the document and clear the editor and title field.
|
||||||
"""
|
"""
|
||||||
if self.hasProject:
|
if not self.hasProject:
|
||||||
self.docEditor.saveCursorPosition()
|
logger.error("No project open")
|
||||||
if self.docEditor.docChanged:
|
return False
|
||||||
self.saveDocument()
|
|
||||||
self.docEditor.clearEditor()
|
self.docEditor.saveCursorPosition()
|
||||||
|
if self.docEditor.docChanged:
|
||||||
|
self.saveDocument()
|
||||||
|
self.docEditor.clearEditor()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def openDocument(self, tHandle, tLine=None, changeFocus=True, doScroll=False):
|
def openDocument(self, tHandle, tLine=None, changeFocus=True, doScroll=False):
|
||||||
"""Open a specific document, optionally at a given line.
|
"""Open a specific document, optionally at a given line.
|
||||||
"""
|
"""
|
||||||
if self.hasProject:
|
if not self.hasProject:
|
||||||
self.closeDocument()
|
logger.error("No project open")
|
||||||
self.tabWidget.setCurrentWidget(self.splitDocs)
|
return False
|
||||||
if self.docEditor.loadText(tHandle, tLine):
|
|
||||||
if changeFocus:
|
self.closeDocument()
|
||||||
self.docEditor.setFocus()
|
self.tabWidget.setCurrentWidget(self.splitDocs)
|
||||||
self.theProject.setLastEdited(tHandle)
|
if self.docEditor.loadText(tHandle, tLine):
|
||||||
self.treeView.setSelectedHandle(tHandle, doScroll=doScroll)
|
if changeFocus:
|
||||||
else:
|
self.docEditor.setFocus()
|
||||||
return False
|
self.theProject.setLastEdited(tHandle)
|
||||||
|
self.treeView.setSelectedHandle(tHandle, doScroll=doScroll)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -493,43 +500,54 @@ class GuiMain(QMainWindow):
|
|||||||
"""Opens the next document in the project tree, following the
|
"""Opens the next document in the project tree, following the
|
||||||
document with the given handle. Stops when reaching the end.
|
document with the given handle. Stops when reaching the end.
|
||||||
"""
|
"""
|
||||||
if self.hasProject:
|
if not self.hasProject:
|
||||||
self.treeView.flushTreeOrder()
|
logger.error("No project open")
|
||||||
nHandle = None # The next handle after tHandle
|
return False
|
||||||
fHandle = None # The first file handle we encounter
|
|
||||||
foundIt = False # We've found tHandle, pick the next we see
|
|
||||||
for tItem in self.theProject.projTree:
|
|
||||||
if tItem is None:
|
|
||||||
continue
|
|
||||||
if tItem.itemType != nwItemType.FILE:
|
|
||||||
continue
|
|
||||||
if fHandle is None:
|
|
||||||
fHandle = tItem.itemHandle
|
|
||||||
if tItem.itemHandle == tHandle:
|
|
||||||
foundIt = True
|
|
||||||
elif foundIt:
|
|
||||||
nHandle = tItem.itemHandle
|
|
||||||
break
|
|
||||||
|
|
||||||
if nHandle is not None:
|
self.treeView.flushTreeOrder()
|
||||||
self.openDocument(nHandle, tLine=0, doScroll=True)
|
nHandle = None # The next handle after tHandle
|
||||||
return True
|
fHandle = None # The first file handle we encounter
|
||||||
elif wrapAround:
|
foundIt = False # We've found tHandle, pick the next we see
|
||||||
self.openDocument(fHandle, tLine=0, doScroll=True)
|
for tItem in self.theProject.projTree:
|
||||||
return False
|
if tItem is None:
|
||||||
|
continue
|
||||||
|
if tItem.itemType != nwItemType.FILE:
|
||||||
|
continue
|
||||||
|
if fHandle is None:
|
||||||
|
fHandle = tItem.itemHandle
|
||||||
|
if tItem.itemHandle == tHandle:
|
||||||
|
foundIt = True
|
||||||
|
elif foundIt:
|
||||||
|
nHandle = tItem.itemHandle
|
||||||
|
break
|
||||||
|
|
||||||
|
if nHandle is not None:
|
||||||
|
self.openDocument(nHandle, tLine=0, doScroll=True)
|
||||||
|
return True
|
||||||
|
elif wrapAround:
|
||||||
|
self.openDocument(fHandle, tLine=0, doScroll=True)
|
||||||
|
return False
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def saveDocument(self):
|
def saveDocument(self):
|
||||||
"""Save the current documents.
|
"""Save the current documents.
|
||||||
"""
|
"""
|
||||||
if self.hasProject:
|
if not self.hasProject:
|
||||||
self.docEditor.saveText()
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.docEditor.saveText()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def viewDocument(self, tHandle=None, tAnchor=None):
|
def viewDocument(self, tHandle=None, tAnchor=None):
|
||||||
"""Load a document for viewing in the view panel.
|
"""Load a document for viewing in the view panel.
|
||||||
"""
|
"""
|
||||||
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
logger.debug("Viewing document, but no handle provided")
|
logger.debug("Viewing document, but no handle provided")
|
||||||
|
|
||||||
@@ -573,8 +591,11 @@ class GuiMain(QMainWindow):
|
|||||||
"""Import the text contained in an out-of-project text file, and
|
"""Import the text contained in an out-of-project text file, and
|
||||||
insert the text into the currently open document.
|
insert the text into the currently open document.
|
||||||
"""
|
"""
|
||||||
lastPath = self.mainConf.lastPath
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
|
lastPath = self.mainConf.lastPath
|
||||||
extFilter = [
|
extFilter = [
|
||||||
"Text files (*.txt)",
|
"Text files (*.txt)",
|
||||||
"Markdown files (*.md)",
|
"Markdown files (*.md)",
|
||||||
@@ -627,16 +648,26 @@ class GuiMain(QMainWindow):
|
|||||||
def mergeDocuments(self):
|
def mergeDocuments(self):
|
||||||
"""Merge multiple documents to one single new document.
|
"""Merge multiple documents to one single new document.
|
||||||
"""
|
"""
|
||||||
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
dlgMerge = GuiDocMerge(self, self.theProject)
|
dlgMerge = GuiDocMerge(self, self.theProject)
|
||||||
dlgMerge.exec_()
|
dlgMerge.exec_()
|
||||||
return
|
|
||||||
|
return True
|
||||||
|
|
||||||
def splitDocument(self):
|
def splitDocument(self):
|
||||||
"""Split a single document into multiple documents.
|
"""Split a single document into multiple documents.
|
||||||
"""
|
"""
|
||||||
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
dlgSplit = GuiDocSplit(self, self.theProject)
|
dlgSplit = GuiDocSplit(self, self.theProject)
|
||||||
dlgSplit.exec_()
|
dlgSplit.exec_()
|
||||||
return
|
|
||||||
|
return True
|
||||||
|
|
||||||
def passDocumentAction(self, theAction):
|
def passDocumentAction(self, theAction):
|
||||||
"""Pass on document action theAction to the document viewer if
|
"""Pass on document action theAction to the document viewer if
|
||||||
@@ -655,6 +686,10 @@ class GuiMain(QMainWindow):
|
|||||||
def openSelectedItem(self):
|
def openSelectedItem(self):
|
||||||
"""Open the selected documents.
|
"""Open the selected documents.
|
||||||
"""
|
"""
|
||||||
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
tHandle = self.treeView.getSelectedHandle()
|
tHandle = self.treeView.getSelectedHandle()
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
logger.warning("No item selected")
|
logger.warning("No item selected")
|
||||||
@@ -673,6 +708,10 @@ class GuiMain(QMainWindow):
|
|||||||
def editItem(self, tHandle=None):
|
def editItem(self, tHandle=None):
|
||||||
"""Open the edit item dialog.
|
"""Open the edit item dialog.
|
||||||
"""
|
"""
|
||||||
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
tHandle = self.treeView.getSelectedHandle()
|
tHandle = self.treeView.getSelectedHandle()
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
@@ -703,6 +742,7 @@ class GuiMain(QMainWindow):
|
|||||||
"""Rebuild the entire index.
|
"""Rebuild the entire index.
|
||||||
"""
|
"""
|
||||||
if not self.hasProject:
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.debug("Rebuilding index ...")
|
logger.debug("Rebuilding index ...")
|
||||||
@@ -748,9 +788,14 @@ class GuiMain(QMainWindow):
|
|||||||
def rebuildOutline(self):
|
def rebuildOutline(self):
|
||||||
"""Force a rebuild of the Outline view.
|
"""Force a rebuild of the Outline view.
|
||||||
"""
|
"""
|
||||||
|
if not self.hasProject:
|
||||||
|
logger.error("No project open")
|
||||||
|
return False
|
||||||
|
|
||||||
logger.verbose("Forcing a rebuild of the Project Outline")
|
logger.verbose("Forcing a rebuild of the Project Outline")
|
||||||
self.tabWidget.setCurrentWidget(self.splitOutline)
|
self.tabWidget.setCurrentWidget(self.splitOutline)
|
||||||
self.projView.refreshTree(overRide=True)
|
self.projView.refreshTree(overRide=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user