Remove 1-1 dependency between locator and locator input widget

Add possibility for filters to set a new search text when accepting
an entry.
Move placeholder text update from locator manager to widget.
Propagate filter update through signal-slot connection instead of directly.
LocatorManager::show is the only place left that directly references the locator widget.

Change-Id: Id61354d9f166c2af8c9d5528ad8998c7c6b8e1ab
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2017-05-29 12:50:20 +02:00
parent 19a47fed29
commit 247639d9c3
36 changed files with 166 additions and 95 deletions

View File

@@ -83,8 +83,12 @@ QList<Core::LocatorFilterEntry> CMakeLocatorFilter::matchesFor(QFutureInterface<
return m_result; return m_result;
} }
void CMakeLocatorFilter::accept(Core::LocatorFilterEntry selection) const void CMakeLocatorFilter::accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
// Get the project containing the target selected // Get the project containing the target selected
const auto cmakeProject = qobject_cast<CMakeProject *>( const auto cmakeProject = qobject_cast<CMakeProject *>(
Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) { Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) {

View File

@@ -40,7 +40,8 @@ public:
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) 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;
void accept(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:

View File

@@ -180,8 +180,12 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
return betterEntries; return betterEntries;
} }
void BaseFileFilter::accept(LocatorFilterEntry selection) const void BaseFileFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
EditorManager::openEditor(selection.internalData.toString(), Id(), EditorManager::openEditor(selection.internalData.toString(), Id(),
EditorManager::CanContainLineAndColumnNumber); EditorManager::CanContainLineAndColumnNumber);
} }

View File

@@ -72,7 +72,8 @@ public:
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) override;
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
protected: protected:
void setFileIterator(Iterator *iterator); void setFileIterator(Iterator *iterator);

View File

@@ -95,8 +95,12 @@ QList<LocatorFilterEntry> CommandLocator::matchesFor(QFutureInterface<LocatorFil
return betterEntries; return betterEntries;
} }
void CommandLocator::accept(LocatorFilterEntry entry) const void CommandLocator::accept(LocatorFilterEntry entry,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
// Retrieve action via index. // Retrieve action via index.
const int index = entry.internalData.toInt(); const int index = entry.internalData.toInt();
QTC_ASSERT(index >= 0 && index < d->commands.size(), return); QTC_ASSERT(index >= 0 && index < d->commands.size(), return);

View File

@@ -47,7 +47,8 @@ public:
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:

View File

@@ -79,8 +79,12 @@ QList<LocatorFilterEntry> ExecuteFilter::matchesFor(QFutureInterface<LocatorFilt
return value; return value;
} }
void ExecuteFilter::accept(LocatorFilterEntry selection) const void ExecuteFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
ExecuteFilter *p = const_cast<ExecuteFilter *>(this); ExecuteFilter *p = const_cast<ExecuteFilter *>(this);
const QString value = selection.displayName.trimmed(); const QString value = selection.displayName.trimmed();

View File

@@ -51,7 +51,8 @@ public:
ExecuteFilter(); ExecuteFilter();
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &) override {} void refresh(QFutureInterface<void> &) override {}
private: private:

View File

@@ -47,8 +47,12 @@ QList<LocatorFilterEntry> ExternalToolsFilter::matchesFor(QFutureInterface<Locat
return m_results; return m_results;
} }
void ExternalToolsFilter::accept(LocatorFilterEntry selection) const void ExternalToolsFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
auto tool = selection.internalData.value<ExternalTool *>(); auto tool = selection.internalData.value<ExternalTool *>();
QTC_ASSERT(tool, return); QTC_ASSERT(tool, return);

View File

@@ -38,7 +38,8 @@ public:
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) override;

View File

