Commit 45b02133 authored by David Schulz's avatar David Schulz
Browse files

Editor: Renaming Link members.



Change-Id: I1ae21152ee7b8e2a9323322575de23d77c260c72
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent d078c31b
......@@ -231,9 +231,9 @@ CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
else
return link;
}
link.fileName = fileName;
link.begin = cursor.position() - positionInBlock + beginPos + 1;
link.end = cursor.position() - positionInBlock + endPos;
link.targetFileName = fileName;
link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1;
link.linkTextEnd = cursor.position() - positionInBlock + endPos;
}
return link;
}
......
......@@ -1178,7 +1178,7 @@ void CPPEditorWidget::switchDeclarationDefinition()
bool isVisible = false;
foreach (Core::IEditor *visEditor, editorManager->visibleEditors()) {
if (visEditor->document() &&
(symbolLink.fileName == visEditor->document()->fileName()) &&
(symbolLink.targetFileName == visEditor->document()->fileName()) &&
(visEditor != editor)) {
isVisible = true;
editorManager->activateEditor(visEditor);
......@@ -1199,15 +1199,15 @@ void CPPEditorWidget::switchDeclarationDefinition()
if (Symbol *def = symbolFinder()->findMatchingDefinition(lastVisibleSymbol, snapshot)) {
Core::IEditor *editor = editorManager->currentEditor();
CPPEditorWidget::Link symbolLink = linkToSymbol(def);
if (editorManager->hasSplitter() && (editor->document()->fileName() != symbolLink.fileName)) {
if (editorManager->hasSplitter() && (editor->document()->fileName() != symbolLink.targetFileName)) {
if (forceOpenLinksInNextSplit()) {
editorManager->gotoOtherSplit();
} else if (openLinksInNextSplit()) {
bool isVisible = false;
foreach (Core::IEditor *visEditor, editorManager->visibleEditors()) {
if (visEditor->document() &&
(symbolLink.fileName == visEditor->document()->fileName()) &&
(visEditor != editor)) {
if (visEditor->document()
&& (symbolLink.targetFileName == visEditor->document()->fileName())
&& (visEditor != editor)) {
isVisible = true;
editorManager->activateEditor(visEditor);
break;
......@@ -1333,8 +1333,10 @@ CPPEditorWidget::Link CPPEditorWidget::attemptFuncDeclDef(const QTextCursor &cur
doc->translationUnit()->getTokenEndPosition(name->lastToken() - 1, &endLine, &endColumn);
QTextDocument *textDocument = cursor.document();
result.begin = textDocument->findBlockByNumber(startLine - 1).position() + startColumn - 1;
result.end = textDocument->findBlockByNumber(endLine - 1).position() + endColumn - 1;
result.linkTextStart =
textDocument->findBlockByNumber(startLine - 1).position() + startColumn - 1;
result.linkTextEnd =
textDocument->findBlockByNumber(endLine - 1).position() + endColumn - 1;
}
return result;
......@@ -1364,8 +1366,8 @@ CPPEditorWidget::Link CPPEditorWidget::findMacroLink(const QByteArray &name,
foreach (const Macro &macro, doc->definedMacros()) {
if (macro.name() == name) {
Link link;
link.fileName = macro.fileName();
link.line = macro.line();
link.targetFileName = macro.fileName();
link.targetLine = macro.line();
return link;
}
}
......@@ -1374,7 +1376,7 @@ CPPEditorWidget::Link CPPEditorWidget::findMacroLink(const QByteArray &name,
for (int index = includes.size() - 1; index != -1; --index) {
const Document::Include &i = includes.at(index);
Link link = findMacroLink(name, snapshot.document(i.fileName()), snapshot, processed);
if (! link.fileName.isEmpty())
if (link.hasValidTarget())
return link;
}
}
......@@ -1415,7 +1417,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
++pos;
if (characterAt(pos) == QLatin1Char('(')) {
link = attemptFuncDeclDef(cursor, m_lastSemanticInfo.doc, snapshot);
if (link.isValid())
if (link.hasValidLinkText())
return link;
}
}
......@@ -1501,9 +1503,9 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
const unsigned lineno = cursor.blockNumber() + 1;
foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineno && incl.resolved()) {
link.fileName = incl.fileName();
link.begin = beginOfToken + 1;
link.end = endOfToken - 1;
link.targetFileName = incl.fileName();
link.linkTextStart = beginOfToken + 1;
link.linkTextEnd = endOfToken - 1;
return link;
}
}
......@@ -1526,10 +1528,10 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
const Document::MacroUse *use = doc->findMacroUseAt(endOfToken - 1);
if (use && use->macro().fileName() != CppModelManagerInterface::configurationFileName()) {
const Macro &macro = use->macro();
link.fileName = macro.fileName();
link.line = macro.line();
link.begin = use->begin();
link.end = use->end();
link.targetFileName = macro.fileName();
link.targetLine = macro.line();
link.linkTextStart = use->begin();
link.linkTextEnd = use->end();
return link;
}
}
......@@ -1597,8 +1599,8 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
}
link = linkToSymbol(def ? def : symbol);
link.begin = beginOfToken;
link.end = endOfToken;
link.linkTextStart = beginOfToken;
link.linkTextEnd = endOfToken;
return link;
}
}
......@@ -1607,9 +1609,9 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
QTextCursor macroCursor = cursor;
const QByteArray name = identifierUnderCursor(&macroCursor).toLatin1();
link = findMacroLink(name);
if (! link.fileName.isEmpty()) {
link.begin = macroCursor.selectionStart();
link.end = macroCursor.selectionEnd();
if (link.hasValidTarget()) {
link.linkTextStart = macroCursor.selectionStart();
link.linkTextEnd = macroCursor.selectionEnd();
return link;
}
......@@ -1920,8 +1922,9 @@ CPPEditorWidget::Link CPPEditorWidget::linkToSymbol(CPlusPlus::Symbol *symbol)
if (!symbol)
return Link();
const QString fileName = QString::fromUtf8(symbol->fileName(),
const QString filename = QString::fromUtf8(symbol->fileName(),
symbol->fileNameLength());
unsigned line = symbol->line();
unsigned column = symbol->column();
......@@ -1931,18 +1934,18 @@ CPPEditorWidget::Link CPPEditorWidget::linkToSymbol(CPlusPlus::Symbol *symbol)
if (symbol->isGenerated())
column = 0;
return Link(fileName, line, column);
return Link(filename, line, column);
}
bool CPPEditorWidget::openCppEditorAt(const Link &link)
{
if (link.fileName.isEmpty())
if (link.targetFileName.isEmpty())
return false;
return TextEditor::BaseTextEditorWidget::openEditorAt(link.fileName,
link.line,
link.column,
Constants::CPPEDITOR_ID);
return TextEditor::BaseTextEditorWidget::openEditorAt(link.targetFileName,
link.targetLine,
link.targetColumn,
Constants::CPPEDITOR_ID);
}
void CPPEditorWidget::semanticRehighlight(bool force)
......
......@@ -105,12 +105,12 @@ public:
private:
void mousePressEvent(QMouseEvent *)
{
if (m_link.fileName.isEmpty())
if (!m_link.hasValidTarget())
return;
TextEditor::BaseTextEditorWidget::openEditorAt(m_link.fileName,
m_link.line,
m_link.column,
TextEditor::BaseTextEditorWidget::openEditorAt(m_link.targetFileName,
m_link.targetLine,
m_link.targetColumn,
Constants::CPPEDITOR_ID);
}
......@@ -207,10 +207,10 @@ void CppTypeHierarchyWidget::onItemClicked(const QModelIndex &index)
{
const TextEditor::BaseTextEditorWidget::Link link
= index.data(LinkRole).value<TextEditor::BaseTextEditorWidget::Link>();
if (!link.fileName.isEmpty())
TextEditor::BaseTextEditorWidget::openEditorAt(link.fileName,
link.line,
link.column,
if (link.hasValidTarget())
TextEditor::BaseTextEditorWidget::openEditorAt(link.targetFileName,
link.targetLine,
link.targetColumn,
Constants::CPPEDITOR_ID);
}
......
......@@ -1106,8 +1106,8 @@ TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const Q
foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) {
if (import.ast() == importAst && import.type() == ImportInfo::FileImport) {
BaseTextEditorWidget::Link link(import.path());
link.begin = importAst->firstSourceLocation().begin();
link.end = importAst->lastSourceLocation().end();
link.linkTextStart = importAst->firstSourceLocation().begin();
link.linkTextEnd = importAst->lastSourceLocation().end();
return link;
}
}
......@@ -1118,17 +1118,17 @@ TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const Q
if (StringLiteral *literal = cast<StringLiteral *>(node)) {
const QString &text = literal->value.toString();
BaseTextEditorWidget::Link link;
link.begin = literal->literalToken.begin();
link.end = literal->literalToken.end();
link.linkTextStart = literal->literalToken.begin();
link.linkTextEnd = literal->literalToken.end();
if (semanticInfo.snapshot.document(text)) {
link.fileName = text;
link.targetFileName = text;
return link;
}
const QString relative = QString::fromLatin1("%1/%2").arg(
semanticInfo.document->path(),
text);
if (semanticInfo.snapshot.document(relative)) {
link.fileName = relative;
link.targetFileName = relative;
return link;
}
}
......@@ -1144,27 +1144,27 @@ TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const Q
return Link();
BaseTextEditorWidget::Link link;
link.fileName = fileName;
link.line = line;
link.column = column - 1; // adjust the column
link.targetFileName = fileName;
link.targetLine = line;
link.targetColumn = column - 1; // adjust the column
if (AST::UiQualifiedId *q = AST::cast<AST::UiQualifiedId *>(node)) {
for (AST::UiQualifiedId *tail = q; tail; tail = tail->next) {
if (! tail->next && cursorPosition <= tail->identifierToken.end()) {
link.begin = tail->identifierToken.begin();
link.end = tail->identifierToken.end();
link.linkTextStart = tail->identifierToken.begin();
link.linkTextEnd = tail->identifierToken.end();
return link;
}
}
} else if (AST::IdentifierExpression *id = AST::cast<AST::IdentifierExpression *>(node)) {
link.begin = id->firstSourceLocation().begin();
link.end = id->lastSourceLocation().end();
link.linkTextStart = id->firstSourceLocation().begin();
link.linkTextEnd = id->lastSourceLocation().end();
return link;
} else if (AST::FieldMemberExpression *mem = AST::cast<AST::FieldMemberExpression *>(node)) {
link.begin = mem->lastSourceLocation().begin();
link.end = mem->lastSourceLocation().end();
link.linkTextStart = mem->lastSourceLocation().begin();
link.linkTextEnd = mem->lastSourceLocation().end();
return link;
}
......
......@@ -178,9 +178,9 @@ ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cur
else
return link;
}
link.fileName = QDir::cleanPath(fileName);
link.begin = cursor.position() - positionInBlock + beginPos + 1;
link.end = cursor.position() - positionInBlock + endPos;
link.targetFileName = QDir::cleanPath(fileName);
link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1;
link.linkTextEnd = cursor.position() - positionInBlock + endPos;
}
return link;
}
......
......@@ -1095,7 +1095,7 @@ void BaseTextEditorWidget::openLinkUnderCursor()
bool isVisible = false;
foreach (Core::IEditor *visEditor, editorManager->visibleEditors()) {
if (visEditor->document() &&
(symbolLink.fileName == visEditor->document()->fileName()) &&
(symbolLink.targetFileName == visEditor->document()->fileName()) &&
(visEditor != editor)) {
isVisible = true;
editorManager->activateEditor(visEditor);
......@@ -4289,7 +4289,7 @@ void BaseTextEditorWidget::mousePressEvent(QMouseEvent *e)
} else {
updateLink(e);
if (d->m_currentLink.isValid())
if (d->m_currentLink.hasValidLinkText())
d->m_linkPressed = true;
}
} else if (e->button() == Qt::RightButton) {
......@@ -4328,7 +4328,7 @@ void BaseTextEditorWidget::mouseReleaseEvent(QMouseEvent *e)
bool isVisible = false;
foreach (Core::IEditor *visEditor, editorManager->visibleEditors())
if (visEditor->document() &&
(symbolLink.fileName == visEditor->document()->fileName()) &&
(symbolLink.targetFileName == visEditor->document()->fileName()) &&
(editor != visEditor)) {
isVisible = true;
editorManager->activateEditor(visEditor);
......@@ -4911,18 +4911,17 @@ BaseTextEditorWidget::Link BaseTextEditorWidget::findLinkAt(const QTextCursor &,
bool BaseTextEditorWidget::openLink(const Link &link)
{
if (link.fileName.isEmpty())
if (!link.hasValidTarget())
return false;
if (baseTextDocument()->fileName() == link.fileName) {
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->addCurrentPositionToNavigationHistory();
gotoLine(link.line, link.column);
if (baseTextDocument()->fileName() == link.targetFileName) {
Core::EditorManager::instance()->addCurrentPositionToNavigationHistory();
gotoLine(link.targetLine, link.targetColumn);
setFocus();
return true;
}
return openEditorAt(link.fileName, link.line, link.column, Core::Id(),
return openEditorAt(link.targetFileName, link.targetLine, link.targetColumn, Core::Id(),
Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::ModeSwitch);
}
......@@ -4945,7 +4944,7 @@ void BaseTextEditorWidget::updateLink(QMouseEvent *e)
const Link link = findLinkAt(cursor, false);
if (onText && link.isValid()) {
if (onText && link.hasValidLinkText()) {
showLink(link);
linkFound = true;
}
......@@ -4962,8 +4961,8 @@ void BaseTextEditorWidget::showLink(const Link &link)
QTextEdit::ExtraSelection sel;
sel.cursor = textCursor();
sel.cursor.setPosition(link.begin);
sel.cursor.setPosition(link.end, QTextCursor::KeepAnchor);
sel.cursor.setPosition(link.linkTextStart);
sel.cursor.setPosition(link.linkTextEnd, QTextCursor::KeepAnchor);
sel.format = d->m_linkFormat;
sel.format.setFontUnderline(true);
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>() << sel);
......@@ -4974,7 +4973,7 @@ void BaseTextEditorWidget::showLink(const Link &link)
void BaseTextEditorWidget::clearLink()
{
if (!d->m_currentLink.isValid())
if (!d->m_currentLink.hasValidLinkText())
return;
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>());
......
......@@ -492,28 +492,29 @@ public:
struct Link
{
Link(const QString &fileName = QString(),
int line = 0,
int column = 0)
: begin(-1)
, end(-1)
, fileName(fileName)
, line(line)
, column(column)
Link(const QString &fileName = QString(), int line = 0, int column = 0)
: linkTextStart(-1)
, linkTextEnd(-1)
, targetFileName(fileName)
, targetLine(line)
, targetColumn(column)
{}
bool isValid() const
{ return begin != end; }
bool hasValidTarget() const
{ return !targetFileName.isEmpty(); }
bool hasValidLinkText() const
{ return linkTextStart != linkTextEnd; }
bool operator==(const Link &other) const
{ return begin == other.begin && end == other.end; }
{ return linkTextStart == other.linkTextStart && linkTextEnd == other.linkTextEnd; }
int begin; // Link position
int end; // Link end position
int linkTextStart;
int linkTextEnd;
QString fileName; // Target file
int line; // Target line
int column; // Target column
QString targetFileName;
int targetLine;
int targetColumn;
};
protected:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment