forked from qt-creator/qt-creator
TextEditors: Implement "Follow Symbol" for HTTP urls in string literals
Task-number: QTCREATORBUG-14967 Change-Id: I30923aa94d761b06edb1f67007fd7e2a67065ef0 Reviewed-by: Xavier BESSON <developer@xavi-b.fr> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -848,7 +848,7 @@ void CppEditorWidget::followSymbolToType(bool inNextSplit)
|
|||||||
CppModelManager::followSymbolToType(cursor, callback, inNextSplit);
|
CppModelManager::followSymbolToType(cursor, callback, inNextSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppEditorWidget::followQrcUrl(const QTextCursor &cursor,
|
bool CppEditorWidget::followUrl(const QTextCursor &cursor,
|
||||||
const Utils::LinkHandler &processLinkCallback)
|
const Utils::LinkHandler &processLinkCallback)
|
||||||
{
|
{
|
||||||
if (!isSemanticInfoValidExceptLocalUses())
|
if (!isSemanticInfoValidExceptLocalUses())
|
||||||
@@ -869,6 +869,15 @@ bool CppEditorWidget::followQrcUrl(const QTextCursor &cursor,
|
|||||||
if (!literal)
|
if (!literal)
|
||||||
return false;
|
return false;
|
||||||
const QString theString = QString::fromUtf8(literal->chars(), literal->size());
|
const QString theString = QString::fromUtf8(literal->chars(), literal->size());
|
||||||
|
|
||||||
|
if (theString.startsWith("https:/") || theString.startsWith("http:/")) {
|
||||||
|
Utils::Link link = FilePath::fromPathPart(theString);
|
||||||
|
link.linkTextStart = d->m_lastSemanticInfo.doc->translationUnit()->getTokenPositionInDocument(literalAst->literal_token, document());
|
||||||
|
link.linkTextEnd = d->m_lastSemanticInfo.doc->translationUnit()->getTokenEndPositionInDocument(literalAst->literal_token, document());
|
||||||
|
processLinkCallback(link);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!theString.startsWith("qrc:/") && !theString.startsWith(":/"))
|
if (!theString.startsWith("qrc:/") && !theString.startsWith(":/"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -897,7 +906,7 @@ 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))
|
if (followUrl(cursor, processLinkCallback))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Utils::FilePath &filePath = textDocument()->filePath();
|
const Utils::FilePath &filePath = textDocument()->filePath();
|
||||||
|
@@ -123,7 +123,7 @@ private:
|
|||||||
|
|
||||||
unsigned documentRevision() const;
|
unsigned documentRevision() const;
|
||||||
bool isOldStyleSignalOrSlot() const;
|
bool isOldStyleSignalOrSlot() const;
|
||||||
bool followQrcUrl(const QTextCursor &cursor, const Utils::LinkHandler &processLinkCallback);
|
bool followUrl(const QTextCursor &cursor, const Utils::LinkHandler &processLinkCallback);
|
||||||
|
|
||||||
QMenu *createRefactorMenu(QWidget *parent) const;
|
QMenu *createRefactorMenu(QWidget *parent) const;
|
||||||
|
|
||||||
|
@@ -789,6 +789,15 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text.startsWith("https:/") || text.startsWith("http:/")) {
|
||||||
|
Link link = Link::fromFilePath(FilePath::fromPathPart(text));
|
||||||
|
link.linkTextStart = literal->literalToken.begin();
|
||||||
|
link.linkTextEnd = literal->literalToken.end();
|
||||||
|
processLinkCallback(link);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Utils::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();
|
||||||
|
@@ -72,6 +72,7 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
@@ -6341,6 +6342,12 @@ bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit)
|
|||||||
if (!link.hasValidTarget())
|
if (!link.hasValidTarget())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
QString url = link.targetFilePath.toString();
|
||||||
|
if (url.startsWith(u"https://"_qs) || url.startsWith(u"http://"_qs)) {
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!inNextSplit && textDocument()->filePath() == link.targetFilePath) {
|
if (!inNextSplit && textDocument()->filePath() == link.targetFilePath) {
|
||||||
EditorManager::addCurrentPositionToNavigationHistory();
|
EditorManager::addCurrentPositionToNavigationHistory();
|
||||||
gotoLine(link.targetLine, link.targetColumn, true, true);
|
gotoLine(link.targetLine, link.targetColumn, true, true);
|
||||||
|
Reference in New Issue
Block a user