forked from qt-creator/qt-creator
Git: Add actions for changes in output window context menu
Change-Id: I5aa46f87b82670286ac225d71a3a045133976e86 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
ab3e2ac0fc
commit
ba87fb2083
@@ -23,7 +23,11 @@
|
||||
****************************************************************************/
|
||||
#include "vcsoutputformatter.h"
|
||||
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QMenu>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextCursor>
|
||||
#include <QUrl>
|
||||
@@ -68,4 +72,18 @@ void VcsOutputFormatter::handleLink(const QString &href)
|
||||
emit referenceClicked(href);
|
||||
}
|
||||
|
||||
void VcsOutputFormatter::fillLinkContextMenu(
|
||||
QMenu *menu, const QString &workingDirectory, const QString &href)
|
||||
{
|
||||
if (href.isEmpty() || href.startsWith("http://") || href.startsWith("https://")) {
|
||||
QAction *action = menu->addAction(
|
||||
tr("&Open \"%1\"").arg(href),
|
||||
[href] { QDesktopServices::openUrl(QUrl(href)); });
|
||||
menu->setDefaultAction(action);
|
||||
return;
|
||||
}
|
||||
if (Core::IVersionControl *vcs = Core::VcsManager::findVersionControlForDirectory(workingDirectory))
|
||||
vcs->fillLinkContextMenu(menu, workingDirectory, href);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||
|
||||
namespace VcsBase {
|
||||
|
||||
class VcsOutputFormatter : public Utils::OutputFormatter
|
||||
@@ -37,6 +39,7 @@ public:
|
||||
~VcsOutputFormatter() override = default;
|
||||
void appendMessage(const QString &text, Utils::OutputFormat format) override;
|
||||
void handleLink(const QString &href) override;
|
||||
void fillLinkContextMenu(QMenu *menu, const QString &workingDirectory, const QString &href);
|
||||
|
||||
signals:
|
||||
void referenceClicked(const QString &reference);
|
||||
|
||||
@@ -175,10 +175,17 @@ QString OutputWindowPlainTextEdit::identifierUnderCursor(const QPoint &widgetPos
|
||||
|
||||
void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu *menu = createStandardContextMenu();
|
||||
const QString href = anchorAt(event->pos());
|
||||
QMenu *menu = href.isEmpty() ? createStandardContextMenu(event->pos()) : new QMenu;
|
||||
// Add 'open file'
|
||||
QString repository;
|
||||
const QString token = identifierUnderCursor(event->pos(), &repository);
|
||||
if (!repository.isEmpty()) {
|
||||
if (VcsOutputFormatter *f = formatter()) {
|
||||
if (!href.isEmpty())
|
||||
f->fillLinkContextMenu(menu, repository, href);
|
||||
}
|
||||
}
|
||||
QAction *openAction = nullptr;
|
||||
if (!token.isEmpty()) {
|
||||
// Check for a file, expand via repository if relative
|
||||
@@ -192,9 +199,12 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
||||
openAction->setData(fi.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
// Add 'clear'
|
||||
menu->addSeparator();
|
||||
QAction *clearAction = menu->addAction(VcsOutputWindow::tr("Clear"));
|
||||
QAction *clearAction = nullptr;
|
||||
if (href.isEmpty()) {
|
||||
// Add 'clear'
|
||||
menu->addSeparator();
|
||||
clearAction = menu->addAction(VcsOutputWindow::tr("Clear"));
|
||||
}
|
||||
|
||||
// Run
|
||||
QAction *action = menu->exec(event->globalPos());
|
||||
|
||||
Reference in New Issue
Block a user