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;
}
QAction *TerminalCommands::openSettingsAction()
{
return ActionManager::command("Preferences.Terminal.General")->action();
}
} // namespace Terminal

View File

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

View File

@@ -21,7 +21,7 @@
#include <QMenu>
#include <QStandardPaths>
#include <QtWidgets/qwidget.h>
#include <QToolButton>
namespace Terminal {
@@ -111,6 +111,14 @@ TerminalPane::TerminalPane(QObject *parent)
if (minMaxCommand)
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()
@@ -252,7 +260,7 @@ QList<QWidget *> TerminalPane::toolBarWidgets() const
widgets.prepend(m_newTerminalButton);
widgets.prepend(m_closeTerminalButton);
return widgets;
return widgets << m_openSettingsButton;
}
QString TerminalPane::displayName() const

View File

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

View File

@@ -26,6 +26,7 @@
#include <QElapsedTimer>
#include <QGlyphRun>
#include <QLoggingCategory>
#include <QMenu>
#include <QPaintEvent>
#include <QPainter>
#include <QPainterPath>
@@ -232,6 +233,7 @@ void TerminalWidget::setupActions()
connect(&a.copy, &QAction::triggered, this, ifHasFocus(&TerminalWidget::copyToClipboard));
connect(&a.paste, &QAction::triggered, this, ifHasFocus(&TerminalWidget::pasteFromClipboard));
connect(&a.clearSelection, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearSelection));
connect(&a.clearTerminal, &QAction::triggered, this, ifHasFocus(&TerminalWidget::clearContents));
// clang-format on
}
@@ -1078,7 +1080,17 @@ void TerminalWidget::mousePressEvent(QMouseEvent *event)
event->accept();
updateViewport();
} 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();
setSelection(std::nullopt);
} else {