diff --git a/novelwriter/enum.py b/novelwriter/enum.py index 1bb85120..4db5cdce 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -262,3 +262,4 @@ class nwStandardButton(Enum): LIST = 7 NEW = 8 CREATE = 9 + RESET = 10 diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 9b3c10d4..441c9cd1 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -57,16 +57,17 @@ STYLES_MIN_TOOLBUTTON = "minimalToolButton" STYLES_BIG_TOOLBUTTON = "bigToolButton" STANDARD_BUTTONS = { - nwStandardButton.OK: (QT_TRANSLATE_NOOP("Button", "OK"), "bullet-on", "blue"), - nwStandardButton.CANCEL: (QT_TRANSLATE_NOOP("Button", "Cancel"), "cancel", "red"), - nwStandardButton.YES: (QT_TRANSLATE_NOOP("Button", "Yes"), "bullet-on", "green"), - nwStandardButton.NO: (QT_TRANSLATE_NOOP("Button", "No"), "bullet-on", "red"), - nwStandardButton.OPEN: (QT_TRANSLATE_NOOP("Button", "Open"), "open", "blue"), - nwStandardButton.CLOSE: (QT_TRANSLATE_NOOP("Button", "Close"), "close", "default"), - nwStandardButton.BROWSE: (QT_TRANSLATE_NOOP("Button", "Browse"), "browse", "yellow"), - nwStandardButton.LIST: (QT_TRANSLATE_NOOP("Button", "List"), "list", "blue"), - nwStandardButton.NEW: (QT_TRANSLATE_NOOP("Button", "New"), "add", "green"), - nwStandardButton.CREATE: (QT_TRANSLATE_NOOP("Button", "Create"), "star", "yellow"), + nwStandardButton.OK: (QT_TRANSLATE_NOOP("Button", "OK"), "btn_ok", "blue"), + nwStandardButton.CANCEL: (QT_TRANSLATE_NOOP("Button", "Cancel"), "btn_cancel", "red"), + nwStandardButton.YES: (QT_TRANSLATE_NOOP("Button", "Yes"), "btn_yes", "green"), + nwStandardButton.NO: (QT_TRANSLATE_NOOP("Button", "No"), "btn_no", "red"), + nwStandardButton.OPEN: (QT_TRANSLATE_NOOP("Button", "Open"), "btn_open", "blue"), + nwStandardButton.CLOSE: (QT_TRANSLATE_NOOP("Button", "Close"), "btn_close", "red"), + nwStandardButton.BROWSE: (QT_TRANSLATE_NOOP("Button", "Browse"), "btn_browse", "yellow"), + nwStandardButton.LIST: (QT_TRANSLATE_NOOP("Button", "List"), "btn_list", "blue"), + nwStandardButton.NEW: (QT_TRANSLATE_NOOP("Button", "New"), "btn_new", "green"), + nwStandardButton.CREATE: (QT_TRANSLATE_NOOP("Button", "Create"), "btn_create", "yellow"), + nwStandardButton.RESET: (QT_TRANSLATE_NOOP("Button", "Reset"), "btn_reset", "green"), } diff --git a/novelwriter/shared.py b/novelwriter/shared.py index 7c971341..be439b48 100644 --- a/novelwriter/shared.py +++ b/novelwriter/shared.py @@ -34,12 +34,12 @@ from typing import TYPE_CHECKING, TypeVar from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot from PyQt6.QtGui import QDesktopServices, QFont, QScreen -from PyQt6.QtWidgets import QApplication, QFileDialog, QFontDialog, QMessageBox, QWidget +from PyQt6.QtWidgets import QApplication, QDialog, QFileDialog, QFontDialog, QMessageBox, QWidget from novelwriter.common import formatFileFilter from novelwriter.constants import nwFiles from novelwriter.core.spellcheck import NWSpellEnchant -from novelwriter.enum import nwChange, nwItemClass +from novelwriter.enum import nwChange, nwItemClass, nwStandardButton if TYPE_CHECKING: from collections.abc import Callable @@ -422,7 +422,7 @@ class SharedData(QObject): alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True) self._lastAlert = alert.logMessage alert.exec() - return alert.result() == QMessageBox.StandardButton.Yes + return alert.finalState ## # Internal Functions @@ -469,6 +469,7 @@ class _GuiAlert(QMessageBox): super().__init__(parent=parent) self._theme = theme self._message = "" + self._state = False logger.debug("Ready: _GuiAlert") def __del__(self) -> None: # pragma: no cover @@ -478,6 +479,10 @@ class _GuiAlert(QMessageBox): def logMessage(self) -> str: return self._message + @property + def finalState(self) -> bool: + return self._state + def setMessage(self, text: str, info: str, details: str) -> None: """Set the alert box message.""" self._message = " ".join(filter(None, [text, info, details])) @@ -496,9 +501,17 @@ class _GuiAlert(QMessageBox): Yes/No buttons or just an Ok button. """ if isYesNo: - self.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) + self._btnYes = self._theme.getStandardButton(nwStandardButton.YES, self) + self._btnYes.clicked.connect(self._onAccept) + self._btnNo = self._theme.getStandardButton(nwStandardButton.NO, self) + self._btnNo.clicked.connect(self._onReject) + self.addButton(self._btnYes, QMessageBox.ButtonRole.YesRole) + self.addButton(self._btnNo, QMessageBox.ButtonRole.NoRole) else: - self.setStandardButtons(QMessageBox.StandardButton.Ok) + self._btnOk = self._theme.getStandardButton(nwStandardButton.OK, self) + self._btnOk.clicked.connect(self._onAccept) + self.addButton(self._btnOk, QMessageBox.ButtonRole.AcceptRole) + pSz = 2*self._theme.baseIconHeight if level == self.INFO: self.setIconPixmap(self._theme.getPixmap("alert_info", (pSz, pSz), "blue")) @@ -512,3 +525,15 @@ class _GuiAlert(QMessageBox): elif level == self.ASK: self.setIconPixmap(self._theme.getPixmap("alert_question", (pSz, pSz), "blue")) self.setWindowTitle(self.tr("Question")) + + @pyqtSlot() + def _onAccept(self) -> None: + """Process accepted state.""" + self._state = True + self.close() + + @pyqtSlot() + def _onReject(self) -> None: + """Process rejected state.""" + self._state = False + self.setResult(QDialog.DialogCode.Rejected)