MacroLocatorFilter: Use Acceptor for LocatorFilterEntry

Change-Id: Ie7aa7d81e1b81190b2966de09dc04b3ffb2691ea
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-04-12 00:11:40 +02:00
parent 99b5d93cfb
commit 3726bfc779
2 changed files with 18 additions and 28 deletions

View File

@@ -8,11 +8,10 @@
#include "macrostr.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
#include <QPixmap>
using namespace Core;
using namespace Macros;
using namespace Macros::Internal;
@@ -28,11 +27,11 @@ MacroLocatorFilter::MacroLocatorFilter()
MacroLocatorFilter::~MacroLocatorFilter() = default;
QList<Core::LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
QList<LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{
Q_UNUSED(future)
QList<Core::LocatorFilterEntry> goodEntries;
QList<Core::LocatorFilterEntry> betterEntries;
QList<LocatorFilterEntry> goodEntries;
QList<LocatorFilterEntry> betterEntries;
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(entry);
@@ -43,17 +42,27 @@ QList<Core::LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<
const QString description = it.value()->description();
int index = displayName.indexOf(entry, 0, entryCaseSensitivity);
Core::LocatorFilterEntry::HighlightInfo::DataType hDataType = Core::LocatorFilterEntry::HighlightInfo::DisplayName;
LocatorFilterEntry::HighlightInfo::DataType hDataType
= LocatorFilterEntry::HighlightInfo::DisplayName;
if (index < 0) {
index = description.indexOf(entry, 0, entryCaseSensitivity);
hDataType = Core::LocatorFilterEntry::HighlightInfo::ExtraInfo;
hDataType = LocatorFilterEntry::HighlightInfo::ExtraInfo;
}
if (index >= 0) {
Core::LocatorFilterEntry filterEntry(this, displayName);
LocatorFilterEntry filterEntry;
filterEntry.displayName = displayName;
filterEntry.acceptor = [displayName] {
IEditor *editor = EditorManager::currentEditor();
if (editor)
editor->widget()->setFocus(Qt::OtherFocusReason);
MacroManager::instance()->executeMacro(displayName);
return AcceptResult();
};
filterEntry.displayIcon = m_icon;
filterEntry.extraInfo = description;
filterEntry.highlightInfo = Core::LocatorFilterEntry::HighlightInfo(index, entry.length(), hDataType);
filterEntry.highlightInfo = LocatorFilterEntry::HighlightInfo(index, entry.length(), hDataType);
if (index == 0)
betterEntries.append(filterEntry);
@@ -64,17 +73,3 @@ QList<Core::LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<
betterEntries.append(goodEntries);
return betterEntries;
}
void MacroLocatorFilter::accept(const Core::LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const
{
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
// Give the focus back to the editor
Core::IEditor *editor = Core::EditorManager::currentEditor();
if (editor)
editor->widget()->setFocus(Qt::OtherFocusReason);
MacroManager::instance()->executeMacro(selection.displayName);
}

View File

@@ -5,8 +5,6 @@
#include <coreplugin/locator/ilocatorfilter.h>
#include <QIcon>
namespace Macros {
namespace Internal {
@@ -20,9 +18,6 @@ public:
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override;
void accept(const Core::LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
private:
const QIcon m_icon;
};