Commit 1fa587b0 authored by Shubham  .'s avatar Shubham . Committed by Christoph Cullmann

Confirm closing muliple tabs.

Summary: BUG: 380963

Test Plan: {F6613230}

Reviewers: dhaumann, #kate, sars, cullmann, ngraham

Reviewed By: #kate, cullmann, ngraham

Subscribers: loh.tar, emateli, mwolff, ngraham, pino, kwrite-devel

Tags: #kate

Differential Revision: https://phabricator.kde.org/D17599
parent ffd82e44
......@@ -1191,6 +1191,56 @@ void KateMainWindow::mousePressEvent(QMouseEvent *e)
}
}
void KateMainWindow::closeEvent(QCloseEvent *e)
{
// Find out if Kate is closed directly by the user or
// by the session manager because the session is closed
const bool closedByUser = !qApp->isSavingSession();
const bool multipleDocumentsOpen = KateApp::self()->documentManager()->documentList().count() > 1;
const bool isLastWindow = KateApp::self()->mainWindowsCount() == 1;
const bool askConfirmation = closedByUser && multipleDocumentsOpen && isLastWindow;
if (askConfirmation) {
QDialog *dialog = new QDialog(this, Qt::Dialog);
dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
dialog->setModal(true);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Kate' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Document"), QIcon::fromTheme(QStringLiteral("tab-close"))));
KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
buttons->button(QDialogButtonBox::Yes)->setDefault(true);
bool doNotAskAgainCheckboxResult = false;
auto view = viewManager()->activeView();
const auto result = KMessageBox::createKMessageBox(dialog,
buttons,
QMessageBox::Warning,
i18n("You have multiple documents open, are you sure you want to quit?"),
QStringList(),
i18n("Do not ask again"),
&doNotAskAgainCheckboxResult,
KMessageBox::Notify);
if (doNotAskAgainCheckboxResult) {
readOptions();
}
switch (result) {
case QDialogButtonBox::Yes:
break;
case QDialogButtonBox::No:
KateApp::self()->documentManager()->closeDocument(view->document());
Q_FALLTHROUGH();
default:
e->ignore();
return;
}
saveOptions();
}
KXmlGuiWindow::closeEvent(e);
}
void KateMainWindow::slotFocusPrevTab()
{
if (m_viewManager->activeViewSpace()) {
......
......@@ -584,6 +584,7 @@ public Q_SLOTS:
protected:
bool event(QEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void closeEvent(QCloseEvent *e) override;
};
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment