-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugindialog.cpp
154 lines (134 loc) · 5.45 KB
/
plugindialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "plugindialog.h"
#include "coreplugintr.h"
//#include "dialogs/restartdialog.h"
//#include "icore.h"
//#include "plugininstallwizard.h"
//#include <app/app_version.h>
#include <extensionsystem/plugindetailsview.h>
#include <extensionsystem/pluginerrorview.h>
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h>
#include <extensionsystem/pluginview.h>
#include <gui/fancylineedit.h>
#include <QtWidgets>
using namespace Utils;
namespace Plugin {
PluginDialog::PluginDialog(QWidget *parent)
: GUI::Dialog(parent)
, m_view(new ExtensionSystem::PluginView(this))
{
auto *widget = new QWidget(this);
setCentralWidget(widget);
auto *vl = new QVBoxLayout(widget);
auto *filterLayout = new QHBoxLayout;
vl->addLayout(filterLayout);
auto *filterEdit = new GUI::FancyLineEdit(this);
filterEdit->setFiltering(true);
connect(filterEdit,
&GUI::FancyLineEdit::filterChanged,
m_view,
&ExtensionSystem::PluginView::setFilter);
filterLayout->addWidget(filterEdit);
vl->addWidget(m_view);
m_detailsButton = new QPushButton(Tr::tr("Details"), this);
m_errorDetailsButton = new QPushButton(Tr::tr("Error Details"), this);
m_installButton = new QPushButton(Tr::tr("Install Plugin..."), this);
m_detailsButton->setEnabled(false);
m_errorDetailsButton->setEnabled(false);
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::tr("Installed Plugins"));
connect(m_view,
&ExtensionSystem::PluginView::currentPluginChanged,
this,
&PluginDialog::updateButtons);
connect(m_view, &ExtensionSystem::PluginView::pluginActivated, this, &PluginDialog::openDetails);
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(buttonBox, &QDialogButtonBox::accepted, this, &PluginDialog::closeDialog);
connect(buttonBox, &QDialogButtonBox::rejected, this, &Dialog::reject);
connect(this, &Dialog::rejected, m_view, &ExtensionSystem::PluginView::cancelChanges);
updateButtons();
}
void PluginDialog::closeDialog()
{
ExtensionSystem::PluginManager::writeSettings();
// if (m_isRestartRequired) {
// RestartDialog restartDialog(ICore::dialogParent(),
// Tr::tr("Plugin changes will take effect after restart."));
// restartDialog.exec();
// }
accept();
}
void PluginDialog::showInstallWizard()
{
// if (PluginInstallWizard::exec())
// m_isRestartRequired = true;
}
void PluginDialog::updateButtons()
{
ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
if (selectedSpec != nullptr) {
m_detailsButton->setEnabled(true);
m_errorDetailsButton->setEnabled(selectedSpec->hasError());
} else {
m_detailsButton->setEnabled(false);
m_errorDetailsButton->setEnabled(false);
}
}
void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
{
if (spec == nullptr) {
return;
}
QDialog dialog(this);
dialog.setWindowTitle(Tr::tr("Plugin Details of %1").arg(spec->name()));
auto *layout = new QVBoxLayout;
dialog.setLayout(layout);
auto *details = new ExtensionSystem::PluginDetailsView(&dialog);
layout->addWidget(details);
details->update(spec);
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close,
Qt::Horizontal,
&dialog);
layout->addWidget(buttons);
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
dialog.resize(400, 500);
dialog.exec();
}
void PluginDialog::openErrorDetails()
{
ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
if (spec == nullptr) {
return;
}
QDialog dialog(this);
dialog.setWindowTitle(Tr::tr("Plugin Errors of %1").arg(spec->name()));
auto *layout = new QVBoxLayout;
dialog.setLayout(layout);
auto *errors = new ExtensionSystem::PluginErrorView(&dialog);
layout->addWidget(errors);
errors->update(spec);
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close,
Qt::Horizontal,
&dialog);
layout->addWidget(buttons);
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
dialog.resize(500, 300);
dialog.exec();
}
} // namespace Plugin