Core: filepathify LocatorFilterEntry

Change-Id: I279af30f6b57e8d1279d96e5cbae4025cf4ef473
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-05-27 10:54:10 +02:00
parent 9a8a7a88a6
commit 6008c5f673
8 changed files with 18 additions and 18 deletions

View File

@@ -87,7 +87,7 @@ void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
Core::LocatorFilterEntry filterEntry(this, target.title, extraData);
filterEntry.extraInfo = path.shortNativePath();
filterEntry.highlightInfo = {index, int(entry.length())};
filterEntry.fileName = path.toString();
filterEntry.filePath = path;
m_result.append(filterEntry);
}

View File

@@ -180,7 +180,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
if (match.hasMatch()) {
QFileInfo fi(path.toString());
LocatorFilterEntry filterEntry(this, fi.fileName(), QString(path.toString() + postfix));
filterEntry.fileName = path.toString();
filterEntry.filePath = path;
filterEntry.extraInfo = FilePath::fromFileInfo(fi).shortNativePath();
const MatchLevel matchLevel = matchLevelFor(match, matchText);
@@ -230,19 +230,19 @@ void BaseFileFilter::accept(LocatorFilterEntry selection,
void BaseFileFilter::openEditorAt(const LocatorFilterEntry& selection)
{
const FilePath selectedPath = FilePath::fromString(selection.fileName);
const FilePath locatorText = FilePath::fromVariant(selection.internalData);
const int postfixLength = locatorText.fileName().length() - selectedPath.fileName().length();
const int postfixLength = locatorText.fileName().length() - selection.filePath.fileName().length();
if (postfixLength > 0) {
const QString postfix = selection.internalData.toString().right(postfixLength);
int postfixPos = -1;
const LineColumn lineColumn = LineColumn::extractFromFileName(postfix, postfixPos);
if (postfixPos >= 0) {
EditorManager::openEditorAt(Link(selectedPath, lineColumn.line, lineColumn.column));
const Link link(selection.filePath, lineColumn.line, lineColumn.column);
EditorManager::openEditorAt(link);
return;
}
}
EditorManager::openEditor(selectedPath);
EditorManager::openEditor(selection.filePath);
}
/*!

View File

@@ -123,7 +123,7 @@ QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorF
const MatchLevel level = matchLevelFor(match, dir);
const QString fullPath = dirInfo.filePath(dir);
LocatorFilterEntry filterEntry(this, dir, QVariant());
filterEntry.fileName = fullPath;
filterEntry.filePath = FilePath::fromString(fullPath);
filterEntry.highlightInfo = highlightInfo(match);
entries[int(level)].append(filterEntry);
@@ -144,7 +144,7 @@ QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorF
const MatchLevel level = matchLevelFor(match, file);
const QString fullPath = dirInfo.filePath(file);
LocatorFilterEntry filterEntry(this, file, QString(fullPath + postfix));
filterEntry.fileName = fullPath;
filterEntry.filePath = FilePath::fromString(fullPath);
filterEntry.highlightInfo = highlightInfo(match);
entries[int(level)].append(filterEntry);
@@ -171,8 +171,7 @@ void FileSystemFilter::accept(LocatorFilterEntry selection,
int *selectionLength) const
{
Q_UNUSED(selectionLength)
QString fileName = selection.fileName;
QFileInfo info(fileName);
QFileInfo info = selection.filePath.toFileInfo();
if (info.isDir()) {
const QString value = shortcutString() + ' '
+ QDir::toNativeSeparators(info.absoluteFilePath() + '/');

View File

@@ -27,6 +27,7 @@
#include <coreplugin/core_global.h>
#include <utils/fileutils.h>
#include <utils/id.h>
#include <utils/optional.h>
@@ -91,8 +92,8 @@ struct LocatorFilterEntry
QVariant internalData;
/* icon to display along with the entry */
Utils::optional<QIcon> displayIcon;
/* file name, if the entry is related to a file, is used e.g. for resolving a file icon */
QString fileName;
/* file path, if the entry is related to a file, is used e.g. for resolving a file icon */
Utils::FilePath filePath;
/* highlighting support */
HighlightInfo highlightInfo{0, 0};

View File

@@ -209,8 +209,8 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
if (index.column() == DisplayNameColumn) {
LocatorFilterEntry &entry = mEntries[index.row()];
if (!entry.displayIcon && !entry.fileName.isEmpty())
entry.displayIcon = FileIconProvider::icon(QFileInfo(entry.fileName));
if (!entry.displayIcon && !entry.filePath.isEmpty())
entry.displayIcon = FileIconProvider::icon(entry.filePath.toFileInfo());
return entry.displayIcon ? entry.displayIcon.value() : QIcon();
}
break;

View File

@@ -80,8 +80,8 @@ QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locat
const QRegularExpressionMatch match = regexp.match(displayName);
if (match.hasMatch()) {
LocatorFilterEntry filterEntry(this, displayName, QString(fileName + postfix));
filterEntry.extraInfo = FilePath::fromString(fileName).shortNativePath();
filterEntry.fileName = fileName;
filterEntry.filePath = FilePath::fromString(fileName);
filterEntry.extraInfo = filterEntry.filePath.shortNativePath();
filterEntry.highlightInfo = highlightInfo(match);
if (match.capturedStart() == 0)
betterEntries.append(filterEntry);

View File

@@ -48,6 +48,6 @@ Core::LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::P
filterEntry.extraInfo = info->symbolScope().isEmpty()
? info->shortNativeFilePath()
: info->symbolScope();
filterEntry.fileName = info->fileName();
filterEntry.filePath = Utils::FilePath::fromString(info->fileName());
return filterEntry;
}

View File

@@ -645,7 +645,7 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
classes << (entry.extraInfo + "::" + entry.displayName);
if (m_completion == Completion::Namespaces) {
if (!project
|| entry.fileName.startsWith(project->projectDirectory().toString())) {
|| entry.filePath.startsWith(project->projectDirectory().toString())) {
namespaces << entry.extraInfo;
}
}