forked from qt-creator/qt-creator
Add "File Name Index" locator filter for Linux
Using the "locate" tool. Change-Id: Ic752b2d17e4874b95432510597ff33d5e3f967c5 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -178,6 +178,11 @@ extend_qtc_plugin(Core
|
||||
DEPENDS ${FWAppKit}
|
||||
SOURCES
|
||||
progressmanager/progressmanager_mac.mm
|
||||
)
|
||||
|
||||
extend_qtc_plugin(Core
|
||||
CONDITION NOT WIN32
|
||||
SOURCES
|
||||
locator/spotlightlocatorfilter.h locator/spotlightlocatorfilter.cpp
|
||||
)
|
||||
|
||||
|
@@ -59,7 +59,7 @@
|
||||
#include <QAction>
|
||||
#include <QSettings>
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
#ifdef Q_OS_UNIX
|
||||
#include "spotlightlocatorfilter.h"
|
||||
#endif
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
MenuBarFilter m_menubarFilter;
|
||||
UrlLocatorFilter m_urlFilter{UrlLocatorFilter::tr("Web Search"), "RemoteHelpFilter"};
|
||||
UrlLocatorFilter m_bugFilter{UrlLocatorFilter::tr("Qt Project Bugs"), "QtProjectBugs"};
|
||||
#ifdef Q_OS_MACOS
|
||||
#ifdef Q_OS_UNIX
|
||||
SpotlightLocatorFilter m_spotlightLocatorFilter;
|
||||
#endif
|
||||
};
|
||||
|
@@ -32,10 +32,12 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QTimer>
|
||||
#include <QWaitCondition>
|
||||
|
||||
@@ -169,8 +171,26 @@ void SpotlightIterator::ensureNext()
|
||||
|
||||
SpotlightLocatorFilter::SpotlightLocatorFilter()
|
||||
{
|
||||
if (HostOsInfo::isMacHost()) {
|
||||
command = [](const QString &query, Qt::CaseSensitivity sensitivity) {
|
||||
QString quoted = query;
|
||||
quoted.replace('\\', "\\\\").replace('\'', "\\\'").replace('\"', "\\\"");
|
||||
return QStringList(
|
||||
{"mdfind",
|
||||
QString("kMDItemFSName = '*%1*'%2")
|
||||
.arg(quoted, sensitivity == Qt::CaseInsensitive ? QString("c") : QString())});
|
||||
};
|
||||
} else {
|
||||
command = [](const QString &query, Qt::CaseSensitivity sensitivity) {
|
||||
QString regex = query;
|
||||
regex = regex.replace('*', ".*");
|
||||
return QStringList({"locate"})
|
||||
+ (sensitivity == Qt::CaseInsensitive ? QStringList({"-i"}) : QStringList())
|
||||
+ QStringList({"-l", "10000", "-r", regex});
|
||||
};
|
||||
}
|
||||
setId("SpotlightFileNamesLocatorFilter");
|
||||
setDisplayName(tr("Spotlight File Name Index"));
|
||||
setDisplayName(tr("File Name Index"));
|
||||
setShortcutString("md");
|
||||
}
|
||||
|
||||
@@ -180,16 +200,10 @@ void SpotlightLocatorFilter::prepareSearch(const QString &entry)
|
||||
if (fp.filePath.isEmpty()) {
|
||||
setFileIterator(new BaseFileFilter::ListIterator(Utils::FilePaths()));
|
||||
} else {
|
||||
// only pass the file name part to spotlight to allow searches like "somepath/*foo"
|
||||
// only pass the file name part to allow searches like "somepath/*foo"
|
||||
int lastSlash = fp.filePath.lastIndexOf(QLatin1Char('/'));
|
||||
QString quoted = fp.filePath.mid(lastSlash + 1);
|
||||
quoted.replace('\\', "\\\\").replace('\'', "\\\'").replace('\"', "\\\"");
|
||||
setFileIterator(new SpotlightIterator(
|
||||
{"mdfind",
|
||||
QString("kMDItemFSName = '*%1*'%2")
|
||||
.arg(quoted,
|
||||
caseSensitivity(fp.filePath) == Qt::CaseInsensitive ? QString("c")
|
||||
: QString())}));
|
||||
const QString query = fp.filePath.mid(lastSlash + 1);
|
||||
setFileIterator(new SpotlightIterator(command(query, caseSensitivity(fp.filePath))));
|
||||
}
|
||||
BaseFileFilter::prepareSearch(entry);
|
||||
}
|
||||
|
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "basefilefilter.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
@@ -38,6 +40,9 @@ public:
|
||||
|
||||
void prepareSearch(const QString &entry) override;
|
||||
void refresh(QFutureInterface<void> &future) override;
|
||||
|
||||
private:
|
||||
std::function<QStringList(QString, Qt::CaseSensitivity)> command;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
Reference in New Issue
Block a user