Use the main gui askQuestion function for yes/no dialogs

This commit is contained in:
Veronica K. B. Olsen
2020-12-19 20:21:43 +01:00
parent 5b746af4bd
commit 8d71ee30d4
5 changed files with 37 additions and 49 deletions
+4 -4
View File
@@ -471,14 +471,14 @@ class NWProject():
# read the file. Introduced in version 0.10. # read the file. Introduced in version 0.10.
if fileVersion == "1.0": if fileVersion == "1.0":
msgRes = self.theParent.askQuestion("Old Project Version", ( msgYes = self.theParent.askQuestion("Old Project Version", (
"The project file and data is created by a novelWriter version " "The project file and data is created by a novelWriter version "
"lower than 0.7. Do you want to upgrade the project to the " "lower than 0.7. Do you want to upgrade the project to the "
"most recent format?<br><br>Note that after the upgrade, you " "most recent format?<br><br>Note that after the upgrade, you "
"cannot open the project with an older version of novelWriter " "cannot open the project with an older version of novelWriter "
"any more, so make sure you have a recent backup." "any more, so make sure you have a recent backup."
)) ))
if not msgRes: if not msgYes:
self.clearProject() self.clearProject()
return False return False
@@ -497,7 +497,7 @@ class NWProject():
# ========================= # =========================
if int(hexVersion, 16) > int(nw.__hexversion__, 16): if int(hexVersion, 16) > int(nw.__hexversion__, 16):
msgRes = self.theParent.askQuestion("Version Conflict", ( msgYes = self.theParent.askQuestion("Version Conflict", (
"This project was saved by a newer version of novelWriter, version %s. " "This project was saved by a newer version of novelWriter, version %s. "
"This is version %s. If you continue to open the project, some attributes " "This is version %s. If you continue to open the project, some attributes "
"and settings may not be preserved, but the overall project should be fine. " "and settings may not be preserved, but the overall project should be fine. "
@@ -505,7 +505,7 @@ class NWProject():
) % ( ) % (
appVersion, nw.__version__ appVersion, nw.__version__
)) ))
if not msgRes: if not msgYes:
self.clearProject() self.clearProject()
return False return False
+7 -10
View File
@@ -31,7 +31,7 @@ import logging
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QComboBox, QListWidget, QAbstractItemView, QDialog, QVBoxLayout, QComboBox, QListWidget, QAbstractItemView,
QListWidgetItem, QDialogButtonBox, QLabel, QMessageBox QListWidgetItem, QDialogButtonBox, QLabel
) )
from nw.core import NWDoc from nw.core import NWDoc
@@ -163,15 +163,12 @@ class GuiDocSplit(QDialog):
), nwAlert.ERROR) ), nwAlert.ERROR)
return return
msgBox = QMessageBox() msgYes = self.theParent.askQuestion("Split Document", (
msgRes = msgBox.question( "The document will be split into %d file(s) in a new folder. "
self, "Split Document", ( "The original document will remain intact.<br><br>"
"The document will be split into %d file(s) in a new folder. " "Continue with the splitting process?"
"The original document will remain intact.<br><br>" ) % nFiles)
"Continue with the splitting process?" if not msgYes:
) % nFiles
)
if msgRes != QMessageBox.Yes:
return return
# Create the folder # Create the folder
+4 -5
View File
@@ -36,7 +36,7 @@ from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QTreeWidget, QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QTreeWidget,
QAbstractItemView, QTreeWidgetItem, QDialogButtonBox, QLabel, QShortcut, QAbstractItemView, QTreeWidgetItem, QDialogButtonBox, QLabel, QShortcut,
QFileDialog, QLineEdit, QMessageBox QFileDialog, QLineEdit
) )
from nw.common import formatInt from nw.common import formatInt
@@ -218,12 +218,11 @@ class GuiProjectLoad(QDialog):
""" """
selList = self.listBox.selectedItems() selList = self.listBox.selectedItems()
if selList: if selList:
msgBox = QMessageBox() msgYes = self.theParent.askQuestion(
msgRes = msgBox.question( "Remove Entry",
self, "Remove Entry",
"Remove the selected entry from the recent projects list?" "Remove the selected entry from the recent projects list?"
) )
if msgRes == QMessageBox.Yes: if msgYes:
self.mainConf.removeFromRecentCache( self.mainConf.removeFromRecentCache(
selList[0].data(self.C_NAME, Qt.UserRole) selList[0].data(self.C_NAME, Qt.UserRole)
) )
+11 -15
View File
@@ -32,8 +32,7 @@ import logging
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
qApp, QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMessageBox, qApp, QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMenu, QAction
QMenu, QAction
) )
from nw.core import NWDoc from nw.core import NWDoc
@@ -391,13 +390,12 @@ class GuiProjectTree(QTreeWidget):
self.makeAlert("The Trash folder is already empty.", nwAlert.INFO) self.makeAlert("The Trash folder is already empty.", nwAlert.INFO)
return False return False
msgBox = QMessageBox() msgYes = self.theParent.askQuestion(
msgRes = msgBox.question( "Empty Trash", "Permanently delete %d file%s from Trash?" % (
self, "Empty Trash", "Permanently delete %d file%s from Trash?" % (
nTrash, "s" if nTrash > 1 else "" nTrash, "s" if nTrash > 1 else ""
) )
) )
if msgRes != QMessageBox.Yes: if not msgYes:
return False return False
logger.verbose("Deleting %d files from Trash" % nTrash) logger.verbose("Deleting %d files from Trash" % nTrash)
@@ -449,11 +447,10 @@ class GuiProjectTree(QTreeWidget):
# user if they want to permanently delete the file. # user if they want to permanently delete the file.
doPermanent = False doPermanent = False
if not alreadyAsked: if not alreadyAsked:
msgBox = QMessageBox() msgYes = self.theParent.askQuestion(
msgRes = msgBox.question( "Delete File", "Permanently delete file '%s'?" % nwItemS.itemName
self, "Delete File", "Permanently delete file '%s'?" % nwItemS.itemName
) )
if msgRes == QMessageBox.Yes: if msgYes:
doPermanent = True doPermanent = True
else: else:
doPermanent = True doPermanent = True
@@ -478,11 +475,10 @@ class GuiProjectTree(QTreeWidget):
# move it there. # move it there.
doTrash = False doTrash = False
if askForTrash: if askForTrash:
msgBox = QMessageBox() msgYes = self.theParent.askQuestion(
msgRes = msgBox.question( "Delete File", "Move file '%s' to Trash?" % nwItemS.itemName
self, "Delete File", "Move file '%s' to Trash?" % nwItemS.itemName
) )
if msgRes == QMessageBox.Yes: if msgYes:
doTrash = True doTrash = True
else: else:
doTrash = True doTrash = True
@@ -1122,7 +1118,7 @@ class GuiProjectTreeMenu(QMenu):
return return
def _doEmptyTrash(self): def _doEmptyTrash(self):
"""Forward the delete item call to the project tree. """Forward the empty trash call to the project tree.
""" """
self.theTree.emptyTrash() self.theTree.emptyTrash()
return return
+11 -15
View File
@@ -320,12 +320,11 @@ class GuiMain(QMainWindow):
return True return True
if not isYes: if not isYes:
msgBox = QMessageBox() msgYes = self.askQuestion(
msgRes = msgBox.question( "Close Project",
self, "Close Project",
"Close the current project?<br>Changes are saved automatically." "Close the current project?<br>Changes are saved automatically."
) )
if msgRes != QMessageBox.Yes: if not msgYes:
return False return False
if self.docEditor.docChanged: if self.docEditor.docChanged:
@@ -337,11 +336,10 @@ class GuiMain(QMainWindow):
if self.theProject.doBackup and self.mainConf.backupOnClose: if self.theProject.doBackup and self.mainConf.backupOnClose:
doBackup = True doBackup = True
if self.mainConf.askBeforeBackup: if self.mainConf.askBeforeBackup:
msgBox = QMessageBox() msgYes = self.askQuestion(
msgRes = msgBox.question( "Backup Project", "Backup the current project?"
self, "Backup Project", "Backup the current project?"
) )
if msgRes != QMessageBox.Yes: if not msgYes:
doBackup = False doBackup = False
if doBackup: if doBackup:
self.theProject.zipIt(False) self.theProject.zipIt(False)
@@ -640,12 +638,11 @@ class GuiMain(QMainWindow):
return False return False
if not self.docEditor.isEmpty(): if not self.docEditor.isEmpty():
msgBox = QMessageBox() msgYes = self.askQuestion("Import Document", (
msgRes = msgBox.question(self, "Import Document", (
"Importing the file will overwrite the current content of the document. " "Importing the file will overwrite the current content of the document. "
"Do you want to proceed?" "Do you want to proceed?"
)) ))
if msgRes != QMessageBox.Yes: if not msgYes:
return False return False
self.docEditor.replaceText(theText) self.docEditor.replaceText(theText)
@@ -1007,12 +1004,11 @@ class GuiMain(QMainWindow):
"""Save everything, and close novelWriter. """Save everything, and close novelWriter.
""" """
if self.hasProject: if self.hasProject:
msgBox = QMessageBox() msgYes = self.askQuestion(
msgRes = msgBox.question( "Exit",
self, "Exit",
"Do you want to exit novelWriter?<br>Changes are saved automatically." "Do you want to exit novelWriter?<br>Changes are saved automatically."
) )
if msgRes != QMessageBox.Yes: if not msgYes:
return False return False
logger.info("Exiting novelWriter") logger.info("Exiting novelWriter")