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)
|
void TestNavigationWidget::onItemActivated(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
const Utils::Link link = index.data(LinkRole).value<Utils::Link>();
|
const Utils::Link link = index.data(LinkRole).value<Utils::Link>();
|
||||||
if (link.hasValidTarget()) {
|
if (link.hasValidTarget())
|
||||||
Core::EditorManager::openEditorAt(link.targetFilePath,
|
Core::EditorManager::openEditorAt(link);
|
||||||
link.targetLine,
|
|
||||||
link.targetColumn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestNavigationWidget::onSortClicked()
|
void TestNavigationWidget::onSortClicked()
|
||||||
|
@@ -489,8 +489,10 @@ 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(), bookmark->lineNumber()))
|
if (IEditor *editor = EditorManager::openEditorAt(
|
||||||
|
Utils::Link(bookmark->fileName(), bookmark->lineNumber()))) {
|
||||||
return editor->currentLine() == bookmark->lineNumber();
|
return editor->currentLine() == bookmark->lineNumber();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -953,16 +953,18 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const FilePath &file
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *EditorManagerPrivate::openEditorAt(EditorView *view, const FilePath &filePath, int line,
|
IEditor *EditorManagerPrivate::openEditorAt(EditorView *view,
|
||||||
int column, Id editorId,
|
const Link &link,
|
||||||
EditorManager::OpenEditorFlags flags, bool *newEditor)
|
Id editorId,
|
||||||
|
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, filePath, editorId, tempFlags, newEditor);
|
IEditor *editor = openEditor(view, link.targetFilePath, editorId, tempFlags, newEditor);
|
||||||
if (editor && line != -1)
|
if (editor && link.targetLine != -1)
|
||||||
editor->gotoLine(line, column);
|
editor->gotoLine(link.targetLine, link.targetColumn);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3110,20 +3112,25 @@ IEditor *EditorManager::openEditor(const QString &fileName, Id editorId,
|
|||||||
\sa openExternalEditor()
|
\sa openExternalEditor()
|
||||||
\sa IEditor::gotoLine()
|
\sa IEditor::gotoLine()
|
||||||
*/
|
*/
|
||||||
IEditor *EditorManager::openEditorAt(const FilePath &filePath, int line, int column,
|
IEditor *EditorManager::openEditorAt(const Link &link,
|
||||||
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(),
|
||||||
filePath, line, column, editorId, flags, newEditor);
|
link,
|
||||||
|
editorId,
|
||||||
|
flags,
|
||||||
|
newEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int column,
|
IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int column,
|
||||||
Id editorId, OpenEditorFlags flags, bool *newEditor)
|
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 "documentmodel.h"
|
||||||
#include "ieditor.h"
|
#include "ieditor.h"
|
||||||
|
|
||||||
|
#include "utils/link.h"
|
||||||
#include "utils/textfileformat.h"
|
#include "utils/textfileformat.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@@ -40,7 +41,9 @@
|
|||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||||
|
|
||||||
namespace Utils { class MimeType; }
|
namespace Utils {
|
||||||
|
class MimeType;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
@@ -86,10 +89,13 @@ public:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
|
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
|
||||||
|
|
||||||
static IEditor *openEditor(const Utils::FilePath &filePath, Utils::Id editorId = {},
|
static IEditor *openEditor(const Utils::FilePath &filePath,
|
||||||
OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr);
|
Utils::Id editorId = {},
|
||||||
static IEditor *openEditorAt(const Utils::FilePath &filePath, int line, int column = 0,
|
OpenEditorFlags flags = NoFlags,
|
||||||
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);
|
bool *newEditor = nullptr);
|
||||||
|
|
||||||
// Kept for a while for transition.
|
// Kept for a while for transition.
|
||||||
|
@@ -85,9 +85,7 @@ public:
|
|||||||
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 Utils::FilePath &filePath,
|
const Utils::Link &filePath,
|
||||||
int line,
|
|
||||||
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);
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
#include <utils/link.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -401,15 +402,16 @@ void EditorView::closeSplit()
|
|||||||
void EditorView::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
|
void EditorView::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
|
||||||
{
|
{
|
||||||
bool first = true;
|
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) {
|
auto openEntry = [&](const DropSupport::FileSpec &spec) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
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) {
|
} else if (spec.column != -1 || spec.line != -1) {
|
||||||
EditorManagerPrivate::openEditorAt(this,
|
EditorManagerPrivate::openEditorAt(this,
|
||||||
FilePath::fromString(spec.filePath),
|
specToLink(spec),
|
||||||
spec.line,
|
|
||||||
spec.column,
|
|
||||||
Id(),
|
Id(),
|
||||||
EditorManager::DoNotChangeCurrentEditor
|
EditorManager::DoNotChangeCurrentEditor
|
||||||
| EditorManager::DoNotMakeVisible);
|
| EditorManager::DoNotMakeVisible);
|
||||||
|
@@ -465,10 +465,7 @@ void CppIncludeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
|||||||
{
|
{
|
||||||
const auto link = index.data(LinkRole).value<Utils::Link>();
|
const auto link = index.data(LinkRole).value<Utils::Link>();
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
EditorManager::openEditorAt(link.targetFilePath,
|
EditorManager::openEditorAt(link, Constants::CPPEDITOR_ID);
|
||||||
link.targetLine,
|
|
||||||
link.targetColumn,
|
|
||||||
Constants::CPPEDITOR_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppIncludeHierarchyWidget::editorsClosed(const QList<IEditor *> &editors)
|
void CppIncludeHierarchyWidget::editorsClosed(const QList<IEditor *> &editors)
|
||||||
|
@@ -336,10 +336,7 @@ void CppTypeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
|||||||
if (updatedLink.hasValidTarget())
|
if (updatedLink.hasValidTarget())
|
||||||
link = updatedLink;
|
link = updatedLink;
|
||||||
|
|
||||||
Core::EditorManager::openEditorAt(link.targetFilePath,
|
Core::EditorManager::openEditorAt(link, Constants::CPPEDITOR_ID);
|
||||||
link.targetLine,
|
|
||||||
link.targetColumn,
|
|
||||||
Constants::CPPEDITOR_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index)
|
void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index)
|
||||||
|
@@ -46,11 +46,7 @@ void VirtualFunctionProposalItem::apply(TextEditor::TextDocumentManipulatorInter
|
|||||||
Core::EditorManager::OpenEditorFlags flags = Core::EditorManager::NoFlags;
|
Core::EditorManager::OpenEditorFlags flags = Core::EditorManager::NoFlags;
|
||||||
if (m_openInSplit)
|
if (m_openInSplit)
|
||||||
flags |= Core::EditorManager::OpenInOtherSplit;
|
flags |= Core::EditorManager::OpenInOtherSplit;
|
||||||
Core::EditorManager::openEditorAt(m_link.targetFilePath,
|
Core::EditorManager::openEditorAt(m_link, CppEditor::Constants::CPPEDITOR_ID, flags);
|
||||||
m_link.targetLine,
|
|
||||||
m_link.targetColumn,
|
|
||||||
CppEditor::Constants::CPPEDITOR_ID,
|
|
||||||
flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
@@ -190,12 +190,10 @@ 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(),
|
const Utils::Link link(m_currentUri.toFilePath(), lineColumn.line + 1, lineColumn.column);
|
||||||
lineColumn.line + 1,
|
Core::EditorManager::openEditorAt(link);
|
||||||
lineColumn.column);
|
|
||||||
} else if (selection.internalData.canConvert<Utils::Link>()) {
|
} else if (selection.internalData.canConvert<Utils::Link>()) {
|
||||||
auto link = qvariant_cast<Utils::Link>(selection.internalData);
|
Core::EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData));
|
||||||
Core::EditorManager::openEditorAt(link.targetFilePath, link.targetLine, link.targetColumn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,10 +291,8 @@ void WorkspaceLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
|||||||
int * /*selectionStart*/,
|
int * /*selectionStart*/,
|
||||||
int * /*selectionLength*/) const
|
int * /*selectionLength*/) const
|
||||||
{
|
{
|
||||||
if (selection.internalData.canConvert<Utils::Link>()) {
|
if (selection.internalData.canConvert<Utils::Link>())
|
||||||
auto link = qvariant_cast<Utils::Link>(selection.internalData);
|
Core::EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData));
|
||||||
Core::EditorManager::openEditorAt(link.targetFilePath, link.targetLine, link.targetColumn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorkspaceLocatorFilter::handleResponse(Client *client,
|
void WorkspaceLocatorFilter::handleResponse(Client *client,
|
||||||
|
@@ -3459,7 +3459,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, line);
|
Core::EditorManager::openEditorAt(Link(path, line));
|
||||||
});
|
});
|
||||||
|
|
||||||
projectMenu->addAction(action);
|
projectMenu->addAction(action);
|
||||||
|
@@ -6254,11 +6254,7 @@ bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit)
|
|||||||
if (inNextSplit)
|
if (inNextSplit)
|
||||||
flags |= EditorManager::OpenInOtherSplit;
|
flags |= EditorManager::OpenInOtherSplit;
|
||||||
|
|
||||||
return EditorManager::openEditorAt(link.targetFilePath,
|
return EditorManager::openEditorAt(link, Id(), flags);
|
||||||
link.targetLine,
|
|
||||||
link.targetColumn,
|
|
||||||
Id(),
|
|
||||||
flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditorWidgetPrivate::isMouseNavigationEvent(QMouseEvent *e) const
|
bool TextEditorWidgetPrivate::isMouseNavigationEvent(QMouseEvent *e) const
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
|
|
||||||
#include <projectexplorer/projectpanelfactory.h>
|
#include <projectexplorer/projectpanelfactory.h>
|
||||||
|
#include <utils/link.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
@@ -103,7 +104,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, item.line);
|
Core::EditorManager::openEditorAt(Utils::Link(item.file, item.line));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TodoPluginPrivate::createItemsProvider()
|
void TodoPluginPrivate::createItemsProvider()
|
||||||
|
Reference in New Issue
Block a user