2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "pluginview.h"
|
|
|
|
|
#include "pluginmanager.h"
|
|
|
|
|
#include "pluginspec.h"
|
2015-03-31 09:55:50 +02:00
|
|
|
#include "pluginspec_p.h"
|
2015-01-13 09:08:41 +01:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2015-06-09 14:04:34 +02:00
|
|
|
#include <utils/categorysortfiltermodel.h>
|
2016-07-25 11:58:28 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2014-04-09 16:02:06 +02:00
|
|
|
#include <utils/itemviews.h>
|
2016-05-04 16:41:15 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-01-03 12:53:55 +01:00
|
|
|
#include <QDebug>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2014-01-03 12:53:55 +01:00
|
|
|
#include <QGridLayout>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHeaderView>
|
2015-01-13 09:08:41 +01:00
|
|
|
#include <QItemSelectionModel>
|
2015-03-31 17:42:14 +02:00
|
|
|
#include <QMessageBox>
|
2015-03-11 16:24:01 +01:00
|
|
|
#include <QSet>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class ExtensionSystem::PluginView
|
2020-06-12 15:27:18 +02:00
|
|
|
\inheaderfile extensionsystem/pluginview.h
|
2020-02-07 16:02:22 +01:00
|
|
|
\inmodule QtCreator
|
2020-06-12 15:27:18 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The PluginView class implements a widget that shows a list of all
|
|
|
|
|
plugins and their state.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-06 11:46:55 +02:00
|
|
|
This class can be embedded for example in a dialog in the application that
|
2008-12-02 12:01:29 +01:00
|
|
|
uses the plugin manager.
|
2013-09-06 11:46:55 +02:00
|
|
|
The class also provides notifications for interaction with the list.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
\sa ExtensionSystem::PluginDetailsView
|
|
|
|
|
\sa ExtensionSystem::PluginErrorView
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-20 10:19:56 +01:00
|
|
|
\fn void ExtensionSystem::PluginView::currentPluginChanged(ExtensionSystem::PluginSpec *spec)
|
2008-12-02 12:01:29 +01:00
|
|
|
The current selection in the plugin list has changed to the
|
|
|
|
|
plugin corresponding to \a spec.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-20 10:19:56 +01:00
|
|
|
\fn void ExtensionSystem::PluginView::pluginActivated(ExtensionSystem::PluginSpec *spec)
|
2008-12-02 12:01:29 +01:00
|
|
|
The plugin list entry corresponding to \a spec has been activated,
|
2013-09-06 11:46:55 +02:00
|
|
|
for example by a double-click.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-02-07 16:02:22 +01:00
|
|
|
/*!
|
2020-02-20 10:19:56 +01:00
|
|
|
\fn void ExtensionSystem::PluginView::pluginSettingsChanged(ExtensionSystem::PluginSpec *spec)
|
2020-02-07 16:02:22 +01:00
|
|
|
The settings for the plugin list entry corresponding to \a spec changed.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-12-16 11:25:28 +01:00
|
|
|
Q_DECLARE_METATYPE(ExtensionSystem::PluginSpec*)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
using namespace Utils;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
namespace ExtensionSystem {
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-04-02 13:44:26 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
enum Columns { NameColumn, LoadedColumn, VersionColumn, VendorColumn, };
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
enum IconIndex { OkIcon, ErrorIcon, NotLoadedIcon };
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-04-01 16:49:43 +02:00
|
|
|
static const int SortRole = Qt::UserRole + 1;
|
|
|
|
|
|
2015-11-24 17:41:44 +01:00
|
|
|
static const QIcon &icon(IconIndex icon)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-11-24 17:41:44 +01:00
|
|
|
switch (icon) {
|
|
|
|
|
case OkIcon: {
|
2016-07-25 11:58:28 +02:00
|
|
|
static const QIcon ok = Utils::Icons::OK.icon();
|
2015-11-24 17:41:44 +01:00
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
case ErrorIcon: {
|
2016-08-05 10:21:41 +02:00
|
|
|
static const QIcon error = Utils::Icons::BROKEN.icon();
|
2015-11-24 17:41:44 +01:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
case NotLoadedIcon: {
|
2016-07-25 11:58:28 +02:00
|
|
|
static const QIcon notLoaded = Utils::Icons::NOTLOADED.icon();
|
2015-11-24 17:41:44 +01:00
|
|
|
return notLoaded;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
class PluginItem : public TreeItem
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-01-13 09:08:41 +01:00
|
|
|
public:
|
|
|
|
|
PluginItem(PluginSpec *spec, PluginView *view)
|
|
|
|
|
: m_spec(spec), m_view(view)
|
|
|
|
|
{}
|
|
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
QVariant data(int column, int role) const override
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
|
|
|
|
switch (column) {
|
|
|
|
|
case NameColumn:
|
2016-12-13 11:10:26 +01:00
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return m_spec->isExperimental() ? PluginView::tr("%1 (experimental)").arg(m_spec->name())
|
|
|
|
|
: m_spec->name();
|
|
|
|
|
if (role == SortRole)
|
2015-01-13 09:08:41 +01:00
|
|
|
return m_spec->name();
|
2015-03-31 17:42:14 +02:00
|
|
|
if (role == Qt::ToolTipRole) {
|
|
|
|
|
QString toolTip;
|
|
|
|
|
if (!m_spec->isAvailableForHostPlatform())
|
|
|
|
|
toolTip = PluginView::tr("Path: %1\nPlugin is not available on this platform.");
|
|
|
|
|
else if (m_spec->isEnabledIndirectly())
|
|
|
|
|
toolTip = PluginView::tr("Path: %1\nPlugin is enabled as dependency of an enabled plugin.");
|
|
|
|
|
else if (m_spec->isForceEnabled())
|
|
|
|
|
toolTip = PluginView::tr("Path: %1\nPlugin is enabled by command line argument.");
|
|
|
|
|
else if (m_spec->isForceDisabled())
|
|
|
|
|
toolTip = PluginView::tr("Path: %1\nPlugin is disabled by command line argument.");
|
|
|
|
|
else
|
|
|
|
|
toolTip = PluginView::tr("Path: %1");
|
|
|
|
|
return toolTip.arg(QDir::toNativeSeparators(m_spec->filePath()));
|
|
|
|
|
}
|
2015-01-13 09:08:41 +01:00
|
|
|
if (role == Qt::DecorationRole) {
|
|
|
|
|
bool ok = !m_spec->hasError();
|
|
|
|
|
QIcon i = icon(ok ? OkIcon : ErrorIcon);
|
|
|
|
|
if (ok && m_spec->state() != PluginSpec::Running)
|
|
|
|
|
i = icon(NotLoadedIcon);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LoadedColumn:
|
|
|
|
|
if (!m_spec->isAvailableForHostPlatform()) {
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::CheckStateRole || role == SortRole)
|
2015-01-13 09:08:41 +01:00
|
|
|
return Qt::Unchecked;
|
|
|
|
|
if (role == Qt::ToolTipRole)
|
|
|
|
|
return PluginView::tr("Plugin is not available on this platform.");
|
|
|
|
|
} else if (m_spec->isRequired()) {
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::CheckStateRole || role == SortRole)
|
2015-01-13 09:08:41 +01:00
|
|
|
return Qt::Checked;
|
|
|
|
|
if (role == Qt::ToolTipRole)
|
|
|
|
|
return PluginView::tr("Plugin is required.");
|
|
|
|
|
} else {
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::CheckStateRole || role == SortRole)
|
2015-03-31 09:55:50 +02:00
|
|
|
return m_spec->isEnabledBySettings() ? Qt::Checked : Qt::Unchecked;
|
2015-01-13 09:08:41 +01:00
|
|
|
if (role == Qt::ToolTipRole)
|
|
|
|
|
return PluginView::tr("Load on startup");
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
case VersionColumn:
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::DisplayRole || role == SortRole)
|
2015-01-13 09:08:41 +01:00
|
|
|
return QString::fromLatin1("%1 (%2)").arg(m_spec->version(), m_spec->compatVersion());
|
|
|
|
|
break;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
case VendorColumn:
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::DisplayRole || role == SortRole)
|
2015-01-13 09:08:41 +01:00
|
|
|
return m_spec->vendor();
|
|
|
|
|
break;
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
return QVariant();
|
2013-02-09 12:45:46 +08:00
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
2015-03-31 17:42:14 +02:00
|
|
|
if (column == LoadedColumn && role == Qt::CheckStateRole)
|
2019-01-18 20:25:30 +01:00
|
|
|
return m_view->setPluginsEnabled({m_spec}, data.toBool());
|
2015-01-13 09:08:41 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
bool isEnabled() const
|
|
|
|
|
{
|
2015-03-31 17:42:14 +02:00
|
|
|
return m_spec->isAvailableForHostPlatform() && !m_spec->isRequired();
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
Qt::ItemFlags flags(int column) const override
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
|
|
|
|
Qt::ItemFlags ret = Qt::ItemIsSelectable;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
if (isEnabled())
|
|
|
|
|
ret |= Qt::ItemIsEnabled;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
if (column == LoadedColumn) {
|
|
|
|
|
if (m_spec->isAvailableForHostPlatform() && !m_spec->isRequired())
|
2017-12-25 16:10:32 +03:00
|
|
|
ret |= Qt::ItemIsUserCheckable;
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
2010-06-07 10:25:39 +02:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
return ret;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
public:
|
|
|
|
|
PluginSpec *m_spec; // Not owned.
|
|
|
|
|
PluginView *m_view; // Not owned.
|
|
|
|
|
};
|
2010-03-12 17:22:46 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
class CollectionItem : public TreeItem
|
2010-03-12 17:22:46 +01:00
|
|
|
{
|
2015-01-13 09:08:41 +01:00
|
|
|
public:
|
2020-02-14 08:51:08 +01:00
|
|
|
CollectionItem(const QString &name, const QVector<PluginSpec *> &plugins, PluginView *view)
|
2019-05-27 14:12:11 +02:00
|
|
|
: m_name(name)
|
|
|
|
|
, m_plugins(plugins)
|
|
|
|
|
, m_view(view)
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
2020-02-14 08:51:08 +01:00
|
|
|
for (PluginSpec *spec : plugins)
|
2015-01-13 09:08:41 +01:00
|
|
|
appendChild(new PluginItem(spec, view));
|
|
|
|
|
}
|
2010-03-12 17:22:46 +01:00
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
QVariant data(int column, int role) const override
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
|
|
|
|
if (column == NameColumn) {
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::DisplayRole || role == SortRole)
|
2015-01-13 09:08:41 +01:00
|
|
|
return m_name;
|
|
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
if (column == LoadedColumn) {
|
|
|
|
|
if (role == Qt::ToolTipRole)
|
|
|
|
|
return PluginView::tr("Load on Startup");
|
2015-04-01 16:49:43 +02:00
|
|
|
if (role == Qt::CheckStateRole || role == SortRole) {
|
2015-01-13 09:08:41 +01:00
|
|
|
int checkedCount = 0;
|
2020-02-14 08:51:08 +01:00
|
|
|
for (PluginSpec *spec : m_plugins) {
|
2015-03-31 09:55:50 +02:00
|
|
|
if (spec->isEnabledBySettings())
|
2015-01-13 09:08:41 +01:00
|
|
|
++checkedCount;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
if (checkedCount == 0)
|
|
|
|
|
return Qt::Unchecked;
|
|
|
|
|
if (checkedCount == m_plugins.length())
|
|
|
|
|
return Qt::Checked;
|
|
|
|
|
return Qt::PartiallyChecked;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
|
|
|
|
if (column == LoadedColumn && role == Qt::CheckStateRole) {
|
2019-05-27 14:12:11 +02:00
|
|
|
const QVector<PluginSpec *> affectedPlugins
|
|
|
|
|
= Utils::filtered(m_plugins, [](PluginSpec *spec) { return !spec->isRequired(); });
|
|
|
|
|
if (m_view->setPluginsEnabled(Utils::transform<QSet>(affectedPlugins,
|
|
|
|
|
[](PluginSpec *s) { return s; }),
|
|
|
|
|
data.toBool())) {
|
2015-03-31 17:42:14 +02:00
|
|
|
update();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-01-13 09:08:41 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
Qt::ItemFlags flags(int column) const override
|
2015-01-13 09:08:41 +01:00
|
|
|
{
|
|
|
|
|
Qt::ItemFlags ret = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
|
if (column == LoadedColumn)
|
2017-12-25 16:10:32 +03:00
|
|
|
ret |= Qt::ItemIsUserCheckable;
|
2015-01-13 09:08:41 +01:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QString m_name;
|
2020-02-14 08:51:08 +01:00
|
|
|
const QVector<PluginSpec *> m_plugins;
|
2015-01-13 09:08:41 +01:00
|
|
|
PluginView *m_view; // Not owned.
|
|
|
|
|
};
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-04-02 13:44:26 +02:00
|
|
|
} // Internal
|
|
|
|
|
|
|
|
|
|
using namespace ExtensionSystem::Internal;
|
|
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
/*!
|
2020-02-07 16:02:22 +01:00
|
|
|
Constructs a plugin view with \a parent that displays a list of plugins
|
|
|
|
|
from a plugin manager.
|
2015-01-13 09:08:41 +01:00
|
|
|
*/
|
|
|
|
|
PluginView::PluginView(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
2010-03-12 16:02:23 +01:00
|
|
|
{
|
2015-01-13 09:08:41 +01:00
|
|
|
m_categoryView = new TreeView(this);
|
|
|
|
|
m_categoryView->setAlternatingRowColors(true);
|
|
|
|
|
m_categoryView->setIndentation(20);
|
|
|
|
|
m_categoryView->setUniformRowHeights(true);
|
|
|
|
|
m_categoryView->setSortingEnabled(true);
|
|
|
|
|
m_categoryView->setColumnWidth(LoadedColumn, 40);
|
|
|
|
|
m_categoryView->header()->setDefaultSectionSize(120);
|
|
|
|
|
m_categoryView->header()->setMinimumSectionSize(35);
|
2015-03-11 16:24:01 +01:00
|
|
|
m_categoryView->header()->setSortIndicator(0, Qt::AscendingOrder);
|
2015-02-03 23:56:02 +02:00
|
|
|
m_categoryView->setActivationMode(DoubleClickActivation);
|
2015-01-13 09:08:41 +01:00
|
|
|
m_categoryView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
m_categoryView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
2016-06-24 09:36:42 +02:00
|
|
|
m_model = new TreeModel<TreeItem, CollectionItem, PluginItem>(this);
|
2016-05-27 11:12:03 +02:00
|
|
|
m_model->setHeader({ tr("Name"), tr("Load"), tr("Version"), tr("Vendor") });
|
2015-03-11 16:24:01 +01:00
|
|
|
|
2020-06-10 07:56:14 +02:00
|
|
|
m_sortModel = new CategorySortFilterModel(this);
|
2015-03-11 16:24:01 +01:00
|
|
|
m_sortModel->setSourceModel(m_model);
|
2015-04-01 16:49:43 +02:00
|
|
|
m_sortModel->setSortRole(SortRole);
|
2015-04-02 13:44:26 +02:00
|
|
|
m_sortModel->setFilterKeyColumn(-1/*all*/);
|
2015-03-11 16:24:01 +01:00
|
|
|
m_categoryView->setModel(m_sortModel);
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
auto *gridLayout = new QGridLayout(this);
|
2015-01-13 09:08:41 +01:00
|
|
|
gridLayout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
|
gridLayout->addWidget(m_categoryView, 1, 0, 1, 1);
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
QHeaderView *header = m_categoryView->header();
|
|
|
|
|
header->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
header->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
connect(PluginManager::instance(), &PluginManager::pluginsChanged,
|
|
|
|
|
this, &PluginView::updatePlugins);
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
connect(m_categoryView, &QAbstractItemView::activated,
|
2018-07-19 23:19:33 +02:00
|
|
|
[this](const QModelIndex &idx) { emit pluginActivated(pluginForIndex(idx)); });
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
connect(m_categoryView->selectionModel(), &QItemSelectionModel::currentChanged,
|
2018-07-19 23:19:33 +02:00
|
|
|
[this](const QModelIndex &idx) { emit currentPluginChanged(pluginForIndex(idx)); });
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
updatePlugins();
|
|
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2018-07-19 23:19:33 +02:00
|
|
|
PluginView::~PluginView() = default;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
/*!
|
|
|
|
|
Returns the current selection in the list of plugins.
|
|
|
|
|
*/
|
|
|
|
|
PluginSpec *PluginView::currentPlugin() const
|
|
|
|
|
{
|
|
|
|
|
return pluginForIndex(m_categoryView->currentIndex());
|
|
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2020-02-07 16:02:22 +01:00
|
|
|
/*!
|
|
|
|
|
Sets the \a filter for listing plugins.
|
|
|
|
|
*/
|
2015-04-02 13:44:26 +02:00
|
|
|
void PluginView::setFilter(const QString &filter)
|
|
|
|
|
{
|
2020-06-22 12:22:11 +02:00
|
|
|
m_sortModel->setFilterRegularExpression(
|
|
|
|
|
QRegularExpression(QRegularExpression::escape(filter),
|
|
|
|
|
QRegularExpression::CaseInsensitiveOption));
|
2015-04-02 13:44:26 +02:00
|
|
|
m_categoryView->expandAll();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
PluginSpec *PluginView::pluginForIndex(const QModelIndex &index) const
|
|
|
|
|
{
|
2015-03-11 16:24:01 +01:00
|
|
|
const QModelIndex &sourceIndex = m_sortModel->mapToSource(index);
|
2016-06-24 09:36:42 +02:00
|
|
|
PluginItem *item = m_model->itemForIndexAtLevel<2>(sourceIndex);
|
2018-07-19 23:19:33 +02:00
|
|
|
return item ? item->m_spec: nullptr;
|
2015-01-13 09:08:41 +01:00
|
|
|
}
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
void PluginView::updatePlugins()
|
2010-03-12 16:02:23 +01:00
|
|
|
{
|
2015-01-13 09:08:41 +01:00
|
|
|
// Model.
|
2015-04-22 14:49:14 +02:00
|
|
|
m_model->clear();
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2019-05-27 14:12:11 +02:00
|
|
|
const QHash<QString, QVector<PluginSpec *>> pluginCollections
|
|
|
|
|
= PluginManager::pluginCollections();
|
|
|
|
|
std::vector<CollectionItem *> collections;
|
2017-10-19 13:34:41 +02:00
|
|
|
const auto end = pluginCollections.cend();
|
|
|
|
|
for (auto it = pluginCollections.cbegin(); it != end; ++it) {
|
2016-08-19 16:49:23 +02:00
|
|
|
const QString name = it.key().isEmpty() ? tr("Utilities") : it.key();
|
2019-05-27 14:12:11 +02:00
|
|
|
collections.push_back(new CollectionItem(name, it.value(), this));
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
2016-08-09 16:32:07 +03:00
|
|
|
Utils::sort(collections, &CollectionItem::m_name);
|
2015-01-13 09:08:41 +01:00
|
|
|
|
2020-02-14 08:51:08 +01:00
|
|
|
for (CollectionItem *collection : qAsConst(collections))
|
2015-01-13 09:08:41 +01:00
|
|
|
m_model->rootItem()->appendChild(collection);
|
|
|
|
|
|
2018-07-19 23:19:33 +02:00
|
|
|
emit m_model->layoutChanged();
|
2015-01-13 09:08:41 +01:00
|
|
|
m_categoryView->expandAll();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2015-01-13 09:08:41 +01:00
|
|
|
|
2015-03-31 17:42:14 +02:00
|
|
|
static QString pluginListString(const QSet<PluginSpec *> &plugins)
|
|
|
|
|
{
|
|
|
|
|
QStringList names = Utils::transform<QList>(plugins, &PluginSpec::name);
|
|
|
|
|
names.sort();
|
|
|
|
|
return names.join(QLatin1Char('\n'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PluginView::setPluginsEnabled(const QSet<PluginSpec *> &plugins, bool enable)
|
|
|
|
|
{
|
|
|
|
|
QSet<PluginSpec *> additionalPlugins;
|
|
|
|
|
if (enable) {
|
2020-02-14 08:51:08 +01:00
|
|
|
for (PluginSpec *spec : plugins) {
|
|
|
|
|
for (PluginSpec *other : PluginManager::pluginsRequiredByPlugin(spec)) {
|
2015-03-31 17:42:14 +02:00
|
|
|
if (!other->isEnabledBySettings())
|
|
|
|
|
additionalPlugins.insert(other);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
additionalPlugins.subtract(plugins);
|
|
|
|
|
if (!additionalPlugins.isEmpty()) {
|
|
|
|
|
if (QMessageBox::question(this, tr("Enabling Plugins"),
|
|
|
|
|
tr("Enabling\n%1\nwill also enable the following plugins:\n\n%2")
|
|
|
|
|
.arg(pluginListString(plugins))
|
|
|
|
|
.arg(pluginListString(additionalPlugins)),
|
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel,
|
|
|
|
|
QMessageBox::Ok) != QMessageBox::Ok)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-02-14 08:51:08 +01:00
|
|
|
for (PluginSpec *spec : plugins) {
|
|
|
|
|
for (PluginSpec *other : PluginManager::pluginsRequiringPlugin(spec)) {
|
2015-03-31 17:42:14 +02:00
|
|
|
if (other->isEnabledBySettings())
|
|
|
|
|
additionalPlugins.insert(other);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
additionalPlugins.subtract(plugins);
|
|
|
|
|
if (!additionalPlugins.isEmpty()) {
|
|
|
|
|
if (QMessageBox::question(this, tr("Disabling Plugins"),
|
|
|
|
|
tr("Disabling\n%1\nwill also disable the following plugins:\n\n%2")
|
|
|
|
|
.arg(pluginListString(plugins))
|
|
|
|
|
.arg(pluginListString(additionalPlugins)),
|
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel,
|
|
|
|
|
QMessageBox::Ok) != QMessageBox::Ok)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 08:51:08 +01:00
|
|
|
const QSet<PluginSpec *> affectedPlugins = plugins + additionalPlugins;
|
|
|
|
|
for (PluginSpec *spec : affectedPlugins) {
|
2016-06-24 09:36:42 +02:00
|
|
|
PluginItem *item = m_model->findItemAtLevel<2>([spec](PluginItem *item) {
|
2015-03-31 17:42:14 +02:00
|
|
|
return item->m_spec == spec;
|
|
|
|
|
});
|
|
|
|
|
QTC_ASSERT(item, continue);
|
2022-06-23 16:30:46 +02:00
|
|
|
if (m_affectedPlugins.find(spec) == m_affectedPlugins.end())
|
|
|
|
|
m_affectedPlugins[spec] = spec->d->enabledBySettings;
|
2015-03-31 17:42:14 +02:00
|
|
|
spec->d->setEnabledBySettings(enable);
|
|
|
|
|
item->updateColumn(LoadedColumn);
|
|
|
|
|
item->parent()->updateColumn(LoadedColumn);
|
|
|
|
|
emit pluginSettingsChanged(spec);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 16:30:46 +02:00
|
|
|
void PluginView::cancelChanges()
|
|
|
|
|
{
|
|
|
|
|
for (auto element : m_affectedPlugins)
|
|
|
|
|
element.first->d->setEnabledBySettings(element.second);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 09:08:41 +01:00
|
|
|
} // namespace ExtensionSystem
|