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
@@ -194,6 +194,10 @@ QString IVersionControl::TopicCache::topic(const QString &topLevel)
|
|||||||
return data.topic = refreshTopic(topLevel);
|
return data.topic = refreshTopic(topLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IVersionControl::fillLinkContextMenu(QMenu *, const QString &, const QString &)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
#if defined(WITH_TESTS)
|
#if defined(WITH_TESTS)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QMenu);
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class ShellCommand;
|
class ShellCommand;
|
||||||
@@ -226,6 +228,10 @@ public:
|
|||||||
const QString &localName,
|
const QString &localName,
|
||||||
const QStringList &extraArgs);
|
const QStringList &extraArgs);
|
||||||
|
|
||||||
|
virtual void fillLinkContextMenu(QMenu *menu,
|
||||||
|
const QString &workingDirectory,
|
||||||
|
const QString &reference);
|
||||||
|
|
||||||
class CORE_EXPORT RepoUrl {
|
class CORE_EXPORT RepoUrl {
|
||||||
public:
|
public:
|
||||||
RepoUrl(const QString &location);
|
RepoUrl(const QString &location);
|
||||||
|
|||||||
@@ -3598,6 +3598,7 @@ GitRemote::GitRemote(const QString &location) : Core::IVersionControl::RepoUrl(l
|
|||||||
|
|
||||||
void GitClient::addChangeActions(QMenu *menu, const QString &workingDir, const QString &change)
|
void GitClient::addChangeActions(QMenu *menu, const QString &workingDir, const QString &change)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(!change.isEmpty(), return);
|
||||||
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] {
|
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] {
|
||||||
m_instance->synchronousCherryPick(workingDir, change);
|
m_instance->synchronousCherryPick(workingDir, change);
|
||||||
});
|
});
|
||||||
@@ -3611,9 +3612,11 @@ void GitClient::addChangeActions(QMenu *menu, const QString &workingDir, const Q
|
|||||||
&QAction::triggered, [workingDir, change] {
|
&QAction::triggered, [workingDir, change] {
|
||||||
GitPlugin::startRebaseFromCommit(workingDir, change);
|
GitPlugin::startRebaseFromCommit(workingDir, change);
|
||||||
});
|
});
|
||||||
menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] {
|
QAction *logAction = menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] {
|
||||||
m_instance->log(workingDir, QString(), false, {change});
|
m_instance->log(workingDir, QString(), false, {change});
|
||||||
});
|
});
|
||||||
|
if (change.contains(".."))
|
||||||
|
menu->setDefaultAction(logAction);
|
||||||
menu->addAction(tr("Add &Tag for Change %1...").arg(change), [workingDir, change] {
|
menu->addAction(tr("Add &Tag for Change %1...").arg(change), [workingDir, change] {
|
||||||
QString output;
|
QString output;
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "annotationhighlighter.h"
|
#include "annotationhighlighter.h"
|
||||||
#include "branchadddialog.h"
|
#include "branchadddialog.h"
|
||||||
#include "gitplugin.h"
|
|
||||||
#include "gitclient.h"
|
#include "gitclient.h"
|
||||||
#include "gitsettings.h"
|
#include "gitsettings.h"
|
||||||
#include "gitsubmiteditorwidget.h"
|
#include "gitsubmiteditorwidget.h"
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -256,6 +257,18 @@ public:
|
|||||||
const QString &localName,
|
const QString &localName,
|
||||||
const QStringList &extraArgs) final;
|
const QStringList &extraArgs) final;
|
||||||
|
|
||||||
|
void fillLinkContextMenu(QMenu *menu,
|
||||||
|
const QString &workingDirectory,
|
||||||
|
const QString &reference) final
|
||||||
|
{
|
||||||
|
menu->addAction(tr("&Copy \"%1\"").arg(reference),
|
||||||
|
[reference] { QApplication::clipboard()->setText(reference); });
|
||||||
|
QAction *action = menu->addAction(tr("&Describe Change %1").arg(reference),
|
||||||
|
[=] { describe(workingDirectory, reference); });
|
||||||
|
menu->setDefaultAction(action);
|
||||||
|
GitClient::addChangeActions(menu, workingDirectory, reference);
|
||||||
|
}
|
||||||
|
|
||||||
RepoUrl getRepoUrl(const QString &location) const override;
|
RepoUrl getRepoUrl(const QString &location) const override;
|
||||||
|
|
||||||
QStringList additionalToolsPath() const final;
|
QStringList additionalToolsPath() const final;
|
||||||
|
|||||||
@@ -23,7 +23,11 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "vcsoutputformatter.h"
|
#include "vcsoutputformatter.h"
|
||||||
|
|
||||||
|
#include <coreplugin/iversioncontrol.h>
|
||||||
|
#include <coreplugin/vcsmanager.h>
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QMenu>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
@@ -68,4 +72,18 @@ void VcsOutputFormatter::handleLink(const QString &href)
|
|||||||
emit referenceClicked(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>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
|
|
||||||
class VcsOutputFormatter : public Utils::OutputFormatter
|
class VcsOutputFormatter : public Utils::OutputFormatter
|
||||||
@@ -37,6 +39,7 @@ public:
|
|||||||
~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;
|
||||||
|
void fillLinkContextMenu(QMenu *menu, const QString &workingDirectory, const QString &href);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void referenceClicked(const QString &reference);
|
void referenceClicked(const QString &reference);
|
||||||
|
|||||||
@@ -175,10 +175,17 @@ QString OutputWindowPlainTextEdit::identifierUnderCursor(const QPoint &widgetPos
|
|||||||
|
|
||||||
void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
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'
|
// Add 'open file'
|
||||||
QString repository;
|
QString repository;
|
||||||
const QString token = identifierUnderCursor(event->pos(), &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;
|
QAction *openAction = nullptr;
|
||||||
if (!token.isEmpty()) {
|
if (!token.isEmpty()) {
|
||||||
// Check for a file, expand via repository if relative
|
// Check for a file, expand via repository if relative
|
||||||
@@ -192,9 +199,12 @@ void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
openAction->setData(fi.absoluteFilePath());
|
openAction->setData(fi.absoluteFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add 'clear'
|
QAction *clearAction = nullptr;
|
||||||
menu->addSeparator();
|
if (href.isEmpty()) {
|
||||||
QAction *clearAction = menu->addAction(VcsOutputWindow::tr("Clear"));
|
// Add 'clear'
|
||||||
|
menu->addSeparator();
|
||||||
|
clearAction = menu->addAction(VcsOutputWindow::tr("Clear"));
|
||||||
|
}
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
QAction *action = menu->exec(event->globalPos());
|
QAction *action = menu->exec(event->globalPos());
|
||||||
|
|||||||
Reference in New Issue
Block a user