Allow to disable ask on exit (#2213)

This commit is contained in:
Veronica Berglyd Olsen
2025-01-29 18:29:25 +01:00
committed by GitHub
5 changed files with 25 additions and 9 deletions
+3
View File
@@ -135,6 +135,7 @@ class Config:
self.emphLabels = True # Add emphasis to H1 and H2 item labels self.emphLabels = True # Add emphasis to H1 and H2 item labels
self.backupOnClose = False # Flag for running automatic backups self.backupOnClose = False # Flag for running automatic backups
self.askBeforeBackup = True # Flag for asking before running automatic backup self.askBeforeBackup = True # Flag for asking before running automatic backup
self.askBeforeExit = True # Flag for asking before exiting the app
# Text Editor Settings # Text Editor Settings
self.textFont = QFont() # Editor font self.textFont = QFont() # Editor font
@@ -628,6 +629,7 @@ class Config:
self._backupPath = conf.rdPath(sec, "backuppath", self._backupPath) self._backupPath = conf.rdPath(sec, "backuppath", self._backupPath)
self.backupOnClose = conf.rdBool(sec, "backuponclose", self.backupOnClose) self.backupOnClose = conf.rdBool(sec, "backuponclose", self.backupOnClose)
self.askBeforeBackup = conf.rdBool(sec, "askbeforebackup", self.askBeforeBackup) self.askBeforeBackup = conf.rdBool(sec, "askbeforebackup", self.askBeforeBackup)
self.askBeforeExit = conf.rdBool(sec, "askbeforeexit", self.askBeforeExit)
# Editor # Editor
sec = "Editor" sec = "Editor"
@@ -739,6 +741,7 @@ class Config:
"backuppath": str(self._backupPath), "backuppath": str(self._backupPath),
"backuponclose": str(self.backupOnClose), "backuponclose": str(self.backupOnClose),
"askbeforebackup": str(self.askBeforeBackup), "askbeforebackup": str(self.askBeforeBackup),
"askbeforeexit": str(self.askBeforeExit),
} }
conf["Editor"] = { conf["Editor"] = {
+14 -5
View File
@@ -271,10 +271,10 @@ class GuiPreferences(NDialog):
self.tr("Include project notes in status bar word count"), self.incNotesWCount self.tr("Include project notes in status bar word count"), self.incNotesWCount
) )
# Auto Save # Behaviour
# ========= # =========
title = self.tr("Auto Save") title = self.tr("Behaviour")
section += 1 section += 1
self.sidebar.addButton(title, section) self.sidebar.addButton(title, section)
self.mainForm.addGroupLabel(title, section) self.mainForm.addGroupLabel(title, section)
@@ -301,6 +301,14 @@ class GuiPreferences(NDialog):
self.tr("How often the project is automatically saved."), unit=self.tr("seconds") self.tr("How often the project is automatically saved."), unit=self.tr("seconds")
) )
# Ask before exiting novelWriter
self.askBeforeExit = NSwitch(self)
self.askBeforeExit.setChecked(CONFIG.askBeforeExit)
self.mainForm.addRow(
self.tr("Ask before exiting novelWriter"), self.askBeforeExit,
self.tr("Only applies when a project is open.")
)
# Project Backup # Project Backup
# ============== # ==============
@@ -927,9 +935,10 @@ class GuiPreferences(NDialog):
CONFIG.incNotesWCount = self.incNotesWCount.isChecked() CONFIG.incNotesWCount = self.incNotesWCount.isChecked()
CONFIG.setTextFont(self._textFont) CONFIG.setTextFont(self._textFont)
# Auto Save # Behaviour
CONFIG.autoSaveDoc = self.autoSaveDoc.value() CONFIG.autoSaveDoc = self.autoSaveDoc.value()
CONFIG.autoSaveProj = self.autoSaveProj.value() CONFIG.autoSaveProj = self.autoSaveProj.value()
CONFIG.askBeforeExit = self.askBeforeExit.isChecked()
# Project Backup # Project Backup
CONFIG.setBackupPath(self.backupPath) CONFIG.setBackupPath(self.backupPath)
+1 -1
View File
@@ -852,7 +852,7 @@ 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 not SHARED.question("%s<br>%s" % ( if SHARED.hasProject and CONFIG.askBeforeExit 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.")
)): )):
+2 -1
View File
@@ -1,5 +1,5 @@
[Meta] [Meta]
timestamp = 2025-01-26 18:17:44 timestamp = 2025-01-29 11:56:34
[Main] [Main]
font = font =
@@ -26,6 +26,7 @@ emphlabels = True
backuppath = backuppath =
backuponclose = False backuponclose = False
askbeforebackup = True askbeforebackup = True
askbeforeexit = True
[Editor] [Editor]
textfont = textfont =
+5 -2
View File
@@ -182,12 +182,14 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
assert CONFIG.showFullPath is True assert CONFIG.showFullPath is True
assert CONFIG.incNotesWCount is True assert CONFIG.incNotesWCount is True
# Auto Save # Behaviour
prefs.autoSaveDoc.stepUp() prefs.autoSaveDoc.stepUp()
prefs.autoSaveProj.stepUp() prefs.autoSaveProj.stepUp()
prefs.askBeforeExit.setChecked(False)
assert CONFIG.autoSaveDoc == 30 assert CONFIG.autoSaveDoc == 30
assert CONFIG.autoSaveProj == 60 assert CONFIG.autoSaveProj == 60
assert CONFIG.askBeforeExit is True
# Project Backup # Project Backup
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
@@ -333,9 +335,10 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
assert CONFIG.showFullPath is False assert CONFIG.showFullPath is False
assert CONFIG.incNotesWCount is False assert CONFIG.incNotesWCount is False
# Auto Save # Behaviour
assert CONFIG.autoSaveDoc == 31 assert CONFIG.autoSaveDoc == 31
assert CONFIG.autoSaveProj == 61 assert CONFIG.autoSaveProj == 61
assert CONFIG.askBeforeExit is False
# Project Backup # Project Backup
assert CONFIG._backupPath == tstPaths.testDir assert CONFIG._backupPath == tstPaths.testDir