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); Core::LocatorFilterEntry filterEntry(this, target.title, extraData);
filterEntry.extraInfo = path.shortNativePath(); filterEntry.extraInfo = path.shortNativePath();
filterEntry.highlightInfo = {index, int(entry.length())}; filterEntry.highlightInfo = {index, int(entry.length())};
filterEntry.fileName = path.toString(); filterEntry.filePath = path;
m_result.append(filterEntry); m_result.append(filterEntry);
} }

View File

@@ -180,7 +180,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
if (match.hasMatch()) { if (match.hasMatch()) {
QFileInfo fi(path.toString()); QFileInfo fi(path.toString());
LocatorFilterEntry filterEntry(this, fi.fileName(), QString(path.toString() + postfix)); LocatorFilterEntry filterEntry(this, fi.fileName(), QString(path.toString() + postfix));
filterEntry.fileName = path.toString(); filterEntry.filePath = path;
filterEntry.extraInfo = FilePath::fromFileInfo(fi).shortNativePath(); filterEntry.extraInfo = FilePath::fromFileInfo(fi).shortNativePath();
const MatchLevel matchLevel = matchLevelFor(match, matchText); const MatchLevel matchLevel = matchLevelFor(match, matchText);
@@ -230,19 +230,19 @@ void BaseFileFilter::accept(LocatorFilterEntry selection,
void BaseFileFilter::openEditorAt(const LocatorFilterEntry& selection) void BaseFileFilter::openEditorAt(const LocatorFilterEntry& selection)
{ {
const FilePath selectedPath = FilePath::fromString(selection.fileName);
const FilePath locatorText = FilePath::fromVariant(selection.internalData); 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) { if (postfixLength > 0) {
const QString postfix = selection.internalData.toString().right(postfixLength); const QString postfix = selection.internalData.toString().right(postfixLength);
int postfixPos = -1; int postfixPos = -1;
const LineColumn lineColumn = LineColumn::extractFromFileName(postfix, postfixPos); const LineColumn lineColumn = LineColumn::extractFromFileName(postfix, postfixPos);
if (postfixPos >= 0) { if (postfixPos >= 0) {
EditorManager::openEditorAt(Link(selectedPath, lineColumn.line, lineColumn.column)); const Link link(selection.filePath, lineColumn.line, lineColumn.column);
EditorManager::openEditorAt(link);
return; 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 MatchLevel level = matchLevelFor(match, dir);
const QString fullPath = dirInfo.filePath(dir); const QString fullPath = dirInfo.filePath(dir);
LocatorFilterEntry filterEntry(this, dir, QVariant()); LocatorFilterEntry filterEntry(this, dir, QVariant());
filterEntry.fileName = fullPath; filterEntry.filePath = FilePath::fromString(fullPath);
filterEntry.highlightInfo = highlightInfo(match); filterEntry.highlightInfo = highlightInfo(match);
entries[int(level)].append(filterEntry); entries[int(level)].append(filterEntry);
@@ -144,7 +144,7 @@ QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorF
const MatchLevel level = matchLevelFor(match, file); const MatchLevel level = matchLevelFor(match, file);
const QString fullPath = dirInfo.filePath(file); const QString fullPath = dirInfo.filePath(file);
LocatorFilterEntry filterEntry(this, file, QString(fullPath + postfix)); LocatorFilterEntry filterEntry(this, file, QString(fullPath + postfix));
filterEntry.fileName = fullPath; filterEntry.filePath = FilePath::fromString(fullPath);
filterEntry.highlightInfo = highlightInfo(match); filterEntry.highlightInfo = highlightInfo(match);
entries[int(level)].append(filterEntry); entries[int(level)].append(filterEntry);
@@ -171,8 +171,7 @@ void FileSystemFilter::accept(LocatorFilterEntry selection,
int *selectionLength) const int *selectionLength) const
{ {
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
QString fileName = selection.fileName; QFileInfo info = selection.filePath.toFileInfo();
QFileInfo info(fileName);
if (info.isDir()) { if (info.isDir()) {
const QString value = shortcutString() + ' ' const QString value = shortcutString() + ' '
+ QDir::toNativeSeparators(info.absoluteFilePath() + '/'); + QDir::toNativeSeparators(info.absoluteFilePath() + '/');

View File

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

View File

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

View File

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

View File

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

View File

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