forked from qt-creator/qt-creator
CppEditor: Follow symbols in generated UI headers to .ui file
Fixes: QTCREATORBUG-2374 Change-Id: I784fe39c11c834525cdd37ca719efa65efcb307c Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -62,6 +62,10 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/find/searchresultwindow.h>
|
#include <coreplugin/find/searchresultwindow.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/projectnodes.h>
|
||||||
|
#include <projectexplorer/projecttree.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
|
|
||||||
#include <texteditor/basefilefind.h>
|
#include <texteditor/basefilefind.h>
|
||||||
#include <texteditor/behaviorsettings.h>
|
#include <texteditor/behaviorsettings.h>
|
||||||
#include <texteditor/codeassist/assistproposalitem.h>
|
#include <texteditor/codeassist/assistproposalitem.h>
|
||||||
@@ -76,8 +80,6 @@
|
|||||||
#include <texteditor/textdocumentlayout.h>
|
#include <texteditor/textdocumentlayout.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <projectexplorer/projecttree.h>
|
|
||||||
|
|
||||||
#include <cplusplus/ASTPath.h>
|
#include <cplusplus/ASTPath.h>
|
||||||
#include <cplusplus/FastPreprocessor.h>
|
#include <cplusplus/FastPreprocessor.h>
|
||||||
#include <cplusplus/MatchingText.h>
|
#include <cplusplus/MatchingText.h>
|
||||||
@@ -101,6 +103,7 @@ enum { UPDATE_FUNCTION_DECL_DEF_LINK_INTERVAL = 200 };
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
using namespace ProjectExplorer;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -1045,7 +1048,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
Utils::ProcessLinkCallback &&processLinkCallback,
|
ProcessLinkCallback &&processLinkCallback,
|
||||||
bool resolveTarget,
|
bool resolveTarget,
|
||||||
bool inNextSplit)
|
bool inNextSplit)
|
||||||
{
|
{
|
||||||
@@ -1054,9 +1057,36 @@ void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
|
|
||||||
const Utils::FilePath &filePath = textDocument()->filePath();
|
const Utils::FilePath &filePath = textDocument()->filePath();
|
||||||
|
|
||||||
|
// Let following a "leaf" C++ symbol take us to the designer, if we are in a generated
|
||||||
|
// UI header.
|
||||||
|
QTextCursor c(cursor);
|
||||||
|
c.select(QTextCursor::WordUnderCursor);
|
||||||
|
ProcessLinkCallback callbackWrapper = [start = c.selectionStart(), end = c.selectionEnd(),
|
||||||
|
doc = QPointer(cursor.document()), callback = std::move(processLinkCallback),
|
||||||
|
filePath](const Link &link) {
|
||||||
|
const int linkPos = doc ? Text::positionInText(doc, link.targetLine, link.targetColumn + 1)
|
||||||
|
: -1;
|
||||||
|
if (link.targetFilePath == filePath && linkPos >= start && linkPos < end) {
|
||||||
|
const QString fileName = filePath.fileName();
|
||||||
|
if (fileName.startsWith("ui_") && fileName.endsWith(".h")) {
|
||||||
|
const QString uiFileName = fileName.mid(3, fileName.length() - 4) + "ui";
|
||||||
|
for (const Project * const project : SessionManager::projects()) {
|
||||||
|
const auto nodeMatcher = [uiFileName](Node *n) {
|
||||||
|
return n->filePath().fileName() == uiFileName;
|
||||||
|
};
|
||||||
|
if (const Node * const uiNode = project->rootProjectNode()
|
||||||
|
->findNode(nodeMatcher)) {
|
||||||
|
EditorManager::openEditor(uiNode->filePath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback(link);
|
||||||
|
};
|
||||||
followSymbolInterface().findLink(
|
followSymbolInterface().findLink(
|
||||||
CursorInEditor{cursor, filePath, this, textDocument()},
|
CursorInEditor{cursor, filePath, this, textDocument()},
|
||||||
std::move(processLinkCallback),
|
std::move(callbackWrapper),
|
||||||
resolveTarget,
|
resolveTarget,
|
||||||
d->m_modelManager->snapshot(),
|
d->m_modelManager->snapshot(),
|
||||||
d->m_lastSemanticInfo.doc,
|
d->m_lastSemanticInfo.doc,
|
||||||
|
Reference in New Issue
Block a user