summaryrefslogtreecommitdiff
path: root/src/plugins/locator/filesystemfilter.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-08-01 10:14:10 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-08-22 09:42:22 +0200
commitef018ddd9ecf87338c58c5747904fcd81c06bbc5 (patch)
tree95af78bdbc2670c87fdca7934aef2577bb04437d /src/plugins/locator/filesystemfilter.cpp
parent541a717933db3f5f83699f412d9268c0fe590e71 (diff)
downloadqt-creator-ef018ddd9ecf87338c58c5747904fcd81c06bbc5.tar.gz
Locator: Case sensitivity of input affects prioritizing
So far candidates were prefix matched case sensitive which led to an unfavorable results order. With this patch, if the input is lower case, the prioritizing happens by a case insensitive prefix match. Otherwise the match happens case sensitive (just like before). Example: Search for e.g. "m cppmodelmanager" Top result before: AbstractEditorSupport (match at parameter type) Top result now: CppModelManager Change-Id: Ic27042cfe717be812a2237a3437399597c98dd74 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: David Schulz <david.schulz@digia.com>
Diffstat (limited to 'src/plugins/locator/filesystemfilter.cpp')
-rw-r--r--src/plugins/locator/filesystemfilter.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/plugins/locator/filesystemfilter.cpp b/src/plugins/locator/filesystemfilter.cpp
index 88cbf36719..d25d45a2a3 100644
--- a/src/plugins/locator/filesystemfilter.cpp
+++ b/src/plugins/locator/filesystemfilter.cpp
@@ -38,6 +38,21 @@ using namespace Core;
using namespace Locator;
using namespace Locator::Internal;
+namespace {
+
+QList<FilterEntry> *categorize(const QString &entry, const QString &candidate,
+ Qt::CaseSensitivity caseSensitivity,
+ QList<FilterEntry> *betterEntries, QList<FilterEntry> *goodEntries)
+{
+ if (entry.isEmpty() || candidate.startsWith(entry, caseSensitivity))
+ return betterEntries;
+ else if (candidate.contains(entry, caseSensitivity))
+ return goodEntries;
+ return 0;
+}
+
+} // anynoumous namespace
+
FileSystemFilter::FileSystemFilter(EditorManager *editorManager, LocatorWidget *locatorWidget)
: m_editorManager(editorManager), m_locatorWidget(locatorWidget), m_includeHidden(true)
{
@@ -49,7 +64,8 @@ FileSystemFilter::FileSystemFilter(EditorManager *editorManager, LocatorWidget *
QList<FilterEntry> FileSystemFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry)
{
- QList<FilterEntry> value;
+ QList<FilterEntry> goodEntries;
+ QList<FilterEntry> betterEntries;
QFileInfo entryInfo(entry);
QString name = entryInfo.fileName();
QString directory = entryInfo.path();
@@ -72,6 +88,7 @@ QList<FilterEntry> FileSystemFilter::matchesFor(QFutureInterface<Locator::Filter
dirFilter |= QDir::Hidden;
fileFilter |= QDir::Hidden;
}
+ const Qt::CaseSensitivity caseSensitivity_ = caseSensitivity(entry);
QStringList dirs = dirInfo.entryList(dirFilter,
QDir::Name|QDir::IgnoreCase|QDir::LocaleAware);
QStringList files = dirInfo.entryList(fileFilter,
@@ -79,11 +96,12 @@ QList<FilterEntry> FileSystemFilter::matchesFor(QFutureInterface<Locator::Filter
foreach (const QString &dir, dirs) {
if (future.isCanceled())
break;
- if (name.isEmpty() || dir.startsWith(name, Qt::CaseInsensitive)) {
+ if (QList<FilterEntry> *category = categorize(name, dir, caseSensitivity_, &betterEntries,
+ &goodEntries)) {
const QString fullPath = dirInfo.filePath(dir);
FilterEntry filterEntry(this, dir, QVariant());
filterEntry.fileName = fullPath;
- value.append(filterEntry);
+ category->append(filterEntry);
}
}
// file names can match with +linenumber or :linenumber
@@ -93,14 +111,16 @@ QList<FilterEntry> FileSystemFilter::matchesFor(QFutureInterface<Locator::Filter
foreach (const QString &file, files) {
if (future.isCanceled())
break;
- if (name.isEmpty() || file.startsWith(name, Qt::CaseInsensitive)) {
+ if (QList<FilterEntry> *category = categorize(name, file, caseSensitivity_, &betterEntries,
+ &goodEntries)) {
const QString fullPath = dirInfo.filePath(file);
FilterEntry filterEntry(this, file, QString(fullPath + lineNoSuffix));
filterEntry.fileName = fullPath;
- value.append(filterEntry);
+ category->append(filterEntry);
}
}
- return value;
+ betterEntries.append(goodEntries);
+ return betterEntries;
}
void FileSystemFilter::accept(FilterEntry selection) const