kateconfigdialog.cpp 19.8 KB
Newer Older
1 2 3
/* This file is part of the KDE project
   Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
   Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
Mirko Stocker's avatar
Mirko Stocker committed
4
   Copyright (C) 2007 Mirko Stocker <me@misto.ch>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "kateconfigdialog.h"

23 24
#include "ui_sessionconfigwidget.h"

25
#include "kateapp.h"
26
#include "kateconfigplugindialogpage.h"
27
#include "katedebug.h"
28 29 30
#include "katedocmanager.h"
#include "katemainwindow.h"
#include "katepluginmanager.h"
31
#include "katequickopenmodel.h"
32 33
#include "katesessionmanager.h"
#include "kateviewmanager.h"
34

Christoph Cullmann's avatar
Christoph Cullmann committed
35
#include <KTextEditor/ConfigPage>
36

37
#include <KConfigGroup>
Michal Humpula's avatar
Michal Humpula committed
38
#include <KLocalizedString>
39
#include <KMessageBox>
40
#include <KPluralHandlingSpinBox>
41 42
#include <KSharedConfig>
#include <KStandardAction>
Michal Humpula's avatar
Michal Humpula committed
43 44

#include <QCheckBox>
45 46
#include <QComboBox>
#include <QDesktopServices>
47
#include <QDialogButtonBox>
Michal Humpula's avatar
Michal Humpula committed
48 49 50 51
#include <QFrame>
#include <QGroupBox>
#include <QLabel>
#include <QVBoxLayout>
52

53 54 55 56
KateConfigDialog::KateConfigDialog(KateMainWindow *parent, KTextEditor::View *view)
    : KPageDialog(parent)
    , m_mainWindow(parent)
    , m_view(view)
57
{
58 59 60 61 62 63 64 65 66 67 68 69 70
    setFaceType(Tree);
    setWindowTitle(i18n("Configure"));
    setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
    setObjectName(QStringLiteral("configdialog"));

    KSharedConfig::Ptr config = KSharedConfig::openConfig();
    KConfigGroup cgGeneral = KConfigGroup(config, "General");

    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);

    KPageWidgetItem *applicationItem = addPage(new QWidget, i18n("Application"));
    applicationItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-other")));
    applicationItem->setHeader(i18n("Application Options"));
71 72
    applicationItem->setCheckable(false);
    applicationItem->setEnabled(false);
73 74
    m_applicationPage = applicationItem;

75
    // BEGIN General page
76 77 78 79 80 81 82
    QFrame *generalFrame = new QFrame;
    KPageWidgetItem *item = addSubPage(applicationItem, generalFrame, i18n("General"));
    item->setHeader(i18n("General Options"));
    item->setIcon(QIcon::fromTheme(QStringLiteral("go-home")));
    setCurrentPage(item);

    QVBoxLayout *layout = new QVBoxLayout(generalFrame);
Laurent Montel's avatar
Laurent Montel committed
83
    layout->setContentsMargins(0, 0, 0, 0);
84 85 86 87 88 89 90

    // GROUP with the one below: "Behavior"
    QGroupBox *buttonGroup = new QGroupBox(i18n("&Behavior"), generalFrame);
    QVBoxLayout *vbox = new QVBoxLayout;
    layout->addWidget(buttonGroup);

    // modified files notification
91
    m_modNotifications = new QCheckBox(i18n("Wa&rn about files modified by foreign processes"), buttonGroup);
92
    m_modNotifications->setChecked(parent->modNotificationEnabled());
93 94 95 96 97
    m_modNotifications->setWhatsThis(
        i18n("If enabled, when Kate receives focus you will be asked what to do with "
             "files that have been modified on the hard disk. If not enabled, you will "
             "be asked what to do with a file that has been modified on the hard disk only "
             "when that file is tried to be saved."));
Laurent Montel's avatar
Laurent Montel committed
98
    connect(m_modNotifications, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
99 100

    vbox->addWidget(m_modNotifications);
101 102

    // Closing last file closes Kate
103
    m_modCloseAfterLast = new QCheckBox(i18n("Close Kate entirely when the last file is closed"), buttonGroup);
104
    m_modCloseAfterLast->setChecked(parent->modCloseAfterLast());
105 106 107
    m_modCloseAfterLast->setWhatsThis(
        i18n("If enabled, Kate will shutdown when the last file being edited is closed, "
             "otherwise a blank page will open so that you can start a new file."));
108 109 110
    connect(m_modCloseAfterLast, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);

    vbox->addWidget(m_modCloseAfterLast);
111 112 113 114 115 116 117 118 119 120
    buttonGroup->setLayout(vbox);

    // GROUP with the one below: "Meta-information"
    buttonGroup = new QGroupBox(i18n("Meta-Information"), generalFrame);
    vbox = new QVBoxLayout;
    layout->addWidget(buttonGroup);

    // save meta infos
    m_saveMetaInfos = new QCheckBox(buttonGroup);
    m_saveMetaInfos->setText(i18n("Keep &meta-information past sessions"));
Christoph Cullmann's avatar
Christoph Cullmann committed
121
    m_saveMetaInfos->setChecked(KateApp::self()->documentManager()->getSaveMetaInfos());
122 123 124 125
    m_saveMetaInfos->setWhatsThis(
        i18n("Check this if you want document configuration like for example "
             "bookmarks to be saved past editor sessions. The configuration will be "
             "restored if the document has not changed when reopened."));
Laurent Montel's avatar
Laurent Montel committed
126
    connect(m_saveMetaInfos, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
127 128 129 130 131 132 133

    vbox->addWidget(m_saveMetaInfos);

    // meta infos days
    QFrame *metaInfos = new QFrame(buttonGroup);
    QHBoxLayout *hlayout = new QHBoxLayout(metaInfos);

Christoph Cullmann's avatar
Christoph Cullmann committed
134
    metaInfos->setEnabled(KateApp::self()->documentManager()->getSaveMetaInfos());
135 136
    QLabel *label = new QLabel(i18n("&Delete unused meta-information after:"), metaInfos);
    hlayout->addWidget(label);
137
    m_daysMetaInfos = new KPluralHandlingSpinBox(metaInfos);
138
    m_daysMetaInfos->setMaximum(180);
139 140
    m_daysMetaInfos->setSpecialValueText(i18nc("The special case of 'Delete unused meta-information after'", "(never)"));
    m_daysMetaInfos->setSuffix(ki18ncp("The suffix of 'Delete unused meta-information after'", " day", " days"));
Christoph Cullmann's avatar
Christoph Cullmann committed
141
    m_daysMetaInfos->setValue(KateApp::self()->documentManager()->getDaysMetaInfos());
142 143
    hlayout->addWidget(m_daysMetaInfos);
    label->setBuddy(m_daysMetaInfos);
Laurent Montel's avatar
Laurent Montel committed
144 145
    connect(m_saveMetaInfos, &QCheckBox::toggled, metaInfos, &QFrame::setEnabled);
    connect(m_daysMetaInfos, static_cast<void (KPluralHandlingSpinBox::*)(int)>(&KPluralHandlingSpinBox::valueChanged), this, &KateConfigDialog::slotChanged);
146 147 148 149

    vbox->addWidget(metaInfos);
    buttonGroup->setLayout(vbox);

150 151
    // quick search
    buttonGroup = new QGroupBox(i18n("&Quick Open"), generalFrame);
152 153 154 155
    vbox = new QVBoxLayout;
    buttonGroup->setLayout(vbox);
    // quick open match mode
    hlayout = new QHBoxLayout;
156 157
    label = new QLabel(i18n("&Match Mode:"), buttonGroup);
    hlayout->addWidget(label);
158
    m_cmbQuickOpenMatchMode = new QComboBox(buttonGroup);
159 160 161 162 163 164
    hlayout->addWidget(m_cmbQuickOpenMatchMode);
    label->setBuddy(m_cmbQuickOpenMatchMode);
    m_cmbQuickOpenMatchMode->addItem(i18n("Filename"), QVariant(KateQuickOpenModel::Columns::FileName));
    m_cmbQuickOpenMatchMode->addItem(i18n("Filepath"), QVariant(KateQuickOpenModel::Columns::FilePath));
    m_cmbQuickOpenMatchMode->setCurrentIndex(m_cmbQuickOpenMatchMode->findData(m_mainWindow->quickOpenMatchMode()));
    m_mainWindow->setQuickOpenMatchMode(m_cmbQuickOpenMatchMode->currentData().toInt());
165
    connect(m_cmbQuickOpenMatchMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateConfigDialog::slotChanged);
166 167 168 169 170 171 172 173 174 175 176
    vbox->addLayout(hlayout);
    // quick open list mode
    hlayout = new QHBoxLayout;
    label = new QLabel(i18n("&List Mode:"), buttonGroup);
    hlayout->addWidget(label);
    m_cmbQuickOpenListMode = new QComboBox(buttonGroup);
    hlayout->addWidget(m_cmbQuickOpenListMode);
    label->setBuddy(m_cmbQuickOpenListMode);
    m_cmbQuickOpenListMode->addItem(i18n("Current Project Files"), QVariant(KateQuickOpenModel::List::CurrentProject));
    m_cmbQuickOpenListMode->addItem(i18n("All Projects Files"), QVariant(KateQuickOpenModel::List::AllProjects));
    m_cmbQuickOpenListMode->setCurrentIndex(m_cmbQuickOpenListMode->findData(m_mainWindow->quickOpenListMode()));
177
    m_mainWindow->setQuickOpenListMode(static_cast<KateQuickOpenModel::List>(m_cmbQuickOpenListMode->currentData().toInt()));
178 179
    connect(m_cmbQuickOpenListMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateConfigDialog::slotChanged);
    vbox->addLayout(hlayout);
180 181
    layout->addWidget(buttonGroup);

182
    layout->addStretch(1); // :-] works correct without autoadd
183
    // END General page
184

185
    // BEGIN Session page
186
    QWidget *sessionsPage = new QWidget();
Ayushmaan jangid's avatar
Ayushmaan jangid committed
187
    item = addSubPage(applicationItem, sessionsPage, i18n("Session"));
188 189 190
    item->setHeader(i18n("Session Management"));
    item->setIcon(QIcon::fromTheme(QStringLiteral("view-history")));

191 192
    sessionConfigUi = new Ui::SessionConfigWidget();
    sessionConfigUi->setupUi(sessionsPage);
193 194

    // restore view  config
195
    sessionConfigUi->restoreVC->setChecked(cgGeneral.readEntry("Restore Window Configuration", true));
Laurent Montel's avatar
Laurent Montel committed
196
    connect(sessionConfigUi->restoreVC, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
197

198
    sessionConfigUi->spinBoxRecentFilesCount->setValue(recentFilesMaxCount());
Laurent Montel's avatar
Laurent Montel committed
199
    connect(sessionConfigUi->spinBoxRecentFilesCount, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &KateConfigDialog::slotChanged);
200

201
    QString sesStart(cgGeneral.readEntry("Startup Session", "manual"));
202
    if (sesStart == QLatin1String("new"))
203
        sessionConfigUi->startNewSessionRadioButton->setChecked(true);
204
    else if (sesStart == QLatin1String("last"))
205
        sessionConfigUi->loadLastUserSessionRadioButton->setChecked(true);
206
    else
207
        sessionConfigUi->manuallyChooseSessionRadioButton->setChecked(true);
208

Laurent Montel's avatar
Laurent Montel committed
209 210 211
    connect(sessionConfigUi->startNewSessionRadioButton, &QRadioButton::toggled, this, &KateConfigDialog::slotChanged);
    connect(sessionConfigUi->loadLastUserSessionRadioButton, &QRadioButton::toggled, this, &KateConfigDialog::slotChanged);
    connect(sessionConfigUi->manuallyChooseSessionRadioButton, &QRadioButton::toggled, this, &KateConfigDialog::slotChanged);
212
    // END Session page
213

214
    // BEGIN Plugins page
215 216
    QFrame *page = new QFrame(this);
    QVBoxLayout *vlayout = new QVBoxLayout(page);
Laurent Montel's avatar
Laurent Montel committed
217
    vlayout->setContentsMargins(0, 0, 0, 0);
218 219 220 221
    vlayout->setSpacing(0);

    KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
    vlayout->addWidget(configPluginPage);
Laurent Montel's avatar
Laurent Montel committed
222
    connect(configPluginPage, &KateConfigPluginPage::changed, this, &KateConfigDialog::slotChanged);
223 224 225 226 227

    item = addSubPage(applicationItem, page, i18n("Plugins"));
    item->setHeader(i18n("Plugin Manager"));
    item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-plugin")));

228 229
    const KatePluginList &pluginList(KateApp::self()->pluginManager()->pluginList());
    for (const KatePluginInfo &plugin : pluginList) {
230
        if (plugin.load) {
231 232 233
            addPluginPage(plugin.plugin);
        }
    }
234
    // END Plugins page
Adam Treat's avatar
Adam Treat committed
235

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
#ifdef WITH_KUSERFEEDBACK
    // KUserFeedback Config
    page = new QFrame(this);
    vlayout = new QVBoxLayout(page);
    vlayout->setContentsMargins(0, 0, 0, 0);
    vlayout->setSpacing(0);

    m_userFeedbackWidget = new KUserFeedback::FeedbackConfigWidget(page);
    m_userFeedbackWidget->setFeedbackProvider(&KateApp::self()->userFeedbackProvider());
    connect(m_userFeedbackWidget, &KUserFeedback::FeedbackConfigWidget::configurationChanged, this, &KateConfigDialog::slotChanged);
    vlayout->addWidget(m_userFeedbackWidget);

    item = addSubPage(applicationItem, page, i18n("User Feedback"));
    item->setHeader(i18n("User Feedback"));
    item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-locale")));
#endif

253
    // editor widgets from kwrite/kwdialog
254 255 256
    m_editorPage = addPage(new QWidget, i18n("Editor Component"));
    m_editorPage->setIcon(QIcon::fromTheme(QStringLiteral("accessories-text-editor")));
    m_editorPage->setHeader(i18n("Editor Component Options"));
257 258
    m_editorPage->setCheckable(false);
    m_editorPage->setEnabled(false);
259

260
    addEditorPages();
261

Laurent Montel's avatar
Laurent Montel committed
262 263 264 265
    connect(this, &KateConfigDialog::accepted, this, &KateConfigDialog::slotApply);
    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);
266

267
    resize(minimumSizeHint());
268 269 270

    // ensure no stray signals already set this!
    m_dataChanged = false;
271 272 273
}

KateConfigDialog::~KateConfigDialog()
274 275 276
{
    delete sessionConfigUi;
}
277

278 279 280 281
void KateConfigDialog::addEditorPages()
{
    for (int i = 0; i < KTextEditor::Editor::instance()->configPages(); ++i) {
        KTextEditor::ConfigPage *page = KTextEditor::Editor::instance()->configPage(i, this);
Laurent Montel's avatar
Laurent Montel committed
282
        connect(page, &KTextEditor::ConfigPage::changed, this, &KateConfigDialog::slotChanged);
283
        m_editorPages.push_back(page);
284 285 286
        KPageWidgetItem *item = addSubPage(m_editorPage, page, page->name());
        item->setHeader(page->fullName());
        item->setIcon(page->icon());
287
    }
Christoph Cullmann's avatar
jowenn:  
Christoph Cullmann committed
288 289
}

290
void KateConfigDialog::addPluginPage(KTextEditor::Plugin *plugin)
291
{
292
    for (int i = 0; i < plugin->configPages(); i++) {
293 294 295
        QFrame *page = new QFrame();
        QVBoxLayout *layout = new QVBoxLayout(page);
        layout->setSpacing(0);
Laurent Montel's avatar
Laurent Montel committed
296
        layout->setContentsMargins(0, 0, 0, 0);
297

298
        KTextEditor::ConfigPage *cp = plugin->configPage(i, page);
299 300 301 302 303
        page->layout()->addWidget(cp);

        KPageWidgetItem *item = addSubPage(m_applicationPage, page, cp->name());
        item->setHeader(cp->fullName());
        item->setIcon(cp->icon());
304 305 306 307

        PluginPageListItem *info = new PluginPageListItem;
        info->plugin = plugin;
        info->pageParent = page;
308
        info->pluginPage = cp;
309 310
        info->idInPlugin = i;
        info->pageWidgetItem = item;
Laurent Montel's avatar
Laurent Montel committed
311
        connect(info->pluginPage, &KTextEditor::ConfigPage::changed, this, &KateConfigDialog::slotChanged);
312 313
        m_pluginPages.insert(item, info);
    }
Christoph Cullmann's avatar
jowenn:  
Christoph Cullmann committed
314 315
}

316
void KateConfigDialog::slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem * /*before*/)
Christoph Cullmann's avatar
jowenn:  
Christoph Cullmann committed
317
{
318 319 320 321 322 323 324
    PluginPageListItem *info = m_pluginPages[current];
    if (!info) {
        return;
    }
    if (info->pluginPage) {
        return;
    }
Yuri Chornoivan's avatar
Yuri Chornoivan committed
325
    qCDebug(LOG_KATE) << "creating config page (should not get here)";
326
    info->pluginPage = info->plugin->configPage(info->idInPlugin, info->pageParent);
327 328
    info->pageParent->layout()->addWidget(info->pluginPage);
    info->pluginPage->show();
Laurent Montel's avatar
Laurent Montel committed
329
    connect(info->pluginPage, &KTextEditor::ConfigPage::changed, this, &KateConfigDialog::slotChanged);
330 331
}

