diff --git a/plugins/projectfilter/CMakeLists.txt b/plugins/projectfilter/CMakeLists.txt index 14f13f2e64..34865f5fc4 100644 --- a/plugins/projectfilter/CMakeLists.txt +++ b/plugins/projectfilter/CMakeLists.txt @@ -1,27 +1,27 @@ ############################## # PLUGIN ##################### ############################## set( projectfilter_SRCS projectfilterprovider.cpp projectfilter.cpp projectfilterdebug.cpp filter.cpp - projectfilterkcm.cpp + projectfilterconfigpage.cpp projectfilterdebug.cpp filter.cpp filtermodel.cpp comboboxdelegate.cpp ) ki18n_wrap_ui(projectfilter_SRCS projectfiltersettings.ui) kconfig_add_kcfg_files(projectfilter_SRCS projectfiltersettings.kcfgc) add_library( kdevprojectfilter MODULE ${projectfilter_SRCS} ) target_link_libraries(kdevprojectfilter KDev::Project KDev::Util KDev::Interfaces) configure_file(kdevprojectfilter.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdevprojectfilter.desktop) kcoreaddons_desktop_to_json(kdevprojectfilter ${CMAKE_CURRENT_BINARY_DIR}/kdevprojectfilter.desktop) install(TARGETS kdevprojectfilter DESTINATION ${PLUGIN_INSTALL_DIR}/kdevplatform/${KDEV_PLUGIN_VERSION}) add_subdirectory(tests) diff --git a/plugins/projectfilter/projectfilterkcm.cpp b/plugins/projectfilter/projectfilterconfigpage.cpp similarity index 90% rename from plugins/projectfilter/projectfilterkcm.cpp rename to plugins/projectfilter/projectfilterconfigpage.cpp index 91010577fc..498171f0ac 100644 --- a/plugins/projectfilter/projectfilterkcm.cpp +++ b/plugins/projectfilter/projectfilterconfigpage.cpp @@ -1,219 +1,217 @@ /* 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 "projectfilterconfigpage.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) +ProjectFilterConfigPage::ProjectFilterConfigPage(ProjectFilterProvider* provider, const ProjectConfigOptions& options, QWidget* 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, &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() +ProjectFilterConfigPage::~ProjectFilterConfigPage() { } -void ProjectFilterKCM::apply() +void ProjectFilterConfigPage::apply() { ProjectConfigPage::apply(); writeFilters(m_model->filters(), project()->projectConfiguration()); m_projectFilterProvider->updateProjectFilters(project()); } -void ProjectFilterKCM::reset() +void ProjectFilterConfigPage::reset() { ProjectConfigPage::reset(); m_model->setFilters(readFilters(project()->projectConfiguration())); } -void ProjectFilterKCM::defaults() +void ProjectFilterConfigPage::defaults() { ProjectConfigPage::defaults(); m_model->setFilters(defaultFilters()); } -bool ProjectFilterKCM::eventFilter(QObject* object, QEvent* event) +bool ProjectFilterConfigPage::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() +void ProjectFilterConfigPage::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() +void ProjectFilterConfigPage::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() +void ProjectFilterConfigPage::remove() { Q_ASSERT(m_ui->filters->currentIndex().isValid()); m_model->removeRows(m_ui->filters->currentIndex().row(), 1); } -void ProjectFilterKCM::moveUp() +void ProjectFilterConfigPage::moveUp() { Q_ASSERT(m_ui->filters->currentIndex().isValid()); m_model->moveFilterUp(m_ui->filters->currentIndex().row()); } -void ProjectFilterKCM::moveDown() +void ProjectFilterConfigPage::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() +void ProjectFilterConfigPage::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 +QString ProjectFilterConfigPage::fullName() const { return i18n("Configure which files and folders inside the project folder should be included or excluded."); } -QIcon ProjectFilterKCM::icon() const +QIcon ProjectFilterConfigPage::icon() const { return QIcon::fromTheme(QStringLiteral("view-filter")); } -QString ProjectFilterKCM::name() const +QString ProjectFilterConfigPage::name() const { return i18n("Project Filter"); } - -#include "projectfilterkcm.moc" diff --git a/plugins/projectfilter/projectfilterkcm.h b/plugins/projectfilter/projectfilterconfigpage.h similarity index 83% rename from plugins/projectfilter/projectfilterkcm.h rename to plugins/projectfilter/projectfilterconfigpage.h index 920a6a0278..92ccf176bb 100644 --- a/plugins/projectfilter/projectfilterkcm.h +++ b/plugins/projectfilter/projectfilterconfigpage.h @@ -1,72 +1,72 @@ /* This file is part of KDevelop Copyright 2013 Milian Wolff 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. */ -#ifndef KDEVPLATFORM_PLUGIN_PROJECTFILTERKCM_H -#define KDEVPLATFORM_PLUGIN_PROJECTFILTERKCM_H +#ifndef KDEVPLATFORM_PLUGIN_PROJECTFILTERCONFIGPAGE_H +#define KDEVPLATFORM_PLUGIN_PROJECTFILTERCONFIGPAGE_H #include #include "projectfiltersettings.h" namespace Ui { class ProjectFilterSettings; } namespace KDevelop { class FilterModel; class ProjectFilterProvider; -class ProjectFilterKCM : public ProjectConfigPage +class ProjectFilterConfigPage : public ProjectConfigPage { Q_OBJECT public: - ProjectFilterKCM(ProjectFilterProvider* provider, const KDevelop::ProjectConfigOptions& options, QWidget* parent); - virtual ~ProjectFilterKCM(); + ProjectFilterConfigPage(ProjectFilterProvider* provider, const KDevelop::ProjectConfigOptions& options, QWidget* parent); + virtual ~ProjectFilterConfigPage(); virtual QString name() const; virtual QIcon icon() const; virtual QString fullName() const; protected: virtual bool eventFilter(QObject* object, QEvent* event); private slots: void add(); void remove(); void moveUp(); void moveDown(); void selectionChanged(); void emitChanged(); public Q_SLOTS: virtual void apply() override; virtual void reset() override; virtual void defaults() override; private: FilterModel *m_model; ProjectFilterProvider* m_projectFilterProvider; QScopedPointer m_ui; }; } #endif diff --git a/plugins/projectfilter/projectfilterprovider.cpp b/plugins/projectfilter/projectfilterprovider.cpp index 16fa50762c..957fee4fc0 100644 --- a/plugins/projectfilter/projectfilterprovider.cpp +++ b/plugins/projectfilter/projectfilterprovider.cpp @@ -1,168 +1,168 @@ /* This file is part of KDevelop Copyright 2013 Milian Wolff 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 "projectfilterprovider.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "projectfilterdebug.h" -#include "projectfilterkcm.h" +#include "projectfilterconfigpage.h" #include using namespace KDevelop; K_PLUGIN_FACTORY_WITH_JSON(ProjectFilterProviderFactory, "kdevprojectfilter.json", registerPlugin();) ProjectFilterProvider::ProjectFilterProvider( QObject* parent, const QVariantList& /*args*/ ) : IPlugin( "kdevprojectfilter", parent ) { KDEV_USE_EXTENSION_INTERFACE( IProjectFilterProvider ) connect(core()->projectController(), &IProjectController::projectClosing, this, &ProjectFilterProvider::projectClosing); connect(core()->projectController(), &IProjectController::projectAboutToBeOpened, this, &ProjectFilterProvider::projectAboutToBeOpened); // initialize the filters for each project foreach(IProject* project, core()->projectController()->projects()) { updateProjectFilters(project); } } QSharedPointer ProjectFilterProvider::createFilter(IProject* project) const { return QSharedPointer(new ProjectFilter(project, m_filters[project])); } ContextMenuExtension ProjectFilterProvider::contextMenuExtension(Context* context) { ContextMenuExtension ret; if (!context->hasType(Context::ProjectItemContext)) { return ret; } ProjectItemContext* ctx = static_cast( context ); QList items = ctx->items(); // filter out project roots and items in targets QList< ProjectBaseItem* >::iterator it = items.begin(); while (it != items.end()) { if ((*it)->isProjectRoot() || !(*it)->parent()->folder()) { it = items.erase(it); } else { ++it; } } if (items.isEmpty()) { return ret; } QAction* action = new QAction(QIcon::fromTheme("view-filter"), i18np("Exclude Item From Project", "Exclude Items From Project", items.size()), this); action->setData(QVariant::fromValue(items)); connect(action, &QAction::triggered, this, &ProjectFilterProvider::addFilterFromContextMenu); ret.addAction(ContextMenuExtension::FileGroup, action); return ret; } void ProjectFilterProvider::addFilterFromContextMenu() { QAction* action = qobject_cast(sender()); Q_ASSERT(action); QList items = action->data().value >(); QHash changedProjectFilters; foreach(ProjectBaseItem* item, items) { if (!changedProjectFilters.contains(item->project())) { changedProjectFilters[item->project()] = readFilters(item->project()->projectConfiguration()); } SerializedFilters& filters = changedProjectFilters[item->project()]; Path path; if (item->target()) { path = Path(item->parent()->path(), item->text()); } else { path = item->path(); } filters << SerializedFilter('/' + item->project()->path().relativePath(path), item->folder() ? Filter::Folders : Filter::Files); } QHash< IProject*, SerializedFilters >::const_iterator it = changedProjectFilters.constBegin(); while (it != changedProjectFilters.constEnd()) { writeFilters(it.value(), it.key()->projectConfiguration()); m_filters[it.key()] = deserialize(it.value()); emit filterChanged(this, it.key()); ++it; } KMessageBox::information(ICore::self()->uiController()->activeMainWindow(), i18np("A filter for the item was added. To undo, use the project filter settings.", "A filter for the items was added. To undo, use the project filter settings.", items.size()), i18n("Project Filter Added"), "projectfilter-addfromctxmenu"); } void ProjectFilterProvider::updateProjectFilters(IProject* project) { Filters newFilters = deserialize(readFilters(project->projectConfiguration())); Filters& filters = m_filters[project]; if (filters != newFilters) { projectFilterDebug() << "project filter changed:" << project->name(); filters = newFilters; emit filterChanged(this, project); } } void ProjectFilterProvider::projectAboutToBeOpened(IProject* project) { m_filters[project] = deserialize(readFilters(project->projectConfiguration())); } void ProjectFilterProvider::projectClosing(IProject* project) { m_filters.remove(project); } int ProjectFilterProvider::perProjectConfigPages() const { return 1; } ConfigPage* ProjectFilterProvider::perProjectConfigPage(int i, const ProjectConfigOptions& options, QWidget* parent) { - return i == 0 ? new ProjectFilterKCM(this, options, parent) : nullptr; + return i == 0 ? new ProjectFilterConfigPage(this, options, parent) : nullptr; } #include "projectfilterprovider.moc"