diff --git a/kate/katemainwindow.h b/kate/katemainwindow.h --- a/kate/katemainwindow.h +++ b/kate/katemainwindow.h @@ -584,6 +584,7 @@ protected: bool event(QEvent *e) override; void mousePressEvent(QMouseEvent *e) override; + void closeEvent(QCloseEvent* event) override; }; #endif diff --git a/kate/katemainwindow.cpp b/kate/katemainwindow.cpp --- a/kate/katemainwindow.cpp +++ b/kate/katemainwindow.cpp @@ -32,6 +32,7 @@ #include "katemwmodonhddialog.h" #include "katesessionsaction.h" #include "katesessionmanager.h" +#include "katetabbar.h" #include "kateviewspace.h" #include "katequickopen.h" #include "kateupdatedisabler.h" @@ -1191,6 +1192,44 @@ } } +void KateMainWindow::closeEvent(QCloseEvent* event) +{ + // Find out if Kate is closed directly by the user or + // by the session manager because the session is closed + bool closedByUser = true; + if (qApp->isSavingSession()) { + closedByUser = false; + } + + KateTabBar *tab = new KateTabBar(window()); + if (tab->count() > 1 && closedByUser) { + KGuiItem yes(i18nc("@action:button 'Quit Kate' button", "&Quit %1", QGuiApplication::applicationDisplayName()), + QIcon::fromTheme(QStringLiteral("application-exit"))); + KGuiItem no(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))); + + const auto result = KMessageBox::warningYesNoCancel(nullptr, + i18n("You have multiple tabs open in this window, are you sure you want to quit?"), + i18n("Confirmation"), + yes, + no, + KStandardGuiItem::cancel(), + i18n("Do not ask again")); + + switch (result) { + case KMessageBox::Yes: + break; + case KMessageBox::No: + // fub=nctionality for closing current tab + Q_FALLTHROUGH(); + default: + event->ignore(); + return; + } + } + + KXmlGuiWindow::closeEvent(event); +} + void KateMainWindow::slotFocusPrevTab() { if (m_viewManager->activeViewSpace()) {