332
void KateConfigDialog::removePluginPage(KTextEditor::Plugin *plugin)
333
{
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    QList<KPageWidgetItem *> remove;
    for (QHash<KPageWidgetItem *, PluginPageListItem *>::const_iterator it = m_pluginPages.constBegin(); it != m_pluginPages.constEnd(); ++it) {
        PluginPageListItem *pli = it.value();
        if (!pli) {
            continue;
        }
        if (pli->plugin == plugin) {
            remove.append(it.key());
        }
    }

    qCDebug(LOG_KATE) << remove.count();
    while (!remove.isEmpty()) {
        KPageWidgetItem *wItem = remove.takeLast();
        PluginPageListItem *pItem = m_pluginPages.take(wItem);
        delete pItem->pluginPage;
        delete pItem->pageParent;
        removePage(wItem);
        delete pItem;
    }
354 355
}

356 357
void KateConfigDialog::slotApply()
{
358 359 360 361 362 363
    KSharedConfig::Ptr config = KSharedConfig::openConfig();

    // if data changed apply the kate app stuff
    if (m_dataChanged) {
        KConfigGroup cg = KConfigGroup(config, "General");

364
        cg.writeEntry("Restore Window Configuration", sessionConfigUi->restoreVC->isChecked());
365

366
        cg.writeEntry("Recent File List Entry Count", sessionConfigUi->spinBoxRecentFilesCount->value());
367

368
        if (sessionConfigUi->startNewSessionRadioButton->isChecked()) {
369
            cg.writeEntry("Startup Session", "new");
370
        } else if (sessionConfigUi->loadLastUserSessionRadioButton->isChecked()) {
371 372 373 374 375 376
            cg.writeEntry("Startup Session", "last");
        } else {
            cg.writeEntry("Startup Session", "manual");
        }

        cg.writeEntry("Save Meta Infos", m_saveMetaInfos->isChecked());
Christoph Cullmann's avatar
Christoph Cullmann committed
377
        KateApp::self()->documentManager()->setSaveMetaInfos(m_saveMetaInfos->isChecked());
378 379

        cg.writeEntry("Days Meta Infos", m_daysMetaInfos->value());
Christoph Cullmann's avatar
Christoph Cullmann committed
380
        KateApp::self()->documentManager()->setDaysMetaInfos(m_daysMetaInfos->value());
381 382 383 384

        cg.writeEntry("Modified Notification", m_modNotifications->isChecked());
        m_mainWindow->setModNotificationEnabled(m_modNotifications->isChecked());

385 386 387
        cg.writeEntry("Close After Last", m_modCloseAfterLast->isChecked());
        m_mainWindow->setModCloseAfterLast(m_modCloseAfterLast->isChecked());

388 389 390
        cg.writeEntry("Quick Open Search Mode", m_cmbQuickOpenMatchMode->currentData().toInt());
        m_mainWindow->setQuickOpenMatchMode(m_cmbQuickOpenMatchMode->currentData().toInt());

391
        cg.writeEntry("Quick Open List Mode", m_cmbQuickOpenListMode->currentData().toInt());
392
        m_mainWindow->setQuickOpenListMode(static_cast<KateQuickOpenModel::List>(m_cmbQuickOpenListMode->currentData().toInt()));
393

394
        // patch document modified warn state
Christoph Cullmann's avatar
Christoph Cullmann committed
395
        const QList<KTextEditor::Document *> &docs = KateApp::self()->documentManager()->documentList();
396
        for (KTextEditor::Document *doc : docs)
397 398 399
            if (qobject_cast<KTextEditor::ModificationInterface *>(doc)) {
                qobject_cast<KTextEditor::ModificationInterface *>(doc)->setModifiedOnDiskWarning(!m_modNotifications->isChecked());
            }
400 401 402 403

        m_mainWindow->saveOptions();

        // save plugin config !!
Christoph Cullmann's avatar
Christoph Cullmann committed
404
        KateSessionManager *sessionmanager = KateApp::self()->sessionManager();
405 406
        KConfig *sessionConfig = sessionmanager->activeSession()->config();
        KateApp::self()->pluginManager()->writeConfig(sessionConfig);
Christoph Cullmann's avatar
Christoph Cullmann committed
407 408 409 410

#ifdef WITH_KUSERFEEDBACK
        // set current active mode + write back the config for future starts
        KateApp::self()->userFeedbackProvider().setTelemetryMode(m_userFeedbackWidget->telemetryMode());
411
        KateApp::self()->userFeedbackProvider().setSurveyInterval(m_userFeedbackWidget->surveyInterval());
Christoph Cullmann's avatar
Christoph Cullmann committed
412
#endif
413 414
    }

415
    for (PluginPageListItem *plugin : qAsConst(m_pluginPages)) {
416 417 418 419 420 421 422 423 424
        if (!plugin) {
            continue;
        }
        if (plugin->pluginPage) {
            plugin->pluginPage->apply();
        }
    }

    // apply ktexteditor pages
425
    for (KTextEditor::ConfigPage *page : qAsConst(m_editorPages))
426
        page->apply();
Christoph Cullmann's avatar
Christoph Cullmann committed
427

428
    config->sync();
429

430 431
    m_dataChanged = false;
    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
432 433 434 435
}

