mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-23 10:52:16 -07:00
refactor save confirmation window into function
This commit is contained in:
parent
977e4ed57b
commit
ca7a1b7c81
2 changed files with 22 additions and 11 deletions
|
|
@ -748,9 +748,7 @@ bool TabDeckEditor::confirmClose()
|
||||||
{
|
{
|
||||||
if (modified) {
|
if (modified) {
|
||||||
tabSupervisor->setCurrentWidget(this);
|
tabSupervisor->setCurrentWidget(this);
|
||||||
QMessageBox::StandardButton ret = QMessageBox::warning(
|
int ret = createSaveConfirmationWindow()->exec();
|
||||||
this, tr("Are you sure?"), tr("The decklist has been modified.\nDo you want to save the changes?"),
|
|
||||||
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
||||||
if (ret == QMessageBox::Save)
|
if (ret == QMessageBox::Save)
|
||||||
return actSaveDeck();
|
return actSaveDeck();
|
||||||
else if (ret == QMessageBox::Cancel)
|
else if (ret == QMessageBox::Cancel)
|
||||||
|
|
@ -1020,18 +1018,14 @@ TabDeckEditor::DeckOpenLocation TabDeckEditor::confirmOpen(const bool openInSame
|
||||||
// do the save confirmation dialogue
|
// do the save confirmation dialogue
|
||||||
tabSupervisor->setCurrentWidget(this);
|
tabSupervisor->setCurrentWidget(this);
|
||||||
|
|
||||||
QMessageBox msgBox;
|
QMessageBox *msgBox = createSaveConfirmationWindow();
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
QPushButton *newTabButton = msgBox->addButton(tr("Open in new tab"), QMessageBox::ApplyRole);
|
||||||
msgBox.setWindowTitle(tr("Are you sure?"));
|
|
||||||
msgBox.setText(tr("The decklist has been modified.\nDo you want to save the changes?"));
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
||||||
QPushButton *newTabButton = msgBox.addButton(tr("Open in new tab"), QMessageBox::ApplyRole);
|
|
||||||
|
|
||||||
int ret = msgBox.exec();
|
int ret = msgBox->exec();
|
||||||
|
|
||||||
// `exec()` returns an opaque value if a non-standard button was clicked.
|
// `exec()` returns an opaque value if a non-standard button was clicked.
|
||||||
// Directly check if newTabButton was clicked before switching over the standard buttons.
|
// Directly check if newTabButton was clicked before switching over the standard buttons.
|
||||||
if (msgBox.clickedButton() == newTabButton) {
|
if (msgBox->clickedButton() == newTabButton) {
|
||||||
return NEW_TAB;
|
return NEW_TAB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1045,6 +1039,21 @@ TabDeckEditor::DeckOpenLocation TabDeckEditor::confirmOpen(const bool openInSame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates the base save confirmation dialogue box.
|
||||||
|
*
|
||||||
|
* @returns A QMessageBox that can be further modified
|
||||||
|
*/
|
||||||
|
QMessageBox *TabDeckEditor::createSaveConfirmationWindow()
|
||||||
|
{
|
||||||
|
QMessageBox *msgBox = new QMessageBox(this);
|
||||||
|
msgBox->setIcon(QMessageBox::Warning);
|
||||||
|
msgBox->setWindowTitle(tr("Are you sure?"));
|
||||||
|
msgBox->setText(tr("The decklist has been modified.\nDo you want to save the changes?"));
|
||||||
|
msgBox->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
||||||
|
return msgBox;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns true if this tab is a blank newly opened tab, as if it was just created with the `New Deck` action.
|
* @brief Returns true if this tab is a blank newly opened tab, as if it was just created with the `New Deck` action.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class Response;
|
||||||
class FilterTreeModel;
|
class FilterTreeModel;
|
||||||
class FilterBuilder;
|
class FilterBuilder;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
|
class QMessageBox;
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
@ -111,6 +112,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
DeckOpenLocation confirmOpen(const bool openInSameTabIfBlank = true);
|
DeckOpenLocation confirmOpen(const bool openInSameTabIfBlank = true);
|
||||||
|
QMessageBox *createSaveConfirmationWindow();
|
||||||
|
|
||||||
bool isBlankNewDeck() const;
|
bool isBlankNewDeck() const;
|
||||||
CardInfoPtr currentCardInfo() const;
|
CardInfoPtr currentCardInfo() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue