Some reorganisation of how stuff is opened and closed.

This commit is contained in:
Veronica K. B. Olsen
2019-05-26 15:34:34 +02:00
parent 367d2c5014
commit 76cb03fad8
6 changed files with 52 additions and 45 deletions
+8 -1
View File
@@ -157,7 +157,7 @@ class GuiMainMenu(QMenuBar):
menuItem = QAction(QIcon.fromTheme("document-revert"), "Close Project", self)
menuItem.setStatusTip("Close Project")
menuItem.setShortcut("Ctrl+Shift+W")
menuItem.triggered.connect(self.theParent.closeProject)
menuItem.triggered.connect(lambda : self.theParent.closeProject(False))
self.projMenu.addAction(menuItem)
# Project > Recent Projects
@@ -253,6 +253,13 @@ class GuiMainMenu(QMenuBar):
menuItem.triggered.connect(self.theParent.saveDocument)
self.docuMenu.addAction(menuItem)
# Document > Close
menuItem = QAction(QIcon.fromTheme("document-revert"), "Close Document", self)
menuItem.setStatusTip("Close Current Document")
menuItem.setShortcut("Ctrl+W")
menuItem.triggered.connect(self.theParent.closeDocument)
self.docuMenu.addAction(menuItem)
# Document > Separator
self.docuMenu.addSeparator()
+28 -35
View File
@@ -216,16 +216,18 @@ class GuiMain(QMainWindow):
return True
def closeProject(self):
def closeProject(self, isYes=False):
"""Closes the project if one is open.
isYes is passed on from the close application event so the user doesn't get prompted twice.
"""
if not self.hasProject:
# There is no project loaded, everything OK
return True
if self.mainConf.showGUI:
if self.mainConf.showGUI and not isYes:
msgBox = QMessageBox()
msgRes = msgBox.question(
self, "Close Project",
"Close current project?<br>Unsaved changes will be saved."
self, "Close Project", "Save changes and close current project?"
)
if msgRes != QMessageBox.Yes:
return False
@@ -244,15 +246,19 @@ class GuiMain(QMainWindow):
return saveOK
def openProject(self, projFile=None):
"""Open a project.
projFile is passed from the open recent projects menu, so can be set. If not, we pop the dialog.
"""
if projFile is None:
projFile = self.openProjectDialog()
if projFile is None:
return False
# Make sure any open project is cleared out first before we load another one
if not self.closeProject():
return False
# Do the stuff
self.theProject.openProject(projFile)
self._setWindowTitle(self.theProject.projName)
self.rebuildTree()
@@ -260,6 +266,7 @@ class GuiMain(QMainWindow):
self.docEditor.setSpellCheck(self.theProject.spellCheck)
self.mainMenu.updateMenu()
# Restore previously open documents, if any
if self.theProject.lastEdited is not None:
self.openDocument(self.theProject.lastEdited)
if self.theProject.lastViewed is not None:
@@ -270,7 +277,9 @@ class GuiMain(QMainWindow):
return True
def saveProject(self):
"""Save the current project.
"""
# If the project is new, it may not have a path, so we need one
if self.theProject.projPath is None:
projPath = self.saveProjectDialog()
self.theProject.setProjectPath(projPath)
@@ -288,13 +297,15 @@ class GuiMain(QMainWindow):
##
def closeDocument(self):
self.saveDocument()
if self.docEditor.docChanged:
self.saveDocument()
self.theDocument.clearDocument()
self.docEditor.clearEditor()
self.theProject.setLastEdited(None)
return True
def openDocument(self, tHandle):
if self.docEditor.docChanged:
self.saveDocument()
self.closeDocument()
self.docEditor.setText(self.theDocument.openDocument(tHandle))
self.docEditor.setReadOnly(False)
self.docEditor.setCursorPosition(self.theDocument.theItem.cursorPos)
@@ -305,13 +316,13 @@ class GuiMain(QMainWindow):
def saveDocument(self):
if self.theDocument.theItem is not None:
docHtml = self.docEditor.getText()
docText = self.docEditor.getText()
cursPos = self.docEditor.getCursorPosition()
self.theDocument.theItem.setCharCount(self.docEditor.charCount)
self.theDocument.theItem.setWordCount(self.docEditor.wordCount)
self.theDocument.theItem.setParaCount(self.docEditor.paraCount)
self.theDocument.theItem.setCursorPos(cursPos)
self.theDocument.saveDocument(docHtml)
self.theDocument.saveDocument(docText)
self.docEditor.setDocumentChanged(False)
return True
@@ -440,18 +451,14 @@ class GuiMain(QMainWindow):
if self.mainConf.showGUI:
msgBox = QMessageBox()
msgRes = msgBox.question(
self, "Exit",
"Do you want to exit %s?" % nw.__package__
self, "Exit", "Do you want to save changes and exit?"
)
if msgRes != QMessageBox.Yes:
return False
logger.info("Exiting %s" % nw.__package__)
if self._takeDocumentAction():
self.saveDocument()
if self._takeProjectAction():
self.saveProject()
self.theProject.closeProject()
self.closeProject(True)
self.mainConf.setWinSize(self.width(), self.height())
self.mainConf.setTreeColWidths(self.treeView.getColumnSizes())
self.mainConf.setMainPanePos(self.splitMain.sizes())
@@ -493,31 +500,17 @@ class GuiMain(QMainWindow):
return True
def _autoSaveProject(self):
if self._takeProjectAction():
if self.hasProject and self.theProject.projChanged and self.theProject.projPath is not None:
logger.debug("Autosaving project")
self.saveProject()
return
def _autoSaveDocument(self):
if self._takeDocumentAction():
if self.hasProject and self.docEditor.docChanged and self.theDocument.theItem is not None:
logger.debug("Autosaving document")
self.saveDocument()
return
def _takeProjectAction(self):
if self.theProject.projPath is None:
return False
if not self.theProject.projChanged:
return False
return True
def _takeDocumentAction(self):
if self.theDocument.theItem is None:
return False
if not self.docEditor.docChanged:
return False
return True
def _makeStatusIcons(self):
self.statusIcons = {}
for sLabel, sCol, _ in self.theProject.statusItems:
+2 -2
View File
@@ -123,14 +123,14 @@ class NWProject():
##
def newProject(self):
hNovel = self.newRoot("Novel", nwItemClass.NOVEL)
hChars = self.newRoot("Characters", nwItemClass.CHARACTER)
hWorld = self.newRoot("Plot", nwItemClass.PLOT)
hWorld = self.newRoot("World", nwItemClass.WORLD)
hChapt = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel)
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt)
self.projOpened = time()
self.setProjectChanged(True)
return True
def clearProject(self):
@@ -13,7 +13,7 @@ Some text here would look good as well, and maybe some "dialogue"?
So, this is some __text__ that weve been adding to this document. It is utterly meaningless text, _but_ since this is just dummy text, that doesnt really matter. The text is perfectly happy to live in this document regardless.
This paragraph is also meaningless. At least a bit. Its also very short. But we could make it less meaningless if we wanted to …
This paragraph is also meaningless. At least a bit. Its also very short. But we could make it less meaningless if we wanted to … but we wont.
This one is a bit longer. “It also has some dialogue in it” she said, before she moved on to check if the spellchecker worked. It did. “Cool,” she concluded.
+7
View File
@@ -1,3 +1,10 @@
Start: 2019-05-26 14:28:28 End: 2019-05-26 14:28:38 Words: -23
Start: 2019-05-26 14:31:12 End: 2019-05-26 14:31:34 Words: 12
Start: 2019-05-26 14:33:27 End: 2019-05-26 14:33:31 Words: 0
Start: 2019-05-26 14:40:29 End: 2019-05-26 14:40:32 Words: 0
Start: 2019-05-26 14:40:43 End: 2019-05-26 14:40:46 Words: 0
Start: 2019-05-26 14:48:40 End: 2019-05-26 14:48:50 Words: 0
Start: 2019-05-26 14:50:18 End: 2019-05-26 14:50:21 Words: 0
Start: 2019-05-26 14:50:29 End: 2019-05-26 14:50:47 Words: 3
Start: 2019-05-26 15:10:52 End: 2019-05-26 15:11:09 Words: 0
Start: 2019-05-26 15:28:56 End: 2019-05-26 15:29:08 Words: 0
+6 -6
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.4" fileVersion="1.0" timeStamp="2019-05-26 14:33:31">
<novelWriterXML appVersion="0.1.4" fileVersion="1.0" timeStamp="2019-05-26 15:29:08">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
@@ -8,9 +8,9 @@
</project>
<settings>
<spellCheck>True</spellCheck>
<lastEdited>636b6aa9b697b</lastEdited>
<lastEdited>None</lastEdited>
<lastViewed>None</lastViewed>
<lastWordCount>535</lastWordCount>
<lastWordCount>538</lastWordCount>
<status>
<entry blue="100" green="100" red="100">New</entry>
<entry blue="0" green="50" red="200">Notes</entry>
@@ -73,10 +73,10 @@
<status>Notes</status>
<expanded>False</expanded>
<layout>SCENE</layout>
<charCount>633</charCount>
<wordCount>116</wordCount>
<charCount>647</charCount>
<wordCount>119</wordCount>
<paraCount>5</paraCount>
<cursorPos>551</cursorPos>
<cursorPos>565</cursorPos>
</item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>New File</name>