forked from qt-creator/qt-creator
Git: Allow clicking references in VcsOutputWindow
Fixes: QTCREATORBUG-16477 Change-Id: If1f36bec0826a3116e5261a270cd63a1536e13f5 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
André Hartmann
parent
d0a11322f4
commit
4cbb24906f
@@ -919,6 +919,14 @@ GitPluginPrivate::GitPluginPrivate()
|
|||||||
m_gerritPlugin->initialize(remoteRepositoryMenu);
|
m_gerritPlugin->initialize(remoteRepositoryMenu);
|
||||||
m_gerritPlugin->updateActions(currentState());
|
m_gerritPlugin->updateActions(currentState());
|
||||||
m_gerritPlugin->addToLocator(m_commandLocator);
|
m_gerritPlugin->addToLocator(m_commandLocator);
|
||||||
|
|
||||||
|
connect(VcsOutputWindow::instance(), &VcsOutputWindow::referenceClicked,
|
||||||
|
this, [this](const QString &name) {
|
||||||
|
const VcsBasePluginState state = currentState();
|
||||||
|
QTC_ASSERT(state.hasTopLevel(), return);
|
||||||
|
m_gitClient.show(state.topLevel(), name);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitPluginPrivate::diffCurrentFile()
|
void GitPluginPrivate::diffCurrentFile()
|
||||||
|
@@ -30,17 +30,24 @@
|
|||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
|
|
||||||
VcsOutputFormatter::VcsOutputFormatter() : m_urlRegexp("https?://\\S*") {}
|
VcsOutputFormatter::VcsOutputFormatter() :
|
||||||
|
m_urlRegexp("https?://\\S*"),
|
||||||
|
m_referenceRegexp("(v[0-9]+\\.[0-9]+\\.[0-9]+[\\-A-Za-z0-9]*)" // v0.1.2-beta3
|
||||||
|
"|([0-9a-f]{6,}(?:\\.\\.[0-9a-f]{6,})?)") // 789acf or 123abc..456cde
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void VcsOutputFormatter::appendMessage(const QString &text, Utils::OutputFormat format)
|
void VcsOutputFormatter::appendMessage(const QString &text, Utils::OutputFormat format)
|
||||||
{
|
{
|
||||||
QString out = text;
|
const QRegularExpressionMatch urlMatch = m_urlRegexp.match(text);
|
||||||
const QRegularExpressionMatch match = m_urlRegexp.match(text);
|
const QRegularExpressionMatch referenceMatch = m_referenceRegexp.match(text);
|
||||||
if (match.hasMatch()) {
|
|
||||||
|
auto append = [this](const QRegularExpressionMatch &match,
|
||||||
|
QString text, Utils::OutputFormat format) {
|
||||||
const QTextCharFormat normalFormat = charFormat(format);
|
const QTextCharFormat normalFormat = charFormat(format);
|
||||||
OutputFormatter::appendMessage(text.left(match.capturedStart()), format);
|
OutputFormatter::appendMessage(text.left(match.capturedStart()), format);
|
||||||
QTextCursor tc = plainTextEdit()->textCursor();
|
QTextCursor tc = plainTextEdit()->textCursor();
|
||||||
QStringRef url = match.capturedRef();
|
QStringView url = match.capturedView();
|
||||||
int end = match.capturedEnd();
|
int end = match.capturedEnd();
|
||||||
while (url.rbegin()->isPunct()) {
|
while (url.rbegin()->isPunct()) {
|
||||||
url.chop(1);
|
url.chop(1);
|
||||||
@@ -50,14 +57,22 @@ void VcsOutputFormatter::appendMessage(const QString &text, Utils::OutputFormat
|
|||||||
tc.insertText(url.toString(), linkFormat(normalFormat, url.toString()));
|
tc.insertText(url.toString(), linkFormat(normalFormat, url.toString()));
|
||||||
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||||
OutputFormatter::appendMessage(text.mid(end), format);
|
OutputFormatter::appendMessage(text.mid(end), format);
|
||||||
} else {
|
};
|
||||||
|
|
||||||
|
if (urlMatch.hasMatch())
|
||||||
|
append(urlMatch, text, format);
|
||||||
|
else if (referenceMatch.hasMatch())
|
||||||
|
append(referenceMatch, text, format);
|
||||||
|
else
|
||||||
OutputFormatter::appendMessage(text, format);
|
OutputFormatter::appendMessage(text, format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsOutputFormatter::handleLink(const QString &href)
|
void VcsOutputFormatter::handleLink(const QString &href)
|
||||||
{
|
{
|
||||||
|
if (href.startsWith("http://") || href.startsWith("https://"))
|
||||||
QDesktopServices::openUrl(QUrl(href));
|
QDesktopServices::openUrl(QUrl(href));
|
||||||
|
else if (!href.isEmpty())
|
||||||
|
emit referenceClicked(href);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -31,14 +31,19 @@ namespace VcsBase {
|
|||||||
|
|
||||||
class VcsOutputFormatter : public Utils::OutputFormatter
|
class VcsOutputFormatter : public Utils::OutputFormatter
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
VcsOutputFormatter();
|
VcsOutputFormatter();
|
||||||
~VcsOutputFormatter() override = default;
|
~VcsOutputFormatter() override = default;
|
||||||
void appendMessage(const QString &text, Utils::OutputFormat format) override;
|
void appendMessage(const QString &text, Utils::OutputFormat format) override;
|
||||||
void handleLink(const QString &href) override;
|
void handleLink(const QString &href) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void referenceClicked(const QString &reference);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QRegularExpression m_urlRegexp;
|
const QRegularExpression m_urlRegexp;
|
||||||
|
const QRegularExpression m_referenceRegexp;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -102,6 +102,7 @@ public:
|
|||||||
void appendLines(const QString &s, const QString &repository = QString());
|
void appendLines(const QString &s, const QString &repository = QString());
|
||||||
void appendLinesWithStyle(const QString &s, VcsOutputWindow::MessageStyle style,
|
void appendLinesWithStyle(const QString &s, VcsOutputWindow::MessageStyle style,
|
||||||
const QString &repository = QString());
|
const QString &repository = QString());
|
||||||
|
VcsOutputFormatter *formatter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
@@ -247,6 +248,11 @@ void OutputWindowPlainTextEdit::appendLinesWithStyle(const QString &s,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VcsOutputFormatter *OutputWindowPlainTextEdit::formatter()
|
||||||
|
{
|
||||||
|
return m_formatter;
|
||||||
|
}
|
||||||
|
|
||||||
void OutputWindowPlainTextEdit::setFormat(VcsOutputWindow::MessageStyle style)
|
void OutputWindowPlainTextEdit::setFormat(VcsOutputWindow::MessageStyle style)
|
||||||
{
|
{
|
||||||
m_formatter->setBoldFontEnabled(style == VcsOutputWindow::Command);
|
m_formatter->setBoldFontEnabled(style == VcsOutputWindow::Command);
|
||||||
@@ -305,6 +311,8 @@ VcsOutputWindow::VcsOutputWindow()
|
|||||||
connect(this, &IOutputPane::resetZoom, &d->widget, &Core::OutputWindow::resetZoom);
|
connect(this, &IOutputPane::resetZoom, &d->widget, &Core::OutputWindow::resetZoom);
|
||||||
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::behaviorSettingsChanged,
|
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::behaviorSettingsChanged,
|
||||||
this, updateBehaviorSettings);
|
this, updateBehaviorSettings);
|
||||||
|
connect(d->widget.formatter(), &VcsOutputFormatter::referenceClicked,
|
||||||
|
VcsOutputWindow::instance(), &VcsOutputWindow::referenceClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString filterPasswordFromUrls(const QString &input)
|
static QString filterPasswordFromUrls(const QString &input)
|
||||||
|
@@ -76,6 +76,9 @@ public:
|
|||||||
Message, // A blue message text (e.g. "command has finished successfully")
|
Message, // A blue message text (e.g. "command has finished successfully")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void referenceClicked(const QString &reference);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static void setRepository(const QString &);
|
static void setRepository(const QString &);
|
||||||
static void clearRepository();
|
static void clearRepository();
|
||||||
|
Reference in New Issue
Block a user