Core: Add FilePath based overloads to EditorManager::openEditor{,at}

Part of the overall FilePath migration. Keep the original version for
a while to allow using code to catch up.

Change-Id: Ia7c5ea14416a06e679e8661c0e4045981db87b9b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2021-05-25 06:52:00 +02:00
parent 925c49a1f1
commit 76db1e3746
21 changed files with 91 additions and 78 deletions

View File

@@ -489,8 +489,7 @@ Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index) const
bool BookmarkManager::gotoBookmark(const Bookmark *bookmark) const bool BookmarkManager::gotoBookmark(const Bookmark *bookmark) const
{ {
if (IEditor *editor = EditorManager::openEditorAt(bookmark->fileName().toString(), if (IEditor *editor = EditorManager::openEditorAt(bookmark->fileName(), bookmark->lineNumber()))
bookmark->lineNumber()))
return editor->currentLine() == bookmark->lineNumber(); return editor->currentLine() == bookmark->lineNumber();
return false; return false;
} }

View File

@@ -137,16 +137,14 @@ void ClangdTests::testFindReferences()
}; };
const auto headerPath = Utils::FilePath::fromString(testDir.absolutePath("defs.h")); const auto headerPath = Utils::FilePath::fromString(testDir.absolutePath("defs.h"));
QVERIFY2(headerPath.exists(), qPrintable(headerPath.toUserOutput())); QVERIFY2(headerPath.exists(), qPrintable(headerPath.toUserOutput()));
QScopedPointer<IEditor, EditorCloser> headerEditor( QScopedPointer<IEditor, EditorCloser> headerEditor(EditorManager::openEditor(headerPath));
EditorManager::openEditor(headerPath.toString()));
QVERIFY(headerEditor); QVERIFY(headerEditor);
const auto headerDoc = qobject_cast<TextEditor::TextDocument *>(headerEditor->document()); const auto headerDoc = qobject_cast<TextEditor::TextDocument *>(headerEditor->document());
QVERIFY(headerDoc); QVERIFY(headerDoc);
QVERIFY(client->documentForFilePath(headerPath) == headerDoc); QVERIFY(client->documentForFilePath(headerPath) == headerDoc);
const auto cppFilePath = Utils::FilePath::fromString(testDir.absolutePath("main.cpp")); const auto cppFilePath = Utils::FilePath::fromString(testDir.absolutePath("main.cpp"));
QVERIFY2(cppFilePath.exists(), qPrintable(cppFilePath.toUserOutput())); QVERIFY2(cppFilePath.exists(), qPrintable(cppFilePath.toUserOutput()));
QScopedPointer<IEditor, EditorCloser> cppFileEditor( QScopedPointer<IEditor, EditorCloser> cppFileEditor(EditorManager::openEditor(cppFilePath));
EditorManager::openEditor(cppFilePath.toString()));
QVERIFY(cppFileEditor); QVERIFY(cppFileEditor);
const auto cppDoc = qobject_cast<TextEditor::TextDocument *>(cppFileEditor->document()); const auto cppDoc = qobject_cast<TextEditor::TextDocument *>(cppFileEditor->document());
QVERIFY(cppDoc); QVERIFY(cppDoc);

View File

