forked from qt-creator/qt-creator
CppEditor: Implement "Follow Symbol" for qrc paths in string literals
The "symbol" in this case is the file that the qrc path points to. Task-number: QTCREATORBUG-28087 Change-Id: I0d3ff96513d51e9dde4fb378695787b839c26100 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -3,11 +3,7 @@
|
|||||||
|
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
|
|
||||||
#include "cppautocompleter.h"
|
|
||||||
#include "cppcanonicalsymbol.h"
|
|
||||||
#include "cppchecksymbols.h"
|
|
||||||
#include "cppcodeformatter.h"
|
#include "cppcodeformatter.h"
|
||||||
#include "cppcodemodelsettings.h"
|
|
||||||
#include "cppcompletionassistprovider.h"
|
#include "cppcompletionassistprovider.h"
|
||||||
#include "doxygengenerator.h"
|
#include "doxygengenerator.h"
|
||||||
#include "cppeditorconstants.h"
|
#include "cppeditorconstants.h"
|
||||||
@@ -15,19 +11,14 @@
|
|||||||
#include "cppeditoroutline.h"
|
#include "cppeditoroutline.h"
|
||||||
#include "cppeditorplugin.h"
|
#include "cppeditorplugin.h"
|
||||||
#include "cppfunctiondecldeflink.h"
|
#include "cppfunctiondecldeflink.h"
|
||||||
#include "cpphighlighter.h"
|
|
||||||
#include "cpplocalrenaming.h"
|
#include "cpplocalrenaming.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
#include "cpppreprocessordialog.h"
|
#include "cpppreprocessordialog.h"
|
||||||
#include "cppsemanticinfo.h"
|
#include "cppsemanticinfo.h"
|
||||||
#include "cppselectionchanger.h"
|
#include "cppselectionchanger.h"
|
||||||
#include "cppqtstyleindenter.h"
|
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
#include "cpptoolsreuse.h"
|
|
||||||
#include "cpptoolssettings.h"
|
#include "cpptoolssettings.h"
|
||||||
#include "cppuseselectionsupdater.h"
|
#include "cppuseselectionsupdater.h"
|
||||||
#include "cppworkingcopy.h"
|
|
||||||
#include "symbolfinder.h"
|
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
@@ -843,6 +834,41 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
|||||||
CppModelManager::switchDeclDef(cursor, std::move(callback));
|
CppModelManager::switchDeclDef(cursor, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppEditorWidget::followQrcUrl(const QTextCursor &cursor,
|
||||||
|
const Utils::LinkHandler &processLinkCallback)
|
||||||
|
{
|
||||||
|
const Project * const project = ProjectTree::currentProject();
|
||||||
|
if (!project || !project->rootProjectNode())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const QList<AST *> astPath = ASTPath(d->m_lastSemanticInfo.doc)(cursor);
|
||||||
|
if (astPath.isEmpty())
|
||||||
|
return false;
|
||||||
|
const StringLiteralAST * const literalAst = astPath.last()->asStringLiteral();
|
||||||
|
if (!literalAst)
|
||||||
|
return false;
|
||||||
|
const StringLiteral * const literal = d->m_lastSemanticInfo.doc->translationUnit()
|
||||||
|
->stringLiteral(literalAst->literal_token);
|
||||||
|
if (!literal)
|
||||||
|
return false;
|
||||||
|
const QString theString = QString::fromUtf8(literal->chars(), literal->size());
|
||||||
|
if (!theString.startsWith("qrc:/") && !theString.startsWith(":/"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const Node * const nodeForPath = project->rootProjectNode()->findNode(
|
||||||
|
[qrcPath = theString.mid(theString.indexOf(':') + 1)](Node *n) {
|
||||||
|
if (!n->asFileNode())
|
||||||
|
return false;
|
||||||
|
const auto qrcNode = dynamic_cast<ResourceFileNode *>(n);
|
||||||
|
return qrcNode && qrcNode->qrcPath() == qrcPath;
|
||||||
|
});
|
||||||
|
if (!nodeForPath)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
processLinkCallback(Link(nodeForPath->filePath()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
const LinkHandler &processLinkCallback,
|
const LinkHandler &processLinkCallback,
|
||||||
bool resolveTarget,
|
bool resolveTarget,
|
||||||
@@ -851,6 +877,9 @@ void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
if (!d->m_modelManager)
|
if (!d->m_modelManager)
|
||||||
return processLinkCallback(Utils::Link());
|
return processLinkCallback(Utils::Link());
|
||||||
|
|
||||||
|
if (followQrcUrl(cursor, processLinkCallback))
|
||||||
|
return;
|
||||||
|
|
||||||
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
|
// Let following a "leaf" C++ symbol take us to the designer, if we are in a generated
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ private:
|
|||||||
|
|
||||||
unsigned documentRevision() const;
|
unsigned documentRevision() const;
|
||||||
bool isOldStyleSignalOrSlot() const;
|
bool isOldStyleSignalOrSlot() const;
|
||||||
|
bool followQrcUrl(const QTextCursor &cursor, const Utils::LinkHandler &processLinkCallback);
|
||||||
|
|
||||||
QMenu *createRefactorMenu(QWidget *parent) const;
|
QMenu *createRefactorMenu(QWidget *parent) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user