diff --git a/kate/kateconfigdialog.cpp b/kate/kateconfigdialog.cpp index 2a9031e4ac21c2bcb6fcb3b8d7a989969ff7efe6..0825e150d8d5d32a00c520ea5aba4b2f396adf86 100644 --- a/kate/kateconfigdialog.cpp +++ b/kate/kateconfigdialog.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -53,6 +54,7 @@ KateConfigDialog::KateConfigDialog(KateMainWindow *parent, KTextEditor::View *vi : KPageDialog(parent) , m_mainWindow(parent) , m_view(view) + , m_dataChanged(false) { setFaceType(Tree); setWindowTitle(i18n("Configure")); @@ -247,7 +249,6 @@ KateConfigDialog::KateConfigDialog(KateMainWindow *parent, KTextEditor::View *vi 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 @@ int KateConfigDialog::recentFilesMaxCount() 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; + } +} diff --git a/kate/kateconfigdialog.h b/kate/kateconfigdialog.h index 738021d589105880937b63d4a9386c64fbf5c82d..466270b59232e486ff1ddbb035f5952b5a55a487 100644 --- a/kate/kateconfigdialog.h +++ b/kate/kateconfigdialog.h @@ -67,6 +67,7 @@ public: void addPluginPage(KTextEditor::Plugin *plugin); void removePluginPage(KTextEditor::Plugin *plugin); void showAppPluginPage(KTextEditor::Plugin *plugin, uint id); + protected Q_SLOTS: void slotApply(); void slotChanged(); @@ -74,6 +75,9 @@ protected Q_SLOTS: void slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before); +protected: + void closeEvent(QCloseEvent *event) override; + private: KateMainWindow *m_mainWindow;