From 95a32d77301c0b736c520577a1594819cf80867a Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 12 Sep 2017 22:32:36 +0200 Subject: [PATCH] Show dialog to ask when closing when more than tab open Summary: The checkbox is checked and says "Warn me on closing more than one tab", for that reason we can't use the default KMessageBox::questionYesNo since there the checkbox is always not checked and it's when checked that you enable it Inspired by code from torham zed torhamzed@yahoo.com at review request 126406 Reviewers: #okular, #kde_applications Subscribers: alexeymin, ngraham, colomar, rkflx, #okular Tags: #okular Differential Revision: https://phabricator.kde.org/D7714 --- autotests/mainshelltest.cpp | 3 ++- shell/shell.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/autotests/mainshelltest.cpp b/autotests/mainshelltest.cpp index 2c27ced9c..90a0572d2 100644 --- a/autotests/mainshelltest.cpp +++ b/autotests/mainshelltest.cpp @@ -123,10 +123,11 @@ void MainShellTest::initTestCase() const QString serviceName = QStringLiteral("org.kde.okular-")+ myPid; QVERIFY( bus->registerService(serviceName) == QDBusConnectionInterface::ServiceRegistered ); - // Tell the presentationWidget to not be annoying + // Tell the presentationWidget and queryClose to not be annoying KSharedConfigPtr c = KSharedConfig::openConfig(); KConfigGroup cg = c->group("Notification Messages"); cg.writeEntry("presentationInfo", false); + cg.writeEntry("ShowTabWarning", false); } void MainShellTest::cleanupTestCase() diff --git a/shell/shell.cpp b/shell/shell.cpp index 2dbbdc2fe..8da410620 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -544,6 +544,39 @@ QSize Shell::sizeHint() const bool Shell::queryClose() { + if (m_tabs.count() > 1) + { + const QString dontAskAgainName = "ShowTabWarning"; + KMessageBox::ButtonCode dummy; + if (shouldBeShownYesNo(dontAskAgainName, dummy)) + { + QDialog *dialog = new QDialog(this); + dialog->setWindowTitle(i18n("Confirm Close")); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); + buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No); + KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), KGuiItem(i18n("Close Tabs"), "tab-close")); + KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), KStandardGuiItem::cancel()); + + + bool checkboxResult = true; + const int result = KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox::Question, + i18n("You have about to close %1 tabs. Are you sure you want to continue?", m_tabs.count()), QStringList(), + i18n("Warn me when I attempt to close multiple tabs"), + &checkboxResult, KMessageBox::Notify); + + if (!checkboxResult) + { + saveDontShowAgainYesNo(dontAskAgainName, dummy); + } + + if (result != QDialogButtonBox::Yes) + { + return false; + } + } + } + for( int i = 0; i < m_tabs.size(); ++i ) { KParts::ReadWritePart* const part = m_tabs[i].part;