forked from qt-creator/qt-creator
LanguageClient: support sorting outline combo box items
(cherry picked from commit 505358cb82
)
Change-Id: I793700e770c830b729d0e8780fc4cbac79c01c0f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <coreplugin/find/itemviewfind.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <languageserverprotocol/languagefeatures.h>
|
||||
#include <texteditor/outlinefactory.h>>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/itemviews.h>
|
||||
@@ -39,6 +40,7 @@
|
||||
#include <utils/treeviewcombobox.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QBoxLayout>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
@@ -328,8 +330,10 @@ private:
|
||||
void updateEntry();
|
||||
void activateEntry();
|
||||
void documentUpdated(TextEditor::TextDocument *document);
|
||||
void setSorted(bool sorted);
|
||||
|
||||
LanguageClientOutlineModel m_model;
|
||||
QSortFilterProxyModel m_proxyModel;
|
||||
QPointer<Client> m_client;
|
||||
TextEditor::TextEditorWidget *m_editorWidget;
|
||||
const DocumentUri m_uri;
|
||||
@@ -353,19 +357,32 @@ OutlineComboBox::OutlineComboBox(Client *client, TextEditor::BaseTextEditor *edi
|
||||
, m_uri(DocumentUri::fromFilePath(editor->document()->filePath()))
|
||||
{
|
||||
m_model.setSymbolStringifier(client->symbolStringifier());
|
||||
setModel(&m_model);
|
||||
m_proxyModel.setSourceModel(&m_model);
|
||||
const bool sorted = LanguageClientSettings::outlineComboBoxIsSorted();
|
||||
m_proxyModel.sort(sorted ? 0 : -1);
|
||||
setModel(&m_proxyModel);
|
||||
setMinimumContentsLength(13);
|
||||
QSizePolicy policy = sizePolicy();
|
||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
setSizePolicy(policy);
|
||||
setMaxVisibleItems(40);
|
||||
|
||||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
const QString sortActionText
|
||||
= QCoreApplication::translate("TextEditor::Internal::OutlineWidgetStack",
|
||||
"Sort Alphabetically");
|
||||
auto sortAction = new QAction(sortActionText, this);
|
||||
sortAction->setCheckable(true);
|
||||
sortAction->setChecked(sorted);
|
||||
addAction(sortAction);
|
||||
|
||||
connect(client->documentSymbolCache(), &DocumentSymbolCache::gotSymbols,
|
||||
this, &OutlineComboBox::updateModel);
|
||||
connect(client, &Client::documentUpdated, this, &OutlineComboBox::documentUpdated);
|
||||
connect(m_editorWidget, &TextEditor::TextEditorWidget::cursorPositionChanged,
|
||||
this, &OutlineComboBox::updateEntry);
|
||||
connect(this, QOverload<int>::of(&QComboBox::activated), this, &OutlineComboBox::activateEntry);
|
||||
connect(sortAction, &QAction::toggled, this, &OutlineComboBox::setSorted);
|
||||
|
||||
documentUpdated(editor->textDocument());
|
||||
}
|
||||
@@ -389,12 +406,12 @@ void OutlineComboBox::updateModel(const DocumentUri &resultUri, const DocumentSy
|
||||
void OutlineComboBox::updateEntry()
|
||||
{
|
||||
if (LanguageClientOutlineItem *item = itemForCursor(m_model, m_editorWidget->textCursor()))
|
||||
setCurrentIndex(m_model.indexForItem(item));
|
||||
setCurrentIndex(m_proxyModel.mapFromSource(m_model.indexForItem(item)));
|
||||
}
|
||||
|
||||
void OutlineComboBox::activateEntry()
|
||||
{
|
||||
const QModelIndex modelIndex = view()->currentIndex();
|
||||
const QModelIndex modelIndex = m_proxyModel.mapToSource(view()->currentIndex());
|
||||
if (modelIndex.isValid()) {
|
||||
const Position &pos = m_model.itemForIndex(modelIndex)->pos();
|
||||
Core::EditorManager::cutForwardNavigationHistory();
|
||||
@@ -411,4 +428,10 @@ void OutlineComboBox::documentUpdated(TextEditor::TextDocument *document)
|
||||
m_client->documentSymbolCache()->requestSymbols(m_uri, Schedule::Delayed);
|
||||
}
|
||||
|
||||
void OutlineComboBox::setSorted(bool sorted)
|
||||
{
|
||||
LanguageClientSettings::setOutlineComboBoxSorted(sorted);
|
||||
m_proxyModel.sort(sorted ? 0 : -1);
|
||||
}
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
@@ -80,6 +80,7 @@ constexpr char argumentsKey[] = "arguments";
|
||||
constexpr char settingsGroupKey[] = "LanguageClient";
|
||||
constexpr char clientsKey[] = "clients";
|
||||
constexpr char typedClientsKey[] = "typedClients";
|
||||
constexpr char outlineSortedKey[] = "outlineSorted";
|
||||
constexpr char mimeType[] = "application/language.client.setting";
|
||||
|
||||
namespace LanguageClient {
|
||||
@@ -686,6 +687,23 @@ void LanguageClientSettings::toSettings(QSettings *settings,
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
bool LanguageClientSettings::outlineComboBoxIsSorted()
|
||||
{
|
||||
auto settings = Core::ICore::settings();
|
||||
settings->beginGroup(settingsGroupKey);
|
||||
bool sorted = settings->value(outlineSortedKey).toBool();
|
||||
settings->endGroup();
|
||||
return sorted;
|
||||
}
|
||||
|
||||
void LanguageClientSettings::setOutlineComboBoxSorted(bool sorted)
|
||||
{
|
||||
auto settings = Core::ICore::settings();
|
||||
settings->beginGroup(settingsGroupKey);
|
||||
settings->setValue(outlineSortedKey, sorted);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
bool StdIOSettings::applyFromSettingsWidget(QWidget *widget)
|
||||
{
|
||||
bool changed = false;
|
||||
|
@@ -169,6 +169,9 @@ public:
|
||||
static void addSettings(BaseSettings *settings);
|
||||
static void enableSettings(const QString &id);
|
||||
static void toSettings(QSettings *settings, const QList<BaseSettings *> &languageClientSettings);
|
||||
|
||||
static bool outlineComboBoxIsSorted();
|
||||
static void setOutlineComboBoxSorted(bool sorted);
|
||||
};
|
||||
|
||||
class LANGUAGECLIENT_EXPORT BaseSettingsWidget : public QWidget
|
||||
|
Reference in New Issue
Block a user