@@ -740,19 +740,19 @@ EditorArea *EditorManagerPrivate::mainEditorArea()
return d->m_editorAreas.at(0); return d->m_editorAreas.at(0);
} }
bool EditorManagerPrivate::skipOpeningBigTextFile(const QString &filePath) bool EditorManagerPrivate::skipOpeningBigTextFile(const FilePath &filePath)
{ {
if (!d->m_settings.warnBeforeOpeningBigFilesEnabled) if (!d->m_settings.warnBeforeOpeningBigFilesEnabled)
return false; return false;
if (!QFileInfo::exists(filePath)) if (!filePath.exists())
return false; return false;
Utils::MimeType mimeType = Utils::mimeTypeForFile(filePath); Utils::MimeType mimeType = Utils::mimeTypeForFile(filePath.toString());
if (!mimeType.inherits("text/plain")) if (!mimeType.inherits("text/plain"))
return false; return false;
const QFileInfo fileInfo(filePath); const QFileInfo fileInfo = filePath.toFileInfo();
const qint64 fileSize = fileInfo.size(); const qint64 fileSize = fileInfo.size();
const double fileSizeInMB = fileSize / 1000.0 / 1000.0; const double fileSizeInMB = fileSize / 1000.0 / 1000.0;
if (fileSizeInMB > d->m_settings.bigFileSizeLimitInMB if (fileSizeInMB > d->m_settings.bigFileSizeLimitInMB
@@ -782,13 +782,13 @@ bool EditorManagerPrivate::skipOpeningBigTextFile(const QString &filePath)
return false; return false;
} }
IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileName, Id editorId, IEditor *EditorManagerPrivate::openEditor(EditorView *view, const FilePath &filePath, Id editorId,
EditorManager::OpenEditorFlags flags, bool *newEditor) EditorManager::OpenEditorFlags flags, bool *newEditor)
{ {
if (debugEditorManager) if (debugEditorManager)
qDebug() << Q_FUNC_INFO << fileName << editorId.name(); qDebug() << Q_FUNC_INFO << filePath << editorId.name();
QString fn = fileName; QString fn = filePath.toString();
QFileInfo fi(fn); QFileInfo fi(fn);
int lineNumber = -1; int lineNumber = -1;
int columnNumber = -1; int columnNumber = -1;
@@ -803,7 +803,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
if (fn.isEmpty()) if (fn.isEmpty())
return nullptr; return nullptr;
if (fn != fileName) if (fn != filePath.toString())
fi.setFile(fn); fi.setFile(fn);
if (newEditor) if (newEditor)
@@ -855,7 +855,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
} }
} }
if (skipOpeningBigTextFile(fileName)) if (skipOpeningBigTextFile(filePath))
return nullptr; return nullptr;
IEditor *editor = nullptr; IEditor *editor = nullptr;
@@ -952,26 +952,25 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
return result; return result;
} }
IEditor *EditorManagerPrivate::openEditorAt(EditorView *view, const QString &fileName, int line, IEditor *EditorManagerPrivate::openEditorAt(EditorView *view, const FilePath &filePath, int line,
int column, Id editorId, int column, Id editorId,
EditorManager::OpenEditorFlags flags, bool *newEditor) EditorManager::OpenEditorFlags flags, bool *newEditor)
{ {
EditorManager::cutForwardNavigationHistory(); EditorManager::cutForwardNavigationHistory();
EditorManager::addCurrentPositionToNavigationHistory(); EditorManager::addCurrentPositionToNavigationHistory();
EditorManager::OpenEditorFlags tempFlags = flags | EditorManager::IgnoreNavigationHistory; EditorManager::OpenEditorFlags tempFlags = flags | EditorManager::IgnoreNavigationHistory;
IEditor *editor = openEditor(view, fileName, editorId, tempFlags, newEditor); IEditor *editor = openEditor(view, filePath, editorId, tempFlags, newEditor);
if (editor && line != -1) if (editor && line != -1)
editor->gotoLine(line, column); editor->gotoLine(line, column);
return editor; return editor;
} }
IEditor *EditorManagerPrivate::openEditorWith(const QString &fileName, Utils::Id editorId) IEditor *EditorManagerPrivate::openEditorWith(const FilePath &filePath, Id editorId)
{ {
// close any open editors that have this file open // close any open editors that have this file open
// remember the views to open new editors in there // remember the views to open new editors in there
QList<EditorView *> views; QList<EditorView *> views;
QList<IEditor *> editorsOpenForFile = DocumentModel::editorsForFilePath( QList<IEditor *> editorsOpenForFile = DocumentModel::editorsForFilePath(filePath);
FilePath::fromString(fileName));
foreach (IEditor *openEditor, editorsOpenForFile) { foreach (IEditor *openEditor, editorsOpenForFile) {
EditorView *view = EditorManagerPrivate::viewForEditor(openEditor); EditorView *view = EditorManagerPrivate::viewForEditor(openEditor);
if (view && view->currentEditor() == openEditor) // visible if (view && view->currentEditor() == openEditor) // visible
@@ -982,7 +981,7 @@ IEditor *EditorManagerPrivate::openEditorWith(const QString &fileName, Utils::Id
IEditor *openedEditor = nullptr; IEditor *openedEditor = nullptr;
if (views.isEmpty()) { if (views.isEmpty()) {
openedEditor = EditorManager::openEditor(fileName, editorId); openedEditor = EditorManager::openEditor(filePath, editorId);
} else { } else {
if (EditorView *currentView = EditorManagerPrivate::currentEditorView()) { if (EditorView *currentView = EditorManagerPrivate::currentEditorView()) {
if (views.removeOne(currentView)) if (views.removeOne(currentView))
@@ -990,7 +989,7 @@ IEditor *EditorManagerPrivate::openEditorWith(const QString &fileName, Utils::Id
} }
EditorManager::OpenEditorFlags flags; EditorManager::OpenEditorFlags flags;
foreach (EditorView *view, views) { foreach (EditorView *view, views) {
IEditor *editor = EditorManagerPrivate::openEditor(view, fileName, editorId, flags); IEditor *editor = EditorManagerPrivate::openEditor(view, filePath, editorId, flags);
if (!openedEditor && editor) if (!openedEditor && editor)
openedEditor = editor; openedEditor = editor;
// Do not change the current editor after opening the first one. That // Do not change the current editor after opening the first one. That
@@ -1592,7 +1591,7 @@ bool EditorManagerPrivate::activateEditorForEntry(EditorView *view, DocumentMode
return editor != nullptr; return editor != nullptr;
} }
if (!openEditor(view, entry->fileName().toString(), entry->id(), flags)) { if (!openEditor(view, entry->fileName(), entry->id(), flags)) {
DocumentModelPrivate::removeEntry(entry); DocumentModelPrivate::removeEntry(entry);
return false; return false;
} }
@@ -2932,7 +2931,7 @@ void EditorManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
// while the menu is still being processed. // while the menu is still being processed.
connect(action, &QAction::triggered, d, connect(action, &QAction::triggered, d,
[fileName, editorId]() { [fileName, editorId]() {
EditorManagerPrivate::openEditorWith(fileName, editorId); EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId);
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
} }
// Add all suitable external editors // Add all suitable external editors
@@ -3061,7 +3060,7 @@ IEditor *EditorManager::activateEditorForDocument(IDocument *document, OpenEdito
} }
/*! /*!
Opens the document specified by \a fileName using the editor type \a Opens the document specified by \a filePath using the editor type \a
editorId and the specified \a flags. editorId and the specified \a flags.
If \a editorId is \c Id(), the editor type is derived from the file's MIME If \a editorId is \c Id(), the editor type is derived from the file's MIME
@@ -3075,18 +3074,24 @@ IEditor *EditorManager::activateEditorForDocument(IDocument *document, OpenEdito
\sa openEditorWithContents() \sa openEditorWithContents()
\sa openExternalEditor() \sa openExternalEditor()
*/ */
IEditor *EditorManager::openEditor(const QString &fileName, Id editorId, IEditor *EditorManager::openEditor(const FilePath &filePath, Id editorId,
OpenEditorFlags flags, bool *newEditor) OpenEditorFlags flags, bool *newEditor)
{ {
if (flags & EditorManager::OpenInOtherSplit) if (flags & EditorManager::OpenInOtherSplit)
EditorManager::gotoOtherSplit(); EditorManager::gotoOtherSplit();
return EditorManagerPrivate::openEditor(EditorManagerPrivate::currentEditorView(), return EditorManagerPrivate::openEditor(EditorManagerPrivate::currentEditorView(),
fileName, editorId, flags, newEditor); filePath, editorId, flags, newEditor);
}
IEditor *EditorManager::openEditor(const QString &fileName, Id editorId,
OpenEditorFlags flags, bool *newEditor)
{
return openEditor(FilePath::fromString(fileName), editorId, flags, newEditor);
} }
/*! /*!
Opens the document specified by \a fileName using the editor type \a Opens the document specified by \a filePath using the editor type \a
editorId and the specified \a flags. editorId and the specified \a flags.
Moves the text cursor to the \a line and \a column. Moves the text cursor to the \a line and \a column.
@@ -3104,14 +3109,20 @@ IEditor *EditorManager::openEditor(const QString &fileName, Id editorId,
\sa openExternalEditor() \sa openExternalEditor()
\sa IEditor::gotoLine() \sa IEditor::gotoLine()
*/ */
IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int column, IEditor *EditorManager::openEditorAt(const FilePath &filePath, int line, int column,
Id editorId, OpenEditorFlags flags, bool *newEditor) Id editorId, OpenEditorFlags flags, bool *newEditor)
{ {
if (flags & EditorManager::OpenInOtherSplit) if (flags & EditorManager::OpenInOtherSplit)
EditorManager::gotoOtherSplit(); EditorManager::gotoOtherSplit();
return EditorManagerPrivate::openEditorAt(EditorManagerPrivate::currentEditorView(), return EditorManagerPrivate::openEditorAt(EditorManagerPrivate::currentEditorView(),
fileName, line, column, editorId, flags, newEditor); filePath, line, column, editorId, flags, newEditor);
}
IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int column,
Id editorId, OpenEditorFlags flags, bool *newEditor)
{
return openEditorAt(FilePath::fromString(fileName), line, column, editorId, flags, newEditor);
} }
/*! /*!
@@ -3186,9 +3197,9 @@ EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QStrin
/*! /*!
Returns whether \a fileName is an auto-save file created by \QC. Returns whether \a fileName is an auto-save file created by \QC.
*/ */
bool EditorManager::isAutoSaveFile(const QString &fileName) bool EditorManager::isAutoSaveFile(const QString &filePath)
{ {
return fileName.endsWith(".autosave"); return filePath.endsWith(".autosave");
} }
/*! /*!
@@ -3348,7 +3359,7 @@ IEditor *EditorManager::openEditorWithContents(Id editorId,
though it is big. Depending on the settings this might ask the user to though it is big. Depending on the settings this might ask the user to
decide whether the file should be opened. decide whether the file should be opened.
*/ */
bool EditorManager::skipOpeningBigTextFile(const QString &filePath) bool EditorManager::skipOpeningBigTextFile(const FilePath &filePath)
{ {
return EditorManagerPrivate::skipOpeningBigTextFile(filePath); return EditorManagerPrivate::skipOpeningBigTextFile(filePath);
} }
@@ -3449,7 +3460,7 @@ void EditorManager::setLastEditLocation(const IEditor* editor)
const QByteArray &state = editor->saveState(); const QByteArray &state = editor->saveState();
EditLocation location; EditLocation location;
location.document = document; location.document = document;
location.fileName = document->filePath().toString(); location.filePath = document->filePath();
location.id = document->id(); location.id = document->id();
location.state = QVariant(state); location.state = QVariant(state);

View File

@@ -94,11 +94,19 @@ public:
}; };
static FilePathInfo splitLineAndColumnNumber(const QString &filePath); static FilePathInfo splitLineAndColumnNumber(const QString &filePath);
static IEditor *openEditor(const QString &fileName, Utils::Id editorId = {}, static IEditor *openEditor(const Utils::FilePath &filePath, Utils::Id editorId = {},
OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr); OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr);
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0, static IEditor *openEditorAt(const Utils::FilePath &filePath, int line, int column = 0,
Utils::Id editorId = {}, OpenEditorFlags flags = NoFlags, Utils::Id editorId = {}, OpenEditorFlags flags = NoFlags,
bool *newEditor = nullptr); bool *newEditor = nullptr);
// Kept for a while for transition.
static IEditor *openEditor(const QString &fileName, Utils::Id editorId = {},
OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr); // FIXME: Remove overload
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
Utils::Id editorId = {}, OpenEditorFlags flags = NoFlags,
bool *newEditor = nullptr); // FIXME: Remove overload
static void openEditorAtSearchResult(const SearchResultItem &item, static void openEditorAtSearchResult(const SearchResultItem &item,
Utils::Id editorId = {}, Utils::Id editorId = {},
OpenEditorFlags flags = NoFlags, OpenEditorFlags flags = NoFlags,
@@ -107,7 +115,7 @@ public:
const QByteArray &contents = QByteArray(), const QByteArray &contents = QByteArray(),
const QString &uniqueId = QString(), const QString &uniqueId = QString(),
OpenEditorFlags flags = NoFlags); OpenEditorFlags flags = NoFlags);
static bool skipOpeningBigTextFile(const QString &filePath); static bool skipOpeningBigTextFile(const Utils::FilePath &filePath);
static void clearUniqueId(IDocument *document); static void clearUniqueId(IDocument *document);
static bool openExternalEditor(const QString &fileName, Utils::Id editorId); static bool openExternalEditor(const QString &fileName, Utils::Id editorId);

View File

@@ -80,18 +80,18 @@ public:
static EditorView *currentEditorView(); static EditorView *currentEditorView();
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false); static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
static IEditor *openEditor(EditorView *view, static IEditor *openEditor(EditorView *view,
const QString &fileName, const Utils::FilePath &filePath,
Utils::Id editorId = {}, Utils::Id editorId = {},
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags, EditorManager::OpenEditorFlags flags = EditorManager::NoFlags,
bool *newEditor = nullptr); bool *newEditor = nullptr);
static IEditor *openEditorAt(EditorView *view, static IEditor *openEditorAt(EditorView *view,
const QString &fileName, const Utils::FilePath &filePath,
int line, int line,
int column = 0, int column = 0,
Utils::Id editorId = {}, Utils::Id editorId = {},
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags, EditorManager::OpenEditorFlags flags = EditorManager::NoFlags,
bool *newEditor = nullptr); bool *newEditor = nullptr);
static IEditor *openEditorWith(const QString &fileName, Utils::Id editorId); static IEditor *openEditorWith(const Utils::FilePath &filePath, Utils::Id editorId);
static IEditor *duplicateEditor(IEditor *editor); static IEditor *duplicateEditor(IEditor *editor);
static IEditor *activateEditor(EditorView *view, IEditor *editor, static IEditor *activateEditor(EditorView *view, IEditor *editor,
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags); EditorManager::OpenEditorFlags flags = EditorManager::NoFlags);
@@ -209,7 +209,7 @@ private:
static void setupSaveActions(IDocument *document, QAction *saveAction, static void setupSaveActions(IDocument *document, QAction *saveAction,
QAction *saveAsAction, QAction *revertToSavedAction); QAction *saveAsAction, QAction *revertToSavedAction);
static void updateWindowTitle(); static void updateWindowTitle();
static bool skipOpeningBigTextFile(const QString &filePath); static bool skipOpeningBigTextFile(const Utils::FilePath &filePath);
private: private:
explicit EditorManagerPrivate(QObject *parent); explicit EditorManagerPrivate(QObject *parent);

View File

@@ -261,15 +261,14 @@ void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &histo
EditLocation location; EditLocation location;
location.document = document; location.document = document;
location.fileName = document->filePath().toString(); location.filePath = document->filePath();
location.id = document->id(); location.id = document->id();
location.state = QVariant(state); location.state = QVariant(state);
for (int i = 0; i < history.size(); ++i) { for (int i = 0; i < history.size(); ++i) {
const EditLocation &item = history.at(i); const EditLocation &item = history.at(i);
if (item.document == document if (item.document == document
|| (!item.document || (!item.document && !DocumentModel::indexOfFilePath(item.filePath))) {
&& !DocumentModel::indexOfFilePath(FilePath::fromString(item.fileName)))) {
history.removeAt(i--); history.removeAt(i--);
} }
} }
@@ -405,10 +404,10 @@ void EditorView::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
auto openEntry = [&](const DropSupport::FileSpec &spec) { auto openEntry = [&](const DropSupport::FileSpec &spec) {
if (first) { if (first) {
first = false; first = false;
EditorManagerPrivate::openEditorAt(this, spec.filePath, spec.line, spec.column); EditorManagerPrivate::openEditorAt(this, FilePath::fromString(spec.filePath), spec.line, spec.column);
} else if (spec.column != -1 || spec.line != -1) { } else if (spec.column != -1 || spec.line != -1) {
EditorManagerPrivate::openEditorAt(this, EditorManagerPrivate::openEditorAt(this,
spec.filePath, FilePath::fromString(spec.filePath),
spec.line, spec.line,
spec.column, spec.column,
Id(), Id(),
@@ -495,7 +494,7 @@ void EditorView::addCurrentPositionToNavigationHistory(const QByteArray &saveSta
EditLocation location; EditLocation location;
location.document = document; location.document = document;
location.fileName = document->filePath().toString(); location.filePath = document->filePath();
location.id = document->id(); location.id = document->id();
location.state = QVariant(state); location.state = QVariant(state);
m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia
@@ -550,17 +549,15 @@ void EditorView::updateCurrentPositionInNavigationHistory()
location = &m_navigationHistory[m_navigationHistory.size()-1]; location = &m_navigationHistory[m_navigationHistory.size()-1];
} }
location->document = document; location->document = document;
location->fileName = document->filePath().toString(); location->filePath = document->filePath();
location->id = document->id(); location->id = document->id();
location->state = QVariant(editor->saveState()); location->state = QVariant(editor->saveState());
} }
namespace { static bool fileNameWasRemoved(const FilePath &filePath)
static inline bool fileNameWasRemoved(const QString &fileName)
{ {
return !fileName.isEmpty() && !QFileInfo::exists(fileName); return !filePath.isEmpty() && !filePath.exists();
} }
} // End of anonymous namespace
void EditorView::goBackInNavigationHistory() void EditorView::goBackInNavigationHistory()
{ {
@@ -574,11 +571,11 @@ void EditorView::goBackInNavigationHistory()
EditorManager::IgnoreNavigationHistory); EditorManager::IgnoreNavigationHistory);
} }
if (!editor) { if (!editor) {
if (fileNameWasRemoved(location.fileName)) { if (fileNameWasRemoved(location.filePath)) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition); m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
continue; continue;
} }
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id, editor = EditorManagerPrivate::openEditor(this, location.filePath, location.id,
EditorManager::IgnoreNavigationHistory); EditorManager::IgnoreNavigationHistory);
if (!editor) { if (!editor) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition); m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
@@ -605,11 +602,11 @@ void EditorView::goForwardInNavigationHistory()
EditorManager::IgnoreNavigationHistory); EditorManager::IgnoreNavigationHistory);
} }
if (!editor) { if (!editor) {
if (fileNameWasRemoved(location.fileName)) { if (fileNameWasRemoved(location.filePath)) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition); m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
continue; continue;
} }
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id, editor = EditorManagerPrivate::openEditor(this, location.filePath, location.id,
EditorManager::IgnoreNavigationHistory); EditorManager::IgnoreNavigationHistory);
if (!editor) { if (!editor) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition); m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
@@ -634,10 +631,10 @@ void EditorView::goToEditLocation(const EditLocation &location)
} }
if (!editor) { if (!editor) {
if (fileNameWasRemoved(location.fileName)) if (fileNameWasRemoved(location.filePath))
return; return;
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id, editor = EditorManagerPrivate::openEditor(this, location.filePath, location.id,
EditorManager::IgnoreNavigationHistory); EditorManager::IgnoreNavigationHistory);
} }
@@ -967,7 +964,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
stream >> fileName >> id >> editorState; stream >> fileName >> id >> editorState;
if (!QFile::exists(fileName)) if (!QFile::exists(fileName))
return; return;
IEditor *e = EditorManagerPrivate::openEditor(view(), fileName, Id::fromString(id), IEditor *e = EditorManagerPrivate::openEditor(view(), FilePath::fromString(fileName), Id::fromString(id),
EditorManager::IgnoreNavigationHistory EditorManager::IgnoreNavigationHistory
| EditorManager::DoNotChangeCurrentEditor); | EditorManager::DoNotChangeCurrentEditor);

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include <utils/dropsupport.h> #include <utils/dropsupport.h>
#include <utils/fileutils.h>
#include <utils/id.h> #include <utils/id.h>
#include <QMap> #include <QMap>
@@ -62,7 +63,7 @@ namespace Internal {
struct EditLocation { struct EditLocation {
QPointer<IDocument> document; QPointer<IDocument> document;
QString fileName; Utils::FilePath filePath;
Utils::Id id; Utils::Id id;
QVariant state; QVariant state;
}; };

View File

@@ -217,7 +217,7 @@ static DocumentModel::Entry *entryForEditLocation(const EditLocation &item)
{ {
if (!item.document.isNull()) if (!item.document.isNull())
return DocumentModel::entryForDocument(item.document); return DocumentModel::entryForDocument(item.document);
return DocumentModel::entryForFilePath(Utils::FilePath::fromString(item.fileName)); return DocumentModel::entryForFilePath(item.filePath);
} }
void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, EditorView *view, void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, EditorView *view,

View File

@@ -950,7 +950,7 @@ void MainWindow::openFileWith()
if (isExternal) if (isExternal)
EditorManager::openExternalEditor(fileName, editorId); EditorManager::openExternalEditor(fileName, editorId);
else else
EditorManagerPrivate::openEditorWith(fileName, editorId); EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId);
} }
} }

