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,7 +1108,10 @@ 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
{
public:
explicit LanguageClientProjectSettingsWidget(Project *project)
: m_settings(project) : m_settings(project)
{ {
setUseGlobalSettingsCheckBoxVisible(false); setUseGlobalSettingsCheckBoxVisible(false);
@@ -1131,4 +1137,27 @@ ProjectSettingsWidget::ProjectSettingsWidget(ProjectExplorer::Project *project)
[=]() { 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