diff --git a/interfaces/configpage.cpp b/interfaces/configpage.cpp index 30f1ed0de0..3f8fee1e0d 100644 --- a/interfaces/configpage.cpp +++ b/interfaces/configpage.cpp @@ -1,154 +1,158 @@ /* * This file is part of KDevelop * Copyright 2014 Alex Richardson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "configpage.h" #include #include #include using namespace KDevelop; -ConfigPage::ConfigPage(KCoreConfigSkeleton* config, QWidget* parent) - : KTextEditor::ConfigPage(parent), m_configSkeleton(config) +ConfigPage::ConfigPage(IPlugin* plugin, KCoreConfigSkeleton* config, QWidget* parent) + : KTextEditor::ConfigPage(parent), m_configSkeleton(config), m_plugin(plugin) { if (m_configSkeleton) { m_configManager.reset(new KConfigDialogManager(parent, m_configSkeleton)); connect(m_configManager.data(), &KConfigDialogManager::widgetModified, this, &ConfigPage::changed); // m_configManager->addWidget(this) must be called from the config dialog, // since the widget tree is not complete yet when calling this constructor } } ConfigPage::~ConfigPage() { - } void ConfigPage::apply() { Q_ASSERT(m_configManager); // if null, this method must be overriden m_configManager->updateSettings(); + m_configSkeleton->load(); m_configManager->updateWidgets(); } void ConfigPage::defaults() { Q_ASSERT(m_configManager); // if null, this method must be overriden m_configManager->updateWidgetsDefault(); } void ConfigPage::reset() { Q_ASSERT(m_configManager); // if null, this method must be overriden m_configManager->updateWidgets(); } void ConfigPage::initConfigManager() { if (m_configManager) { m_configManager->addWidget(this); m_configManager->updateWidgets(); } } - QList ConfigPage::childPages() { return {}; } +IPlugin* ConfigPage::plugin() +{ + return m_plugin; +} + KTextEditorConfigPageAdapter::KTextEditorConfigPageAdapter(KTextEditor::ConfigPage* page, QWidget* parent) - : ConfigPage(nullptr, parent), m_page(page) + : ConfigPage(nullptr, nullptr, parent), m_page(page) { page->setParent(this); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(page); this->setLayout(layout); } KTextEditorConfigPageAdapter::~KTextEditorConfigPageAdapter() { } void KTextEditorConfigPageAdapter::apply() { m_page->apply(); } void KTextEditorConfigPageAdapter::defaults() { m_page->defaults(); } void KTextEditorConfigPageAdapter::reset() { m_page->reset(); } QString KTextEditorConfigPageAdapter::fullName() const { return m_page->fullName(); } QIcon KTextEditorConfigPageAdapter::icon() const { return m_page->icon(); } QString KTextEditorConfigPageAdapter::name() const { return m_page->name(); } EditorConfigPage::EditorConfigPage(QWidget* parent) - : ConfigPage(nullptr, parent) + : ConfigPage(nullptr, nullptr, parent) { qDebug("Editor config page created"); setObjectName("editorconfig"); } EditorConfigPage::~EditorConfigPage() { qDebug("Editor config page deleted"); } QString EditorConfigPage::name() const { return i18n("Editor"); } QIcon EditorConfigPage::icon() const { return QIcon::fromTheme(QStringLiteral("accessories-text-editor")); } QString EditorConfigPage::fullName() const { return i18n("Configure Text editor"); } QList EditorConfigPage::childPages() { QList ret; auto editor = KTextEditor::Editor::instance(); for (int i = 0; i < editor->configPages(); ++i) { ret.append(new KTextEditorConfigPageAdapter(editor->configPage(i, this), this)); } return ret; }; diff --git a/interfaces/configpage.h b/interfaces/configpage.h index 068f6db2a1..dab4265789 100644 --- a/interfaces/configpage.h +++ b/interfaces/configpage.h @@ -1,115 +1,123 @@ /* * This file is part of KDevelop * Copyright 2014 Alex Richardson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KDEVELOP_CONFIGPAGE_H #define KDEVELOP_CONFIGPAGE_H #include #include #include #include #include "interfacesexport.h" namespace KDevelop { +class IPlugin; class KDEVPLATFORMINTERFACES_EXPORT ConfigPage : public KTextEditor::ConfigPage { Q_OBJECT public: /** * Create a new config page + * @param plugin the plugin that created this config page * @param config the config skeleton that is used to store the preferences. If you don't use * a K(Core)ConfigSkeleton to save the settings you can also pass null here. * However this means that you will have to manually implement the apply(), defaults() and reset() slots */ - explicit ConfigPage(KCoreConfigSkeleton* config = nullptr, QWidget* parent = nullptr); + explicit ConfigPage(IPlugin* plugin, KCoreConfigSkeleton* config = nullptr, QWidget* parent = nullptr); virtual ~ConfigPage(); /** * Get any subpages of the current page. * @return By default returns an empty list */ virtual QList childPages(); + /** + * @return the plugin that this config page was created by or nullptr if it was not created by a plugin. + */ + IPlugin* plugin(); + public Q_SLOTS: virtual void apply() override; virtual void defaults() override; virtual void reset() override; public: /** * Initializes the KConfigDialogManager. * Must be called explicitly since not all child widgets are available at the end of the constructor. * This is handled automatically by KDevelop::ConfigDialog, subclasses don't need to call this. */ void initConfigManager(); KCoreConfigSkeleton* configSkeleton() { return m_configSkeleton; } private: QScopedPointer m_configManager; KCoreConfigSkeleton* m_configSkeleton; + IPlugin* m_plugin; }; class KDEVPLATFORMINTERFACES_EXPORT KTextEditorConfigPageAdapter : public ConfigPage { Q_OBJECT public: explicit KTextEditorConfigPageAdapter(KTextEditor::ConfigPage* page, QWidget* parent = nullptr); virtual ~KTextEditorConfigPageAdapter(); virtual QString name() const override; virtual QIcon icon() const override; virtual QString fullName() const override; public Q_SLOTS: virtual void apply() override; virtual void defaults() override; virtual void reset() override; private: KTextEditor::ConfigPage* m_page; }; class KDEVPLATFORMINTERFACES_EXPORT EditorConfigPage : public ConfigPage { Q_OBJECT public: EditorConfigPage(QWidget* parent); virtual ~EditorConfigPage(); virtual QString name() const override; virtual QIcon icon() const override; virtual QString fullName() const override; virtual QList childPages() override; public Q_SLOTS: virtual void apply() override {}; virtual void reset() override {}; virtual void defaults() override {}; }; } #endif // KDEVELOP_CONFIGPAGE_H diff --git a/plugins/projectfilter/projectfilterkcm.cpp b/plugins/projectfilter/projectfilterkcm.cpp index 6cd5f72945..a0e2cb82f7 100644 --- a/plugins/projectfilter/projectfilterkcm.cpp +++ b/plugins/projectfilter/projectfilterkcm.cpp @@ -1,219 +1,219 @@ /* This file is part of KDevelop Copyright 2008 Alexander Dymo This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 "projectfilterkcm.h" #include #include #include #include #include #include #include #include #include #include #include #include "ui_projectfiltersettings.h" #include "projectfilterdebug.h" #include "filtermodel.h" #include "comboboxdelegate.h" #include "projectfilterprovider.h" using namespace KDevelop; ProjectFilterKCM::ProjectFilterKCM(ProjectFilterProvider* provider, const ProjectConfigOptions& options, QWidget* parent) - : ProjectConfigPage(options, parent) + : ProjectConfigPage(provider, options, parent) , m_model(new FilterModel(this)) , m_projectFilterProvider(provider) , m_ui(new Ui::ProjectFilterSettings) { QVBoxLayout *l = new QVBoxLayout(this); QWidget *w = new QWidget; m_ui->setupUi(w); m_ui->filters->setSelectionMode(QAbstractItemView::SingleSelection); m_ui->filters->setModel(m_model); m_ui->filters->setRootIsDecorated(false); m_ui->filters->header()->setSectionResizeMode(FilterModel::Pattern, QHeaderView::Stretch); m_ui->filters->header()->setSectionResizeMode(FilterModel::Targets, QHeaderView::ResizeToContents); m_ui->filters->header()->setSectionResizeMode(FilterModel::Inclusive, QHeaderView::ResizeToContents); m_ui->filters->setItemDelegateForColumn(FilterModel::Targets, new ComboBoxDelegate(QVector() << ComboBoxDelegate::Item(i18n("Files"), static_cast(Filter::Files)) << ComboBoxDelegate::Item(i18n("Folders"), static_cast(Filter::Folders)) << ComboBoxDelegate::Item(i18n("Files and Folders"), static_cast(Filter::Folders | Filter::Files)) , this)); m_ui->filters->setItemDelegateForColumn(FilterModel::Inclusive, new ComboBoxDelegate(QVector() << ComboBoxDelegate::Item(i18n("Exclude"), false) << ComboBoxDelegate::Item(i18n("Include"), true) , this)); m_ui->filters->installEventFilter(this); m_ui->filters->setDragEnabled(true); m_ui->filters->setDragDropMode(QAbstractItemView::InternalMove); m_ui->filters->setAutoScroll(true); l->addWidget(w); reset(); selectionChanged(); connect(m_ui->filters->selectionModel(), &QItemSelectionModel::currentChanged, this, &ProjectFilterKCM::selectionChanged); connect(this, static_cast(&ProjectFilterKCM::changed), this, &ProjectFilterKCM::selectionChanged); connect(m_model, &FilterModel::dataChanged, this, &ProjectFilterKCM::emitChanged); connect(m_model, &FilterModel::rowsInserted, this, &ProjectFilterKCM::emitChanged); connect(m_model, &FilterModel::rowsRemoved, this, &ProjectFilterKCM::emitChanged); connect(m_model, &FilterModel::modelReset, this, &ProjectFilterKCM::emitChanged); connect(m_model, &FilterModel::rowsMoved, this, &ProjectFilterKCM::emitChanged); connect(m_ui->add, &QPushButton::clicked, this, &ProjectFilterKCM::add); connect(m_ui->remove, &QPushButton::clicked, this, &ProjectFilterKCM::remove); connect(m_ui->moveUp, &QPushButton::clicked, this, &ProjectFilterKCM::moveUp); connect(m_ui->moveDown, &QPushButton::clicked, this, &ProjectFilterKCM::moveDown); } ProjectFilterKCM::~ProjectFilterKCM() { } void ProjectFilterKCM::apply() { ProjectConfigPage::apply(); writeFilters(m_model->filters(), project()->projectConfiguration()); m_projectFilterProvider->updateProjectFilters(project()); } void ProjectFilterKCM::reset() { ProjectConfigPage::reset(); m_model->setFilters(readFilters(project()->projectConfiguration())); } void ProjectFilterKCM::defaults() { ProjectConfigPage::defaults(); m_model->setFilters(defaultFilters()); } bool ProjectFilterKCM::eventFilter(QObject* object, QEvent* event) { Q_ASSERT(object == m_ui->filters); Q_UNUSED(object); if (event->type() == QEvent::KeyRelease) { QKeyEvent* key = static_cast(event); if (key->key() == Qt::Key_Delete && key->modifiers() == Qt::NoModifier && m_ui->filters->currentIndex().isValid()) { // workaround https://bugs.kde.org/show_bug.cgi?id=324451 // there is no other way I see to figure out whether an editor is showing... QWidget* editor = m_ui->filters->viewport()->findChild(); if (editor && editor->isVisible()) { // editor is showing return false; } remove(); return true; } } return false; } void ProjectFilterKCM::selectionChanged() { bool hasSelection = m_ui->filters->currentIndex().isValid(); int row = -1; if (hasSelection) { row = m_ui->filters->currentIndex().row(); } m_ui->remove->setEnabled(hasSelection); m_ui->moveDown->setEnabled(hasSelection && row != m_model->rowCount() - 1); m_ui->moveUp->setEnabled(hasSelection && row != 0); } void ProjectFilterKCM::add() { m_model->insertRows(m_model->rowCount(), 1); const QModelIndex index = m_model->index(m_model->rowCount() - 1, FilterModel::Pattern, QModelIndex()); m_ui->filters->setCurrentIndex(index); m_ui->filters->edit(index); } void ProjectFilterKCM::remove() { Q_ASSERT(m_ui->filters->currentIndex().isValid()); m_model->removeRows(m_ui->filters->currentIndex().row(), 1); } void ProjectFilterKCM::moveUp() { Q_ASSERT(m_ui->filters->currentIndex().isValid()); m_model->moveFilterUp(m_ui->filters->currentIndex().row()); } void ProjectFilterKCM::moveDown() { Q_ASSERT(m_ui->filters->currentIndex().isValid()); m_model->moveFilterDown(m_ui->filters->currentIndex().row()); } static void addError(const QString& message, QWidget* parent) { KMessageWidget* widget = new KMessageWidget(parent); widget->setMessageType(KMessageWidget::Error); widget->setText(message); parent->layout()->addWidget(widget); } void ProjectFilterKCM::emitChanged() { qDeleteAll(m_ui->messages->findChildren()); foreach(const Filter& filter, m_model->filters()) { const QString &pattern = filter.pattern.pattern(); if (pattern.isEmpty()) { addError(i18n("A filter with an empty pattern will match all items. Use \"*\" to make this explicit."), m_ui->messages); } else if (pattern.endsWith('/') && filter.targets == Filter::Files) { addError(i18n("A filter ending on \"/\" can never match a file."), m_ui->messages); } } emit changed(); } QString ProjectFilterKCM::fullName() const { return i18n("Configure which files and folders inside the project folder should be included or excluded."); } QIcon ProjectFilterKCM::icon() const { return QIcon::fromTheme(QStringLiteral("view-filter")); } QString ProjectFilterKCM::name() const { return i18n("Project Filter"); } #include "projectfilterkcm.moc" diff --git a/project/projectconfigpage.h b/project/projectconfigpage.h index 462673e7ca..00bf2a1aa9 100644 --- a/project/projectconfigpage.h +++ b/project/projectconfigpage.h @@ -1,88 +1,88 @@ /* KDevelop * * Copyright 2007 Andreas Pakulat * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #ifndef KDEVPLATFORM_PROJECTCONFIGPAGE_H #define KDEVPLATFORM_PROJECTCONFIGPAGE_H #include #include #include #include #include "projectconfigskeleton.h" class KComponentData; class QWidget; class QStringList; namespace KDevelop { /** This is needed because IProject does not expose these methods */ struct ProjectConfigOptions { QString developerTempFile; Path developerFile; QString projectTempFile; Path projectFile; QString projectName; }; } /** * @tparam T a class derived from KDevelop::ProjectConfigSkeleton. */ template class ProjectConfigPage : public KDevelop::ConfigPage { static_assert(std::is_base_of::value, "T must inherit from KDevelop::ProjectConfigSkeleton"); public: - ProjectConfigPage(const KDevelop::ProjectConfigOptions& options, QWidget* parent) - : KDevelop::ConfigPage(initConfigSkeleton(options), parent), projectName(options.projectName) + ProjectConfigPage(KDevelop::IPlugin* plugin, const KDevelop::ProjectConfigOptions& options, QWidget* parent) + : KDevelop::ConfigPage(plugin, initConfigSkeleton(options), parent), projectName(options.projectName) { KDevelop::ProjectConfigSkeleton* conf = T::self(); conf->setDeveloperTempFile(options.developerTempFile); conf->setDeveloperFile(options.developerFile); conf->setProjectTempFile(options.projectTempFile); conf->setProjectFile(options.projectFile); } virtual ~ProjectConfigPage() { delete T::self(); } KDevelop::IProject* project() const { return KDevelop::ICore::self()->projectController()->findProjectByName( projectName ); } private: static inline KDevelop::ProjectConfigSkeleton* initConfigSkeleton(const KDevelop::ProjectConfigOptions& options) { T::instance(options.developerTempFile); return T::self(); } private: QString projectName; }; #endif diff --git a/shell/settings/uipreferences.cpp b/shell/settings/uipreferences.cpp index 41dcce5bbb..f2401eab80 100644 --- a/shell/settings/uipreferences.cpp +++ b/shell/settings/uipreferences.cpp @@ -1,75 +1,75 @@ /* KDevelop * * Copyright 2007 Andreas Pakulat * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #include "uipreferences.h" #include #include #include "../core.h" #include "../mainwindow.h" #include "../uicontroller.h" #include "ui_uiconfig.h" #include "uiconfig.h" using namespace KDevelop; UiPreferences::UiPreferences(QWidget* parent) - : ConfigPage(UiConfig::self(), parent) + : ConfigPage(nullptr, UiConfig::self(), parent) { QVBoxLayout* l = new QVBoxLayout( this ); QWidget* w = new QWidget(parent); m_uiconfigUi = new Ui::UiConfig(); m_uiconfigUi->setupUi( w ); l->addWidget( w ); } UiPreferences::~UiPreferences() { delete m_uiconfigUi; } void UiPreferences::apply() { KDevelop::ConfigPage::apply(); UiController *uiController = Core::self()->uiControllerInternal(); foreach (Sublime::MainWindow *window, uiController->mainWindows()) (static_cast(window))->loadSettings(); uiController->loadSettings(); } QString UiPreferences::name() const { return i18n("User Interface"); } QIcon UiPreferences::icon() const { return QIcon::fromTheme(QStringLiteral("preferences-desktop-theme")); } QString UiPreferences::fullName() const { return i18n("Configure User Interface"); } #include "uipreferences.moc"