Core: Rename DocumentModel::fileName() to filePath()

That's what it returns nowadays.

Change-Id: Ia5b8b643ad37e773db9788d8391edbb021844aec
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2022-11-24 17:22:03 +01:00
parent 40ba25b691
commit 4ad9f53989
10 changed files with 41 additions and 41 deletions

View File

@@ -1033,7 +1033,7 @@ static FileInfos fileInfosMatchingDocuments(const FileInfos &fileInfos,
QSet<Utils::FilePath> documentPaths; QSet<Utils::FilePath> documentPaths;
for (const Core::DocumentModel::Entry *e : Core::DocumentModel::entries()) { for (const Core::DocumentModel::Entry *e : Core::DocumentModel::entries()) {
if (predicate(e->document)) if (predicate(e->document))
documentPaths.insert(e->fileName()); documentPaths.insert(e->filePath());
} }
return Utils::filtered(fileInfos, [documentPaths](const FileInfo &fileInfo) { return Utils::filtered(fileInfos, [documentPaths](const FileInfo &fileInfo) {

View File

@@ -36,7 +36,7 @@ bool compare(const DocumentModel::Entry *e1, const DocumentModel::Entry *e2)
return e1->pinned; return e1->pinned;
const int cmp = e1->plainDisplayName().localeAwareCompare(e2->plainDisplayName()); const int cmp = e1->plainDisplayName().localeAwareCompare(e2->plainDisplayName());
return (cmp < 0) || (cmp == 0 && e1->fileName() < e2->fileName()); return (cmp < 0) || (cmp == 0 && e1->filePath() < e2->filePath());
} }
// Return a pair of indices. The first is the index that needs to be removed or -1 if no removal // Return a pair of indices. The first is the index that needs to be removed or -1 if no removal
@@ -81,7 +81,7 @@ int DocumentModelPrivate::rowCount(const QModelIndex &parent) const
void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry) void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry)
{ {
const Utils::FilePath filePath = entry->fileName(); const Utils::FilePath filePath = entry->filePath();
// replace a non-loaded entry (aka 'suspended') if possible // replace a non-loaded entry (aka 'suspended') if possible
DocumentModel::Entry *previousEntry = DocumentModel::entryForFilePath(filePath); DocumentModel::Entry *previousEntry = DocumentModel::entryForFilePath(filePath);
@@ -224,7 +224,7 @@ void DocumentModelPrivate::removeDocument(int idx)
DocumentModel::Entry *entry = m_entries.takeAt(idx); DocumentModel::Entry *entry = m_entries.takeAt(idx);
endRemoveRows(); endRemoveRows();
const FilePath fixedPath = DocumentManager::filePathKey(entry->fileName(), const FilePath fixedPath = DocumentManager::filePathKey(entry->filePath(),
DocumentManager::ResolveLinks); DocumentManager::ResolveLinks);
if (!fixedPath.isEmpty()) if (!fixedPath.isEmpty())
m_entryByFixedPath.remove(fixedPath); m_entryByFixedPath.remove(fixedPath);
@@ -246,7 +246,7 @@ std::optional<int> DocumentModelPrivate::indexOfDocument(IDocument *document) co
Qt::ItemFlags DocumentModelPrivate::flags(const QModelIndex &index) const Qt::ItemFlags DocumentModelPrivate::flags(const QModelIndex &index) const
{ {
const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row()); const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row());
if (!e || e->fileName().isEmpty()) if (!e || e->filePath().isEmpty())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
} }
@@ -256,9 +256,9 @@ QMimeData *DocumentModelPrivate::mimeData(const QModelIndexList &indexes) const
auto data = new Utils::DropMimeData; auto data = new Utils::DropMimeData;
for (const QModelIndex &index : indexes) { for (const QModelIndex &index : indexes) {
const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row()); const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row());
if (!e || e->fileName().isEmpty()) if (!e || e->filePath().isEmpty())
continue; continue;
data->addFile(e->fileName()); data->addFile(e->filePath());
} }
return data; return data;
} }
@@ -311,7 +311,7 @@ QVariant DocumentModelPrivate::data(const QModelIndex &index, int role) const
return pinnedIcon(); return pinnedIcon();
return QVariant(); return QVariant();
case Qt::ToolTipRole: case Qt::ToolTipRole:
return entry->fileName().isEmpty() ? entry->displayName() : entry->fileName().toUserOutput(); return entry->filePath().isEmpty() ? entry->displayName() : entry->filePath().toUserOutput();
default: default:
break; break;
} }
@@ -463,7 +463,7 @@ void DocumentModelPrivate::removeAllSuspendedEntries(PinnedFileRemovalPolicy pin
if (pinnedFileRemovalPolicy == DoNotRemovePinnedFiles && entry->pinned) if (pinnedFileRemovalPolicy == DoNotRemovePinnedFiles && entry->pinned)
continue; continue;
const FilePath fixedPath = DocumentManager::filePathKey(entry->fileName(), const FilePath fixedPath = DocumentManager::filePathKey(entry->filePath(),
DocumentManager::ResolveLinks); DocumentManager::ResolveLinks);
int row = i + 1/*<no document>*/; int row = i + 1/*<no document>*/;
d->beginRemoveRows(QModelIndex(), row, row); d->beginRemoveRows(QModelIndex(), row, row);
@@ -496,7 +496,7 @@ DocumentModel::Entry *DocumentModelPrivate::DynamicEntry::operator->() const
void DocumentModelPrivate::DynamicEntry::disambiguate() void DocumentModelPrivate::DynamicEntry::disambiguate()
{ {
const QString display = entry->fileName().fileNameWithPathComponents(++pathComponents); const QString display = entry->filePath().fileNameWithPathComponents(++pathComponents);
entry->document->setUniqueDisplayName(display); entry->document->setUniqueDisplayName(display);
} }
@@ -544,7 +544,7 @@ QAbstractItemModel *DocumentModel::model()
return d; return d;
} }
Utils::FilePath DocumentModel::Entry::fileName() const Utils::FilePath DocumentModel::Entry::filePath() const
{ {
return document->filePath(); return document->filePath();
} }

