forked from qt-creator/qt-creator
TextEditor: move Link class to separate header in Utils
Link is a common class and is used across the plugins. Change-Id: Id92e47e1b8604316ca8b970804e57abaf404ec28 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
62
src/libs/utils/link.h
Normal file
62
src/libs/utils/link.h
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <qmetatype.h>
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
struct Link
|
||||||
|
{
|
||||||
|
Link(const QString &fileName = QString(), int line = 0, int column = 0)
|
||||||
|
: linkTextStart(-1)
|
||||||
|
, linkTextEnd(-1)
|
||||||
|
, targetFileName(fileName)
|
||||||
|
, targetLine(line)
|
||||||
|
, targetColumn(column)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool hasValidTarget() const
|
||||||
|
{ return !targetFileName.isEmpty(); }
|
||||||
|
|
||||||
|
bool hasValidLinkText() const
|
||||||
|
{ return linkTextStart != linkTextEnd; }
|
||||||
|
|
||||||
|
bool operator==(const Link &other) const
|
||||||
|
{ return linkTextStart == other.linkTextStart && linkTextEnd == other.linkTextEnd; }
|
||||||
|
|
||||||
|
int linkTextStart;
|
||||||
|
int linkTextEnd;
|
||||||
|
|
||||||
|
QString targetFileName;
|
||||||
|
int targetLine;
|
||||||
|
int targetColumn;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Utils::Link)
|
@@ -255,7 +255,8 @@ HEADERS += \
|
|||||||
$$PWD/predicates.h \
|
$$PWD/predicates.h \
|
||||||
$$PWD/url.h \
|
$$PWD/url.h \
|
||||||
$$PWD/filecrumblabel.h \
|
$$PWD/filecrumblabel.h \
|
||||||
$$PWD/linecolumn.h
|
$$PWD/linecolumn.h \
|
||||||
|
$$PWD/link.h
|
||||||
|
|
||||||
FORMS += $$PWD/filewizardpage.ui \
|
FORMS += $$PWD/filewizardpage.ui \
|
||||||
$$PWD/projectintropage.ui \
|
$$PWD/projectintropage.ui \
|
||||||
|
@@ -138,6 +138,7 @@ Project {
|
|||||||
"linecolumn.h",
|
"linecolumn.h",
|
||||||
"linecolumnlabel.cpp",
|
"linecolumnlabel.cpp",
|
||||||
"linecolumnlabel.h",
|
"linecolumnlabel.h",
|
||||||
|
"link.h",
|
||||||
"listutils.h",
|
"listutils.h",
|
||||||
"macroexpander.cpp",
|
"macroexpander.cpp",
|
||||||
"macroexpander.h",
|
"macroexpander.h",
|
||||||
|
@@ -236,8 +236,7 @@ QList<QToolButton *> TestNavigationWidget::createToolButtons()
|
|||||||
|
|
||||||
void TestNavigationWidget::onItemActivated(const QModelIndex &index)
|
void TestNavigationWidget::onItemActivated(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
const TextEditor::TextEditorWidget::Link link
|
const Utils::Link link = index.data(LinkRole).value<Utils::Link>();
|
||||||
= index.data(LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
|
||||||
if (link.hasValidTarget()) {
|
if (link.hasValidTarget()) {
|
||||||
Core::EditorManager::openEditorAt(link.targetFileName, link.targetLine,
|
Core::EditorManager::openEditorAt(link.targetFileName, link.targetLine,
|
||||||
link.targetColumn);
|
link.targetColumn);
|
||||||
|
@@ -77,7 +77,7 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
case LinkRole: {
|
case LinkRole: {
|
||||||
QVariant itemLink;
|
QVariant itemLink;
|
||||||
itemLink.setValue(TextEditor::TextEditorWidget::Link(m_filePath, m_line, m_column));
|
itemLink.setValue(Utils::Link(m_filePath, m_line, m_column));
|
||||||
return itemLink;
|
return itemLink;
|
||||||
}
|
}
|
||||||
case ItalicRole:
|
case ItalicRole:
|
||||||
@@ -268,10 +268,8 @@ bool TestTreeItem::lessThan(const TestTreeItem *other, SortMode mode) const
|
|||||||
return index().row() > other->index().row();
|
return index().row() > other->index().row();
|
||||||
return lhs > rhs;
|
return lhs > rhs;
|
||||||
case Naturally: {
|
case Naturally: {
|
||||||
const TextEditor::TextEditorWidget::Link &leftLink =
|
const Utils::Link &leftLink = data(0, LinkRole).value<Utils::Link>();
|
||||||
data(0, LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
const Utils::Link &rightLink = other->data(0, LinkRole).value<Utils::Link>();
|
||||||
const TextEditor::TextEditorWidget::Link &rightLink =
|
|
||||||
other->data(0, LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
|
||||||
if (leftLink.targetFileName == rightLink.targetFileName) {
|
if (leftLink.targetFileName == rightLink.targetFileName) {
|
||||||
return leftLink.targetLine == rightLink.targetLine
|
return leftLink.targetLine == rightLink.targetLine
|
||||||
? leftLink.targetColumn > rightLink.targetColumn
|
? leftLink.targetColumn > rightLink.targetColumn
|
||||||
|
@@ -65,13 +65,10 @@ static int getMarkPos(QTextCursor cursor, const ClangBackEnd::HighlightingMarkCo
|
|||||||
return cursor.position();
|
return cursor.position();
|
||||||
}
|
}
|
||||||
|
|
||||||
static TextEditor::TextEditorWidget::Link linkAtCursor(QTextCursor cursor,
|
static Utils::Link linkAtCursor(QTextCursor cursor, const QString &filePath, uint line, uint column,
|
||||||
const QString &filePath,
|
ClangEditorDocumentProcessor *processor)
|
||||||
uint line,
|
|
||||||
uint column,
|
|
||||||
ClangEditorDocumentProcessor *processor)
|
|
||||||
{
|
{
|
||||||
using Link = TextEditor::TextEditorWidget::Link;
|
using Link = Utils::Link;
|
||||||
|
|
||||||
const QVector<ClangBackEnd::HighlightingMarkContainer> &marks
|
const QVector<ClangBackEnd::HighlightingMarkContainer> &marks
|
||||||
= processor->highlightingMarks();
|
= processor->highlightingMarks();
|
||||||
@@ -95,13 +92,12 @@ static TextEditor::TextEditorWidget::Link linkAtCursor(QTextCursor cursor,
|
|||||||
return Link();
|
return Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::TextEditorWidget::Link ClangFollowSymbol::findLink(
|
Utils::Link ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
||||||
const CppTools::CursorInEditor &data,
|
bool resolveTarget,
|
||||||
bool resolveTarget,
|
const CPlusPlus::Snapshot &,
|
||||||
const CPlusPlus::Snapshot &,
|
const CPlusPlus::Document::Ptr &,
|
||||||
const CPlusPlus::Document::Ptr &,
|
CppTools::SymbolFinder *,
|
||||||
CppTools::SymbolFinder *,
|
bool)
|
||||||
bool)
|
|
||||||
{
|
{
|
||||||
int lineNumber = 0, positionInBlock = 0;
|
int lineNumber = 0, positionInBlock = 0;
|
||||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||||
|
@@ -113,7 +113,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool save(const QString &fileName = QString());
|
bool save(const QString &fileName = QString());
|
||||||
Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true, bool inNextSplit = false) override;
|
Utils::Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true, bool inNextSplit = false) override;
|
||||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -132,10 +132,10 @@ static bool isValidFileNameChar(const QChar &c)
|
|||||||
|| c == QLatin1Char('\\');
|
|| c == QLatin1Char('\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
Utils::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
bool/* resolveTarget*/, bool /*inNextSplit*/)
|
bool/* resolveTarget*/, bool /*inNextSplit*/)
|
||||||
{
|
{
|
||||||
Link link;
|
Utils::Link link;
|
||||||
|
|
||||||
int lineNumber = 0, positionInBlock = 0;
|
int lineNumber = 0, positionInBlock = 0;
|
||||||
convertPosition(cursor.position(), &lineNumber, &positionInBlock);
|
convertPosition(cursor.position(), &lineNumber, &positionInBlock);
|
||||||
|
@@ -679,7 +679,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Link to function definition/declaration
|
// Link to function definition/declaration
|
||||||
CppEditorWidget::Link symbolLink;
|
Utils::Link symbolLink;
|
||||||
if (functionDeclarationSymbol) {
|
if (functionDeclarationSymbol) {
|
||||||
symbolLink = linkToSymbol(
|
symbolLink = linkToSymbol(
|
||||||
d->m_modelManager->symbolFinder()
|
d->m_modelManager->symbolFinder()
|
||||||
@@ -716,21 +716,21 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
|||||||
openLink(symbolLink, inNextSplit != alwaysOpenLinksInNextSplit());
|
openLink(symbolLink, inNextSplit != alwaysOpenLinksInNextSplit());
|
||||||
}
|
}
|
||||||
|
|
||||||
CppEditorWidget::Link CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
Utils::Link CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
bool resolveTarget,
|
bool resolveTarget,
|
||||||
bool inNextSplit)
|
bool inNextSplit)
|
||||||
{
|
{
|
||||||
if (!d->m_modelManager)
|
if (!d->m_modelManager)
|
||||||
return Link();
|
return Utils::Link();
|
||||||
|
|
||||||
const Utils::FileName &filePath = textDocument()->filePath();
|
const Utils::FileName &filePath = textDocument()->filePath();
|
||||||
|
|
||||||
return followSymbolInterface().findLink(CppTools::CursorInEditor{cursor, filePath, this},
|
return followSymbolInterface().findLink(CppTools::CursorInEditor{cursor, filePath, this},
|
||||||
resolveTarget,
|
resolveTarget,
|
||||||
d->m_modelManager->snapshot(),
|
d->m_modelManager->snapshot(),
|
||||||
d->m_lastSemanticInfo.doc,
|
d->m_lastSemanticInfo.doc,
|
||||||
d->m_modelManager->symbolFinder(),
|
d->m_modelManager->symbolFinder(),
|
||||||
inNextSplit);
|
inNextSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CppEditorWidget::documentRevision() const
|
unsigned CppEditorWidget::documentRevision() const
|
||||||
|
@@ -100,8 +100,8 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
bool handleStringSplitting(QKeyEvent *e) const;
|
bool handleStringSplitting(QKeyEvent *e) const;
|
||||||
|
|
||||||
Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
Utils::Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
||||||
bool inNextSplit = false) override;
|
bool inNextSplit = false) override;
|
||||||
|
|
||||||
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
|
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
|
||||||
|
|
||||||
|
@@ -264,7 +264,7 @@ CppInclude::CppInclude(const Document::Include &includeFile) :
|
|||||||
helpCategory = TextEditor::HelpItem::Brief;
|
helpCategory = TextEditor::HelpItem::Brief;
|
||||||
helpIdCandidates = QStringList(fileName);
|
helpIdCandidates = QStringList(fileName);
|
||||||
helpMark = fileName;
|
helpMark = fileName;
|
||||||
link = TextEditor::TextEditorWidget::Link(path);
|
link = Utils::Link(path);
|
||||||
tooltip = path;
|
tooltip = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ CppMacro::CppMacro(const Macro ¯o)
|
|||||||
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
||||||
helpIdCandidates = QStringList(macroName);
|
helpIdCandidates = QStringList(macroName);
|
||||||
helpMark = macroName;
|
helpMark = macroName;
|
||||||
link = TextEditor::TextEditorWidget::Link(macro.fileName(), macro.line());
|
link = Utils::Link(macro.fileName(), macro.line());
|
||||||
tooltip = macro.toStringWithLineBreaks();
|
tooltip = macro.toStringWithLineBreaks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,7 +93,7 @@ public:
|
|||||||
TextEditor::HelpItem::Category helpCategory;
|
TextEditor::HelpItem::Category helpCategory;
|
||||||
QStringList helpIdCandidates;
|
QStringList helpIdCandidates;
|
||||||
QString helpMark;
|
QString helpMark;
|
||||||
TextEditor::TextEditorWidget::Link link;
|
Utils::Link link;
|
||||||
QString tooltip;
|
QString tooltip;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -156,7 +156,7 @@ private:
|
|||||||
|
|
||||||
Qt::ItemFlags flags(int) const override
|
Qt::ItemFlags flags(int) const override
|
||||||
{
|
{
|
||||||
TextEditorWidget::Link link(m_filePath, m_line);
|
Utils::Link link(m_filePath, m_line);
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
@@ -193,7 +193,7 @@ QVariant CppIncludeHierarchyItem::data(int column, int role) const
|
|||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return FileIconProvider::icon(QFileInfo(m_filePath));
|
return FileIconProvider::icon(QFileInfo(m_filePath));
|
||||||
case LinkRole:
|
case LinkRole:
|
||||||
return QVariant::fromValue(TextEditorWidget::Link(m_filePath, m_line));
|
return QVariant::fromValue(Utils::Link(m_filePath, m_line));
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -274,7 +274,7 @@ QMimeData *CppIncludeHierarchyModel::mimeData(const QModelIndexList &indexes) co
|
|||||||
{
|
{
|
||||||
auto data = new DropMimeData;
|
auto data = new DropMimeData;
|
||||||
foreach (const QModelIndex &index, indexes) {
|
foreach (const QModelIndex &index, indexes) {
|
||||||
auto link = index.data(LinkRole).value<TextEditorWidget::Link>();
|
auto link = index.data(LinkRole).value<Utils::Link>();
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
||||||
}
|
}
|
||||||
@@ -406,7 +406,7 @@ void CppIncludeHierarchyWidget::perform()
|
|||||||
m_model.buildHierarchy(document);
|
m_model.buildHierarchy(document);
|
||||||
|
|
||||||
m_inspectedFile->setText(m_editor->textDocument()->displayName());
|
m_inspectedFile->setText(m_editor->textDocument()->displayName());
|
||||||
m_inspectedFile->setLink(TextEditorWidget::Link(document));
|
m_inspectedFile->setLink(Utils::Link(document));
|
||||||
|
|
||||||
// expand "Includes" and "Included by"
|
// expand "Includes" and "Included by"
|
||||||
m_treeView->expand(m_model.index(0, 0));
|
m_treeView->expand(m_model.index(0, 0));
|
||||||
@@ -417,7 +417,7 @@ void CppIncludeHierarchyWidget::perform()
|
|||||||
|
|
||||||
void CppIncludeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
void CppIncludeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
const auto link = index.data(LinkRole).value<TextEditorWidget::Link>();
|
const auto link = index.data(LinkRole).value<Utils::Link>();
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
EditorManager::openEditorAt(link.targetFileName,
|
EditorManager::openEditorAt(link.targetFileName,
|
||||||
link.targetLine,
|
link.targetLine,
|
||||||
|
@@ -65,7 +65,7 @@ QStandardItem *itemForClass(const CppClass &cppClass)
|
|||||||
item->setData(cppClass.qualifiedName, AnnotationRole);
|
item->setData(cppClass.qualifiedName, AnnotationRole);
|
||||||
item->setData(cppClass.icon, Qt::DecorationRole);
|
item->setData(cppClass.icon, Qt::DecorationRole);
|
||||||
QVariant link;
|
QVariant link;
|
||||||
link.setValue(CppEditorWidget::Link(cppClass.link));
|
link.setValue(Utils::Link(cppClass.link));
|
||||||
item->setData(link, LinkRole);
|
item->setData(link, LinkRole);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ void CppTypeHierarchyWidget::clearTypeHierarchy()
|
|||||||
|
|
||||||
void CppTypeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
void CppTypeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
auto link = index.data(LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
auto link = index.data(LinkRole).value<Utils::Link>();
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
Core::EditorManager::openEditorAt(link.targetFileName,
|
Core::EditorManager::openEditorAt(link.targetFileName,
|
||||||
link.targetLine,
|
link.targetLine,
|
||||||
@@ -246,7 +246,7 @@ QMimeData *CppTypeHierarchyModel::mimeData(const QModelIndexList &indexes) const
|
|||||||
auto data = new DropMimeData;
|
auto data = new DropMimeData;
|
||||||
data->setOverrideFileDropAction(Qt::CopyAction); // do not remove the item from the model
|
data->setOverrideFileDropAction(Qt::CopyAction); // do not remove the item from the model
|
||||||
foreach (const QModelIndex &index, indexes) {
|
foreach (const QModelIndex &index, indexes) {
|
||||||
auto link = index.data(LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
auto link = index.data(LinkRole).value<Utils::Link>();
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
||||||
}
|
}
|
||||||
|
@@ -246,7 +246,7 @@ void CppEditorOutline::gotoSymbolInEditor()
|
|||||||
if (!symbol)
|
if (!symbol)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const TextEditor::TextEditorWidget::Link &link = CppTools::linkToSymbol(symbol);
|
const Utils::Link &link = CppTools::linkToSymbol(symbol);
|
||||||
if (!link.hasValidTarget())
|
if (!link.hasValidTarget())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@
|
|||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
typedef TextEditorWidget::Link Link;
|
using Link = Utils::Link;
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
|
@@ -230,12 +230,10 @@ const Macro *findCanonicalMacro(const QTextCursor &cursor, Document::Ptr documen
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::TextEditorWidget::Link linkToSymbol(Symbol *symbol)
|
Utils::Link linkToSymbol(Symbol *symbol)
|
||||||
{
|
{
|
||||||
typedef TextEditor::TextEditorWidget::Link Link;
|
|
||||||
|
|
||||||
if (!symbol)
|
if (!symbol)
|
||||||
return Link();
|
return Utils::Link();
|
||||||
|
|
||||||
const QString filename = QString::fromUtf8(symbol->fileName(),
|
const QString filename = QString::fromUtf8(symbol->fileName(),
|
||||||
symbol->fileNameLength());
|
symbol->fileNameLength());
|
||||||
@@ -249,7 +247,7 @@ TextEditor::TextEditorWidget::Link linkToSymbol(Symbol *symbol)
|
|||||||
if (symbol->isGenerated())
|
if (symbol->isGenerated())
|
||||||
column = 0;
|
column = 0;
|
||||||
|
|
||||||
return Link(filename, line, column);
|
return Utils::Link(filename, line, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<CppCodeModelSettings> codeModelSettings()
|
QSharedPointer<CppCodeModelSettings> codeModelSettings()
|
||||||
|
@@ -58,7 +58,7 @@ bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch);
|
|||||||
bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
|
bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
|
||||||
bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
|
bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
|
||||||
|
|
||||||
TextEditor::TextEditorWidget::Link CPPTOOLS_EXPORT linkToSymbol(CPlusPlus::Symbol *symbol);
|
Utils::Link CPPTOOLS_EXPORT linkToSymbol(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
QString CPPTOOLS_EXPORT identifierUnderCursor(QTextCursor *cursor);
|
QString CPPTOOLS_EXPORT identifierUnderCursor(QTextCursor *cursor);
|
||||||
|
|
||||||
|
@@ -126,7 +126,7 @@ public:
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(m_params.function, return 0);
|
QTC_ASSERT(m_params.function, return 0);
|
||||||
|
|
||||||
auto *hintItem = new VirtualFunctionProposalItem(TextEditorWidget::Link());
|
auto *hintItem = new VirtualFunctionProposalItem(Utils::Link());
|
||||||
hintItem->setText(QCoreApplication::translate("VirtualFunctionsAssistProcessor",
|
hintItem->setText(QCoreApplication::translate("VirtualFunctionsAssistProcessor",
|
||||||
"...searching overrides"));
|
"...searching overrides"));
|
||||||
hintItem->setOrder(-1000);
|
hintItem->setOrder(-1000);
|
||||||
@@ -173,7 +173,7 @@ private:
|
|||||||
|
|
||||||
VirtualFunctionProposalItem *itemFromFunction(Function *func) const
|
VirtualFunctionProposalItem *itemFromFunction(Function *func) const
|
||||||
{
|
{
|
||||||
const TextEditorWidget::Link link = CppTools::linkToSymbol(maybeDefinitionFor(func));
|
const Utils::Link link = CppTools::linkToSymbol(maybeDefinitionFor(func));
|
||||||
QString text = m_overview.prettyName(LookupContext::fullyQualifiedName(func));
|
QString text = m_overview.prettyName(LookupContext::fullyQualifiedName(func));
|
||||||
if (func->isPureVirtual())
|
if (func->isPureVirtual())
|
||||||
text += QLatin1String(" = 0");
|
text += QLatin1String(" = 0");
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
VirtualFunctionProposalItem::VirtualFunctionProposalItem(
|
VirtualFunctionProposalItem::VirtualFunctionProposalItem(
|
||||||
const TextEditor::TextEditorWidget::Link &link, bool openInSplit)
|
const Utils::Link &link, bool openInSplit)
|
||||||
: m_link(link), m_openInSplit(openInSplit)
|
: m_link(link), m_openInSplit(openInSplit)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -35,15 +35,15 @@ namespace CppTools {
|
|||||||
class CPPTOOLS_EXPORT VirtualFunctionProposalItem final : public TextEditor::AssistProposalItem
|
class CPPTOOLS_EXPORT VirtualFunctionProposalItem final : public TextEditor::AssistProposalItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VirtualFunctionProposalItem(const TextEditor::TextEditorWidget::Link &link,
|
VirtualFunctionProposalItem(const Utils::Link &link,
|
||||||
bool openInSplit = true);
|
bool openInSplit = true);
|
||||||
~VirtualFunctionProposalItem() Q_DECL_NOEXCEPT {}
|
~VirtualFunctionProposalItem() Q_DECL_NOEXCEPT {}
|
||||||
void apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
void apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||||
int basePosition) const override;
|
int basePosition) const override;
|
||||||
TextEditor::TextEditorWidget::Link link() const { return m_link; } // Exposed for tests
|
Utils::Link link() const { return m_link; } // Exposed for tests
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::TextEditorWidget::Link m_link;
|
Utils::Link m_link;
|
||||||
bool m_openInSplit;
|
bool m_openInSplit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -39,7 +39,7 @@ class SymbolFinder;
|
|||||||
class CPPTOOLS_EXPORT FollowSymbolInterface
|
class CPPTOOLS_EXPORT FollowSymbolInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Link = TextEditor::TextEditorWidget::Link;
|
using Link = Utils::Link;
|
||||||
|
|
||||||
virtual ~FollowSymbolInterface() {}
|
virtual ~FollowSymbolInterface() {}
|
||||||
virtual Link findLink(const CursorInEditor &data,
|
virtual Link findLink(const CursorInEditor &data,
|
||||||
|
@@ -72,9 +72,9 @@ static bool isValidFileNameChar(const QChar &c)
|
|||||||
|| c == QLatin1Char('\\');
|
|| c == QLatin1Char('\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
Utils::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
bool /*resolveTarget*/,
|
bool /*resolveTarget*/,
|
||||||
bool /*inNextSplit*/)
|
bool /*inNextSplit*/)
|
||||||
{
|
{
|
||||||
Link link;
|
Link link;
|
||||||
|
|
||||||
|
@@ -707,36 +707,36 @@ void QmlJSEditorWidget::inspectElementUnderCursor() const
|
|||||||
widget->textDocument()->setPlainText(buf);
|
widget->textDocument()->setPlainText(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
Utils::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
bool /*resolveTarget*/,
|
bool /*resolveTarget*/,
|
||||||
bool /*inNextSplit*/)
|
bool /*inNextSplit*/)
|
||||||
{
|
{
|
||||||
const SemanticInfo semanticInfo = m_qmlJsEditorDocument->semanticInfo();
|
const SemanticInfo semanticInfo = m_qmlJsEditorDocument->semanticInfo();
|
||||||
if (! semanticInfo.isValid())
|
if (! semanticInfo.isValid())
|
||||||
return Link();
|
return Utils::Link();
|
||||||
|
|
||||||
const unsigned cursorPosition = cursor.position();
|
const unsigned cursorPosition = cursor.position();
|
||||||
|
|
||||||
AST::Node *node = semanticInfo.astNodeAt(cursorPosition);
|
AST::Node *node = semanticInfo.astNodeAt(cursorPosition);
|
||||||
QTC_ASSERT(node, return Link());
|
QTC_ASSERT(node, return Utils::Link());
|
||||||
|
|
||||||
if (AST::UiImport *importAst = cast<AST::UiImport *>(node)) {
|
if (AST::UiImport *importAst = cast<AST::UiImport *>(node)) {
|
||||||
// if it's a file import, link to the file
|
// if it's a file import, link to the file
|
||||||
foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) {
|
foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) {
|
||||||
if (import.ast() == importAst && import.type() == ImportType::File) {
|
if (import.ast() == importAst && import.type() == ImportType::File) {
|
||||||
TextEditorWidget::Link link(import.path());
|
Utils::Link link(import.path());
|
||||||
link.linkTextStart = importAst->firstSourceLocation().begin();
|
link.linkTextStart = importAst->firstSourceLocation().begin();
|
||||||
link.linkTextEnd = importAst->lastSourceLocation().end();
|
link.linkTextEnd = importAst->lastSourceLocation().end();
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Link();
|
return Utils::Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
// string literals that could refer to a file link to them
|
// string literals that could refer to a file link to them
|
||||||
if (StringLiteral *literal = cast<StringLiteral *>(node)) {
|
if (StringLiteral *literal = cast<StringLiteral *>(node)) {
|
||||||
const QString &text = literal->value.toString();
|
const QString &text = literal->value.toString();
|
||||||
TextEditorWidget::Link link;
|
Utils::Link link;
|
||||||
link.linkTextStart = literal->literalToken.begin();
|
link.linkTextStart = literal->literalToken.begin();
|
||||||
link.linkTextEnd = literal->literalToken.end();
|
link.linkTextEnd = literal->literalToken.end();
|
||||||
if (semanticInfo.snapshot.document(text)) {
|
if (semanticInfo.snapshot.document(text)) {
|
||||||
@@ -760,9 +760,9 @@ TextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
|
|
||||||
if (! (value && value->getSourceLocation(&fileName, &line, &column)))
|
if (! (value && value->getSourceLocation(&fileName, &line, &column)))
|
||||||
return Link();
|
return Utils::Link();
|
||||||
|
|
||||||
TextEditorWidget::Link link;
|
Utils::Link link;
|
||||||
link.targetFileName = fileName;
|
link.targetFileName = fileName;
|
||||||
link.targetLine = line;
|
link.targetLine = line;
|
||||||
link.targetColumn = column - 1; // adjust the column
|
link.targetColumn = column - 1; // adjust the column
|
||||||
@@ -787,7 +787,7 @@ TextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Link();
|
return Utils::Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorWidget::findUsages()
|
void QmlJSEditorWidget::findUsages()
|
||||||
|
@@ -105,9 +105,9 @@ protected:
|
|||||||
void scrollContentsBy(int dx, int dy) override;
|
void scrollContentsBy(int dx, int dy) override;
|
||||||
void applyFontSettings() override;
|
void applyFontSettings() override;
|
||||||
void createToolBar();
|
void createToolBar();
|
||||||
TextEditor::TextEditorWidget::Link findLinkAt(const QTextCursor &cursor,
|
Utils::Link findLinkAt(const QTextCursor &cursor,
|
||||||
bool resolveTarget = true,
|
bool resolveTarget = true,
|
||||||
bool inNextSplit = false) override;
|
bool inNextSplit = false) override;
|
||||||
QString foldReplacementText(const QTextBlock &block) const override;
|
QString foldReplacementText(const QTextBlock &block) const override;
|
||||||
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
|
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ void QmlTaskManager::collectMessages(
|
|||||||
QHash<QString, QList<DiagnosticMessage> > linkMessages;
|
QHash<QString, QList<DiagnosticMessage> > linkMessages;
|
||||||
ContextPtr context;
|
ContextPtr context;
|
||||||
if (updateSemantic) {
|
if (updateSemantic) {
|
||||||
Link link(snapshot, vContext, snapshot.libraryInfo(info.qtImportsPath));
|
QmlJS::Link link(snapshot, vContext, snapshot.libraryInfo(info.qtImportsPath));
|
||||||
context = link(&linkMessages);
|
context = link(&linkMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -505,7 +505,7 @@ public:
|
|||||||
|
|
||||||
void requestUpdateLink(QMouseEvent *e, bool immediate = false);
|
void requestUpdateLink(QMouseEvent *e, bool immediate = false);
|
||||||
void updateLink();
|
void updateLink();
|
||||||
void showLink(const TextEditorWidget::Link &);
|
void showLink(const Utils::Link &);
|
||||||
void clearLink();
|
void clearLink();
|
||||||
|
|
||||||
void universalHelper(); // test function for development
|
void universalHelper(); // test function for development
|
||||||
@@ -637,7 +637,7 @@ public:
|
|||||||
uint m_maybeFakeTooltipEvent : 1;
|
uint m_maybeFakeTooltipEvent : 1;
|
||||||
int m_visibleWrapColumn = 0;
|
int m_visibleWrapColumn = 0;
|
||||||
|
|
||||||
TextEditorWidget::Link m_currentLink;
|
Utils::Link m_currentLink;
|
||||||
bool m_linkPressed = false;
|
bool m_linkPressed = false;
|
||||||
QTextCursor m_pendingLinkUpdate;
|
QTextCursor m_pendingLinkUpdate;
|
||||||
QTextCursor m_lastLinkUpdate;
|
QTextCursor m_lastLinkUpdate;
|
||||||
@@ -1789,14 +1789,14 @@ void TextEditorWidget::redo()
|
|||||||
void TextEditorWidget::openLinkUnderCursor()
|
void TextEditorWidget::openLinkUnderCursor()
|
||||||
{
|
{
|
||||||
const bool openInNextSplit = alwaysOpenLinksInNextSplit();
|
const bool openInNextSplit = alwaysOpenLinksInNextSplit();
|
||||||
Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
Utils::Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
||||||
openLink(symbolLink, openInNextSplit);
|
openLink(symbolLink, openInNextSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidget::openLinkUnderCursorInNextSplit()
|
void TextEditorWidget::openLinkUnderCursorInNextSplit()
|
||||||
{
|
{
|
||||||
const bool openInNextSplit = !alwaysOpenLinksInNextSplit();
|
const bool openInNextSplit = !alwaysOpenLinksInNextSplit();
|
||||||
Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
Utils::Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
||||||
openLink(symbolLink, openInNextSplit);
|
openLink(symbolLink, openInNextSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6064,12 +6064,12 @@ void TextEditorWidget::zoomReset()
|
|||||||
showZoomIndicator(this, 100);
|
showZoomIndicator(this, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorWidget::Link TextEditorWidget::findLinkAt(const QTextCursor &, bool, bool)
|
Utils::Link TextEditorWidget::findLinkAt(const QTextCursor &, bool, bool)
|
||||||
{
|
{
|
||||||
return Link();
|
return Utils::Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditorWidget::openLink(const Link &link, bool inNextSplit)
|
bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit)
|
||||||
{
|
{
|
||||||
if (!link.hasValidTarget())
|
if (!link.hasValidTarget())
|
||||||
return false;
|
return false;
|
||||||
@@ -6132,14 +6132,14 @@ void TextEditorWidgetPrivate::updateLink()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_lastLinkUpdate = m_pendingLinkUpdate;
|
m_lastLinkUpdate = m_pendingLinkUpdate;
|
||||||
const TextEditorWidget::Link link = q->findLinkAt(m_pendingLinkUpdate, false);
|
const Utils::Link link = q->findLinkAt(m_pendingLinkUpdate, false);
|
||||||
if (link.hasValidLinkText())
|
if (link.hasValidLinkText())
|
||||||
showLink(link);
|
showLink(link);
|
||||||
else
|
else
|
||||||
clearLink();
|
clearLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidgetPrivate::showLink(const TextEditorWidget::Link &link)
|
void TextEditorWidgetPrivate::showLink(const Utils::Link &link)
|
||||||
{
|
{
|
||||||
if (m_currentLink == link)
|
if (m_currentLink == link)
|
||||||
return;
|
return;
|
||||||
@@ -6165,7 +6165,7 @@ void TextEditorWidgetPrivate::clearLink()
|
|||||||
|
|
||||||
q->setExtraSelections(TextEditorWidget::OtherSelection, QList<QTextEdit::ExtraSelection>());
|
q->setExtraSelections(TextEditorWidget::OtherSelection, QList<QTextEdit::ExtraSelection>());
|
||||||
q->viewport()->setCursor(Qt::IBeamCursor);
|
q->viewport()->setCursor(Qt::IBeamCursor);
|
||||||
m_currentLink = TextEditorWidget::Link();
|
m_currentLink = Utils::Link();
|
||||||
m_linkPressed = false;
|
m_linkPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8383,12 +8383,12 @@ TextEditorLinkLabel::TextEditorLinkLabel(QWidget *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorLinkLabel::setLink(TextEditorWidget::Link link)
|
void TextEditorLinkLabel::setLink(Utils::Link link)
|
||||||
{
|
{
|
||||||
m_link = link;
|
m_link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorWidget::Link TextEditorLinkLabel::link() const
|
Utils::Link TextEditorLinkLabel::link() const
|
||||||
{
|
{
|
||||||
return m_link;
|
return m_link;
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
|
|
||||||
|
#include <utils/link.h>
|
||||||
#include <utils/uncommentselection.h>
|
#include <utils/uncommentselection.h>
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
@@ -515,33 +516,6 @@ protected:
|
|||||||
void addHoverHandler(BaseHoverHandler *handler);
|
void addHoverHandler(BaseHoverHandler *handler);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Link
|
|
||||||
{
|
|
||||||
Link(const QString &fileName = QString(), int line = 0, int column = 0)
|
|
||||||
: linkTextStart(-1)
|
|
||||||
, linkTextEnd(-1)
|
|
||||||
, targetFileName(fileName)
|
|
||||||
, targetLine(line)
|
|
||||||
, targetColumn(column)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool hasValidTarget() const
|
|
||||||
{ return !targetFileName.isEmpty(); }
|
|
||||||
|
|
||||||
bool hasValidLinkText() const
|
|
||||||
{ return linkTextStart != linkTextEnd; }
|
|
||||||
|
|
||||||
bool operator==(const Link &other) const
|
|
||||||
{ return linkTextStart == other.linkTextStart && linkTextEnd == other.linkTextEnd; }
|
|
||||||
|
|
||||||
int linkTextStart;
|
|
||||||
int linkTextEnd;
|
|
||||||
|
|
||||||
QString targetFileName;
|
|
||||||
int targetLine;
|
|
||||||
int targetColumn;
|
|
||||||
};
|
|
||||||
|
|
||||||
QString selectedText() const;
|
QString selectedText() const;
|
||||||
|
|
||||||
void setupGenericHighlighter();
|
void setupGenericHighlighter();
|
||||||
@@ -564,13 +538,13 @@ protected:
|
|||||||
\a resolveTarget is set to true when the target of the link is relevant
|
\a resolveTarget is set to true when the target of the link is relevant
|
||||||
(it isn't until the link is used).
|
(it isn't until the link is used).
|
||||||
*/
|
*/
|
||||||
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
virtual Utils::Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
||||||
bool inNextSplit = false);
|
bool inNextSplit = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns whether the link was opened successfully.
|
Returns whether the link was opened successfully.
|
||||||
*/
|
*/
|
||||||
bool openLink(const Link &link, bool inNextSplit = false);
|
bool openLink(const Utils::Link &link, bool inNextSplit = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Reimplement this function to change the default replacement text.
|
Reimplement this function to change the default replacement text.
|
||||||
@@ -616,8 +590,8 @@ class TEXTEDITOR_EXPORT TextEditorLinkLabel : public QLabel
|
|||||||
public:
|
public:
|
||||||
TextEditorLinkLabel(QWidget *parent = 0);
|
TextEditorLinkLabel(QWidget *parent = 0);
|
||||||
|
|
||||||
void setLink(TextEditorWidget::Link link);
|
void setLink(Utils::Link link);
|
||||||
TextEditorWidget::Link link() const;
|
Utils::Link link() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
@@ -626,7 +600,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint m_dragStartPosition;
|
QPoint m_dragStartPosition;
|
||||||
TextEditorWidget::Link m_link;
|
Utils::Link m_link;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
|
class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
|
||||||
@@ -679,5 +653,3 @@ QT_BEGIN_NAMESPACE
|
|||||||
uint qHash(const QColor &color);
|
uint qHash(const QColor &color);
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(TextEditor::TextEditorWidget::Link)
|
|
||||||
|
Reference in New Issue
Block a user