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;
|
return item->m_spec == spec;
|
||||||
});
|
});
|
||||||
QTC_ASSERT(item, continue);
|
QTC_ASSERT(item, continue);
|
||||||
|
if (m_affectedPlugins.find(spec) == m_affectedPlugins.end())
|
||||||
|
m_affectedPlugins[spec] = spec->d->enabledBySettings;
|
||||||
spec->d->setEnabledBySettings(enable);
|
spec->d->setEnabledBySettings(enable);
|
||||||
item->updateColumn(LoadedColumn);
|
item->updateColumn(LoadedColumn);
|
||||||
item->parent()->updateColumn(LoadedColumn);
|
item->parent()->updateColumn(LoadedColumn);
|
||||||
@@ -447,4 +449,10 @@ bool PluginView::setPluginsEnabled(const QSet<PluginSpec *> &plugins, bool enabl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PluginView::cancelChanges()
|
||||||
|
{
|
||||||
|
for (auto element : m_affectedPlugins)
|
||||||
|
element.first->d->setEnabledBySettings(element.second);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ExtensionSystem
|
} // namespace ExtensionSystem
|
||||||
|
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
class CategorySortFilterModel;
|
class CategorySortFilterModel;
|
||||||
class TreeView;
|
class TreeView;
|
||||||
@@ -55,6 +57,7 @@ public:
|
|||||||
|
|
||||||
PluginSpec *currentPlugin() const;
|
PluginSpec *currentPlugin() const;
|
||||||
void setFilter(const QString &filter);
|
void setFilter(const QString &filter);
|
||||||
|
void cancelChanges();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentPluginChanged(ExtensionSystem::PluginSpec *spec);
|
void currentPluginChanged(ExtensionSystem::PluginSpec *spec);
|
||||||
@@ -69,6 +72,7 @@ private:
|
|||||||
Utils::TreeView *m_categoryView;
|
Utils::TreeView *m_categoryView;
|
||||||
Utils::TreeModel<Utils::TreeItem, Internal::CollectionItem, Internal::PluginItem> *m_model;
|
Utils::TreeModel<Utils::TreeItem, Internal::CollectionItem, Internal::PluginItem> *m_model;
|
||||||
Utils::CategorySortFilterModel *m_sortModel;
|
Utils::CategorySortFilterModel *m_sortModel;
|
||||||
|
std::unordered_map<PluginSpec *, bool> m_affectedPlugins;
|
||||||
|
|
||||||
friend class Internal::CollectionItem;
|
friend class Internal::CollectionItem;
|
||||||
friend class Internal::PluginItem;
|
friend class Internal::PluginItem;
|
||||||
|
@@ -54,8 +54,6 @@ using namespace Utils;
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static bool s_isRestartRequired = false;
|
|
||||||
|
|
||||||
PluginDialog::PluginDialog(QWidget *parent)
|
PluginDialog::PluginDialog(QWidget *parent)
|
||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
m_view(new ExtensionSystem::PluginView(this))
|
m_view(new ExtensionSystem::PluginView(this))
|
||||||
@@ -74,27 +72,15 @@ PluginDialog::PluginDialog(QWidget *parent)
|
|||||||
|
|
||||||
m_detailsButton = new QPushButton(tr("Details"), this);
|
m_detailsButton = new QPushButton(tr("Details"), this);
|
||||||
m_errorDetailsButton = new QPushButton(tr("Error 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_installButton = new QPushButton(tr("Install Plugin..."), this);
|
||||||
m_detailsButton->setEnabled(false);
|
m_detailsButton->setEnabled(false);
|
||||||
m_errorDetailsButton->setEnabled(false);
|
m_errorDetailsButton->setEnabled(false);
|
||||||
m_closeButton->setEnabled(true);
|
|
||||||
m_closeButton->setDefault(true);
|
|
||||||
|
|
||||||
m_restartRequired = new QLabel(tr("Restart required."), this);
|
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
if (!s_isRestartRequired)
|
buttonBox->addButton(m_detailsButton, QDialogButtonBox::ActionRole);
|
||||||
m_restartRequired->setVisible(false);
|
buttonBox->addButton(m_errorDetailsButton, QDialogButtonBox::ActionRole);
|
||||||
|
buttonBox->addButton(m_installButton, QDialogButtonBox::ActionRole);
|
||||||
auto hl = new QHBoxLayout;
|
vl->addWidget(buttonBox);
|
||||||
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);
|
|
||||||
|
|
||||||
resize(650, 400);
|
resize(650, 400);
|
||||||
setWindowTitle(tr("Installed Plugins"));
|
setWindowTitle(tr("Installed Plugins"));
|
||||||
@@ -103,21 +89,24 @@ PluginDialog::PluginDialog(QWidget *parent)
|
|||||||
this, &PluginDialog::updateButtons);
|
this, &PluginDialog::updateButtons);
|
||||||
connect(m_view, &ExtensionSystem::PluginView::pluginActivated,
|
connect(m_view, &ExtensionSystem::PluginView::pluginActivated,
|
||||||
this, &PluginDialog::openDetails);
|
this, &PluginDialog::openDetails);
|
||||||
connect(m_view, &ExtensionSystem::PluginView::pluginSettingsChanged,
|
connect(m_view, &ExtensionSystem::PluginView::pluginSettingsChanged, this, [this] {
|
||||||
this, &PluginDialog::updateRestartRequired);
|
m_isRestartRequired = true;
|
||||||
connect(m_detailsButton, &QAbstractButton::clicked,
|
});
|
||||||
|
connect(m_detailsButton, &QAbstractButton::clicked, this,
|
||||||
[this] { openDetails(m_view->currentPlugin()); });
|
[this] { openDetails(m_view->currentPlugin()); });
|
||||||
connect(m_errorDetailsButton, &QAbstractButton::clicked,
|
connect(m_errorDetailsButton, &QAbstractButton::clicked,
|
||||||
this, &PluginDialog::openErrorDetails);
|
this, &PluginDialog::openErrorDetails);
|
||||||
connect(m_installButton, &QAbstractButton::clicked, this, &PluginDialog::showInstallWizard);
|
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();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginDialog::closeDialog()
|
void PluginDialog::closeDialog()
|
||||||
{
|
{
|
||||||
ExtensionSystem::PluginManager::writeSettings();
|
ExtensionSystem::PluginManager::writeSettings();
|
||||||
if (s_isRestartRequired) {
|
if (m_isRestartRequired) {
|
||||||
RestartDialog restartDialog(ICore::dialogParent(),
|
RestartDialog restartDialog(ICore::dialogParent(),
|
||||||
tr("Plugin changes will take effect after restart."));
|
tr("Plugin changes will take effect after restart."));
|
||||||
restartDialog.exec();
|
restartDialog.exec();
|
||||||
@@ -128,14 +117,7 @@ void PluginDialog::closeDialog()
|
|||||||
void PluginDialog::showInstallWizard()
|
void PluginDialog::showInstallWizard()
|
||||||
{
|
{
|
||||||
if (PluginInstallWizard::exec())
|
if (PluginInstallWizard::exec())
|
||||||
updateRestartRequired();
|
m_isRestartRequired = true;
|
||||||
}
|
|
||||||
|
|
||||||
void PluginDialog::updateRestartRequired()
|
|
||||||
{
|
|
||||||
// just display the notice all the time after once changing something
|
|
||||||
s_isRestartRequired = true;
|
|
||||||
m_restartRequired->setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginDialog::updateButtons()
|
void PluginDialog::updateButtons()
|
||||||
|
@@ -48,7 +48,6 @@ public:
|
|||||||
explicit PluginDialog(QWidget *parent);
|
explicit PluginDialog(QWidget *parent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateRestartRequired();
|
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
void openDetails(ExtensionSystem::PluginSpec *spec);
|
void openDetails(ExtensionSystem::PluginSpec *spec);
|
||||||
void openErrorDetails();
|
void openErrorDetails();
|
||||||
@@ -60,8 +59,7 @@ private:
|
|||||||
QPushButton *m_detailsButton;
|
QPushButton *m_detailsButton;
|
||||||
QPushButton *m_errorDetailsButton;
|
QPushButton *m_errorDetailsButton;
|
||||||
QPushButton *m_installButton;
|
QPushButton *m_installButton;
|
||||||
QPushButton *m_closeButton;
|
bool m_isRestartRequired = false;
|
||||||
QLabel *m_restartRequired;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user