Let the shared class handle alert dialogs
This commit is contained in:
@@ -25,7 +25,6 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from pathlib import Path
|
||||
|
||||
from PyQt5.QtCore import QSize, QTimer, Qt, pyqtSlot
|
||||
@@ -36,7 +35,7 @@ from PyQt5.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.enum import nwAlert, nwBuildFmt
|
||||
from novelwriter.enum import nwBuildFmt
|
||||
from novelwriter.common import makeFileNameSafe
|
||||
from novelwriter.constants import nwLabels
|
||||
from novelwriter.core.item import NWItem
|
||||
@@ -44,9 +43,6 @@ from novelwriter.core.docbuild import NWBuildDocument
|
||||
from novelwriter.core.buildsettings import BuildSettings
|
||||
from novelwriter.extensions.simpleprogress import NProgressSimple
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from novelwriter.guimain import GuiMain
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -59,14 +55,12 @@ class GuiManuscriptBuild(QDialog):
|
||||
|
||||
D_KEY = Qt.ItemDataRole.UserRole
|
||||
|
||||
def __init__(self, parent: QWidget, mainGui: GuiMain, build: BuildSettings):
|
||||
def __init__(self, parent: QWidget, build: BuildSettings):
|
||||
super().__init__(parent=parent)
|
||||
|
||||
logger.debug("Create: GuiManuscriptBuild")
|
||||
self.setObjectName("GuiManuscriptBuild")
|
||||
|
||||
self.mainGui = mainGui
|
||||
|
||||
self._parent = parent
|
||||
self._build = build
|
||||
|
||||
@@ -308,14 +302,14 @@ class GuiManuscriptBuild(QDialog):
|
||||
self.buildProgress.setValue(0)
|
||||
bPath = Path(self.buildPath.text())
|
||||
if not bPath.is_dir():
|
||||
self.mainGui.makeAlert(self.tr("Output folder does not exist."), level=nwAlert.ERROR)
|
||||
SHARED.error(self.tr("Output folder does not exist."))
|
||||
return False
|
||||
|
||||
bExt = nwLabels.BUILD_EXT[bFormat]
|
||||
buildPath = (bPath / makeFileNameSafe(bName)).with_suffix(bExt)
|
||||
|
||||
if buildPath.exists():
|
||||
if not self.mainGui.askQuestion(
|
||||
if not SHARED.question(
|
||||
self.tr("The file already exists. Do you want to overwrite it?")
|
||||
):
|
||||
return False
|
||||
|
||||
@@ -268,7 +268,7 @@ class GuiManuscript(QDialog):
|
||||
"""Delete the currently selected build settings entry."""
|
||||
build = self._getSelectedBuild()
|
||||
if build is not None:
|
||||
if self.mainGui.askQuestion(self.tr("Delete build '{0}'?".format(build.name))):
|
||||
if SHARED.question(self.tr("Delete build '{0}'?".format(build.name))):
|
||||
self._builds.removeBuild(build.buildID)
|
||||
self._updateBuildsList()
|
||||
return
|
||||
@@ -325,7 +325,7 @@ class GuiManuscript(QDialog):
|
||||
"""Open the build dialog and build the manuscript."""
|
||||
build = self._getSelectedBuild()
|
||||
if isinstance(build, BuildSettings):
|
||||
dlgBuild = GuiManuscriptBuild(self, self.mainGui, build)
|
||||
dlgBuild = GuiManuscriptBuild(self, build)
|
||||
dlgBuild.exec_()
|
||||
|
||||
# After the build is done, save build settings changes
|
||||
|
||||
@@ -76,8 +76,6 @@ class GuiBuildSettings(QDialog):
|
||||
if CONFIG.osDarwin:
|
||||
self.setWindowFlag(Qt.WindowType.Tool)
|
||||
|
||||
self.mainGui = mainGui
|
||||
|
||||
self._build = build
|
||||
|
||||
self.setWindowTitle(self.tr("Manuscript Build Settings"))
|
||||
@@ -245,7 +243,7 @@ class GuiBuildSettings(QDialog):
|
||||
whether the user wants to save them.
|
||||
"""
|
||||
if self._build.changed:
|
||||
response = self.mainGui.askQuestion(self.tr(
|
||||
response = SHARED.question(self.tr(
|
||||
"Do you want to save your changes to '{0}'?".format(self._build.name)
|
||||
))
|
||||
if response:
|
||||
|
||||
@@ -37,7 +37,6 @@ from PyQt5.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.enum import nwAlert
|
||||
from novelwriter.error import formatException
|
||||
from novelwriter.common import formatTime, checkInt, checkIntTuple, minmax
|
||||
from novelwriter.constants import nwConst
|
||||
@@ -72,8 +71,6 @@ class GuiWritingStats(QDialog):
|
||||
if CONFIG.osDarwin:
|
||||
self.setWindowFlag(Qt.WindowType.Tool)
|
||||
|
||||
self.mainGui = mainGui
|
||||
|
||||
self.logData = []
|
||||
self.filterData = []
|
||||
self.timeFilter = 0.0
|
||||
@@ -413,14 +410,14 @@ class GuiWritingStats(QDialog):
|
||||
|
||||
# Report to user
|
||||
if wSuccess:
|
||||
self.mainGui.makeAlert(
|
||||
SHARED.info(
|
||||
self.tr("{0} file successfully written to:").format(textFmt),
|
||||
info=savePath
|
||||
)
|
||||
else:
|
||||
self.mainGui.makeAlert(
|
||||
SHARED.error(
|
||||
self.tr("Failed to write {0} file.").format(textFmt),
|
||||
info=errMsg, level=nwAlert.ERROR
|
||||
info=errMsg
|
||||
)
|
||||
|
||||
return wSuccess
|
||||
|
||||
Reference in New Issue
Block a user