LanguageClient: Use new construction pattern for project panel

Change-Id: If3fa41d33a5d9b39d2596d619251bff3cfdf4b5d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-11-15 15:07:42 +01:00
parent e7b140fbfb
commit 2b39aa22fc
3 changed files with 52 additions and 39 deletions

View File

@@ -11,8 +11,6 @@
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <projectexplorer/projectpanelfactory.h>
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
@@ -40,12 +38,7 @@ void LanguageClientPlugin::initialize()
{ {
using namespace Core; using namespace Core;
auto panelFactory = new ProjectExplorer::ProjectPanelFactory; setupLanguageClientProjectPanel();
panelFactory->setPriority(35);
panelFactory->setDisplayName(Tr::tr("Language Server"));
panelFactory->setCreateWidgetFunction(
[](ProjectExplorer::Project *project) { return new ProjectSettingsWidget(project); });
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
LanguageClientManager::init(); LanguageClientManager::init();
LanguageClientSettings::registerClientType({Constants::LANGUAGECLIENT_STDIO_SETTINGS_ID, LanguageClientSettings::registerClientType({Constants::LANGUAGECLIENT_STDIO_SETTINGS_ID,

View File

@@ -15,6 +15,8 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectmanager.h> #include <projectexplorer/projectmanager.h>
#include <projectexplorer/projectpanelfactory.h>
#include <projectexplorer/projectsettingswidget.h>
#include <texteditor/plaintexteditorfactory.h> #include <texteditor/plaintexteditorfactory.h>
#include <texteditor/textmark.h> #include <texteditor/textmark.h>
@@ -66,6 +68,7 @@ constexpr char typedClientsKey[] = "typedClients";
constexpr char outlineSortedKey[] = "outlineSorted"; constexpr char outlineSortedKey[] = "outlineSorted";
constexpr char mimeType[] = "application/language.client.setting"; constexpr char mimeType[] = "application/language.client.setting";
using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace LanguageClient { namespace LanguageClient {
@@ -1105,30 +1108,56 @@ void ProjectSettings::setJson(const QByteArray &json)
LanguageClientManager::updateWorkspaceConfiguration(m_project, newConfig); LanguageClientManager::updateWorkspaceConfiguration(m_project, newConfig);
} }
ProjectSettingsWidget::ProjectSettingsWidget(ProjectExplorer::Project *project) class LanguageClientProjectSettingsWidget : public ProjectSettingsWidget
: m_settings(project)
{ {
setUseGlobalSettingsCheckBoxVisible(false); public:
setGlobalSettingsId(Constants::LANGUAGECLIENT_SETTINGS_PAGE); explicit LanguageClientProjectSettingsWidget(Project *project)
setExpanding(true); : m_settings(project)
{
setUseGlobalSettingsCheckBoxVisible(false);
setGlobalSettingsId(Constants::LANGUAGECLIENT_SETTINGS_PAGE);
setExpanding(true);
TextEditor::BaseTextEditor *editor = jsonEditor(); TextEditor::BaseTextEditor *editor = jsonEditor();
editor->document()->setContents(m_settings.json()); editor->document()->setContents(m_settings.json());
auto layout = new QVBoxLayout; auto layout = new QVBoxLayout;
setLayout(layout); setLayout(layout);
auto group = new QGroupBox(Tr::tr("Workspace Configuration")); auto group = new QGroupBox(Tr::tr("Workspace Configuration"));
group->setLayout(new QVBoxLayout); group->setLayout(new QVBoxLayout);
group->layout()->addWidget(new QLabel(Tr::tr( group->layout()->addWidget(new QLabel(Tr::tr(
"Additional JSON configuration sent to all running language servers for this project.\n" "Additional JSON configuration sent to all running language servers for this project.\n"
"See the documentation of the specific language server for valid settings."))); "See the documentation of the specific language server for valid settings.")));
group->layout()->addWidget(editor->widget()); group->layout()->addWidget(editor->widget());
layout->addWidget(group); layout->addWidget(group);
connect(editor->editorWidget()->textDocument(), connect(editor->editorWidget()->textDocument(),
&TextEditor::TextDocument::contentsChanged, &TextEditor::TextDocument::contentsChanged,
this, this,
[=]() { m_settings.setJson(editor->document()->contents()); }); [=]() { m_settings.setJson(editor->document()->contents()); });
}
private:
ProjectSettings m_settings;
};
class LanguageClientProjectPanelFactory : public ProjectPanelFactory
{
public:
LanguageClientProjectPanelFactory()
{
setPriority(35);
setDisplayName(Tr::tr("Language Server"));
setCreateWidgetFunction([](Project *project) {
return new LanguageClientProjectSettingsWidget(project);
});
ProjectPanelFactory::registerFactory(this);
}
};
void setupLanguageClientProjectPanel()
{
static LanguageClientProjectPanelFactory theLanguageClientProjectPanelFactory;
} }
} // namespace LanguageClient } // namespace LanguageClient

View File

@@ -7,8 +7,6 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <projectexplorer/projectsettingswidget.h>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QCoreApplication> #include <QCoreApplication>
#include <QJsonObject> #include <QJsonObject>
@@ -208,15 +206,8 @@ private:
QByteArray m_json; QByteArray m_json;
}; };
class ProjectSettingsWidget : public ProjectExplorer::ProjectSettingsWidget
{
public:
explicit ProjectSettingsWidget(ProjectExplorer::Project *project);
private:
ProjectSettings m_settings;
};
LANGUAGECLIENT_EXPORT TextEditor::BaseTextEditor *jsonEditor(); LANGUAGECLIENT_EXPORT TextEditor::BaseTextEditor *jsonEditor();
void setupLanguageClientProjectPanel();
} // namespace LanguageClient } // namespace LanguageClient