diff --git a/kate/kateconfigdialog.h b/kate/kateconfigdialog.h --- a/kate/kateconfigdialog.h +++ b/kate/kateconfigdialog.h @@ -67,13 +67,17 @@ void addPluginPage(KTextEditor::Plugin *plugin); void removePluginPage(KTextEditor::Plugin *plugin); void showAppPluginPage(KTextEditor::Plugin *plugin, uint id); + protected Q_SLOTS: void slotApply(); void slotChanged(); void slotHelp(); void slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before); +protected: + void closeEvent(QCloseEvent *event) override; + private: KateMainWindow *m_mainWindow; diff --git a/kate/kateconfigdialog.cpp b/kate/kateconfigdialog.cpp --- a/kate/kateconfigdialog.cpp +++ b/kate/kateconfigdialog.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -53,6 +54,7 @@ : KPageDialog(parent) , m_mainWindow(parent) , m_view(view) + , m_dataChanged(false) { setFaceType(Tree); setWindowTitle(i18n("Configure")); @@ -247,7 +249,6 @@ connect(buttonBox()->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KateConfigDialog::slotApply); connect(buttonBox()->button(QDialogButtonBox::Help), &QPushButton::clicked, this, &KateConfigDialog::slotHelp); connect(this, &KateConfigDialog::currentPageChanged, this, &KateConfigDialog::slotCurrentPageChanged); - m_dataChanged = false; resize(minimumSizeHint()); } @@ -435,3 +436,30 @@ return maxItems; } +void KateConfigDialog::closeEvent(QCloseEvent *event) +{ + if (!m_dataChanged) { + event->accept(); + return; + } + + const auto response = KMessageBox::warningYesNoCancel(this, + i18n("You have have unsaved changes. Do you want to apply the changes or discard them?"), + i18n("Warning"), + KStandardGuiItem::save(), + KStandardGuiItem::discard(), + KStandardGuiItem::cancel()); + switch (response) { + case KMessageBox::Yes: + slotApply(); + Q_FALLTHROUGH(); + case KMessageBox::No: + event->accept(); + break; + case KMessageBox::Cancel: + event->ignore(); + break; + default: + break; + } +}