Add line/column number handling to spotlight locator filter

Otherwise it is not possible to directly open a file at a location with
the spotlight filter (in the style of "md qwidget.cpp:100").

Task-number: QTCREATORBUG-20473
Change-Id: I9ee70c411f77ca715ebba864ef16eab7c9b31bde
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-08-20 13:01:32 +02:00
parent 7a739b3b32
commit e40b250d13

View File

@@ -25,6 +25,7 @@
#include "spotlightlocatorfilter.h" #include "spotlightlocatorfilter.h"
#include <coreplugin/editormanager/editormanager.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QMutex> #include <QMutex>
@@ -180,19 +181,20 @@ void SpotlightIterator::ensureNext()
void SpotlightLocatorFilter::prepareSearch(const QString &entry) void SpotlightLocatorFilter::prepareSearch(const QString &entry)
{ {
if (entry.isEmpty()) { const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry);
if (fp.filePath.isEmpty()) {
setFileIterator(new BaseFileFilter::ListIterator(QStringList())); setFileIterator(new BaseFileFilter::ListIterator(QStringList()));
} else { } else {
// only pass the file name part to spotlight to allow searches like "somepath/*foo" // only pass the file name part to spotlight to allow searches like "somepath/*foo"
int lastSlash = entry.lastIndexOf(QLatin1Char('/')); int lastSlash = fp.filePath.lastIndexOf(QLatin1Char('/'));
QString quoted = entry.mid(lastSlash + 1); QString quoted = fp.filePath.mid(lastSlash + 1);
quoted.replace(QLatin1Char('\\'), QLatin1String("\\\\")) quoted.replace(QLatin1Char('\\'), QLatin1String("\\\\"))
.replace(QLatin1Char('\''), QLatin1String("\\\'")) .replace(QLatin1Char('\''), QLatin1String("\\\'"))
.replace(QLatin1Char('\"'), QLatin1String("\\\"")); .replace(QLatin1Char('\"'), QLatin1String("\\\""));
setFileIterator(new SpotlightIterator( setFileIterator(new SpotlightIterator(
QString::fromLatin1("kMDItemFSName like%1 \"*%2*\"") QString::fromLatin1("kMDItemFSName like%1 \"*%2*\"")
.arg(caseSensitivity(entry) == Qt::CaseInsensitive ? QLatin1String("[c]") .arg(caseSensitivity(fp.filePath) == Qt::CaseInsensitive ? QLatin1String("[c]")
: QString()) : QString())
.arg(quoted))); .arg(quoted)));
} }
BaseFileFilter::prepareSearch(entry); BaseFileFilter::prepareSearch(entry);