@@ -57,8 +57,7 @@ QList<LocatorFilterEntry> *categorize(const QString &entry, const QString &candi
} // anynoumous namespace } // anynoumous namespace
FileSystemFilter::FileSystemFilter(LocatorWidget *locatorWidget) FileSystemFilter::FileSystemFilter()
: m_locatorWidget(locatorWidget)
{ {
setId("Files in file system"); setId("Files in file system");
setDisplayName(tr("Files in File System")); setDisplayName(tr("Files in File System"));
@@ -148,15 +147,18 @@ QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorF
return betterEntries; return betterEntries;
} }
void FileSystemFilter::accept(LocatorFilterEntry selection) const void FileSystemFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(selectionLength)
QString fileName = selection.fileName; QString fileName = selection.fileName;
QFileInfo info(fileName); QFileInfo info(fileName);
if (info.isDir()) { if (info.isDir()) {
QString value = shortcutString(); QString value = shortcutString();
value += QLatin1Char(' '); value += QLatin1Char(' ');
value += QDir::toNativeSeparators(info.absoluteFilePath() + QLatin1Char('/')); value += QDir::toNativeSeparators(info.absoluteFilePath() + QLatin1Char('/'));
m_locatorWidget->show(value, value.length()); *newText = value;
*selectionStart = value.length();
return; return;
} else if (!info.exists()) { } else if (!info.exists()) {
QFile file(selection.internalData.toString()); QFile file(selection.internalData.toString());

View File

@@ -36,25 +36,23 @@
namespace Core { namespace Core {
namespace Internal { namespace Internal {
class LocatorWidget;
class FileSystemFilter : public ILocatorFilter class FileSystemFilter : public ILocatorFilter
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FileSystemFilter(LocatorWidget *locatorWidget); explicit FileSystemFilter();
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) override;
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
QByteArray saveState() const override; QByteArray saveState() const override;
void restoreState(const QByteArray &state) override; void restoreState(const QByteArray &state) override;
bool openConfigDialog(QWidget *parent, bool &needsRefresh) override; bool openConfigDialog(QWidget *parent, bool &needsRefresh) override;
void refresh(QFutureInterface<void> &) override {} void refresh(QFutureInterface<void> &) override {}
private: private:
LocatorWidget *m_locatorWidget;
bool m_includeHidden = true; bool m_includeHidden = true;
QString m_currentDocumentDirectory; QString m_currentDocumentDirectory;
}; };

View File

@@ -419,10 +419,12 @@ void ILocatorFilter::setConfigurable(bool configurable)
*/ */
/*! /*!
\fn void ILocatorFilter::accept(LocatorFilterEntry selection) const \fn void ILocatorFilter::accept(LocatorFilterEntry selection, QString *newText, int *selectionStart, int *selectionLength) const
Called with the entry specified by \a selection when the user activates it Called with the entry specified by \a selection when the user activates it
in the result list. in the result list.
Implementations can return a new search term \a newText, which has \a selectionLength characters
starting from \a selectionStart preselected, and the cursor set to the end of the selection.
*/ */
/*! /*!

View File

@@ -117,7 +117,8 @@ public:
virtual QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry) = 0; virtual QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry) = 0;
virtual void accept(LocatorFilterEntry selection) const = 0; virtual void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const = 0;
virtual void refresh(QFutureInterface<void> &future) = 0; virtual void refresh(QFutureInterface<void> &future) = 0;

View File

@@ -48,6 +48,7 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/mapreduce.h> #include <utils/mapreduce.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/utilsicons.h>
#include <QSettings> #include <QSettings>
#include <QtPlugin> #include <QtPlugin>
@@ -89,31 +90,29 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *)
m_settingsPage = new LocatorSettingsPage(this); m_settingsPage = new LocatorSettingsPage(this);
m_corePlugin->addObject(m_settingsPage); m_corePlugin->addObject(m_settingsPage);
m_locatorWidget = new LocatorWidget(this); QAction *action = new QAction(Utils::Icons::ZOOM.icon(), tr("Locate..."), this);
m_locatorWidget->setEnabled(false);
StatusBarWidget *view = new StatusBarWidget;
view->setWidget(m_locatorWidget);
view->setContext(Context("LocatorWidget"));
view->setPosition(StatusBarWidget::First);
m_corePlugin->addAutoReleasedObject(view);
QAction *action = new QAction(m_locatorWidget->windowIcon(), m_locatorWidget->windowTitle(), this);
Command *cmd = ActionManager::registerAction(action, Constants::LOCATE); Command *cmd = ActionManager::registerAction(action, Constants::LOCATE);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+K"))); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+K")));
connect(action, &QAction::triggered, this, &Locator::openLocator); connect(action, &QAction::triggered, this, [] {
connect(cmd, &Command::keySequenceChanged, LocatorManager::show(QString());
this, [this, cmd]() { updatePlaceholderText(cmd); }); });
updatePlaceholderText(cmd);
ActionContainer *mtools = ActionManager::actionContainer(Constants::M_TOOLS); ActionContainer *mtools = ActionManager::actionContainer(Constants::M_TOOLS);
mtools->addAction(cmd); mtools->addAction(cmd);
m_corePlugin->addObject(new LocatorManager(m_locatorWidget)); auto locatorWidget = new LocatorWidget(this);
StatusBarWidget *view = new StatusBarWidget;
view->setWidget(locatorWidget);
view->setContext(Context("LocatorWidget"));
view->setPosition(StatusBarWidget::First);
m_corePlugin->addAutoReleasedObject(view);
m_corePlugin->addObject(new LocatorManager(locatorWidget));
m_openDocumentsFilter = new OpenDocumentsFilter; m_openDocumentsFilter = new OpenDocumentsFilter;
m_corePlugin->addObject(m_openDocumentsFilter); m_corePlugin->addObject(m_openDocumentsFilter);
m_fileSystemFilter = new FileSystemFilter(m_locatorWidget); m_fileSystemFilter = new FileSystemFilter();
m_corePlugin->addObject(m_fileSystemFilter); m_corePlugin->addObject(m_fileSystemFilter);
m_executeFilter = new ExecuteFilter(); m_executeFilter = new ExecuteFilter();
@@ -122,7 +121,7 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *)
m_externalToolsFilter = new ExternalToolsFilter; m_externalToolsFilter = new ExternalToolsFilter;
m_corePlugin->addObject(m_externalToolsFilter); m_corePlugin->addObject(m_externalToolsFilter);
m_corePlugin->addAutoReleasedObject(new LocatorFiltersFilter(this, m_locatorWidget)); m_corePlugin->addAutoReleasedObject(new LocatorFiltersFilter(this));
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
m_corePlugin->addAutoReleasedObject(new SpotlightLocatorFilter); m_corePlugin->addAutoReleasedObject(new SpotlightLocatorFilter);
#endif #endif
@@ -130,21 +129,6 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *)
connect(ICore::instance(), &ICore::saveSettingsRequested, this, &Locator::saveSettings); connect(ICore::instance(), &ICore::saveSettingsRequested, this, &Locator::saveSettings);
} }
void Locator::updatePlaceholderText(Command *command)
{
QTC_ASSERT(command, return);
if (command->keySequence().isEmpty())
m_locatorWidget->setPlaceholderText(tr("Type to locate"));
else
m_locatorWidget->setPlaceholderText(tr("Type to locate (%1)").arg(
command->keySequence().toString(QKeySequence::NativeText)));
}
void Locator::openLocator()
{
m_locatorWidget->show(QString());
}
void Locator::extensionsInitialized() void Locator::extensionsInitialized()
{ {
m_filters = ExtensionSystem::PluginManager::getObjects<ILocatorFilter>(); m_filters = ExtensionSystem::PluginManager::getObjects<ILocatorFilter>();
@@ -198,11 +182,10 @@ void Locator::loadSettings()
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
m_locatorWidget->updateFilterList();
m_locatorWidget->setEnabled(true);
if (m_refreshTimer.interval() > 0) if (m_refreshTimer.interval() > 0)
m_refreshTimer.start(); m_refreshTimer.start();
m_settingsInitialized = true; m_settingsInitialized = true;
emit filtersChanged();
} }
void Locator::updateEditorManagerPlaceholderText() void Locator::updateEditorManagerPlaceholderText()
@@ -296,7 +279,7 @@ void Locator::setFilters(QList<ILocatorFilter *> f)
{ {
m_filters = f; m_filters = f;
updateEditorManagerPlaceholderText(); // possibly some shortcut changed updateEditorManagerPlaceholderText(); // possibly some shortcut changed
m_locatorWidget->updateFilterList(); emit filtersChanged();
} }
void Locator::setCustomFilters(QList<ILocatorFilter *> filters) void Locator::setCustomFilters(QList<ILocatorFilter *> filters)

View File

@@ -40,7 +40,6 @@ namespace Core {
namespace Internal { namespace Internal {
class CorePlugin; class CorePlugin;
class LocatorWidget;
class OpenDocumentsFilter; class OpenDocumentsFilter;
class FileSystemFilter; class FileSystemFilter;
class LocatorSettingsPage; class LocatorSettingsPage;
@@ -65,17 +64,17 @@ public:
int refreshInterval(); int refreshInterval();
void setRefreshInterval(int interval); void setRefreshInterval(int interval);
signals:
void filtersChanged();
public slots: public slots:
void refresh(QList<ILocatorFilter *> filters = QList<ILocatorFilter *>()); void refresh(QList<ILocatorFilter *> filters = QList<ILocatorFilter *>());
void saveSettings(); void saveSettings();
void openLocator();
private: private:
void updatePlaceholderText(Core::Command *command);
void loadSettings(); void loadSettings();
void updateEditorManagerPlaceholderText(); void updateEditorManagerPlaceholderText();
LocatorWidget *m_locatorWidget;
LocatorSettingsPage *m_settingsPage; LocatorSettingsPage *m_settingsPage;
bool m_settingsInitialized = false; bool m_settingsInitialized = false;

View File

@@ -35,10 +35,8 @@ using namespace Core::Internal;
Q_DECLARE_METATYPE(ILocatorFilter*) Q_DECLARE_METATYPE(ILocatorFilter*)
LocatorFiltersFilter::LocatorFiltersFilter(Locator *plugin, LocatorFiltersFilter::LocatorFiltersFilter(Locator *plugin):
LocatorWidget *locatorWidget):
m_plugin(plugin), m_plugin(plugin),
m_locatorWidget(locatorWidget),
m_icon(Utils::Icons::NEXT.icon()) m_icon(Utils::Icons::NEXT.icon())
{ {
setId("FiltersFilter"); setId("FiltersFilter");
@@ -87,15 +85,18 @@ QList<LocatorFilterEntry> LocatorFiltersFilter::matchesFor(QFutureInterface<Loca
return entries; return entries;
} }
void LocatorFiltersFilter::accept(LocatorFilterEntry selection) const void LocatorFiltersFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(selectionLength)
bool ok; bool ok;
int index = selection.internalData.toInt(&ok); int index = selection.internalData.toInt(&ok);
QTC_ASSERT(ok && index >= 0 && index < m_filterShortcutStrings.size(), return); QTC_ASSERT(ok && index >= 0 && index < m_filterShortcutStrings.size(), return);
const QString shortcutString = m_filterShortcutStrings.at(index); const QString shortcutString = m_filterShortcutStrings.at(index);
if (!shortcutString.isEmpty()) if (!shortcutString.isEmpty()) {
m_locatorWidget->show(shortcutString + QLatin1Char(' '), *newText = shortcutString + QLatin1Char(' ');
shortcutString.length() + 1); *selectionStart = shortcutString.length() + 1;
}
} }
void LocatorFiltersFilter::refresh(QFutureInterface<void> &future) void LocatorFiltersFilter::refresh(QFutureInterface<void> &future)

View File

@@ -33,7 +33,6 @@ namespace Core {
namespace Internal { namespace Internal {
class Locator; class Locator;
class LocatorWidget;
/*! /*!
This filter provides the user with the list of available Locator filters. This filter provides the user with the list of available Locator filters.
@@ -44,19 +43,18 @@ class LocatorFiltersFilter : public ILocatorFilter
Q_OBJECT Q_OBJECT
public: public:
LocatorFiltersFilter(Locator *plugin, LocatorFiltersFilter(Locator *plugin);
LocatorWidget *locatorWidget);
// ILocatorFilter // ILocatorFilter
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) override;
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:
Locator *m_plugin; Locator *m_plugin;
LocatorWidget *m_locatorWidget;
QStringList m_filterShortcutStrings; QStringList m_filterShortcutStrings;
QStringList m_filterDisplayNames; QStringList m_filterDisplayNames;
QIcon m_icon; QIcon m_icon;

View File

@@ -283,7 +283,6 @@ LocatorWidget::LocatorWidget(Locator *qop) :
setAttribute(Qt::WA_Hover); setAttribute(Qt::WA_Hover);
setFocusProxy(m_fileLineEdit); setFocusProxy(m_fileLineEdit);
setWindowTitle(tr("Locate..."));
resize(200, 90); resize(200, 90);
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0); sizePolicy.setHorizontalStretch(0);
@@ -296,7 +295,6 @@ LocatorWidget::LocatorWidget(Locator *qop) :
layout->setMargin(0); layout->setMargin(0);
layout->addWidget(m_fileLineEdit); layout->addWidget(m_fileLineEdit);
setWindowIcon(Utils::Icons::ZOOM.icon());
const QPixmap pixmap = Utils::Icons::MAGNIFIER.pixmap(); const QPixmap pixmap = Utils::Icons::MAGNIFIER.pixmap();
m_fileLineEdit->setFiltering(true); m_fileLineEdit->setFiltering(true);
m_fileLineEdit->setButtonPixmap(Utils::FancyLineEdit::Left, pixmap); m_fileLineEdit->setButtonPixmap(Utils::FancyLineEdit::Left, pixmap);
@@ -345,11 +343,27 @@ LocatorWidget::LocatorWidget(Locator *qop) :
m_showProgressTimer.setSingleShot(true); m_showProgressTimer.setSingleShot(true);
m_showProgressTimer.setInterval(50); // don't show progress for < 50ms tasks m_showProgressTimer.setInterval(50); // don't show progress for < 50ms tasks
connect(&m_showProgressTimer, &QTimer::timeout, [this]() { setProgressIndicatorVisible(true);}); connect(&m_showProgressTimer, &QTimer::timeout, [this]() { setProgressIndicatorVisible(true);});
Command *locateCmd = ActionManager::command(Constants::LOCATE);
if (QTC_GUARD(locateCmd)) {
connect(locateCmd, &Command::keySequenceChanged, this, [this,locateCmd] {
updatePlaceholderText(locateCmd);
});
updatePlaceholderText(locateCmd);
} }
void LocatorWidget::setPlaceholderText(const QString &text) connect(m_locatorPlugin, &Locator::filtersChanged, this, &LocatorWidget::updateFilterList);
updateFilterList();
}
void LocatorWidget::updatePlaceholderText(Command *command)
{ {
m_fileLineEdit->setPlaceholderText(text); QTC_ASSERT(command, return);
if (command->keySequence().isEmpty())
m_fileLineEdit->setPlaceholderText(tr("Type to locate"));
else
m_fileLineEdit->setPlaceholderText(tr("Type to locate (%1)").arg(
command->keySequence().toString(QKeySequence::NativeText)));
} }
void LocatorWidget::updateFilterList() void LocatorWidget::updateFilterList()
@@ -658,10 +672,17 @@ void LocatorWidget::acceptCurrentEntry()
if (!index.isValid()) if (!index.isValid())
return; return;
const LocatorFilterEntry entry = m_locatorModel->data(index, ItemDataRoles::ResultItemRole).value<LocatorFilterEntry>(); const LocatorFilterEntry entry = m_locatorModel->data(index, ItemDataRoles::ResultItemRole).value<LocatorFilterEntry>();
Q_ASSERT(entry.filter != nullptr);
QString newText;
int selectionStart = -1;
int selectionLength = 0;
entry.filter->accept(entry, &newText, &selectionStart, &selectionLength);
if (newText.isEmpty()) {
m_completionList->hide(); m_completionList->hide();
m_fileLineEdit->clearFocus(); m_fileLineEdit->clearFocus();
Q_ASSERT(entry.filter != nullptr); } else {
entry.filter->accept(entry); show(newText, selectionStart, selectionLength);
}
} }
void LocatorWidget::show(const QString &text, int selectionStart, int selectionLength) void LocatorWidget::show(const QString &text, int selectionStart, int selectionLength)

View File

@@ -58,7 +58,7 @@ public:
void show(const QString &text, int selectionStart = -1, int selectionLength = 0); void show(const QString &text, int selectionStart = -1, int selectionLength = 0);
void setPlaceholderText(const QString &text); void updatePlaceholderText(Command *command);
private: private:
void showPopup(); void showPopup();

View File

@@ -114,8 +114,12 @@ void OpenDocumentsFilter::refresh(QFutureInterface<void> &future)
QMetaObject::invokeMethod(this, "refreshInternally", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(this, "refreshInternally", Qt::BlockingQueuedConnection);
} }
void OpenDocumentsFilter::accept(LocatorFilterEntry selection) const void OpenDocumentsFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
EditorManager::openEditor(selection.internalData.toString(), Id(), EditorManager::openEditor(selection.internalData.toString(), Id(),
EditorManager::CanContainLineAndColumnNumber); EditorManager::CanContainLineAndColumnNumber);
} }

View File

@@ -45,7 +45,8 @@ public:
OpenDocumentsFilter(); OpenDocumentsFilter();
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(LocatorFilterEntry selection) const override; void accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
public slots: public slots:

View File

@@ -119,8 +119,13 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
return betterEntries; return betterEntries;
} }
void CppCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection) const void CppCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart,
int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<CppTools::IndexItem::Ptr>(selection.internalData); IndexItem::Ptr info = qvariant_cast<CppTools::IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column()); Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
} }

View File

@@ -48,7 +48,8 @@ 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(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:

View File

@@ -121,8 +121,12 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
return betterEntries; return betterEntries;
} }
void CppLocatorFilter::accept(Core::LocatorFilterEntry selection) const void CppLocatorFilter::accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData); IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column()); Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
} }

View File

@@ -43,7 +43,8 @@ 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(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
protected: protected:

View File

@@ -137,8 +137,12 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi
return entries; return entries;
} }
void HelpIndexFilter::accept(LocatorFilterEntry selection) const void HelpIndexFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
const QString &key = selection.displayName; const QString &key = selection.displayName;
const QMap<QString, QUrl> &links = HelpManager::linksForKeyword(key); const QMap<QString, QUrl> &links = HelpManager::linksForKeyword(key);

View File

@@ -45,7 +45,8 @@ public:
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) 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;
void accept(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
Q_INVOKABLE QSet<QString> searchMatches(const QString &databaseFilePath, Q_INVOKABLE QSet<QString> searchMatches(const QString &databaseFilePath,

View File

@@ -143,8 +143,12 @@ QList<Core::LocatorFilterEntry> RemoteHelpFilter::matchesFor(QFutureInterface<Co
return entries; return entries;
} }
void RemoteHelpFilter::accept(Core::LocatorFilterEntry selection) const void RemoteHelpFilter::accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
const QString &url = selection.displayName; const QString &url = selection.displayName;
if (!url.isEmpty()) if (!url.isEmpty())
emit linkActivated(url); emit linkActivated(url);

View File

@@ -45,7 +45,8 @@ public:
// ILocatorFilter // ILocatorFilter
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(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
QByteArray saveState() const override; QByteArray saveState() const override;
void restoreState(const QByteArray &state) override; void restoreState(const QByteArray &state) override;

View File

@@ -86,8 +86,12 @@ QList<Core::LocatorFilterEntry> MacroLocatorFilter::matchesFor(QFutureInterface<
return betterEntries; return betterEntries;
} }
void MacroLocatorFilter::accept(Core::LocatorFilterEntry selection) const void MacroLocatorFilter::accept(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 // Give the focus back to the editor
Core::IEditor *editor = Core::EditorManager::currentEditor(); Core::IEditor *editor = Core::EditorManager::currentEditor();
if (editor) if (editor)

View File

@@ -45,7 +45,8 @@ 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(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:

View File

@@ -104,8 +104,12 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
return betterEntries; return betterEntries;
} }
void FunctionFilter::accept(Core::LocatorFilterEntry selection) const void FunctionFilter::accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
const LocatorData::Entry entry = qvariant_cast<LocatorData::Entry>(selection.internalData); const LocatorData::Entry entry = qvariant_cast<LocatorData::Entry>(selection.internalData);
Core::EditorManager::openEditorAt(entry.fileName, entry.line, entry.column); Core::EditorManager::openEditorAt(entry.fileName, entry.line, entry.column);
} }

View File

@@ -42,7 +42,8 @@ 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(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:

View File

@@ -88,8 +88,12 @@ QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<LocatorF
return value; return value;
} }
void LineNumberFilter::accept(LocatorFilterEntry selection) const void LineNumberFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
if (editor) { if (editor) {
EditorManager::addCurrentPositionToNavigationHistory(); EditorManager::addCurrentPositionToNavigationHistory();

View File

@@ -46,7 +46,8 @@ public:
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) 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;
void accept(Core::LocatorFilterEntry selection) const override; void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &) override {} void refresh(QFutureInterface<void> &) override {}
private: private: