diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2020-06-18 07:52:26 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2020-06-18 16:52:03 +0000 |
commit | 6cfd2402852a00066d76339d100cd73600c6a592 (patch) | |
tree | 15cca24b744cb972ab92081e4ee9bf28ec7f721d /src | |
parent | c7b09409775a58a6bdb595aaebf7a88afddb889a (diff) |
OutputWindow: Do not activate links for empty reference
Change-Id: I1d4fc0f25f1882a34058c66c51376982cc70238e
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/utils/outputformatter.cpp | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/outputwindow.cpp | 3 | ||||
-rw-r--r-- | src/plugins/projectexplorer/taskwindow.cpp | 7 | ||||
-rw-r--r-- | src/plugins/qtsupport/qtoutputformatter.cpp | 121 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsoutputformatter.cpp | 8 |
5 files changed, 74 insertions, 66 deletions
diff --git a/src/libs/utils/outputformatter.cpp b/src/libs/utils/outputformatter.cpp index 85033ef0f5d..ac4412c8d3c 100644 --- a/src/libs/utils/outputformatter.cpp +++ b/src/libs/utils/outputformatter.cpp @@ -492,6 +492,7 @@ void OutputFormatter::dumpIncompleteLine(const QString &line, OutputFormat forma void OutputFormatter::handleLink(const QString &href) { + QTC_ASSERT(!href.isEmpty(), return); // We can handle absolute file paths ourselves. Other types of references are forwarded // to the line parsers. if (OutputLineParser::isLinkTarget(href)) { diff --git a/src/plugins/coreplugin/outputwindow.cpp b/src/plugins/coreplugin/outputwindow.cpp index 6b08863ea62..b8a5351abda 100644 --- a/src/plugins/coreplugin/outputwindow.cpp +++ b/src/plugins/coreplugin/outputwindow.cpp @@ -187,7 +187,8 @@ void OutputWindow::mouseReleaseEvent(QMouseEvent *e) { if (d->linksActive && d->mouseButtonPressed == Qt::LeftButton) { const QString href = anchorAt(e->pos()); - d->formatter.handleLink(href); + if (!href.isEmpty()) + d->formatter.handleLink(href); } // Mouse was released, activate links again diff --git a/src/plugins/projectexplorer/taskwindow.cpp b/src/plugins/projectexplorer/taskwindow.cpp index 438e0b3c2e4..64ccf827544 100644 --- a/src/plugins/projectexplorer/taskwindow.cpp +++ b/src/plugins/projectexplorer/taskwindow.cpp @@ -262,8 +262,11 @@ TaskView::Location TaskView::locationForPos(const QPoint &pos) loc.file = fp; loc.line = line; loc.column = column; - }); - formatter.handleLink(delegate->hrefForPos(pos)); + }); + + const QString href = delegate->hrefForPos(pos); + if (!href.isEmpty()) + formatter.handleLink(href); return loc; } diff --git a/src/plugins/qtsupport/qtoutputformatter.cpp b/src/plugins/qtsupport/qtoutputformatter.cpp index 62cee367969..8975328dd0d 100644 --- a/src/plugins/qtsupport/qtoutputformatter.cpp +++ b/src/plugins/qtsupport/qtoutputformatter.cpp @@ -163,67 +163,66 @@ OutputLineParser::Result QtOutputLineParser::handleLine(const QString &txt, Outp bool QtOutputLineParser::handleLink(const QString &href) { - if (!href.isEmpty()) { - static const QRegularExpression qmlLineColumnLink("^(" QT_QML_URL_REGEXP ")" // url - ":(\\d+)" // line - ":(\\d+)$"); // column - const QRegularExpressionMatch qmlLineColumnMatch = qmlLineColumnLink.match(href); - - const auto getFileToOpen = [this](const QUrl &fileUrl) { - return chooseFileFromList(d->projectFinder.findFile(fileUrl)).toString(); - }; - if (qmlLineColumnMatch.hasMatch()) { - const QUrl fileUrl = QUrl(qmlLineColumnMatch.captured(1)); - const int line = qmlLineColumnMatch.captured(2).toInt(); - const int column = qmlLineColumnMatch.captured(3).toInt(); - openEditor(getFileToOpen(fileUrl), line, column - 1); - return true; - } - - static const QRegularExpression qmlLineLink("^(" QT_QML_URL_REGEXP ")" // url - ":(\\d+)$"); // line - const QRegularExpressionMatch qmlLineMatch = qmlLineLink.match(href); - - if (qmlLineMatch.hasMatch()) { - const char scheme[] = "file://"; - const QString filePath = qmlLineMatch.captured(1); - QUrl fileUrl = QUrl(filePath); - if (!fileUrl.isValid() && filePath.startsWith(scheme)) - fileUrl = QUrl::fromLocalFile(filePath.mid(int(strlen(scheme)))); - const int line = qmlLineMatch.captured(2).toInt(); - openEditor(getFileToOpen(fileUrl), line); - return true; - } - - QString fileName; - int line = -1; - - static const QRegularExpression qtErrorLink("^(.*):(\\d+)$"); - const QRegularExpressionMatch qtErrorMatch = qtErrorLink.match(href); - if (qtErrorMatch.hasMatch()) { - fileName = qtErrorMatch.captured(1); - line = qtErrorMatch.captured(2).toInt(); - } - - static const QRegularExpression qtAssertLink("^(.+), line (\\d+)$"); - const QRegularExpressionMatch qtAssertMatch = qtAssertLink.match(href); - if (qtAssertMatch.hasMatch()) { - fileName = qtAssertMatch.captured(1); - line = qtAssertMatch.captured(2).toInt(); - } - - static const QRegularExpression qtTestFailLink("^(.*)\\((\\d+)\\)$"); - const QRegularExpressionMatch qtTestFailMatch = qtTestFailLink.match(href); - if (qtTestFailMatch.hasMatch()) { - fileName = qtTestFailMatch.captured(1); - line = qtTestFailMatch.captured(2).toInt(); - } - - if (!fileName.isEmpty()) { - fileName = getFileToOpen(QUrl::fromLocalFile(fileName)); - openEditor(fileName, line); - return true; - } + QTC_ASSERT(!href.isEmpty(), return false); + static const QRegularExpression qmlLineColumnLink("^(" QT_QML_URL_REGEXP ")" // url + ":(\\d+)" // line + ":(\\d+)$"); // column + const QRegularExpressionMatch qmlLineColumnMatch = qmlLineColumnLink.match(href); + + const auto getFileToOpen = [this](const QUrl &fileUrl) { + return chooseFileFromList(d->projectFinder.findFile(fileUrl)).toString(); + }; + if (qmlLineColumnMatch.hasMatch()) { + const QUrl fileUrl = QUrl(qmlLineColumnMatch.captured(1)); + const int line = qmlLineColumnMatch.captured(2).toInt(); + const int column = qmlLineColumnMatch.captured(3).toInt(); + openEditor(getFileToOpen(fileUrl), line, column - 1); + return true; + } + + static const QRegularExpression qmlLineLink("^(" QT_QML_URL_REGEXP ")" // url + ":(\\d+)$"); // line + const QRegularExpressionMatch qmlLineMatch = qmlLineLink.match(href); + + if (qmlLineMatch.hasMatch()) { + const char scheme[] = "file://"; + const QString filePath = qmlLineMatch.captured(1); + QUrl fileUrl = QUrl(filePath); + if (!fileUrl.isValid() && filePath.startsWith(scheme)) + fileUrl = QUrl::fromLocalFile(filePath.mid(int(strlen(scheme)))); + const int line = qmlLineMatch.captured(2).toInt(); + openEditor(getFileToOpen(fileUrl), line); + return true; + } + + QString fileName; + int line = -1; + + static const QRegularExpression qtErrorLink("^(.*):(\\d+)$"); + const QRegularExpressionMatch qtErrorMatch = qtErrorLink.match(href); + if (qtErrorMatch.hasMatch()) { + fileName = qtErrorMatch.captured(1); + line = qtErrorMatch.captured(2).toInt(); + } + + static const QRegularExpression qtAssertLink("^(.+), line (\\d+)$"); + const QRegularExpressionMatch qtAssertMatch = qtAssertLink.match(href); + if (qtAssertMatch.hasMatch()) { + fileName = qtAssertMatch.captured(1); + line = qtAssertMatch.captured(2).toInt(); + } + + static const QRegularExpression qtTestFailLink("^(.*)\\((\\d+)\\)$"); + const QRegularExpressionMatch qtTestFailMatch = qtTestFailLink.match(href); + if (qtTestFailMatch.hasMatch()) { + fileName = qtTestFailMatch.captured(1); + line = qtTestFailMatch.captured(2).toInt(); + } + + if (!fileName.isEmpty()) { + fileName = getFileToOpen(QUrl::fromLocalFile(fileName)); + openEditor(fileName, line); + return true; } return false; } diff --git a/src/plugins/vcsbase/vcsoutputformatter.cpp b/src/plugins/vcsbase/vcsoutputformatter.cpp index 9fd116dda07..f2fb8fd3be6 100644 --- a/src/plugins/vcsbase/vcsoutputformatter.cpp +++ b/src/plugins/vcsbase/vcsoutputformatter.cpp @@ -26,6 +26,8 @@ #include <coreplugin/iversioncontrol.h> #include <coreplugin/vcsmanager.h> +#include <utils/qtcassert.h> + #include <QDesktopServices> #include <QMenu> #include <QPlainTextEdit> @@ -64,9 +66,10 @@ Utils::OutputLineParser::Result VcsOutputLineParser::handleLine(const QString &t bool VcsOutputLineParser::handleLink(const QString &href) { + QTC_ASSERT(!href.isEmpty(), return false); if (href.startsWith("http://") || href.startsWith("https://")) QDesktopServices::openUrl(QUrl(href)); - else if (!href.isEmpty()) + else emit referenceClicked(href); return true; } @@ -74,7 +77,8 @@ bool VcsOutputLineParser::handleLink(const QString &href) void VcsOutputLineParser::fillLinkContextMenu( QMenu *menu, const QString &workingDirectory, const QString &href) { - if (href.isEmpty() || href.startsWith("http://") || href.startsWith("https://")) { + QTC_ASSERT(!href.isEmpty(), return); + if (href.startsWith("http://") || href.startsWith("https://")) { QAction *action = menu->addAction( tr("&Open \"%1\"").arg(href), [href] { QDesktopServices::openUrl(QUrl(href)); }); |