forked from qt-creator/qt-creator
MacroLocatorFilter: Reimplement matchers()
Change-Id: I90e638e68414e8b6fc38cc98d85720d05a78df50 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Macros;
|
using namespace Macros;
|
||||||
using namespace Macros::Internal;
|
using namespace Macros::Internal;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
MacroLocatorFilter::MacroLocatorFilter()
|
MacroLocatorFilter::MacroLocatorFilter()
|
||||||
: m_icon(QPixmap(":/macros/images/macro.png"))
|
: m_icon(QPixmap(":/macros/images/macro.png"))
|
||||||
@@ -25,7 +26,55 @@ MacroLocatorFilter::MacroLocatorFilter()
|
|||||||
setDefaultShortcutString("rm");
|
setDefaultShortcutString("rm");
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroLocatorFilter::~MacroLocatorFilter() = default;
|
LocatorMatcherTasks MacroLocatorFilter::matchers()
|
||||||
|
{
|
||||||
|
using namespace Tasking;
|
||||||
|
|
||||||
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
|
const auto onSetup = [storage, icon = m_icon] {
|
||||||
|
const QString input = storage->input();
|
||||||
|
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(input);
|
||||||
|
const QMap<QString, Macro *> ¯os = MacroManager::macros();
|
||||||
|
LocatorFilterEntries goodEntries;
|
||||||
|
LocatorFilterEntries betterEntries;
|
||||||
|
for (auto it = macros.cbegin(); it != macros.cend(); ++it) {
|
||||||
|
const QString displayName = it.key();
|
||||||
|
const QString description = it.value()->description();
|
||||||
|
int index = displayName.indexOf(input, 0, entryCaseSensitivity);
|
||||||
|
LocatorFilterEntry::HighlightInfo::DataType hDataType
|
||||||
|
= LocatorFilterEntry::HighlightInfo::DisplayName;
|
||||||
|
if (index < 0) {
|
||||||
|
index = description.indexOf(input, 0, entryCaseSensitivity);
|
||||||
|
hDataType = LocatorFilterEntry::HighlightInfo::ExtraInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index >= 0) {
|
||||||
|
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 = icon;
|
||||||
|
filterEntry.extraInfo = description;
|
||||||
|
filterEntry.highlightInfo = LocatorFilterEntry::HighlightInfo(index, input.length(),
|
||||||
|
hDataType);
|
||||||
|
if (index == 0)
|
||||||
|
betterEntries.append(filterEntry);
|
||||||
|
else
|
||||||
|
goodEntries.append(filterEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage->reportOutput(betterEntries + goodEntries);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {{Sync(onSetup), storage}};
|
||||||
|
}
|
||||||
|
|
||||||
QList<LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
|
QList<LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
|
||||||
{
|
{
|
||||||
|
@@ -14,11 +14,12 @@ class MacroLocatorFilter : public Core::ILocatorFilter
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
MacroLocatorFilter();
|
MacroLocatorFilter();
|
||||||
~MacroLocatorFilter() override;
|
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
private:
|
private:
|
||||||
|
Core::LocatorMatcherTasks matchers() final;
|
||||||
|
|
||||||
const QIcon m_icon;
|
const QIcon m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user