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/url.h \
|
||||
$$PWD/filecrumblabel.h \
|
||||
$$PWD/linecolumn.h
|
||||
$$PWD/linecolumn.h \
|
||||
$$PWD/link.h
|
||||
|
||||
FORMS += $$PWD/filewizardpage.ui \
|
||||
$$PWD/projectintropage.ui \
|
||||
|
@@ -138,6 +138,7 @@ Project {
|
||||
"linecolumn.h",
|
||||
"linecolumnlabel.cpp",
|
||||
"linecolumnlabel.h",
|
||||
"link.h",
|
||||
"listutils.h",
|
||||
"macroexpander.cpp",
|
||||
"macroexpander.h",
|
||||
|
@@ -236,8 +236,7 @@ QList<QToolButton *> TestNavigationWidget::createToolButtons()
|
||||
|
||||
void TestNavigationWidget::onItemActivated(const QModelIndex &index)
|
||||
{
|
||||
const TextEditor::TextEditorWidget::Link link
|
||||
= index.data(LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
||||
const Utils::Link link = index.data(LinkRole).value<Utils::Link>();
|
||||
if (link.hasValidTarget()) {
|
||||
Core::EditorManager::openEditorAt(link.targetFileName, link.targetLine,
|
||||
link.targetColumn);
|
||||
|
@@ -77,7 +77,7 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
|
||||
return QVariant();
|
||||
case LinkRole: {
|
||||
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;
|
||||
}
|
||||
case ItalicRole:
|
||||
@@ -268,10 +268,8 @@ bool TestTreeItem::lessThan(const TestTreeItem *other, SortMode mode) const
|
||||
return index().row() > other->index().row();
|
||||
return lhs > rhs;
|
||||
case Naturally: {
|
||||
const TextEditor::TextEditorWidget::Link &leftLink =
|
||||
data(0, LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
||||
const TextEditor::TextEditorWidget::Link &rightLink =
|
||||
other->data(0, LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
||||
const Utils::Link &leftLink = data(0, LinkRole).value<Utils::Link>();
|
||||
const Utils::Link &rightLink = other->data(0, LinkRole).value<Utils::Link>();
|
||||
if (leftLink.targetFileName == rightLink.targetFileName) {
|
||||
return leftLink.targetLine == rightLink.targetLine
|
||||
? leftLink.targetColumn > rightLink.targetColumn
|
||||
|
@@ -65,13 +65,10 @@ static int getMarkPos(QTextCursor cursor, const ClangBackEnd::HighlightingMarkCo
|
||||
return cursor.position();
|
||||
}
|
||||
|
||||
static TextEditor::TextEditorWidget::Link linkAtCursor(QTextCursor cursor,
|
||||
const QString &filePath,
|
||||
uint line,
|
||||
uint column,
|
||||
static Utils::Link linkAtCursor(QTextCursor cursor, const QString &filePath, uint line, uint column,
|
||||
ClangEditorDocumentProcessor *processor)
|
||||
{
|
||||
using Link = TextEditor::TextEditorWidget::Link;
|
||||
using Link = Utils::Link;
|
||||
|
||||
const QVector<ClangBackEnd::HighlightingMarkContainer> &marks
|
||||
= processor->highlightingMarks();
|
||||
@@ -95,8 +92,7 @@ static TextEditor::TextEditorWidget::Link linkAtCursor(QTextCursor cursor,
|
||||
return Link();
|
||||
}
|
||||
|
||||
TextEditor::TextEditorWidget::Link ClangFollowSymbol::findLink(
|
||||
const CppTools::CursorInEditor &data,
|
||||
Utils::Link ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
||||
bool resolveTarget,
|
||||
const CPlusPlus::Snapshot &,
|
||||
const CPlusPlus::Document::Ptr &,
|
||||
|
@@ -113,7 +113,7 @@ public:
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -132,10 +132,10 @@ static bool isValidFileNameChar(const QChar &c)
|
||||
|| c == QLatin1Char('\\');
|
||||
}
|
||||
|
||||
CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
Utils::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
bool/* resolveTarget*/, bool /*inNextSplit*/)
|
||||
{
|
||||
Link link;
|
||||
Utils::Link link;
|
||||
|
||||
int lineNumber = 0, positionInBlock = 0;
|
||||
convertPosition(cursor.position(), &lineNumber, &positionInBlock);
|
||||
|
@@ -679,7 +679,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
}
|
||||
|
||||
// Link to function definition/declaration
|
||||
CppEditorWidget::Link symbolLink;
|
||||
Utils::Link symbolLink;
|
||||
if (functionDeclarationSymbol) {
|
||||
symbolLink = linkToSymbol(
|
||||
d->m_modelManager->symbolFinder()
|
||||
@@ -716,12 +716,12 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
openLink(symbolLink, inNextSplit != alwaysOpenLinksInNextSplit());
|
||||
}
|
||||
|
||||
CppEditorWidget::Link CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
Utils::Link CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
bool resolveTarget,
|
||||
bool inNextSplit)
|
||||
{
|
||||
if (!d->m_modelManager)
|
||||
return Link();
|
||||
return Utils::Link();
|
||||
|
||||
const Utils::FileName &filePath = textDocument()->filePath();
|
||||
|
||||
|
@@ -100,7 +100,7 @@ protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
bool handleStringSplitting(QKeyEvent *e) const;
|
||||
|
||||
Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
||||
Utils::Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
||||
bool inNextSplit = false) override;
|
||||
|
||||
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
|
||||
|
@@ -264,7 +264,7 @@ CppInclude::CppInclude(const Document::Include &includeFile) :
|
||||
helpCategory = TextEditor::HelpItem::Brief;
|
||||
helpIdCandidates = QStringList(fileName);
|
||||
helpMark = fileName;
|
||||
link = TextEditor::TextEditorWidget::Link(path);
|
||||
link = Utils::Link(path);
|
||||
tooltip = path;
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ CppMacro::CppMacro(const Macro ¯o)
|
||||
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
||||
helpIdCandidates = QStringList(macroName);
|
||||
helpMark = macroName;
|
||||
link = TextEditor::TextEditorWidget::Link(macro.fileName(), macro.line());
|
||||
link = Utils::Link(macro.fileName(), macro.line());
|
||||
tooltip = macro.toStringWithLineBreaks();
|
||||
}
|
||||
|
||||
|
@@ -93,7 +93,7 @@ public:
|
||||
TextEditor::HelpItem::Category helpCategory;
|
||||
QStringList helpIdCandidates;
|
||||
QString helpMark;
|
||||
TextEditor::TextEditorWidget::Link link;
|
||||
Utils::Link link;
|
||||
QString tooltip;
|
||||
};
|
||||
|
||||
|
@@ -156,7 +156,7 @@ private:
|
||||
|
||||
Qt::ItemFlags flags(int) const override
|
||||
{
|
||||
TextEditorWidget::Link link(m_filePath, m_line);
|
||||
Utils::Link link(m_filePath, m_line);
|
||||
if (link.hasValidTarget())
|
||||
return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
@@ -193,7 +193,7 @@ QVariant CppIncludeHierarchyItem::data(int column, int role) const
|
||||
case Qt::DecorationRole:
|
||||
return FileIconProvider::icon(QFileInfo(m_filePath));
|
||||
case LinkRole:
|
||||
return QVariant::fromValue(TextEditorWidget::Link(m_filePath, m_line));
|
||||
return QVariant::fromValue(Utils::Link(m_filePath, m_line));
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
@@ -274,7 +274,7 @@ QMimeData *CppIncludeHierarchyModel::mimeData(const QModelIndexList &indexes) co
|
||||
{
|
||||
auto data = new DropMimeData;
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
auto link = index.data(LinkRole).value<TextEditorWidget::Link>();
|
||||
auto link = index.data(LinkRole).value<Utils::Link>();
|
||||
if (link.hasValidTarget())
|
||||
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
||||
}
|
||||
@@ -406,7 +406,7 @@ void CppIncludeHierarchyWidget::perform()
|
||||
m_model.buildHierarchy(document);
|
||||
|
||||
m_inspectedFile->setText(m_editor->textDocument()->displayName());
|
||||
m_inspectedFile->setLink(TextEditorWidget::Link(document));
|
||||
m_inspectedFile->setLink(Utils::Link(document));
|
||||
|
||||
// expand "Includes" and "Included by"
|
||||
m_treeView->expand(m_model.index(0, 0));
|
||||
@@ -417,7 +417,7 @@ void CppIncludeHierarchyWidget::perform()
|
||||
|
||||
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())
|
||||
EditorManager::openEditorAt(link.targetFileName,
|
||||
link.targetLine,
|
||||
|
@@ -65,7 +65,7 @@ QStandardItem *itemForClass(const CppClass &cppClass)
|
||||
item->setData(cppClass.qualifiedName, AnnotationRole);
|
||||
item->setData(cppClass.icon, Qt::DecorationRole);
|
||||
QVariant link;
|
||||
link.setValue(CppEditorWidget::Link(cppClass.link));
|
||||
link.setValue(Utils::Link(cppClass.link));
|
||||
item->setData(link, LinkRole);
|
||||
return item;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ void CppTypeHierarchyWidget::clearTypeHierarchy()
|
||||
|
||||
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())
|
||||
Core::EditorManager::openEditorAt(link.targetFileName,
|
||||
link.targetLine,
|
||||
@@ -246,7 +246,7 @@ QMimeData *CppTypeHierarchyModel::mimeData(const QModelIndexList &indexes) const
|
||||
auto data = new DropMimeData;
|
||||
data->setOverrideFileDropAction(Qt::CopyAction); // do not remove the item from the model
|
||||
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())
|
||||
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
||||
}
|
||||
|
@@ -246,7 +246,7 @@ void CppEditorOutline::gotoSymbolInEditor()
|
||||
if (!symbol)
|
||||
return;
|
||||
|
||||
const TextEditor::TextEditorWidget::Link &link = CppTools::linkToSymbol(symbol);
|
||||
const Utils::Link &link = CppTools::linkToSymbol(symbol);
|
||||
if (!link.hasValidTarget())
|
||||
return;
|
||||
|
||||
|
@@ -46,7 +46,7 @@
|
||||
using namespace CPlusPlus;
|
||||
using namespace TextEditor;
|
||||
|
||||
typedef TextEditorWidget::Link Link;
|
||||
using Link = Utils::Link;
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
|
@@ -230,12 +230,10 @@ const Macro *findCanonicalMacro(const QTextCursor &cursor, Document::Ptr documen
|
||||
return 0;
|
||||
}
|
||||
|
||||
TextEditor::TextEditorWidget::Link linkToSymbol(Symbol *symbol)
|
||||
Utils::Link linkToSymbol(Symbol *symbol)
|
||||
{
|
||||
typedef TextEditor::TextEditorWidget::Link Link;
|
||||
|
||||
if (!symbol)
|
||||
return Link();
|
||||
return Utils::Link();
|
||||
|
||||
const QString filename = QString::fromUtf8(symbol->fileName(),
|
||||
symbol->fileNameLength());
|
||||
@@ -249,7 +247,7 @@ TextEditor::TextEditorWidget::Link linkToSymbol(Symbol *symbol)
|
||||
if (symbol->isGenerated())
|
||||
column = 0;
|
||||
|
||||
return Link(filename, line, column);
|
||||
return Utils::Link(filename, line, column);
|
||||
}
|
||||
|
||||
QSharedPointer<CppCodeModelSettings> codeModelSettings()
|
||||
|
@@ -58,7 +58,7 @@ bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch);
|
||||
bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
|
||||
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);
|
||||
|
||||
|
@@ -126,7 +126,7 @@ public:
|
||||
{
|
||||
QTC_ASSERT(m_params.function, return 0);
|
||||
|
||||
auto *hintItem = new VirtualFunctionProposalItem(TextEditorWidget::Link());
|
||||
auto *hintItem = new VirtualFunctionProposalItem(Utils::Link());
|
||||
hintItem->setText(QCoreApplication::translate("VirtualFunctionsAssistProcessor",
|
||||
"...searching overrides"));
|
||||
hintItem->setOrder(-1000);
|
||||
@@ -173,7 +173,7 @@ private:
|
||||
|
||||
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));
|
||||
if (func->isPureVirtual())
|
||||
text += QLatin1String(" = 0");
|
||||
|
@@ -32,7 +32,7 @@
|
||||
namespace CppTools {
|
||||
|
||||
VirtualFunctionProposalItem::VirtualFunctionProposalItem(
|
||||
const TextEditor::TextEditorWidget::Link &link, bool openInSplit)
|
||||
const Utils::Link &link, bool openInSplit)
|
||||
: m_link(link), m_openInSplit(openInSplit)
|
||||
{
|
||||
}
|
||||
|
@@ -35,15 +35,15 @@ namespace CppTools {
|
||||
class CPPTOOLS_EXPORT VirtualFunctionProposalItem final : public TextEditor::AssistProposalItem
|
||||
{
|
||||
public:
|
||||
VirtualFunctionProposalItem(const TextEditor::TextEditorWidget::Link &link,
|
||||
VirtualFunctionProposalItem(const Utils::Link &link,
|
||||
bool openInSplit = true);
|
||||
~VirtualFunctionProposalItem() Q_DECL_NOEXCEPT {}
|
||||
void apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
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:
|
||||
TextEditor::TextEditorWidget::Link m_link;
|
||||
Utils::Link m_link;
|
||||
bool m_openInSplit;
|
||||
};
|
||||
|
||||
|
@@ -39,7 +39,7 @@ class SymbolFinder;
|
||||
class CPPTOOLS_EXPORT FollowSymbolInterface
|
||||
{
|
||||
public:
|
||||
using Link = TextEditor::TextEditorWidget::Link;
|
||||
using Link = Utils::Link;
|
||||
|
||||
virtual ~FollowSymbolInterface() {}
|
||||
virtual Link findLink(const CursorInEditor &data,
|
||||
|
@@ -72,7 +72,7 @@ static bool isValidFileNameChar(const QChar &c)
|
||||
|| c == QLatin1Char('\\');
|
||||
}
|
||||
|
||||
ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
Utils::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
bool /*resolveTarget*/,
|
||||
bool /*inNextSplit*/)
|
||||
{
|
||||
|
@@ -707,36 +707,36 @@ void QmlJSEditorWidget::inspectElementUnderCursor() const
|
||||
widget->textDocument()->setPlainText(buf);
|
||||
}
|
||||
|
||||
TextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
Utils::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
bool /*resolveTarget*/,
|
||||
bool /*inNextSplit*/)
|
||||
{
|
||||
const SemanticInfo semanticInfo = m_qmlJsEditorDocument->semanticInfo();
|
||||
if (! semanticInfo.isValid())
|
||||
return Link();
|
||||
return Utils::Link();
|
||||
|
||||
const unsigned cursorPosition = cursor.position();
|
||||
|
||||
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 it's a file import, link to the file
|
||||
foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) {
|
||||
if (import.ast() == importAst && import.type() == ImportType::File) {
|
||||
TextEditorWidget::Link link(import.path());
|
||||
Utils::Link link(import.path());
|
||||
link.linkTextStart = importAst->firstSourceLocation().begin();
|
||||
link.linkTextEnd = importAst->lastSourceLocation().end();
|
||||
return link;
|
||||
}
|
||||
}
|
||||
return Link();
|
||||
return Utils::Link();
|
||||
}
|
||||
|
||||
// string literals that could refer to a file link to them
|
||||
if (StringLiteral *literal = cast<StringLiteral *>(node)) {
|
||||
const QString &text = literal->value.toString();
|
||||
TextEditorWidget::Link link;
|
||||
Utils::Link link;
|
||||
link.linkTextStart = literal->literalToken.begin();
|
||||
link.linkTextEnd = literal->literalToken.end();
|
||||
if (semanticInfo.snapshot.document(text)) {
|
||||
@@ -760,9 +760,9 @@ TextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
int line = 0, column = 0;
|
||||
|
||||
if (! (value && value->getSourceLocation(&fileName, &line, &column)))
|
||||
return Link();
|
||||
return Utils::Link();
|
||||
|
||||
TextEditorWidget::Link link;
|
||||
Utils::Link link;
|
||||
link.targetFileName = fileName;
|
||||
link.targetLine = line;
|
||||
link.targetColumn = column - 1; // adjust the column
|
||||
@@ -787,7 +787,7 @@ TextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
return link;
|
||||
}
|
||||
|
||||
return Link();
|
||||
return Utils::Link();
|
||||
}
|
||||
|
||||
void QmlJSEditorWidget::findUsages()
|
||||
|
@@ -105,7 +105,7 @@ protected:
|
||||
void scrollContentsBy(int dx, int dy) override;
|
||||
void applyFontSettings() override;
|
||||
void createToolBar();
|
||||
TextEditor::TextEditorWidget::Link findLinkAt(const QTextCursor &cursor,
|
||||
Utils::Link findLinkAt(const QTextCursor &cursor,
|
||||
bool resolveTarget = true,
|
||||
bool inNextSplit = false) override;
|
||||
QString foldReplacementText(const QTextBlock &block) const override;
|
||||
|
@@ -90,7 +90,7 @@ void QmlTaskManager::collectMessages(
|
||||
QHash<QString, QList<DiagnosticMessage> > linkMessages;
|
||||
ContextPtr context;
|
||||
if (updateSemantic) {
|
||||
Link link(snapshot, vContext, snapshot.libraryInfo(info.qtImportsPath));
|
||||
QmlJS::Link link(snapshot, vContext, snapshot.libraryInfo(info.qtImportsPath));
|
||||
context = link(&linkMessages);
|
||||
}
|
||||
|
||||
|
@@ -505,7 +505,7 @@ public:
|
||||
|
||||
void requestUpdateLink(QMouseEvent *e, bool immediate = false);
|
||||
void updateLink();
|
||||
void showLink(const TextEditorWidget::Link &);
|
||||
void showLink(const Utils::Link &);
|
||||
void clearLink();
|
||||
|
||||
void universalHelper(); // test function for development
|
||||
@@ -637,7 +637,7 @@ public:
|
||||
uint m_maybeFakeTooltipEvent : 1;
|
||||
int m_visibleWrapColumn = 0;
|
||||
|
||||
TextEditorWidget::Link m_currentLink;
|
||||
Utils::Link m_currentLink;
|
||||
bool m_linkPressed = false;
|
||||
QTextCursor m_pendingLinkUpdate;
|
||||
QTextCursor m_lastLinkUpdate;
|
||||
@@ -1789,14 +1789,14 @@ void TextEditorWidget::redo()
|
||||
void TextEditorWidget::openLinkUnderCursor()
|
||||
{
|
||||
const bool openInNextSplit = alwaysOpenLinksInNextSplit();
|
||||
Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
||||
Utils::Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
||||
openLink(symbolLink, openInNextSplit);
|
||||
}
|
||||
|
||||
void TextEditorWidget::openLinkUnderCursorInNextSplit()
|
||||
{
|
||||
const bool openInNextSplit = !alwaysOpenLinksInNextSplit();
|
||||
Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
||||
Utils::Link symbolLink = findLinkAt(textCursor(), true, openInNextSplit);
|
||||
openLink(symbolLink, openInNextSplit);
|
||||
}
|
||||
|
||||
@@ -6064,12 +6064,12 @@ void TextEditorWidget::zoomReset()
|
||||
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())
|
||||
return false;
|
||||
@@ -6132,14 +6132,14 @@ void TextEditorWidgetPrivate::updateLink()
|
||||
return;
|
||||
|
||||
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())
|
||||
showLink(link);
|
||||
else
|
||||
clearLink();
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::showLink(const TextEditorWidget::Link &link)
|
||||
void TextEditorWidgetPrivate::showLink(const Utils::Link &link)
|
||||
{
|
||||
if (m_currentLink == link)
|
||||
return;
|
||||
@@ -6165,7 +6165,7 @@ void TextEditorWidgetPrivate::clearLink()
|
||||
|
||||
q->setExtraSelections(TextEditorWidget::OtherSelection, QList<QTextEdit::ExtraSelection>());
|
||||
q->viewport()->setCursor(Qt::IBeamCursor);
|
||||
m_currentLink = TextEditorWidget::Link();
|
||||
m_currentLink = Utils::Link();
|
||||
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;
|
||||
}
|
||||
|
||||
TextEditorWidget::Link TextEditorLinkLabel::link() const
|
||||
Utils::Link TextEditorLinkLabel::link() const
|
||||
{
|
||||
return m_link;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
|
||||
#include <utils/link.h>
|
||||
#include <utils/uncommentselection.h>
|
||||
|
||||
#include <QLabel>
|
||||
@@ -515,33 +516,6 @@ protected:
|
||||
void addHoverHandler(BaseHoverHandler *handler);
|
||||
|
||||
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;
|
||||
|
||||
void setupGenericHighlighter();
|
||||
@@ -564,13 +538,13 @@ protected:
|
||||
\a resolveTarget is set to true when the target of the link is relevant
|
||||
(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);
|
||||
|
||||
/*!
|
||||
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.
|
||||
@@ -616,8 +590,8 @@ class TEXTEDITOR_EXPORT TextEditorLinkLabel : public QLabel
|
||||
public:
|
||||
TextEditorLinkLabel(QWidget *parent = 0);
|
||||
|
||||
void setLink(TextEditorWidget::Link link);
|
||||
TextEditorWidget::Link link() const;
|
||||
void setLink(Utils::Link link);
|
||||
Utils::Link link() const;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
@@ -626,7 +600,7 @@ protected:
|
||||
|
||||
private:
|
||||
QPoint m_dragStartPosition;
|
||||
TextEditorWidget::Link m_link;
|
||||
Utils::Link m_link;
|
||||
};
|
||||
|
||||
class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
|
||||
@@ -679,5 +653,3 @@ QT_BEGIN_NAMESPACE
|
||||
uint qHash(const QColor &color);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(TextEditor::TextEditorWidget::Link)
|
||||
|
Reference in New Issue
Block a user