void KateConfigDialog::slotChanged()
{
436 437
    m_dataChanged = true;
    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
438
}
Adam Treat's avatar
Adam Treat committed
439

440
void KateConfigDialog::showAppPluginPage(KTextEditor::Plugin *p, int id)
441
{
442
    for (PluginPageListItem *plugin : qAsConst(m_pluginPages)) {
443
        if ((plugin->plugin == p) && (id == plugin->idInPlugin)) {
444 445 446
            setCurrentPage(plugin->pageWidgetItem);
            break;
        }
447 448 449
    }
}

Christoph Cullmann's avatar
Christoph Cullmann committed
450 451
void KateConfigDialog::slotHelp()
{
452
    QDesktopServices::openUrl(QUrl(QStringLiteral("help:/")));
Christoph Cullmann's avatar
Christoph Cullmann committed
453
}
454

455
int KateConfigDialog::recentFilesMaxCount()
456
{
457
    int maxItems = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("Recent File List Entry Count", 10);
458 459 460
    return maxItems;
}

461 462 463 464 465 466 467
void KateConfigDialog::closeEvent(QCloseEvent *event)
{
    if (!m_dataChanged) {
        event->accept();
        return;
    }

468 469
    const auto response =
        KMessageBox::warningYesNoCancel(this, i18n("You have unsaved changes. Do you want to apply the changes or discard them?"), i18n("Warning"), KStandardGuiItem::save(), KStandardGuiItem::discard(), KStandardGuiItem::cancel());
470
    switch (response) {
471 472 473 474 475 476 477 478 479 480 481
    case KMessageBox::Yes:
        slotApply();
        Q_FALLTHROUGH();
    case KMessageBox::No:
        event->accept();
        break;
    case KMessageBox::Cancel:
        event->ignore();
        break;
    default:
        break;
482 483
    }
}