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:
David Schulz
2019-03-26 13:48:06 +01:00
parent 0c6f234d43
commit dac8262aeb
11 changed files with 156 additions and 11 deletions

View File

@@ -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