View File

@@ -32,7 +32,7 @@ public:
struct CORE_EXPORT Entry { struct CORE_EXPORT Entry {
Entry(); Entry();
~Entry(); ~Entry();
Utils::FilePath fileName() const; Utils::FilePath filePath() const;
QString displayName() const; QString displayName() const;
QString plainDisplayName() const; QString plainDisplayName() const;
QString uniqueDisplayName() const; QString uniqueDisplayName() const;

View File

@@ -551,22 +551,22 @@ void EditorManagerPrivate::init()
this, &EditorManagerPrivate::closeAllEditorsExceptVisible); this, &EditorManagerPrivate::closeAllEditorsExceptVisible);
connect(m_openGraphicalShellContextAction, &QAction::triggered, this, [this] { connect(m_openGraphicalShellContextAction, &QAction::triggered, this, [this] {
if (!m_contextMenuEntry || m_contextMenuEntry->fileName().isEmpty()) if (!m_contextMenuEntry || m_contextMenuEntry->filePath().isEmpty())
return; return;
FileUtils::showInGraphicalShell(ICore::dialogParent(), m_contextMenuEntry->fileName()); FileUtils::showInGraphicalShell(ICore::dialogParent(), m_contextMenuEntry->filePath());
}); });
connect(m_showInFileSystemViewContextAction, &QAction::triggered, this, [this] { connect(m_showInFileSystemViewContextAction, &QAction::triggered, this, [this] {
if (!m_contextMenuEntry || m_contextMenuEntry->fileName().isEmpty()) if (!m_contextMenuEntry || m_contextMenuEntry->filePath().isEmpty())
return; return;
FileUtils::showInFileSystemView(m_contextMenuEntry->fileName()); FileUtils::showInFileSystemView(m_contextMenuEntry->filePath());
}); });
connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal); connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal);
connect(m_findInDirectoryAction, &QAction::triggered, connect(m_findInDirectoryAction, &QAction::triggered,
this, &EditorManagerPrivate::findInDirectory); this, &EditorManagerPrivate::findInDirectory);
connect(m_filePropertiesAction, &QAction::triggered, this, []() { connect(m_filePropertiesAction, &QAction::triggered, this, []() {
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty()) if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
return; return;
DocumentManager::showFilePropertiesDialog(d->m_contextMenuEntry->fileName()); DocumentManager::showFilePropertiesDialog(d->m_contextMenuEntry->filePath());
}); });
connect(m_pinAction, &QAction::triggered, this, &EditorManagerPrivate::togglePinned); connect(m_pinAction, &QAction::triggered, this, &EditorManagerPrivate::togglePinned);
@@ -1593,7 +1593,7 @@ bool EditorManagerPrivate::activateEditorForEntry(EditorView *view, DocumentMode
return editor != nullptr; return editor != nullptr;
} }
if (!openEditor(view, entry->fileName(), entry->id(), flags)) { if (!openEditor(view, entry->filePath(), entry->id(), flags)) {
DocumentModelPrivate::removeEntry(entry); DocumentModelPrivate::removeEntry(entry);
return false; return false;
} }
@@ -2409,14 +2409,14 @@ void EditorManagerPrivate::copyFilePathFromContextMenu()
{ {
if (!d->m_contextMenuEntry) if (!d->m_contextMenuEntry)
return; return;
setClipboardAndSelection(d->m_contextMenuEntry->fileName().toUserOutput()); setClipboardAndSelection(d->m_contextMenuEntry->filePath().toUserOutput());
} }
void EditorManagerPrivate::copyLocationFromContextMenu() void EditorManagerPrivate::copyLocationFromContextMenu()
{ {
if (!d->m_contextMenuEntry) if (!d->m_contextMenuEntry)
return; return;
const QString text = d->m_contextMenuEntry->fileName().toUserOutput() const QString text = d->m_contextMenuEntry->filePath().toUserOutput()
+ QLatin1Char(':') + m_copyLocationContextAction->data().toString(); + QLatin1Char(':') + m_copyLocationContextAction->data().toString();
setClipboardAndSelection(text); setClipboardAndSelection(text);
} }
@@ -2425,7 +2425,7 @@ void EditorManagerPrivate::copyFileNameFromContextMenu()
{ {
if (!d->m_contextMenuEntry) if (!d->m_contextMenuEntry)
return; return;
setClipboardAndSelection(d->m_contextMenuEntry->fileName().fileName()); setClipboardAndSelection(d->m_contextMenuEntry->filePath().fileName());
} }
void EditorManagerPrivate::saveDocumentFromContextMenu() void EditorManagerPrivate::saveDocumentFromContextMenu()
@@ -2622,23 +2622,23 @@ void EditorManagerPrivate::autoSuspendDocuments()
void EditorManagerPrivate::openTerminal() void EditorManagerPrivate::openTerminal()
{ {
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty()) if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
return; return;
FileUtils::openTerminal(d->m_contextMenuEntry->fileName().parentDir()); FileUtils::openTerminal(d->m_contextMenuEntry->filePath().parentDir());
} }
void EditorManagerPrivate::findInDirectory() void EditorManagerPrivate::findInDirectory()
{ {
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty()) if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
return; return;
const FilePath path = d->m_contextMenuEntry->fileName(); const FilePath path = d->m_contextMenuEntry->filePath();
emit m_instance->findOnFileSystemRequest( emit m_instance->findOnFileSystemRequest(
(path.isDir() ? path : path.parentDir()).toString()); (path.isDir() ? path : path.parentDir()).toString());
} }
void EditorManagerPrivate::togglePinned() void EditorManagerPrivate::togglePinned()
{ {
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty()) if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
return; return;
const bool currentlyPinned = d->m_contextMenuEntry->pinned; const bool currentlyPinned = d->m_contextMenuEntry->pinned;
@@ -2852,7 +2852,7 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod
d->m_contextMenuEntry = entry; d->m_contextMenuEntry = entry;
d->m_contextMenuEditor = editor; d->m_contextMenuEditor = editor;
const FilePath filePath = entry ? entry->fileName() : FilePath(); const FilePath filePath = entry ? entry->filePath() : FilePath();
const bool copyActionsEnabled = !filePath.isEmpty(); const bool copyActionsEnabled = !filePath.isEmpty();
d->m_copyFilePathContextAction->setEnabled(copyActionsEnabled); d->m_copyFilePathContextAction->setEnabled(copyActionsEnabled);
d->m_copyLocationContextAction->setEnabled(copyActionsEnabled); d->m_copyLocationContextAction->setEnabled(copyActionsEnabled);
@@ -2929,7 +2929,7 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
{ {
QTC_ASSERT(contextMenu, return); QTC_ASSERT(contextMenu, return);
d->m_contextMenuEntry = entry; d->m_contextMenuEntry = entry;
bool enabled = entry && !entry->fileName().isEmpty(); bool enabled = entry && !entry->filePath().isEmpty();
d->m_openGraphicalShellContextAction->setEnabled(enabled); d->m_openGraphicalShellContextAction->setEnabled(enabled);
d->m_showInFileSystemViewContextAction->setEnabled(enabled); d->m_showInFileSystemViewContextAction->setEnabled(enabled);
d->m_openTerminalAction->setEnabled(enabled); d->m_openTerminalAction->setEnabled(enabled);
@@ -2943,7 +2943,7 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
QMenu *openWith = contextMenu->addMenu(tr("Open With")); QMenu *openWith = contextMenu->addMenu(tr("Open With"));
openWith->setEnabled(enabled); openWith->setEnabled(enabled);
if (enabled) if (enabled)
populateOpenWithMenu(openWith, entry->fileName()); populateOpenWithMenu(openWith, entry->filePath());
} }
/*! /*!
@@ -3274,7 +3274,7 @@ static QString makeTitleUnique(QString *titlePattern)
QSet<QString> docnames; QSet<QString> docnames;
const QList<DocumentModel::Entry *> entries = DocumentModel::entries(); const QList<DocumentModel::Entry *> entries = DocumentModel::entries();
for (const DocumentModel::Entry *entry : entries) { for (const DocumentModel::Entry *entry : entries) {
QString name = entry->fileName().toString(); QString name = entry->filePath().toString();
if (name.isEmpty()) if (name.isEmpty())
name = entry->displayName(); name = entry->displayName();
else else
@@ -3562,7 +3562,7 @@ QByteArray EditorManager::saveState()
for (const DocumentModel::Entry *entry : entries) { for (const DocumentModel::Entry *entry : entries) {
if (!entry->document->isTemporary()) { if (!entry->document->isTemporary()) {
stream << entry->fileName().toString() << entry->plainDisplayName() << entry->id() stream << entry->filePath().toString() << entry->plainDisplayName() << entry->id()
<< entry->pinned; << entry->pinned;
} }
} }

View File

@@ -227,10 +227,10 @@ void OpenEditorsWindow::addItem(DocumentModel::Entry *entry,
auto item = new QTreeWidgetItem(); auto item = new QTreeWidgetItem();
if (entry->document->isModified()) if (entry->document->isModified())
title += tr("*"); title += tr("*");
item->setIcon(0, !entry->fileName().isEmpty() && entry->document->isFileReadOnly() item->setIcon(0, !entry->filePath().isEmpty() && entry->document->isFileReadOnly()
? DocumentModel::lockedIcon() : Utils::FileIconProvider::icon(entry->fileName())); ? DocumentModel::lockedIcon() : Utils::FileIconProvider::icon(entry->filePath()));
item->setText(0, title); item->setText(0, title);
item->setToolTip(0, entry->fileName().toString()); item->setToolTip(0, entry->filePath().toString());
item->setData(0, int(Role::Entry), QVariant::fromValue(entry)); item->setData(0, int(Role::Entry), QVariant::fromValue(entry));
item->setData(0, int(Role::View), QVariant::fromValue(view)); item->setData(0, int(Role::View), QVariant::fromValue(view));
item->setTextAlignment(0, Qt::AlignLeft); item->setTextAlignment(0, Qt::AlignLeft);

View File

@@ -425,7 +425,7 @@ bool EditorToolBar::eventFilter(QObject *obj, QEvent *event)
return Utils::StyledBar::eventFilter(obj, event); return Utils::StyledBar::eventFilter(obj, event);
auto drag = new QDrag(this); auto drag = new QDrag(this);
auto data = new Utils::DropMimeData; auto data = new Utils::DropMimeData;
data->addFile(entry->fileName()); data->addFile(entry->filePath());
drag->setMimeData(data); drag->setMimeData(data);
Qt::DropAction action = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction); Qt::DropAction action = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
if (action == Qt::MoveAction) if (action == Qt::MoveAction)

View File

@@ -81,7 +81,7 @@ void OpenDocumentsFilter::refreshInternally()
// create copy with only the information relevant to use // create copy with only the information relevant to use
// to avoid model deleting entries behind our back // to avoid model deleting entries behind our back
entry.displayName = e->displayName(); entry.displayName = e->displayName();
entry.fileName = e->fileName(); entry.fileName = e->filePath();
m_editors.append(entry); m_editors.append(entry);
} }
} }

View File

@@ -135,7 +135,7 @@ void CppIncludesFilter::prepareSearch(const QString &entry)
const QList<DocumentModel::Entry *> entries = DocumentModel::entries(); const QList<DocumentModel::Entry *> entries = DocumentModel::entries();
for (DocumentModel::Entry *entry : entries) { for (DocumentModel::Entry *entry : entries) {
if (entry) if (entry)
seedPaths.insert(entry->fileName()); seedPaths.insert(entry->filePath());
} }
CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
setFileIterator(new CppIncludesIterator(snapshot, seedPaths)); setFileIterator(new CppIncludesIterator(snapshot, seedPaths));

View File

@@ -2367,13 +2367,13 @@ bool ProjectExplorerPluginPrivate::closeAllFilesInProject(const Project *project
QTC_ASSERT(project, return false); QTC_ASSERT(project, return false);
QList<DocumentModel::Entry *> openFiles = DocumentModel::entries(); QList<DocumentModel::Entry *> openFiles = DocumentModel::entries();
Utils::erase(openFiles, [project](const DocumentModel::Entry *entry) { Utils::erase(openFiles, [project](const DocumentModel::Entry *entry) {
return entry->pinned || !project->isKnownFile(entry->fileName()); return entry->pinned || !project->isKnownFile(entry->filePath());
}); });
for (const Project * const otherProject : SessionManager::projects()) { for (const Project * const otherProject : SessionManager::projects()) {
if (otherProject == project) if (otherProject == project)
continue; continue;
Utils::erase(openFiles, [otherProject](const DocumentModel::Entry *entry) { Utils::erase(openFiles, [otherProject](const DocumentModel::Entry *entry) {
return otherProject->isKnownFile(entry->fileName()); return otherProject->isKnownFile(entry->filePath());
}); });
} }
return EditorManager::closeDocuments(openFiles); return EditorManager::closeDocuments(openFiles);

View File

@@ -45,7 +45,7 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
QList<QTextCodec *> codecs; QList<QTextCodec *> codecs;
const QList<Core::DocumentModel::Entry *> entries = Core::DocumentModel::entries(); const QList<Core::DocumentModel::Entry *> entries = Core::DocumentModel::entries();
for (Core::DocumentModel::Entry *entry : entries) { for (Core::DocumentModel::Entry *entry : entries) {
const Utils::FilePath fileName = entry->fileName(); const Utils::FilePath fileName = entry->filePath();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
fileNames.append(fileName); fileNames.append(fileName);
QTextCodec *codec = openEditorEncodings.value(fileName); QTextCodec *codec = openEditorEncodings.value(fileName);