Convert Preferences dialog to save/cancel like Project Settings
This commit is contained in:
@@ -29,8 +29,8 @@ import logging
|
||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||
from PyQt5.QtGui import QCloseEvent, QKeyEvent, QKeySequence
|
||||
from PyQt5.QtWidgets import (
|
||||
QAbstractButton, QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout,
|
||||
QLineEdit, QPushButton, QVBoxLayout, QWidget
|
||||
QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QLineEdit,
|
||||
QPushButton, QVBoxLayout, QWidget
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
@@ -43,10 +43,7 @@ from novelwriter.extensions.modified import (
|
||||
)
|
||||
from novelwriter.extensions.pagedsidebar import NPagedSideBar
|
||||
from novelwriter.extensions.switch import NSwitch
|
||||
from novelwriter.types import (
|
||||
QtAlignCenter, QtDialogApply, QtDialogClose, QtDialogSave, QtRoleAccept,
|
||||
QtRoleApply, QtRoleReject
|
||||
)
|
||||
from novelwriter.types import QtAlignCenter, QtDialogCancel, QtDialogSave
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -89,8 +86,9 @@ class GuiPreferences(NDialog):
|
||||
self.mainForm.setHelpTextStyle(SHARED.theme.helpText)
|
||||
|
||||
# Buttons
|
||||
self.buttonBox = QDialogButtonBox(QtDialogApply | QtDialogSave | QtDialogClose, self)
|
||||
self.buttonBox.clicked.connect(self._dialogButtonClicked)
|
||||
self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogCancel, self)
|
||||
self.buttonBox.accepted.connect(self._doSave)
|
||||
self.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
# Assemble
|
||||
self.searchBox = QHBoxLayout()
|
||||
@@ -784,19 +782,6 @@ class GuiPreferences(NDialog):
|
||||
# Private Slots
|
||||
##
|
||||
|
||||
@pyqtSlot("QAbstractButton*")
|
||||
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
|
||||
"""Handle button clicks from the dialog button box."""
|
||||
role = self.buttonBox.buttonRole(button)
|
||||
if role == QtRoleApply:
|
||||
self._saveValues()
|
||||
elif role == QtRoleAccept:
|
||||
self._saveValues()
|
||||
self.close()
|
||||
elif role == QtRoleReject:
|
||||
self.close()
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def _sidebarClicked(self, section: int) -> None:
|
||||
"""Process a user request to switch page."""
|
||||
@@ -897,7 +882,7 @@ class GuiPreferences(NDialog):
|
||||
CONFIG.setPreferencesWinSize(self.width(), self.height())
|
||||
return
|
||||
|
||||
def _saveValues(self) -> None:
|
||||
def _doSave(self) -> None:
|
||||
"""Save the values set in the form."""
|
||||
updateTheme = False
|
||||
needsRestart = False
|
||||
@@ -1012,4 +997,6 @@ class GuiPreferences(NDialog):
|
||||
CONFIG.saveConfig()
|
||||
self.newPreferencesReady.emit(needsRestart, refreshTree, updateTheme, updateSyntax)
|
||||
|
||||
self.close()
|
||||
|
||||
return
|
||||
|
||||
@@ -30,7 +30,7 @@ from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.constants import nwUnicode
|
||||
from novelwriter.dialogs.preferences import GuiPreferences
|
||||
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
||||
from novelwriter.types import QtDialogApply, QtDialogClose, QtDialogSave, QtModNone
|
||||
from novelwriter.types import QtDialogCancel, QtDialogSave, QtModNone
|
||||
|
||||
KEY_DELAY = 1
|
||||
|
||||
@@ -116,12 +116,6 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
|
||||
prefs._gotoSearch()
|
||||
assert value.args[0] < old
|
||||
|
||||
# Check Apply Button
|
||||
prefs.show()
|
||||
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
||||
prefs.buttonBox.button(QtDialogApply).click()
|
||||
assert signal.args == [False, False, False, False]
|
||||
|
||||
# Check Save Button
|
||||
prefs.show()
|
||||
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
||||
@@ -130,7 +124,7 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
|
||||
|
||||
# Check Close Button
|
||||
prefs.show()
|
||||
prefs.buttonBox.button(QtDialogClose).click()
|
||||
prefs.buttonBox.button(QtDialogCancel).click()
|
||||
assert prefs.isHidden() is True
|
||||
|
||||
# Close Using Escape Key
|
||||
@@ -315,7 +309,7 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QFontDatabase, "families", lambda *a: ["TestFont"])
|
||||
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
||||
prefs.buttonBox.button(QtDialogApply).click()
|
||||
prefs.buttonBox.button(QtDialogSave).click()
|
||||
assert signal.args == [True, True, True, True]
|
||||
|
||||
# Check Settings
|
||||
|
||||
Reference in New Issue
Block a user