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:
|
||||
"""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("Changes are saved automatically.")
|
||||
)):
|
||||
logger.info("Exiting novelWriter")
|
||||
return False
|
||||
|
||||
if not SHARED.focusMode:
|
||||
CONFIG.setMainPanePos(self.splitMain.sizes())
|
||||
CONFIG.setOutlinePanePos(self.outlineView.splitSizes())
|
||||
if self.docViewerPanel.isVisible():
|
||||
CONFIG.setViewPanePos(self.splitView.sizes())
|
||||
logger.info("Exiting novelWriter")
|
||||
|
||||
CONFIG.showViewerPanel = self.docViewerPanel.isVisible()
|
||||
wFull = Qt.WindowState.WindowFullScreen
|
||||
if self.windowState() & wFull != wFull:
|
||||
# Ignore window size if in full screen mode
|
||||
CONFIG.setMainWinSize(self.width(), self.height())
|
||||
if not SHARED.focusMode:
|
||||
CONFIG.setMainPanePos(self.splitMain.sizes())
|
||||
CONFIG.setOutlinePanePos(self.outlineView.splitSizes())
|
||||
if self.docViewerPanel.isVisible():
|
||||
CONFIG.setViewPanePos(self.splitView.sizes())
|
||||
|
||||
if SHARED.hasProject:
|
||||
self.closeProject(True)
|
||||
CONFIG.saveConfig()
|
||||
CONFIG.showViewerPanel = self.docViewerPanel.isVisible()
|
||||
wFull = Qt.WindowState.WindowFullScreen
|
||||
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:
|
||||
"""Close the document view panel."""
|
||||
|
||||
@@ -85,6 +85,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
|
||||
# Defaults w/None Args
|
||||
nwGUI = main()
|
||||
assert nwGUI is not None
|
||||
assert logger.getEffectiveLevel() == logging.WARNING
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
|
||||
@@ -92,6 +93,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
nwGUI = main(
|
||||
["--testmode", f"--config={fncPath}", f"--data={fncPath}", "--style=Fusion"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert logger.getEffectiveLevel() == logging.WARNING
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
|
||||
@@ -99,12 +101,14 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
nwGUI = main(
|
||||
["--testmode", "--info", f"--config={fncPath}", f"--data={fncPath}"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert logger.getEffectiveLevel() == logging.INFO
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
|
||||
nwGUI = main(
|
||||
["--testmode", "--debug", f"--config={fncPath}", f"--data={fncPath}"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert logger.getEffectiveLevel() == logging.DEBUG
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
|
||||
@@ -113,6 +117,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
nwGUI = main(
|
||||
["--testmode", "--help", f"--config={fncPath}", f"--data={fncPath}"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
assert ex.value.code == 0
|
||||
|
||||
@@ -120,6 +125,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
nwGUI = main(
|
||||
["--testmode", "--version", f"--config={fncPath}", f"--data={fncPath}"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
assert ex.value.code == 0
|
||||
|
||||
@@ -128,6 +134,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
nwGUI = main(
|
||||
["--testmode", "--invalid", f"--config={fncPath}", f"--data={fncPath}"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
assert ex.value.code == 2
|
||||
|
||||
@@ -135,6 +142,7 @@ def testBaseInit_Options(monkeypatch, fncPath):
|
||||
nwGUI = main(
|
||||
["--testmode", f"--config={fncPath}", f"--data={fncPath}", "sample/"]
|
||||
)
|
||||
assert nwGUI is not None
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
|
||||
|
||||
|
||||
@@ -100,6 +100,13 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
|
||||
assert nwGUI.openProject(projPath) is True
|
||||
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
|
||||
assert CONFIG.lastNotes != "0x0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user