forked from qt-creator/qt-creator
LanguageClient: show icon with assigned server names in toolbar
Change-Id: I44ceeb184812a4c48f042a19197c7f0ffd4299f8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -26,8 +26,11 @@
|
||||
#include "languageclientutils.h"
|
||||
|
||||
#include "client.h"
|
||||
#include "languageclient_global.h"
|
||||
#include "languageclientmanager.h"
|
||||
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
|
||||
#include <texteditor/refactoringchanges.h>
|
||||
@@ -37,6 +40,8 @@
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextDocument>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace Utils;
|
||||
@@ -185,4 +190,44 @@ void updateCodeActionRefactoringMarker(Client *client,
|
||||
}
|
||||
}
|
||||
|
||||
void updateEditorToolBar(Core::IEditor *editor)
|
||||
{
|
||||
auto *textEditor = qobject_cast<BaseTextEditor *>(editor);
|
||||
if (!textEditor)
|
||||
return;
|
||||
TextEditorWidget *widget = textEditor->editorWidget();
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
const Core::IDocument *document = editor->document();
|
||||
QStringList clientsWithDoc;
|
||||
for (auto client : LanguageClientManager::clients()) {
|
||||
if (client->documentOpen(document))
|
||||
clientsWithDoc << client->name();
|
||||
}
|
||||
|
||||
static QMap<QWidget *, QAction *> actions;
|
||||
|
||||
if (actions.contains(widget)) {
|
||||
auto action = actions[widget];
|
||||
if (clientsWithDoc.isEmpty()) {
|
||||
widget->toolBar()->removeAction(action);
|
||||
actions.remove(widget);
|
||||
} else {
|
||||
action->setText(clientsWithDoc.join(';'));
|
||||
}
|
||||
} else if (!clientsWithDoc.isEmpty()) {
|
||||
const QIcon icon
|
||||
= Utils::Icon({{":/languageclient/images/languageclient.png",
|
||||
Utils::Theme::IconsBaseColor}})
|
||||
.icon();
|
||||
actions[widget] = widget->toolBar()->addAction(icon, clientsWithDoc.join(';'), []() {
|
||||
Core::ICore::showOptionsDialog(Constants::LANGUAGECLIENT_SETTINGS_PAGE);
|
||||
});
|
||||
QObject::connect(widget, &QWidget::destroyed, [widget]() {
|
||||
actions.remove(widget);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
||||
Reference in New Issue
Block a user