Fix closing app with no project bug
This commit is contained in:
+18
-18
@@ -845,33 +845,33 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
def closeMain(self) -> bool:
|
def closeMain(self) -> bool:
|
||||||
"""Save everything, and close novelWriter."""
|
"""Save everything, and close novelWriter."""
|
||||||
if SHARED.hasProject and SHARED.question("%s<br>%s" % (
|
if SHARED.hasProject and not SHARED.question("%s<br>%s" % (
|
||||||
self.tr("Do you want to exit novelWriter?"),
|
self.tr("Do you want to exit novelWriter?"),
|
||||||
self.tr("Changes are saved automatically.")
|
self.tr("Changes are saved automatically.")
|
||||||
)):
|
)):
|
||||||
logger.info("Exiting novelWriter")
|
return False
|
||||||
|
|
||||||
if not SHARED.focusMode:
|
logger.info("Exiting novelWriter")
|
||||||
CONFIG.setMainPanePos(self.splitMain.sizes())
|
|
||||||
CONFIG.setOutlinePanePos(self.outlineView.splitSizes())
|
|
||||||
if self.docViewerPanel.isVisible():
|
|
||||||
CONFIG.setViewPanePos(self.splitView.sizes())
|
|
||||||
|
|
||||||
CONFIG.showViewerPanel = self.docViewerPanel.isVisible()
|
if not SHARED.focusMode:
|
||||||
wFull = Qt.WindowState.WindowFullScreen
|
CONFIG.setMainPanePos(self.splitMain.sizes())
|
||||||
if self.windowState() & wFull != wFull:
|
CONFIG.setOutlinePanePos(self.outlineView.splitSizes())
|
||||||
# Ignore window size if in full screen mode
|
if self.docViewerPanel.isVisible():
|
||||||
CONFIG.setMainWinSize(self.width(), self.height())
|
CONFIG.setViewPanePos(self.splitView.sizes())
|
||||||
|
|
||||||
if SHARED.hasProject:
|
CONFIG.showViewerPanel = self.docViewerPanel.isVisible()
|
||||||
self.closeProject(True)
|
wFull = Qt.WindowState.WindowFullScreen
|
||||||
CONFIG.saveConfig()
|
if self.windowState() & wFull != wFull:
|
||||||
|
# Ignore window size if in full screen mode
|
||||||
|
CONFIG.setMainWinSize(self.width(), self.height())
|
||||||
|
|
||||||
QApplication.quit()
|
if SHARED.hasProject:
|
||||||
|
self.closeProject(True)
|
||||||
|
CONFIG.saveConfig()
|
||||||
|
|
||||||
return True
|
QApplication.quit()
|
||||||
|
|
||||||
return False
|
return True
|
||||||
|
|
||||||
def closeViewerPanel(self, byUser: bool = True) -> bool:
|
def closeViewerPanel(self, byUser: bool = True) -> bool:
|
||||||
"""Close the document view panel."""
|
"""Close the document view panel."""
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
|
|
||||||
# Defaults w/None Args
|
# Defaults w/None Args
|
||||||
nwGUI = main()
|
nwGUI = main()
|
||||||
|
assert nwGUI is not None
|
||||||
assert logger.getEffectiveLevel() == logging.WARNING
|
assert logger.getEffectiveLevel() == logging.WARNING
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", f"--config={fncPath}", f"--data={fncPath}", "--style=Fusion"]
|
["--testmode", f"--config={fncPath}", f"--data={fncPath}", "--style=Fusion"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert logger.getEffectiveLevel() == logging.WARNING
|
assert logger.getEffectiveLevel() == logging.WARNING
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
|
|
||||||
@@ -99,12 +101,14 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", "--info", f"--config={fncPath}", f"--data={fncPath}"]
|
["--testmode", "--info", f"--config={fncPath}", f"--data={fncPath}"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert logger.getEffectiveLevel() == logging.INFO
|
assert logger.getEffectiveLevel() == logging.INFO
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
|
|
||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", "--debug", f"--config={fncPath}", f"--data={fncPath}"]
|
["--testmode", "--debug", f"--config={fncPath}", f"--data={fncPath}"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert logger.getEffectiveLevel() == logging.DEBUG
|
assert logger.getEffectiveLevel() == logging.DEBUG
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
|
|
||||||
@@ -113,6 +117,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", "--help", f"--config={fncPath}", f"--data={fncPath}"]
|
["--testmode", "--help", f"--config={fncPath}", f"--data={fncPath}"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
assert ex.value.code == 0
|
assert ex.value.code == 0
|
||||||
|
|
||||||
@@ -120,6 +125,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", "--version", f"--config={fncPath}", f"--data={fncPath}"]
|
["--testmode", "--version", f"--config={fncPath}", f"--data={fncPath}"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
assert ex.value.code == 0
|
assert ex.value.code == 0
|
||||||
|
|
||||||
@@ -128,6 +134,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", "--invalid", f"--config={fncPath}", f"--data={fncPath}"]
|
["--testmode", "--invalid", f"--config={fncPath}", f"--data={fncPath}"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
assert ex.value.code == 2
|
assert ex.value.code == 2
|
||||||
|
|
||||||
@@ -135,6 +142,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
|||||||
nwGUI = main(
|
nwGUI = main(
|
||||||
["--testmode", f"--config={fncPath}", f"--data={fncPath}", "sample/"]
|
["--testmode", f"--config={fncPath}", f"--data={fncPath}", "sample/"]
|
||||||
)
|
)
|
||||||
|
assert nwGUI is not None
|
||||||
assert nwGUI.closeMain() == "closeMain"
|
assert nwGUI.closeMain() == "closeMain"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,13 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
|
|||||||
assert nwGUI.openProject(projPath) is True
|
assert nwGUI.openProject(projPath) is True
|
||||||
nwGUI.closeProject()
|
nwGUI.closeProject()
|
||||||
|
|
||||||
|
# Check that closes can be blocked
|
||||||
|
with monkeypatch.context() as mp:
|
||||||
|
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
|
||||||
|
assert nwGUI.openProject(projPath) is True
|
||||||
|
assert nwGUI.closeMain() is False
|
||||||
|
nwGUI.closeProject()
|
||||||
|
|
||||||
# Check that latest release info updated
|
# Check that latest release info updated
|
||||||
assert CONFIG.lastNotes != "0x0"
|
assert CONFIG.lastNotes != "0x0"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user