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}
|
DEPENDS ${FWAppKit}
|
||||||
SOURCES
|
SOURCES
|
||||||
progressmanager/progressmanager_mac.mm
|
progressmanager/progressmanager_mac.mm
|
||||||
|
)
|
||||||
|
|
||||||
|
extend_qtc_plugin(Core
|
||||||
|
CONDITION NOT WIN32
|
||||||
|
SOURCES
|
||||||
locator/spotlightlocatorfilter.h locator/spotlightlocatorfilter.cpp
|
locator/spotlightlocatorfilter.h locator/spotlightlocatorfilter.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -59,7 +59,7 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_UNIX
|
||||||
#include "spotlightlocatorfilter.h"
|
#include "spotlightlocatorfilter.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public:
|
|||||||
MenuBarFilter m_menubarFilter;
|
MenuBarFilter m_menubarFilter;
|
||||||
UrlLocatorFilter m_urlFilter{UrlLocatorFilter::tr("Web Search"), "RemoteHelpFilter"};
|
UrlLocatorFilter m_urlFilter{UrlLocatorFilter::tr("Web Search"), "RemoteHelpFilter"};
|
||||||
UrlLocatorFilter m_bugFilter{UrlLocatorFilter::tr("Qt Project Bugs"), "QtProjectBugs"};
|
UrlLocatorFilter m_bugFilter{UrlLocatorFilter::tr("Qt Project Bugs"), "QtProjectBugs"};
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_UNIX
|
||||||
SpotlightLocatorFilter m_spotlightLocatorFilter;
|
SpotlightLocatorFilter m_spotlightLocatorFilter;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@@ -32,10 +32,12 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
|
||||||
@@ -169,8 +171,26 @@ void SpotlightIterator::ensureNext()
|
|||||||
|
|
||||||
SpotlightLocatorFilter::SpotlightLocatorFilter()
|
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");
|
setId("SpotlightFileNamesLocatorFilter");
|
||||||
setDisplayName(tr("Spotlight File Name Index"));
|
setDisplayName(tr("File Name Index"));
|
||||||
setShortcutString("md");
|
setShortcutString("md");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,16 +200,10 @@ void SpotlightLocatorFilter::prepareSearch(const QString &entry)
|
|||||||
if (fp.filePath.isEmpty()) {
|
if (fp.filePath.isEmpty()) {
|
||||||
setFileIterator(new BaseFileFilter::ListIterator(Utils::FilePaths()));
|
setFileIterator(new BaseFileFilter::ListIterator(Utils::FilePaths()));
|
||||||
} else {
|
} 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('/'));
|
int lastSlash = fp.filePath.lastIndexOf(QLatin1Char('/'));
|
||||||
QString quoted = fp.filePath.mid(lastSlash + 1);
|
const QString query = fp.filePath.mid(lastSlash + 1);
|
||||||
quoted.replace('\\', "\\\\").replace('\'', "\\\'").replace('\"', "\\\"");
|
setFileIterator(new SpotlightIterator(command(query, caseSensitivity(fp.filePath))));
|
||||||
setFileIterator(new SpotlightIterator(
|
|
||||||
{"mdfind",
|
|
||||||
QString("kMDItemFSName = '*%1*'%2")
|
|
||||||
.arg(quoted,
|
|
||||||
caseSensitivity(fp.filePath) == Qt::CaseInsensitive ? QString("c")
|
|
||||||
: QString())}));
|
|
||||||
}
|
}
|
||||||
BaseFileFilter::prepareSearch(entry);
|
BaseFileFilter::prepareSearch(entry);
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "basefilefilter.h"
|
#include "basefilefilter.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -38,6 +40,9 @@ public:
|
|||||||
|
|
||||||
void prepareSearch(const QString &entry) override;
|
void prepareSearch(const QString &entry) override;
|
||||||
void refresh(QFutureInterface<void> &future) override;
|
void refresh(QFutureInterface<void> &future) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<QStringList(QString, Qt::CaseSensitivity)> command;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
Reference in New Issue
Block a user