forked from qt-creator/qt-creator
Terminal: Open Link with line/column info
Change-Id: I3e70a7c33a935b7bd3e12fb903148bcd60ff55aa Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -27,7 +27,11 @@ public:
|
||||
static Link fromString(const QString &filePathWithNumbers, bool canContainLineNumber = false);
|
||||
|
||||
bool hasValidTarget() const
|
||||
{ return !targetFilePath.isEmpty(); }
|
||||
{
|
||||
if (!targetFilePath.isEmpty())
|
||||
return true;
|
||||
return !targetFilePath.scheme().isEmpty() || !targetFilePath.host().isEmpty();
|
||||
}
|
||||
|
||||
bool hasValidLinkText() const
|
||||
{ return linkTextStart != linkTextEnd; }
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "terminalwidget.h"
|
||||
#include "glyphcache.h"
|
||||
#include "keys.h"
|
||||
#include "terminalsettings.h"
|
||||
#include "terminalsurface.h"
|
||||
#include "terminaltr.h"
|
||||
@@ -993,11 +992,12 @@ void TerminalWidget::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier) {
|
||||
if (m_linkSelection) {
|
||||
if (m_linkSelection->filePath.scheme().toString().startsWith("http")) {
|
||||
QDesktopServices::openUrl(m_linkSelection->filePath.toUrl());
|
||||
if (m_linkSelection->link.targetFilePath.scheme().toString().startsWith("http")) {
|
||||
QDesktopServices::openUrl(m_linkSelection->link.targetFilePath.toUrl());
|
||||
return;
|
||||
}
|
||||
Core::EditorManager::openEditorAt(Utils::Link(m_linkSelection->filePath));
|
||||
|
||||
Core::EditorManager::openEditorAt(m_linkSelection->link);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1062,17 +1062,20 @@ void TerminalWidget::checkLinkAt(const QPoint &pos)
|
||||
const TextAndOffsets hit = textAt(pos);
|
||||
|
||||
if (hit.text.size() > 0) {
|
||||
QString t = QString::fromUcs4(hit.text.c_str(), hit.text.size());
|
||||
QString t
|
||||
= Utils::chopIfEndsWith(QString::fromUcs4(hit.text.c_str(), hit.text.size()).trimmed(),
|
||||
':');
|
||||
if (t.startsWith("~/")) {
|
||||
t = QDir::homePath() + t.mid(1);
|
||||
}
|
||||
|
||||
// Todo: Windows path support
|
||||
const FilePath p = FilePath::fromString(t.trimmed());
|
||||
Utils::Link link = Utils::Link::fromString(t, true);
|
||||
|
||||
if (!p.isEmpty() && (p.scheme().toString().startsWith("http") || p.exists())) {
|
||||
const LinkSelection newSelection = LinkSelection{{hit.start, hit.end}, p};
|
||||
if (*m_linkSelection != newSelection) {
|
||||
if (link.hasValidTarget()
|
||||
&& (link.targetFilePath.scheme().toString().startsWith("http")
|
||||
|| link.targetFilePath.exists())) {
|
||||
const LinkSelection newSelection = LinkSelection{{hit.start, hit.end}, link};
|
||||
if (!m_linkSelection || *m_linkSelection != newSelection) {
|
||||
m_linkSelection = newSelection;
|
||||
updateViewport();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "terminalsurface.h"
|
||||
|
||||
#include <utils/link.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/terminalhooks.h>
|
||||
|
||||
@@ -59,11 +60,11 @@ public:
|
||||
|
||||
struct LinkSelection : public Selection
|
||||
{
|
||||
Utils::FilePath filePath;
|
||||
Utils::Link link;
|
||||
|
||||
bool operator!=(const LinkSelection &other) const
|
||||
{
|
||||
return filePath != other.filePath || Selection::operator!=(other);
|
||||
return link != other.link || Selection::operator!=(other);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
22
src/plugins/terminal/tests/filenames
Executable file
22
src/plugins/terminal/tests/filenames
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "Home:"
|
||||
echo "~/"
|
||||
|
||||
FULLPATH=$(readlink -f "$0")
|
||||
|
||||
echo "This file:"
|
||||
echo "$FULLPATH"
|
||||
|
||||
echo "This file, this line:"
|
||||
echo "$FULLPATH:11"
|
||||
|
||||
echo "This file, this line, this word:"
|
||||
echo "$FULLPATH:14:34"
|
||||
|
||||
echo "This file, with an error message:"
|
||||
echo "$FULLPATH:18:23: error: C++ requires a type specifier for all declarations"
|
||||
|
||||
echo "A link: http://google.com"
|
||||
echo "Another link: https://www.qt.io"
|
||||
echo "Another one: https://codereview.qt-project.org/c/qt-creator/qt-creator/+/464740"
|
||||
Reference in New Issue
Block a user