forked from qt-creator/qt-creator
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:
@@ -8,11 +8,10 @@
|
|||||||
#include "macrostr.h"
|
#include "macrostr.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace Macros;
|
using namespace Macros;
|
||||||
using namespace Macros::Internal;
|
using namespace Macros::Internal;
|
||||||
|
|
||||||
@@ -28,11 +27,11 @@ MacroLocatorFilter::MacroLocatorFilter()
|
|||||||
|
|
||||||
MacroLocatorFilter::~MacroLocatorFilter() = default;
|
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)
|
Q_UNUSED(future)
|
||||||
QList<Core::LocatorFilterEntry> goodEntries;
|
QList<LocatorFilterEntry> goodEntries;
|
||||||
QList<Core::LocatorFilterEntry> betterEntries;
|
QList<LocatorFilterEntry> betterEntries;
|
||||||
|
|
||||||
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(entry);
|
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(entry);
|
||||||
|
|
||||||
@@ -43,17 +42,27 @@ QList<Core::LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<
|
|||||||
const QString description = it.value()->description();
|
const QString description = it.value()->description();
|
||||||
|
|
||||||
int index = displayName.indexOf(entry, 0, entryCaseSensitivity);
|
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) {
|
if (index < 0) {
|
||||||
index = description.indexOf(entry, 0, entryCaseSensitivity);
|
index = description.indexOf(entry, 0, entryCaseSensitivity);
|
||||||
hDataType = Core::LocatorFilterEntry::HighlightInfo::ExtraInfo;
|
hDataType = LocatorFilterEntry::HighlightInfo::ExtraInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= 0) {
|
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.displayIcon = m_icon;
|
||||||
filterEntry.extraInfo = description;
|
filterEntry.extraInfo = description;
|
||||||
filterEntry.highlightInfo = Core::LocatorFilterEntry::HighlightInfo(index, entry.length(), hDataType);
|
filterEntry.highlightInfo = LocatorFilterEntry::HighlightInfo(index, entry.length(), hDataType);
|
||||||
|
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
betterEntries.append(filterEntry);
|
betterEntries.append(filterEntry);
|
||||||
@@ -64,17 +73,3 @@ QList<Core::LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<
|
|||||||
betterEntries.append(goodEntries);
|
betterEntries.append(goodEntries);
|
||||||
return betterEntries;
|
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);
|
|
||||||
}
|
|
||||||
|
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/locator/ilocatorfilter.h>
|
#include <coreplugin/locator/ilocatorfilter.h>
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
|
|
||||||
namespace Macros {
|
namespace Macros {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -20,9 +18,6 @@ public:
|
|||||||
|
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
void accept(const Core::LocatorFilterEntry &selection,
|
|
||||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QIcon m_icon;
|
const QIcon m_icon;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user