forked from qt-creator/qt-creator
CorePlugin: Add ok and cancel button to plugin dialog
Change-Id: I842be8fe3521026b98177e44925669fc5e67c83f Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -439,6 +439,8 @@ bool PluginView::setPluginsEnabled(const QSet<PluginSpec *> &plugins, bool enabl
|
||||
return item->m_spec == spec;
|
||||
});
|
||||
QTC_ASSERT(item, continue);
|
||||
if (m_affectedPlugins.find(spec) == m_affectedPlugins.end())
|
||||
m_affectedPlugins[spec] = spec->d->enabledBySettings;
|
||||
spec->d->setEnabledBySettings(enable);
|
||||
item->updateColumn(LoadedColumn);
|
||||
item->parent()->updateColumn(LoadedColumn);
|
||||
@@ -447,4 +449,10 @@ bool PluginView::setPluginsEnabled(const QSet<PluginSpec *> &plugins, bool enabl
|
||||
return true;
|
||||
}
|
||||
|
||||
void PluginView::cancelChanges()
|
||||
{
|
||||
for (auto element : m_affectedPlugins)
|
||||
element.first->d->setEnabledBySettings(element.second);
|
||||
}
|
||||
|
||||
} // namespace ExtensionSystem
|
||||
|
@@ -31,6 +31,8 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Utils {
|
||||
class CategorySortFilterModel;
|
||||
class TreeView;
|
||||
@@ -55,6 +57,7 @@ public:
|
||||
|
||||
PluginSpec *currentPlugin() const;
|
||||
void setFilter(const QString &filter);
|
||||
void cancelChanges();
|
||||
|
||||
signals:
|
||||
void currentPluginChanged(ExtensionSystem::PluginSpec *spec);
|
||||
@@ -69,6 +72,7 @@ private:
|
||||
Utils::TreeView *m_categoryView;
|
||||
Utils::TreeModel<Utils::TreeItem, Internal::CollectionItem, Internal::PluginItem> *m_model;
|
||||
Utils::CategorySortFilterModel *m_sortModel;
|
||||
std::unordered_map<PluginSpec *, bool> m_affectedPlugins;
|
||||
|
||||
friend class Internal::CollectionItem;
|
||||
friend class Internal::PluginItem;
|
||||
|
@@ -54,8 +54,6 @@ using namespace Utils;
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
static bool s_isRestartRequired = false;
|
||||
|
||||
PluginDialog::PluginDialog(QWidget *parent)
|
||||
: QDialog(parent),
|
||||
m_view(new ExtensionSystem::PluginView(this))
|
||||
@@ -74,27 +72,15 @@ PluginDialog::PluginDialog(QWidget *parent)
|
||||
|
||||
m_detailsButton = new QPushButton(tr("Details"), this);
|
||||
m_errorDetailsButton = new QPushButton(tr("Error Details"), this);
|
||||
m_closeButton = new QPushButton(tr("Close"), this);
|
||||
m_installButton = new QPushButton(tr("Install Plugin..."), this);
|
||||
m_detailsButton->setEnabled(false);
|
||||
m_errorDetailsButton->setEnabled(false);
|
||||
m_closeButton->setEnabled(true);
|
||||
m_closeButton->setDefault(true);
|
||||
|
||||
m_restartRequired = new QLabel(tr("Restart required."), this);
|
||||
if (!s_isRestartRequired)
|
||||
m_restartRequired->setVisible(false);
|
||||
|
||||
auto hl = new QHBoxLayout;
|
||||
hl->addWidget(m_detailsButton);
|
||||
hl->addWidget(m_errorDetailsButton);
|
||||
hl->addWidget(m_installButton);
|
||||
hl->addSpacing(10);
|
||||
hl->addWidget(m_restartRequired);
|
||||
hl->addStretch(5);
|
||||
hl->addWidget(m_closeButton);
|
||||
|
||||
vl->addLayout(hl);
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttonBox->addButton(m_detailsButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(m_errorDetailsButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(m_installButton, QDialogButtonBox::ActionRole);
|
||||
vl->addWidget(buttonBox);
|
||||
|
||||
resize(650, 400);
|
||||
setWindowTitle(tr("Installed Plugins"));
|
||||
@@ -103,21 +89,24 @@ PluginDialog::PluginDialog(QWidget *parent)
|
||||
this, &PluginDialog::updateButtons);
|
||||
connect(m_view, &ExtensionSystem::PluginView::pluginActivated,
|
||||
this, &PluginDialog::openDetails);
|
||||
connect(m_view, &ExtensionSystem::PluginView::pluginSettingsChanged,
|
||||
this, &PluginDialog::updateRestartRequired);
|
||||
connect(m_detailsButton, &QAbstractButton::clicked,
|
||||
connect(m_view, &ExtensionSystem::PluginView::pluginSettingsChanged, this, [this] {
|
||||
m_isRestartRequired = true;
|
||||
});
|
||||
connect(m_detailsButton, &QAbstractButton::clicked, this,
|
||||
[this] { openDetails(m_view->currentPlugin()); });
|
||||
connect(m_errorDetailsButton, &QAbstractButton::clicked,
|
||||
this, &PluginDialog::openErrorDetails);
|
||||
connect(m_installButton, &QAbstractButton::clicked, this, &PluginDialog::showInstallWizard);
|
||||
connect(m_closeButton, &QAbstractButton::clicked, this, &PluginDialog::closeDialog);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &PluginDialog::closeDialog);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
connect(this, &QDialog::rejected, m_view, &ExtensionSystem::PluginView::cancelChanges);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void PluginDialog::closeDialog()
|
||||
{
|
||||
ExtensionSystem::PluginManager::writeSettings();
|
||||
if (s_isRestartRequired) {
|
||||
if (m_isRestartRequired) {
|
||||
RestartDialog restartDialog(ICore::dialogParent(),
|
||||
tr("Plugin changes will take effect after restart."));
|
||||
restartDialog.exec();
|
||||
@@ -128,14 +117,7 @@ void PluginDialog::closeDialog()
|
||||
void PluginDialog::showInstallWizard()
|
||||
{
|
||||
if (PluginInstallWizard::exec())
|
||||
updateRestartRequired();
|
||||
}
|
||||
|
||||
void PluginDialog::updateRestartRequired()
|
||||
{
|
||||
// just display the notice all the time after once changing something
|
||||
s_isRestartRequired = true;
|
||||
m_restartRequired->setVisible(true);
|
||||
m_isRestartRequired = true;
|
||||
}
|
||||
|
||||
void PluginDialog::updateButtons()
|
||||
|
@@ -48,7 +48,6 @@ public:
|
||||
explicit PluginDialog(QWidget *parent);
|
||||
|
||||
private:
|
||||
void updateRestartRequired();
|
||||
void updateButtons();
|
||||
void openDetails(ExtensionSystem::PluginSpec *spec);
|
||||
void openErrorDetails();
|
||||
@@ -60,8 +59,7 @@ private:
|
||||
QPushButton *m_detailsButton;
|
||||
QPushButton *m_errorDetailsButton;
|
||||
QPushButton *m_installButton;
|
||||
QPushButton *m_closeButton;
|
||||
QLabel *m_restartRequired;
|
||||
bool m_isRestartRequired = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user