View File

@@ -1490,7 +1490,7 @@ void BreakHandler::gotoLocation(const Breakpoint &bp) const
// Don't use gotoLocation unconditionally as this ends up in // Don't use gotoLocation unconditionally as this ends up in
// disassembly if OperateByInstruction is on. But fallback // disassembly if OperateByInstruction is on. But fallback
// to disassembly if we can't open the file. // to disassembly if we can't open the file.
if (IEditor *editor = EditorManager::openEditor(bp->markerFileName().toString())) if (IEditor *editor = EditorManager::openEditor(bp->markerFileName()))
editor->gotoLine(bp->markerLineNumber(), 0); editor->gotoLine(bp->markerLineNumber(), 0);
else else
m_engine->openDisassemblerView(Location(bp->m_parameters.address)); m_engine->openDisassemblerView(Location(bp->m_parameters.address));
@@ -2694,7 +2694,7 @@ bool BreakpointManager::contextMenuEvent(const ItemViewEvent &ev)
void BreakpointManager::gotoLocation(const GlobalBreakpoint &gbp) const void BreakpointManager::gotoLocation(const GlobalBreakpoint &gbp) const
{ {
QTC_ASSERT(gbp, return); QTC_ASSERT(gbp, return);
if (IEditor *editor = EditorManager::openEditor(gbp->markerFileName().toString())) if (IEditor *editor = EditorManager::openEditor(gbp->markerFileName()))
editor->gotoLine(gbp->markerLineNumber(), 0); editor->gotoLine(gbp->markerLineNumber(), 0);
} }

