VCS: Pass links to the correct VCS

Current implementation requires each VCS to connect to the referenceClicked
signal. Only Git does it, but this is conceptually wrong. If other VCSs
would connect to the same signal, all of them will act upon clicking a
link, which can result in multiple editors, most of them are likely to be
invalid anyway.

By default executes vcsDescribe. Can be extended or modified by subclasses.

Change-Id: Ib953009efd77446a4b2963f0aa8a2f3f3d26509f
Reviewed-by: Artur Shepilko <artur.shepilko@nomadbyte.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2020-06-18 00:04:17 +03:00
committed by Orgad Shaneh
parent cb0b8556c8
commit 92a4c0d38a
11 changed files with 70 additions and 37 deletions

View File

@@ -64,14 +64,17 @@ Utils::OutputLineParser::Result VcsOutputLineParser::handleLine(const QString &t
return {Status::Done, linkSpecs};
}
bool VcsOutputLineParser::handleLink(const QString &href)
bool VcsOutputLineParser::handleVcsLink(const QString &workingDirectory, const QString &href)
{
using namespace Core;
QTC_ASSERT(!href.isEmpty(), return false);
if (href.startsWith("http://") || href.startsWith("https://"))
if (href.startsWith("http://") || href.startsWith("https://")) {
QDesktopServices::openUrl(QUrl(href));
else
emit referenceClicked(href);
return true;
return true;
}
if (IVersionControl *vcs = VcsManager::findVersionControlForDirectory(workingDirectory))
return vcs->handleLink(workingDirectory, href);
return false;
}
void VcsOutputLineParser::fillLinkContextMenu(

View File

@@ -37,13 +37,10 @@ class VcsOutputLineParser : public Utils::OutputLineParser
public:
VcsOutputLineParser();
void fillLinkContextMenu(QMenu *menu, const QString &workingDirectory, const QString &href);
signals:
void referenceClicked(const QString &reference);
bool handleVcsLink(const QString &workingDirectory, const QString &href);
private:
Result handleLine(const QString &text, Utils::OutputFormat format) override;
bool handleLink(const QString &href) override;
const QRegularExpression m_regexp;
};

View File

@@ -104,6 +104,7 @@ public:
protected:
void contextMenuEvent(QContextMenuEvent *event) override;
void handleLink(const QPoint &pos) override;
private:
void setFormat(VcsOutputWindow::MessageStyle style);
@@ -214,6 +215,23 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
delete menu;
}
void OutputWindowPlainTextEdit::handleLink(const QPoint &pos)
{
const QString href = anchorAt(pos);
if (href.isEmpty())
return;
QString repository;
identifierUnderCursor(pos, &repository);
if (repository.isEmpty()) {
OutputWindow::handleLink(pos);
return;
}
if (outputFormatter()->handleFileLink(href))
return;
if (VcsOutputLineParser * const p = parser())
p->handleVcsLink(repository, href);
}
void OutputWindowPlainTextEdit::appendLines(const QString &s, const QString &repository)
{
if (s.isEmpty())
@@ -310,8 +328,6 @@ VcsOutputWindow::VcsOutputWindow()
connect(this, &IOutputPane::resetZoom, &d->widget, &Core::OutputWindow::resetZoom);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::behaviorSettingsChanged,
this, updateBehaviorSettings);
connect(d->widget.parser(), &VcsOutputLineParser::referenceClicked,
VcsOutputWindow::instance(), &VcsOutputWindow::referenceClicked);
}
static QString filterPasswordFromUrls(QString input)

View File

@@ -76,9 +76,6 @@ public:
Message, // A blue message text (e.g. "command has finished successfully")
};
signals:
void referenceClicked(const QString &reference);
public slots:
static void setRepository(const QString &);
static void clearRepository();