Terminal: Add context menu & Settings button

Fixes: QTCREATORBUG-28937
Change-Id: I9dab5da0adccb8cff4d4e824ead0eba3e27eef5c
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-03-23 12:28:44 +01:00
parent a485f18a94
commit af809b3a52
5 changed files with 32 additions and 3 deletions

View File

@@ -129,4 +129,9 @@ bool TerminalCommands::triggerAction(QKeyEvent *event)
return false; return false;
} }
QAction *TerminalCommands::openSettingsAction()
{
return ActionManager::command("Preferences.Terminal.General")->action();
}
} // namespace Terminal } // namespace Terminal

View File

@@ -20,6 +20,7 @@ struct WidgetActions
QAction copy{Tr::tr("Copy")}; QAction copy{Tr::tr("Copy")};
QAction paste{Tr::tr("Paste")}; QAction paste{Tr::tr("Paste")};
QAction clearSelection{Tr::tr("Clear Selection")}; QAction clearSelection{Tr::tr("Clear Selection")};
QAction clearTerminal{Tr::tr("Clear Terminal")};
}; };
struct PaneActions struct PaneActions
@@ -45,6 +46,8 @@ public:
static bool triggerAction(QKeyEvent *event); static bool triggerAction(QKeyEvent *event);
static QAction *openSettingsAction();
protected: protected:
void initWidgetActions(const Core::Context &context); void initWidgetActions(const Core::Context &context);
void initPaneActions(const Core::Context &context); void initPaneActions(const Core::Context &context);

View File

@@ -21,7 +21,7 @@
#include <QMenu> #include <QMenu>
#include <QStandardPaths> #include <QStandardPaths>
#include <QtWidgets/qwidget.h> #include <QToolButton>
namespace Terminal { namespace Terminal {
@@ -111,6 +111,14 @@ TerminalPane::TerminalPane(QObject *parent)
if (minMaxCommand) if (minMaxCommand)
emit minMaxCommand->action()->triggered(); emit minMaxCommand->action()->triggered();
}); });
m_openSettingsButton = new QToolButton();
m_openSettingsButton->setToolTip(Tr::tr("Open Terminal Settings"));
m_openSettingsButton->setIcon(Icons::SETTINGS_TOOLBAR.icon());
connect(m_openSettingsButton, &QToolButton::clicked, m_openSettingsButton, []() {
TerminalCommands::openSettingsAction()->trigger();
});
} }
TerminalPane::~TerminalPane() TerminalPane::~TerminalPane()
@@ -252,7 +260,7 @@ QList<QWidget *> TerminalPane::toolBarWidgets() const
widgets.prepend(m_newTerminalButton); widgets.prepend(m_newTerminalButton);
widgets.prepend(m_closeTerminalButton); widgets.prepend(m_closeTerminalButton);
return widgets; return widgets << m_openSettingsButton;
} }
QString TerminalPane::displayName() const QString TerminalPane::displayName() const

View File

@@ -53,6 +53,7 @@ private:
QToolButton *m_newTerminalButton{nullptr}; QToolButton *m_newTerminalButton{nullptr};
QToolButton *m_closeTerminalButton{nullptr}; QToolButton *m_closeTerminalButton{nullptr};
QToolButton *m_openSettingsButton{nullptr};
bool m_widgetInitialized{false}; bool m_widgetInitialized{false};
}; };

View File

@@ -26,6 +26,7 @@
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QGlyphRun> #include <QGlyphRun>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QMenu>
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
@@ -232,6 +233,7 @@ void TerminalWidget::setupActions()
connect(&a.copy, &QAction::triggered, this, ifHasFocus(&TerminalWidget::copyToClipboard)); connect(&a.copy, &QAction::triggered, this, ifHasFocus(&TerminalWidget::copyToClipboard));
connect(&a.paste, &QAction::triggered, this, ifHasFocus(&TerminalWidget::pasteFromClipboard)); connect(&a.paste, &QAction::triggered, this, ifHasFocus(&TerminalWidget::pasteFromClipboard));
connect(&a.clearSelection, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearSelection)); connect(&a.clearSelection, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearSelection));
connect(&a.clearTerminal, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearContents));
// clang-format on // clang-format on
} }
@@ -1078,7 +1080,17 @@ void TerminalWidget::mousePressEvent(QMouseEvent *event)
event->accept(); event->accept();
updateViewport(); updateViewport();
} else if (event->button() == Qt::RightButton) { } else if (event->button() == Qt::RightButton) {
if (m_selection) { if (event->modifiers() == Qt::ShiftModifier) {
QMenu *contextMenu = new QMenu(this);
contextMenu->addAction(&TerminalCommands::widgetActions().copy);
contextMenu->addAction(&TerminalCommands::widgetActions().paste);
contextMenu->addSeparator();
contextMenu->addAction(&TerminalCommands::widgetActions().clearTerminal);
contextMenu->addSeparator();
contextMenu->addAction(TerminalCommands::openSettingsAction());
contextMenu->popup(event->globalPos());
} else if (m_selection) {
copyToClipboard(); copyToClipboard();
setSelection(std::nullopt); setSelection(std::nullopt);
} else { } else {