forked from qt-creator/qt-creator
LanguageServer: Use IOptionPage::setWidgetCreator() for settings
Change-Id: I6d05e739bc1348f09f3df7ab3ae8a701ce137b3c Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -104,17 +104,39 @@ private:
|
|||||||
QList<BaseSettings *> m_removed;
|
QList<BaseSettings *> m_removed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LanguageClientSettingsPageWidget : public QWidget
|
class LanguageClientSettingsPageWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LanguageClientSettingsPageWidget(LanguageClientSettingsModel &settings);
|
LanguageClientSettingsPageWidget(LanguageClientSettingsModel &settings,
|
||||||
|
QSet<QString> &changedSettings);
|
||||||
|
|
||||||
void currentChanged(const QModelIndex &index);
|
void currentChanged(const QModelIndex &index);
|
||||||
int currentRow() const;
|
int currentRow() const;
|
||||||
void resetCurrentSettings(int row);
|
void resetCurrentSettings(int row);
|
||||||
void applyCurrentSettings();
|
void applyCurrentSettings();
|
||||||
|
|
||||||
|
void apply() final
|
||||||
|
{
|
||||||
|
applyCurrentSettings();
|
||||||
|
LanguageClientManager::applySettings();
|
||||||
|
|
||||||
|
for (BaseSettings *setting : m_model.removed()) {
|
||||||
|
for (Client *client : LanguageClientManager::clientsForSetting(setting))
|
||||||
|
LanguageClientManager::shutdownClient(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
int row = currentRow();
|
||||||
|
m_model.reset(LanguageClientManager::currentSettings());
|
||||||
|
resetCurrentSettings(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
void finish()
|
||||||
|
{
|
||||||
|
m_settings.reset(LanguageClientManager::currentSettings());
|
||||||
|
m_changedSettings.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LanguageClientSettingsModel &m_settings;
|
|
||||||
QTreeView *m_view = nullptr;
|
QTreeView *m_view = nullptr;
|
||||||
struct CurrentSettings {
|
struct CurrentSettings {
|
||||||
BaseSettings *setting = nullptr;
|
BaseSettings *setting = nullptr;
|
||||||
@@ -123,30 +145,10 @@ private:
|
|||||||
|
|
||||||
void addItem(const Utils::Id &clientTypeId);
|
void addItem(const Utils::Id &clientTypeId);
|
||||||
void deleteItem();
|
void deleteItem();
|
||||||
};
|
|
||||||
|
|
||||||
class LanguageClientSettingsPage : public Core::IOptionsPage
|
LanguageClientSettingsModel &m_settings;
|
||||||
{
|
QSet<QString> &m_changedSettings;
|
||||||
public:
|
|
||||||
LanguageClientSettingsPage();
|
|
||||||
~LanguageClientSettingsPage() override;
|
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// IOptionsPage interface
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
QList<BaseSettings *> settings() const;
|
|
||||||
QList<BaseSettings *> changedSettings() const;
|
|
||||||
void addSettings(BaseSettings *settings);
|
|
||||||
void enableSettings(const QString &id, bool enable = true);
|
|
||||||
|
|
||||||
private:
|
|
||||||
LanguageClientSettingsModel m_model;
|
LanguageClientSettingsModel m_model;
|
||||||
QSet<QString> m_changedSettings;
|
|
||||||
QPointer<LanguageClientSettingsPageWidget> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<Utils::Id, ClientType> &clientTypes()
|
QMap<Utils::Id, ClientType> &clientTypes()
|
||||||
@@ -155,9 +157,11 @@ QMap<Utils::Id, ClientType> &clientTypes()
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageClientSettingsPageWidget::LanguageClientSettingsPageWidget(LanguageClientSettingsModel &settings)
|
LanguageClientSettingsPageWidget::LanguageClientSettingsPageWidget(LanguageClientSettingsModel &settings,
|
||||||
: m_settings(settings)
|
QSet<QString> &changedSettings)
|
||||||
, m_view(new QTreeView())
|
: m_view(new QTreeView())
|
||||||
|
, m_settings(settings)
|
||||||
|
, m_changedSettings(changedSettings)
|
||||||
{
|
{
|
||||||
auto mainLayout = new QVBoxLayout();
|
auto mainLayout = new QVBoxLayout();
|
||||||
auto layout = new QHBoxLayout();
|
auto layout = new QHBoxLayout();
|
||||||
@@ -264,6 +268,23 @@ void LanguageClientSettingsPageWidget::deleteItem()
|
|||||||
m_settings.removeRows(index.row());
|
m_settings.removeRows(index.row());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LanguageClientSettingsPage : public Core::IOptionsPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LanguageClientSettingsPage();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
QList<BaseSettings *> settings() const;
|
||||||
|
QList<BaseSettings *> changedSettings() const;
|
||||||
|
void addSettings(BaseSettings *settings);
|
||||||
|
void enableSettings(const QString &id, bool enable = true);
|
||||||
|
|
||||||
|
private:
|
||||||
|
LanguageClientSettingsModel m_model;
|
||||||
|
QSet<QString> m_changedSettings;
|
||||||
|
};
|
||||||
|
|
||||||
LanguageClientSettingsPage::LanguageClientSettingsPage()
|
LanguageClientSettingsPage::LanguageClientSettingsPage()
|
||||||
{
|
{
|
||||||
setId(Constants::LANGUAGECLIENT_SETTINGS_PAGE);
|
setId(Constants::LANGUAGECLIENT_SETTINGS_PAGE);
|
||||||
@@ -271,18 +292,13 @@ LanguageClientSettingsPage::LanguageClientSettingsPage()
|
|||||||
setCategory(Constants::LANGUAGECLIENT_SETTINGS_CATEGORY);
|
setCategory(Constants::LANGUAGECLIENT_SETTINGS_CATEGORY);
|
||||||
setDisplayCategory(Tr::tr(Constants::LANGUAGECLIENT_SETTINGS_TR));
|
setDisplayCategory(Tr::tr(Constants::LANGUAGECLIENT_SETTINGS_TR));
|
||||||
setCategoryIconPath(":/languageclient/images/settingscategory_languageclient.png");
|
setCategoryIconPath(":/languageclient/images/settingscategory_languageclient.png");
|
||||||
|
setWidgetCreator([this] { return new LanguageClientSettingsPageWidget(m_model, m_changedSettings); });
|
||||||
connect(&m_model, &LanguageClientSettingsModel::dataChanged, [this](const QModelIndex &index) {
|
connect(&m_model, &LanguageClientSettingsModel::dataChanged, [this](const QModelIndex &index) {
|
||||||
if (BaseSettings *setting = m_model.settingForIndex(index))
|
if (BaseSettings *setting = m_model.settingForIndex(index))
|
||||||
m_changedSettings << setting->m_id;
|
m_changedSettings << setting->m_id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageClientSettingsPage::~LanguageClientSettingsPage()
|
|
||||||
{
|
|
||||||
if (m_widget)
|
|
||||||
delete m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LanguageClientSettingsPage::init()
|
void LanguageClientSettingsPage::init()
|
||||||
{
|
{
|
||||||
m_model.reset(LanguageClientSettings::fromSettings(Core::ICore::settings()));
|
m_model.reset(LanguageClientSettings::fromSettings(Core::ICore::settings()));
|
||||||
@@ -290,39 +306,6 @@ void LanguageClientSettingsPage::init()
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *LanguageClientSettingsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_widget)
|
|
||||||
m_widget = new LanguageClientSettingsPageWidget(m_model);
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LanguageClientSettingsPage::apply()
|
|
||||||
{
|
|
||||||
if (m_widget)
|
|
||||||
m_widget->applyCurrentSettings();
|
|
||||||
LanguageClientManager::applySettings();
|
|
||||||
|
|
||||||
for (BaseSettings *setting : m_model.removed()) {
|
|
||||||
for (Client *client : LanguageClientManager::clientsForSetting(setting))
|
|
||||||
LanguageClientManager::shutdownClient(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_widget) {
|
|
||||||
int row = m_widget->currentRow();
|
|
||||||
m_model.reset(LanguageClientManager::currentSettings());
|
|
||||||
m_widget->resetCurrentSettings(row);
|
|
||||||
} else {
|
|
||||||
m_model.reset(LanguageClientManager::currentSettings());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LanguageClientSettingsPage::finish()
|
|
||||||
{
|
|
||||||
m_model.reset(LanguageClientManager::currentSettings());
|
|
||||||
m_changedSettings.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<BaseSettings *> LanguageClientSettingsPage::settings() const
|
QList<BaseSettings *> LanguageClientSettingsPage::settings() const
|
||||||
{
|
{
|
||||||
return m_model.settings();
|
return m_model.settings();
|
||||||
|
Reference in New Issue
Block a user