View File

@@ -571,7 +571,7 @@ void DiffEditorPluginPrivate::diffExternalFiles()
QString()); QString());
if (fileName1.isNull()) if (fileName1.isNull())
return; return;
if (EditorManager::skipOpeningBigTextFile(fileName1)) if (EditorManager::skipOpeningBigTextFile(FilePath::fromString(fileName1)))
return; return;
const QString fileName2 = QFileDialog::getOpenFileName(ICore::dialogParent(), const QString fileName2 = QFileDialog::getOpenFileName(ICore::dialogParent(),
@@ -579,7 +579,7 @@ void DiffEditorPluginPrivate::diffExternalFiles()
QString()); QString());
if (fileName2.isNull()) if (fileName2.isNull())
return; return;
if (EditorManager::skipOpeningBigTextFile(fileName2)) if (EditorManager::skipOpeningBigTextFile(FilePath::fromString(fileName2)))
return; return;
const QString documentId = Constants::DIFF_EDITOR_PLUGIN const QString documentId = Constants::DIFF_EDITOR_PLUGIN

View File

@@ -190,7 +190,7 @@ void DocumentLocatorFilter::accept(Core::LocatorFilterEntry selection,
{ {
if (selection.internalData.canConvert<Utils::LineColumn>()) { if (selection.internalData.canConvert<Utils::LineColumn>()) {
auto lineColumn = qvariant_cast<Utils::LineColumn>(selection.internalData); auto lineColumn = qvariant_cast<Utils::LineColumn>(selection.internalData);
Core::EditorManager::openEditorAt(m_currentUri.toFilePath().toString(), Core::EditorManager::openEditorAt(m_currentUri.toFilePath(),
lineColumn.line + 1, lineColumn.line + 1,
lineColumn.column); lineColumn.column);
} else if (selection.internalData.canConvert<Utils::Link>()) { } else if (selection.internalData.canConvert<Utils::Link>()) {

View File

@@ -643,8 +643,7 @@ void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusI
return; return;
} }
Core::IEditor *editor = Core::EditorManager::openEditor(saver.filePath().toString(), Core::IEditor *editor = Core::EditorManager::openEditor(saver.filePath(), Constants::COMMIT_ID);
Constants::COMMIT_ID);
if (!editor) { if (!editor) {
VcsOutputWindow::appendError(tr("Unable to create an editor for the commit.")); VcsOutputWindow::appendError(tr("Unable to create an editor for the commit."));
return; return;

View File

@@ -514,7 +514,7 @@ void JsonWizard::openProjectForNode(Node *node)
Utils::optional<FilePath> projFilePath = projNode->visibleAfterAddFileAction(); Utils::optional<FilePath> projFilePath = projNode->visibleAfterAddFileAction();
if (projFilePath && !Core::EditorManager::openEditor(projFilePath.value().toString())) { if (projFilePath && !Core::EditorManager::openEditor(projFilePath.value())) {
auto errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", auto errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"Failed to open an editor for \"%1\".") "Failed to open an editor for \"%1\".")
.arg(QDir::toNativeSeparators(projFilePath.value().toString())); .arg(QDir::toNativeSeparators(projFilePath.value().toString()));

View File

@@ -1347,7 +1347,7 @@ void ProjectExplorerPlugin::testProject_multipleBuildConfigs()
QCOMPARE(SessionManager::startupProject(), theProject.project()); QCOMPARE(SessionManager::startupProject(), theProject.project());
QCOMPARE(ProjectTree::currentProject(), theProject.project()); QCOMPARE(ProjectTree::currentProject(), theProject.project());
QVERIFY(Core::EditorManager::openEditor(projectDir.pathAppended("main.cpp").toString())); QVERIFY(Core::EditorManager::openEditor(projectDir.pathAppended("main.cpp")));
QVERIFY(ProjectTree::currentNode()); QVERIFY(ProjectTree::currentNode());
ProjectTree::instance()->expandAll(); ProjectTree::instance()->expandAll();
SessionManager::closeAllProjects(); // QTCREATORBUG-25655 SessionManager::closeAllProjects(); // QTCREATORBUG-25655

View File

@@ -3442,7 +3442,7 @@ void ProjectExplorerPluginPrivate::updateLocationSubMenus()
: tr("%1 in %2").arg(li.displayName).arg(li.path.toUserOutput()); : tr("%1 in %2").arg(li.displayName).arg(li.path.toUserOutput());
auto *action = new QAction(displayName, nullptr); auto *action = new QAction(displayName, nullptr);
connect(action, &QAction::triggered, this, [line, path]() { connect(action, &QAction::triggered, this, [line, path]() {
Core::EditorManager::openEditorAt(path.toString(), line); Core::EditorManager::openEditorAt(path, line);
}); });
projectMenu->addAction(action); projectMenu->addAction(action);
@@ -3622,7 +3622,7 @@ void ProjectExplorerPluginPrivate::openFile()
{ {
const Node *currentNode = ProjectTree::currentNode(); const Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode, return); QTC_ASSERT(currentNode, return);
EditorManager::openEditor(currentNode->filePath().toString()); EditorManager::openEditor(currentNode->filePath());
} }
void ProjectExplorerPluginPrivate::searchOnFileSystem() void ProjectExplorerPluginPrivate::searchOnFileSystem()

View File

@@ -557,7 +557,7 @@ void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
Node *node = m_model->nodeForIndex(mainIndex); Node *node = m_model->nodeForIndex(mainIndex);
if (!node || !node->asFileNode()) if (!node || !node->asFileNode())
return; return;
IEditor *editor = EditorManager::openEditor(node->filePath().toString()); IEditor *editor = EditorManager::openEditor(node->filePath());
if (editor && node->line() >= 0) if (editor && node->line() >= 0)
editor->gotoLine(node->line()); editor->gotoLine(node->line());
} }

View File

@@ -62,7 +62,7 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
setState(LoadState::Busy); setState(LoadState::Busy);
m_retryCount = std::max(MinRetry, static_cast<int>((timeoutSecs * 1000) / RetryIntervalMs)); m_retryCount = std::max(MinRetry, static_cast<int>((timeoutSecs * 1000) / RetryIntervalMs));
m_currentEditor = Core::EditorManager::openEditor(path.toString(), Utils::Id(), m_currentEditor = Core::EditorManager::openEditor(path, Utils::Id(),
Core::EditorManager::DoNotMakeVisible); Core::EditorManager::DoNotMakeVisible);
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN); Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
Core::ModeManager::setFocusToCurrentMode(); Core::ModeManager::setFocusToCurrentMode();

View File

@@ -178,7 +178,7 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
} else { } else {
crumblePath()->popElement(); crumblePath()->popElement();
nextFileIsCalledInternally(); nextFileIsCalledInternally();
Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName.toString(), Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName,
Utils::Id(), Utils::Id(),
Core::EditorManager::DoNotMakeVisible); Core::EditorManager::DoNotMakeVisible);
if (clickedCrumbleBarInfo.modelNode.isValid()) { if (clickedCrumbleBarInfo.modelNode.isValid()) {

View File

@@ -213,7 +213,7 @@ public:
const Utils::FilePath qmlFile = Core::ICore::resourcePath("examples") const Utils::FilePath qmlFile = Core::ICore::resourcePath("examples")
/ example / formFile; / example / formFile;
Core::EditorManager::openEditor(qmlFile.toString()); Core::EditorManager::openEditor(qmlFile);
} }
public slots: public slots:
void resetProjects(); void resetProjects();

View File

@@ -103,7 +103,7 @@ void TodoPluginPrivate::scanningScopeChanged(ScanningScope scanningScope)
void TodoPluginPrivate::todoItemClicked(const TodoItem &item) void TodoPluginPrivate::todoItemClicked(const TodoItem &item)
{ {
if (item.file.exists()) if (item.file.exists())
Core::EditorManager::openEditorAt(item.file.toString(), item.line); Core::EditorManager::openEditorAt(item.file, item.line);
} }
void TodoPluginPrivate::createItemsProvider() void TodoPluginPrivate::createItemsProvider()