forked from qt-creator/qt-creator
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:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "spotlightlocatorfilter.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QMutex>
|
||||
@@ -180,18 +181,19 @@ void SpotlightIterator::ensureNext()
|
||||
|
||||
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()));
|
||||
} else {
|
||||
// only pass the file name part to spotlight to allow searches like "somepath/*foo"
|
||||
int lastSlash = entry.lastIndexOf(QLatin1Char('/'));
|
||||
QString quoted = entry.mid(lastSlash + 1);
|
||||
int lastSlash = fp.filePath.lastIndexOf(QLatin1Char('/'));
|
||||
QString quoted = fp.filePath.mid(lastSlash + 1);
|
||||
quoted.replace(QLatin1Char('\\'), QLatin1String("\\\\"))
|
||||
.replace(QLatin1Char('\''), QLatin1String("\\\'"))
|
||||
.replace(QLatin1Char('\"'), QLatin1String("\\\""));
|
||||
setFileIterator(new SpotlightIterator(
|
||||
QString::fromLatin1("kMDItemFSName like%1 \"*%2*\"")
|
||||
.arg(caseSensitivity(entry) == Qt::CaseInsensitive ? QLatin1String("[c]")
|
||||
.arg(caseSensitivity(fp.filePath) == Qt::CaseInsensitive ? QLatin1String("[c]")
|
||||
: QString())
|
||||
.arg(quoted)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user