forked from qt-creator/qt-creator
Core: Use Utils::Link for openEditorAt
Change-Id: I246e06b11b4f32f46d7f3ec93df81bcc676aebbe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -266,11 +266,8 @@ void TestNavigationWidget::updateExpandedStateCache()
|
||||
void TestNavigationWidget::onItemActivated(const QModelIndex &index)
|
||||
{
|
||||
const Utils::Link link = index.data(LinkRole).value<Utils::Link>();
|
||||
if (link.hasValidTarget()) {
|
||||
Core::EditorManager::openEditorAt(link.targetFilePath,
|
||||
link.targetLine,
|
||||
link.targetColumn);
|
||||
}
|
||||
if (link.hasValidTarget())
|
||||
Core::EditorManager::openEditorAt(link);
|
||||
}
|
||||
|
||||
void TestNavigationWidget::onSortClicked()
|
||||
|
@@ -489,8 +489,10 @@ Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index) const
|
||||
|
||||
bool BookmarkManager::gotoBookmark(const Bookmark *bookmark) const
|
||||
{
|
||||
if (IEditor *editor = EditorManager::openEditorAt(bookmark->fileName(), bookmark->lineNumber()))
|
||||
if (IEditor *editor = EditorManager::openEditorAt(
|
||||
Utils::Link(bookmark->fileName(), bookmark->lineNumber()))) {
|
||||
return editor->currentLine() == bookmark->lineNumber();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -953,16 +953,18 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const FilePath &file
|
||||
return result;
|
||||
}
|
||||
|
||||
IEditor *EditorManagerPrivate::openEditorAt(EditorView *view, const FilePath &filePath, int line,
|
||||
int column, Id editorId,
|
||||
EditorManager::OpenEditorFlags flags, bool *newEditor)
|
||||
IEditor *EditorManagerPrivate::openEditorAt(EditorView *view,
|
||||
const Link &link,
|
||||
Id editorId,
|
||||
EditorManager::OpenEditorFlags flags,
|
||||
bool *newEditor)
|
||||
{
|
||||
EditorManager::cutForwardNavigationHistory();
|
||||
EditorManager::addCurrentPositionToNavigationHistory();
|
||||
EditorManager::OpenEditorFlags tempFlags = flags | EditorManager::IgnoreNavigationHistory;
|
||||
IEditor *editor = openEditor(view, filePath, editorId, tempFlags, newEditor);
|
||||
if (editor && line != -1)
|
||||
editor->gotoLine(line, column);
|
||||
IEditor *editor = openEditor(view, link.targetFilePath, editorId, tempFlags, newEditor);
|
||||
if (editor && link.targetLine != -1)
|
||||
editor->gotoLine(link.targetLine, link.targetColumn);
|
||||
return editor;
|
||||
}
|
||||
|
||||
@@ -3110,20 +3112,25 @@ IEditor *EditorManager::openEditor(const QString &fileName, Id editorId,
|
||||
\sa openExternalEditor()
|
||||
\sa IEditor::gotoLine()
|
||||
*/
|
||||
IEditor *EditorManager::openEditorAt(const FilePath &filePath, int line, int column,
|
||||
Id editorId, OpenEditorFlags flags, bool *newEditor)
|
||||
IEditor *EditorManager::openEditorAt(const Link &link,
|
||||
Id editorId,
|
||||
OpenEditorFlags flags,
|
||||
bool *newEditor)
|
||||
{
|
||||
if (flags & EditorManager::OpenInOtherSplit)
|
||||
EditorManager::gotoOtherSplit();
|
||||
|
||||
return EditorManagerPrivate::openEditorAt(EditorManagerPrivate::currentEditorView(),
|
||||
filePath, line, column, editorId, flags, newEditor);
|
||||
link,
|
||||
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);
|
||||
return openEditorAt(Link(FilePath::fromString(fileName), line, column), editorId, flags, newEditor);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "documentmodel.h"
|
||||
#include "ieditor.h"
|
||||
|
||||
#include "utils/link.h"
|
||||
#include "utils/textfileformat.h"
|
||||
|
||||
#include <QList>
|
||||
@@ -40,7 +41,9 @@
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||
|
||||
namespace Utils { class MimeType; }
|
||||
namespace Utils {
|
||||
class MimeType;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
|
||||
@@ -86,10 +89,13 @@ public:
|
||||
};
|
||||
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
|
||||
|
||||
static IEditor *openEditor(const Utils::FilePath &filePath, Utils::Id editorId = {},
|
||||
OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr);
|
||||
static IEditor *openEditorAt(const Utils::FilePath &filePath, int line, int column = 0,
|
||||
Utils::Id editorId = {}, OpenEditorFlags flags = NoFlags,
|
||||
static IEditor *openEditor(const Utils::FilePath &filePath,
|
||||
Utils::Id editorId = {},
|
||||
OpenEditorFlags flags = NoFlags,
|
||||
bool *newEditor = nullptr);
|
||||
static IEditor *openEditorAt(const Utils::Link &link,
|
||||
Utils::Id editorId = {},
|
||||
OpenEditorFlags flags = NoFlags,
|
||||
bool *newEditor = nullptr);
|
||||
|
||||
// Kept for a while for transition.
|
||||
|
@@ -85,9 +85,7 @@ public:
|
||||
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags,
|
||||
bool *newEditor = nullptr);
|
||||
static IEditor *openEditorAt(EditorView *view,
|
||||
const Utils::FilePath &filePath,
|
||||
int line,
|
||||
int column = 0,
|
||||
const Utils::Link &filePath,
|
||||
Utils::Id editorId = {},
|
||||
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags,
|
||||
bool *newEditor = nullptr);
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/link.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -401,15 +402,16 @@ void EditorView::closeSplit()
|
||||
void EditorView::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
|
||||
{
|
||||
bool first = true;
|
||||
auto specToLink = [](const DropSupport::FileSpec &spec) {
|
||||
return Utils::Link(FilePath::fromString(spec.filePath), spec.line, spec.column);
|
||||
};
|
||||
auto openEntry = [&](const DropSupport::FileSpec &spec) {
|
||||
if (first) {
|
||||
first = false;
|
||||
EditorManagerPrivate::openEditorAt(this, FilePath::fromString(spec.filePath), spec.line, spec.column);
|
||||
EditorManagerPrivate::openEditorAt(this, specToLink(spec));
|
||||
} else if (spec.column != -1 || spec.line != -1) {
|
||||
EditorManagerPrivate::openEditorAt(this,
|
||||
FilePath::fromString(spec.filePath),
|
||||
spec.line,
|
||||
spec.column,
|
||||
specToLink(spec),
|
||||
Id(),
|
||||
EditorManager::DoNotChangeCurrentEditor
|
||||
| EditorManager::DoNotMakeVisible);
|
||||
|
@@ -465,10 +465,7 @@ void CppIncludeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
||||
{
|
||||
const auto link = index.data(LinkRole).value<Utils::Link>();
|
||||
if (link.hasValidTarget())
|
||||
EditorManager::openEditorAt(link.targetFilePath,
|
||||
link.targetLine,
|
||||
link.targetColumn,
|
||||
Constants::CPPEDITOR_ID);
|
||||
EditorManager::openEditorAt(link, Constants::CPPEDITOR_ID);
|
||||
}
|
||||
|
||||
void CppIncludeHierarchyWidget::editorsClosed(const QList<IEditor *> &editors)
|
||||
|
@@ -336,10 +336,7 @@ void CppTypeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
||||
if (updatedLink.hasValidTarget())
|
||||
link = updatedLink;
|
||||
|
||||
Core::EditorManager::openEditorAt(link.targetFilePath,
|
||||
link.targetLine,
|
||||
link.targetColumn,
|
||||
Constants::CPPEDITOR_ID);
|
||||
Core::EditorManager::openEditorAt(link, Constants::CPPEDITOR_ID);
|
||||
}
|
||||
|
||||
void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index)
|
||||
|
@@ -46,11 +46,7 @@ void VirtualFunctionProposalItem::apply(TextEditor::TextDocumentManipulatorInter
|
||||
Core::EditorManager::OpenEditorFlags flags = Core::EditorManager::NoFlags;
|
||||
if (m_openInSplit)
|
||||
flags |= Core::EditorManager::OpenInOtherSplit;
|
||||
Core::EditorManager::openEditorAt(m_link.targetFilePath,
|
||||
m_link.targetLine,
|
||||
m_link.targetColumn,
|
||||
CppEditor::Constants::CPPEDITOR_ID,
|
||||
flags);
|
||||
Core::EditorManager::openEditorAt(m_link, CppEditor::Constants::CPPEDITOR_ID, flags);
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
||||
|
@@ -190,12 +190,10 @@ void DocumentLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
||||
{
|
||||
if (selection.internalData.canConvert<Utils::LineColumn>()) {
|
||||
auto lineColumn = qvariant_cast<Utils::LineColumn>(selection.internalData);
|
||||
Core::EditorManager::openEditorAt(m_currentUri.toFilePath(),
|
||||
lineColumn.line + 1,
|
||||
lineColumn.column);
|
||||
const Utils::Link link(m_currentUri.toFilePath(), lineColumn.line + 1, lineColumn.column);
|
||||
Core::EditorManager::openEditorAt(link);
|
||||
} else if (selection.internalData.canConvert<Utils::Link>()) {
|
||||
auto link = qvariant_cast<Utils::Link>(selection.internalData);
|
||||
Core::EditorManager::openEditorAt(link.targetFilePath, link.targetLine, link.targetColumn);
|
||||
Core::EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,10 +291,8 @@ void WorkspaceLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
||||
int * /*selectionStart*/,
|
||||
int * /*selectionLength*/) const
|
||||
{
|
||||
if (selection.internalData.canConvert<Utils::Link>()) {
|
||||
auto link = qvariant_cast<Utils::Link>(selection.internalData);
|
||||
Core::EditorManager::openEditorAt(link.targetFilePath, link.targetLine, link.targetColumn);
|
||||
}
|
||||
if (selection.internalData.canConvert<Utils::Link>())
|
||||
Core::EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData));
|
||||
}
|
||||
|
||||
void WorkspaceLocatorFilter::handleResponse(Client *client,
|
||||
|
@@ -3459,7 +3459,7 @@ void ProjectExplorerPluginPrivate::updateLocationSubMenus()
|
||||
: tr("%1 in %2").arg(li.displayName).arg(li.path.toUserOutput());
|
||||
auto *action = new QAction(displayName, nullptr);
|
||||
connect(action, &QAction::triggered, this, [line, path]() {
|
||||
Core::EditorManager::openEditorAt(path, line);
|
||||
Core::EditorManager::openEditorAt(Link(path, line));
|
||||
});
|
||||
|
||||
projectMenu->addAction(action);
|
||||
|
@@ -6254,11 +6254,7 @@ bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit)
|
||||
if (inNextSplit)
|
||||
flags |= EditorManager::OpenInOtherSplit;
|
||||
|
||||
return EditorManager::openEditorAt(link.targetFilePath,
|
||||
link.targetLine,
|
||||
link.targetColumn,
|
||||
Id(),
|
||||
flags);
|
||||
return EditorManager::openEditorAt(link, Id(), flags);
|
||||
}
|
||||
|
||||
bool TextEditorWidgetPrivate::isMouseNavigationEvent(QMouseEvent *e) const
|
||||
|
@@ -37,6 +37,7 @@
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <projectexplorer/projectpanelfactory.h>
|
||||
#include <utils/link.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
@@ -103,7 +104,7 @@ void TodoPluginPrivate::scanningScopeChanged(ScanningScope scanningScope)
|
||||
void TodoPluginPrivate::todoItemClicked(const TodoItem &item)
|
||||
{
|
||||
if (item.file.exists())
|
||||
Core::EditorManager::openEditorAt(item.file, item.line);
|
||||
Core::EditorManager::openEditorAt(Utils::Link(item.file, item.line));
|
||||
}
|
||||
|
||||
void TodoPluginPrivate::createItemsProvider()
|
||||
|
Reference in New Issue
Block a user