From a0c05cabcc3df0eee80e08ecb4955632e0669cb4 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 27 Nov 2023 07:51:39 +0100 Subject: [PATCH] Terminal: Refactor actions Change actions to use ActionBuilder and use ToggleAspects for tool buttons. Change-Id: I0f4a58c3a98cb2804e3d387ea02cac043bd71ae7 Reviewed-by: Cristian Adam --- src/plugins/terminal/terminalconstants.h | 1 + src/plugins/terminal/terminalpane.cpp | 141 ++++++------------ src/plugins/terminal/terminalpane.h | 8 +- src/plugins/terminal/terminalplugin.cpp | 2 +- src/plugins/terminal/terminalsettings.cpp | 24 ++++ src/plugins/terminal/terminalsettings.h | 4 +- src/plugins/terminal/terminalwidget.cpp | 166 ++++++++++++---------- src/plugins/terminal/terminalwidget.h | 3 +- 8 files changed, 163 insertions(+), 186 deletions(-) diff --git a/src/plugins/terminal/terminalconstants.h b/src/plugins/terminal/terminalconstants.h index a55bd05f2c3..f53484d28ed 100644 --- a/src/plugins/terminal/terminalconstants.h +++ b/src/plugins/terminal/terminalconstants.h @@ -5,6 +5,7 @@ namespace Terminal::Constants { constexpr char NEWTERMINAL[] = "Terminal.NewTerminal"; +constexpr char CLOSETERMINAL[] = "Terminal.CloseTerminal"; constexpr char NEXTTERMINAL[] = "Terminal.NextTerminal"; constexpr char PREVTERMINAL[] = "Terminal.PrevTerminal"; constexpr char MINMAX[] = "Terminal.MinMax"; diff --git a/src/plugins/terminal/terminalpane.cpp b/src/plugins/terminal/terminalpane.cpp index cdbbb850173..e6a9af415fb 100644 --- a/src/plugins/terminal/terminalpane.cpp +++ b/src/plugins/terminal/terminalpane.cpp @@ -4,7 +4,6 @@ #include "terminalpane.h" #include "shellmodel.h" -#include "shortcutmap.h" #include "terminalconstants.h" #include "terminalicons.h" #include "terminalsettings.h" @@ -15,7 +14,6 @@ #include #include #include -#include #include #include @@ -57,13 +55,16 @@ TerminalPane::TerminalPane(QObject *parent) currentTerminal()->zoomOut(); }); + createShellMenu(); initActions(); m_newTerminalButton = new QToolButton(); - m_newTerminalButton->setDefaultAction(&newTerminal); + m_newTerminalButton->setDefaultAction(m_newTerminalAction); + m_newTerminalButton->setMenu(&m_shellMenu); + m_newTerminalButton->setPopupMode(QToolButton::MenuButtonPopup); m_closeTerminalButton = new QToolButton(); - m_closeTerminalButton->setDefaultAction(&closeTerminal); + m_closeTerminalButton->setDefaultAction(m_closeTerminalAction); m_openSettingsButton = new QToolButton(); m_openSettingsButton->setToolTip(Tr::tr("Configure...")); @@ -73,66 +74,11 @@ TerminalPane::TerminalPane(QObject *parent) ICore::showOptionsDialog("Terminal.General"); }); - const auto updateEscButton = [this] { - m_escSettingButton->setChecked(settings().sendEscapeToTerminal()); - static const QString escKey - = QKeySequence(Qt::Key_Escape).toString(QKeySequence::NativeText); - static const QString shiftEsc = QKeySequence( - QKeyCombination(Qt::ShiftModifier, Qt::Key_Escape)) - .toString(QKeySequence::NativeText); - if (settings().sendEscapeToTerminal()) { - m_escSettingButton->setText(escKey); - //: %1 is the application name (Qt Creator) - m_escSettingButton->setToolTip(Tr::tr("Sends Esc to terminal instead of %1.") - .arg(QGuiApplication::applicationDisplayName())); - } else { - m_escSettingButton->setText(shiftEsc); - m_escSettingButton->setToolTip( - Tr::tr("Press %1 to send Esc to terminal.").arg(shiftEsc)); - } - }; - m_escSettingButton = new QToolButton(); - m_escSettingButton->setCheckable(true); - - updateEscButton(); - - connect(m_escSettingButton, &QToolButton::toggled, this, [this, updateEscButton] { - settings().sendEscapeToTerminal.setValue(m_escSettingButton->isChecked()); - updateEscButton(); - }); - - connect(&settings(), &TerminalSettings::applied, this, updateEscButton); - - const auto updateLockButton = [this] { - m_lockKeyboardButton->setChecked(settings().lockKeyboard()); - if (settings().lockKeyboard()) { - m_lockKeyboardButton->setIcon(LOCK_KEYBOARD_ICON.icon()); - m_lockKeyboardButton->setToolTip( - //: %1 is the application name (Qt Creator) - Tr::tr("%1 shortcuts are blocked when focus is inside the terminal.") - .arg(QGuiApplication::applicationDisplayName())); - } else { - m_lockKeyboardButton->setIcon(UNLOCK_KEYBOARD_ICON.icon()); - //: %1 is the application name (Qt Creator) - m_lockKeyboardButton->setToolTip(Tr::tr("%1 shortcuts take precedence.") - .arg(QGuiApplication::applicationDisplayName())); - } - }; + m_escSettingButton->setDefaultAction(settings().sendEscapeToTerminal.action()); m_lockKeyboardButton = new QToolButton(); - m_lockKeyboardButton->setCheckable(true); - - updateLockButton(); - - connect(&toggleKeyboardLock, &QAction::triggered, m_lockKeyboardButton, &QToolButton::toggle); - - connect(m_lockKeyboardButton, &QToolButton::toggled, this, [this, updateLockButton] { - settings().lockKeyboard.setValue(m_lockKeyboardButton->isChecked()); - updateLockButton(); - }); - - connect(&settings(), &TerminalSettings::applied, this, updateLockButton); + m_lockKeyboardButton->setDefaultAction(m_toggleKeyboardLockAction); } TerminalPane::~TerminalPane() {} @@ -164,7 +110,6 @@ void TerminalPane::openTerminal(const OpenTerminalParameters ¶meters) using namespace Constants; terminalWidget->unlockGlobalAction("Coreplugin.OutputPane.minmax"); - terminalWidget->unlockGlobalAction(Core::Constants::LOCATE); terminalWidget->unlockGlobalAction(NEWTERMINAL); terminalWidget->unlockGlobalAction(NEXTTERMINAL); terminalWidget->unlockGlobalAction(PREVTERMINAL); @@ -281,55 +226,51 @@ void TerminalPane::setupTerminalWidget(TerminalWidget *terminal) void TerminalPane::initActions() { - createShellMenu(); - - newTerminal.setText(Tr::tr("New Terminal")); - newTerminal.setIcon(NEW_TERMINAL_ICON.icon()); - newTerminal.setToolTip(Tr::tr("Create a new Terminal.")); - newTerminal.setMenu(&m_shellMenu); - - nextTerminal.setText(Tr::tr("Next Terminal")); - prevTerminal.setText(Tr::tr("Previous Terminal")); - - closeTerminal.setIcon(CLOSE_TERMINAL_ICON.icon()); - closeTerminal.setToolTip(Tr::tr("Close the current Terminal.")); - - toggleKeyboardLock.setText(Tr::tr("Toggle Keyboard Lock")); - using namespace Constants; - Command *cmd = ActionManager::registerAction(&newTerminal, NEWTERMINAL, m_selfContext); - cmd->setDefaultKeySequences({QKeySequence( + ActionBuilder newTerminalAction(this, NEWTERMINAL); + newTerminalAction.setText(Tr::tr("New Terminal")); + newTerminalAction.setIcon(NEW_TERMINAL_ICON.icon()); + newTerminalAction.setToolTip(Tr::tr("Create a new Terminal.")); + newTerminalAction.setDefaultKeySequences({QKeySequence( HostOsInfo::isMacHost() ? QLatin1String("Ctrl+T") : QLatin1String("Ctrl+Shift+T"))}); + newTerminalAction.setOnTriggered(this, [this] { openTerminal({}); }); + m_newTerminalAction = newTerminalAction.commandAction(); - ActionManager::registerAction(&nextTerminal, NEXTTERMINAL, m_selfContext) - ->setDefaultKeySequences( - {QKeySequence("Alt+Tab"), - QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+[") - : QLatin1String("Ctrl+PgUp"))}); + ActionBuilder closeTerminalAction(this, CLOSETERMINAL); + closeTerminalAction.setText(Tr::tr("Close Terminal")); + closeTerminalAction.setIcon(CLOSE_TERMINAL_ICON.icon()); + closeTerminalAction.setToolTip(Tr::tr("Close the current Terminal.")); + closeTerminalAction.setOnTriggered(this, [this] { removeTab(m_tabWidget.currentIndex()); }); + m_closeTerminalAction = closeTerminalAction.commandAction(); - ActionManager::registerAction(&prevTerminal, PREVTERMINAL, m_selfContext) - ->setDefaultKeySequences( - {QKeySequence("Alt+Shift+Tab"), - QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+]") - : QLatin1String("Ctrl+PgDown"))}); - - ActionManager::registerAction(&toggleKeyboardLock, - TOGGLE_KEYBOARD_LOCK, - m_selfContext); - - connect(&newTerminal, &QAction::triggered, this, [this] { openTerminal({}); }); - connect(&closeTerminal, &QAction::triggered, this, [this] { - removeTab(m_tabWidget.currentIndex()); - }); - connect(&nextTerminal, &QAction::triggered, this, [this] { + ActionBuilder nextTerminalAction(this, NEXTTERMINAL); + nextTerminalAction.setText(Tr::tr("Next Terminal")); + nextTerminalAction.setDefaultKeySequences( + {QKeySequence("Alt+Tab"), + QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+[") + : QLatin1String("Ctrl+PgUp"))}); + nextTerminalAction.setOnTriggered(this, [this] { if (canNavigate()) goToNext(); }); - connect(&prevTerminal, &QAction::triggered, this, [this] { + + ActionBuilder prevTerminalAction(this, PREVTERMINAL); + prevTerminalAction.setText(Tr::tr("Previous Terminal")); + prevTerminalAction.setDefaultKeySequences( + {QKeySequence("Alt+Shift+Tab"), + QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+]") + : QLatin1String("Ctrl+PgDown"))}); + prevTerminalAction.setOnTriggered(this, [this] { if (canPrevious()) goToPrev(); }); + + Command *cmd = ActionManager::registerAction(settings().lockKeyboard.action(), + TOGGLE_KEYBOARD_LOCK); + m_toggleKeyboardLockAction = cmd->action(); + cmd->setAttribute(Command::CA_UpdateText); + cmd->setAttribute(Command::CA_UpdateIcon); } void TerminalPane::createShellMenu() diff --git a/src/plugins/terminal/terminalpane.h b/src/plugins/terminal/terminalpane.h index dc3b4d30f15..52fa6660750 100644 --- a/src/plugins/terminal/terminalpane.h +++ b/src/plugins/terminal/terminalpane.h @@ -62,11 +62,9 @@ private: QToolButton *m_escSettingButton{nullptr}; QToolButton *m_lockKeyboardButton{nullptr}; - QAction newTerminal; - QAction nextTerminal; - QAction prevTerminal; - QAction closeTerminal; - QAction toggleKeyboardLock; + QAction *m_newTerminalAction{nullptr}; + QAction *m_closeTerminalAction{nullptr}; + QAction *m_toggleKeyboardLockAction{nullptr}; QMenu m_shellMenu; diff --git a/src/plugins/terminal/terminalplugin.cpp b/src/plugins/terminal/terminalplugin.cpp index 7940fb712b9..50b5771f3fe 100644 --- a/src/plugins/terminal/terminalplugin.cpp +++ b/src/plugins/terminal/terminalplugin.cpp @@ -44,7 +44,7 @@ public: m_terminalPane = new TerminalPane; ExtensionSystem::PluginManager::addObject(m_terminalPane); - TerminalWidget::initActions(); + TerminalWidget::initActions(this); auto enable = [this] { Utils::Terminal::Hooks::instance() diff --git a/src/plugins/terminal/terminalsettings.cpp b/src/plugins/terminal/terminalsettings.cpp index b6bfe3c37c7..426dd6d4b17 100644 --- a/src/plugins/terminal/terminalsettings.cpp +++ b/src/plugins/terminal/terminalsettings.cpp @@ -3,6 +3,7 @@ #include "terminalsettings.h" +#include "terminalicons.h" #include "terminaltr.h" #include @@ -19,6 +20,7 @@ #include #include +#include #include #include #include @@ -486,12 +488,34 @@ TerminalSettings::TerminalSettings() "instead of closing the terminal.")); sendEscapeToTerminal.setDefaultValue(false); + static const QString escKey = QKeySequence(Qt::Key_Escape).toString(QKeySequence::NativeText); + static const QString shiftEsc = QKeySequence(QKeyCombination(Qt::ShiftModifier, Qt::Key_Escape)) + .toString(QKeySequence::NativeText); + sendEscapeToTerminal.setOnText(escKey); + sendEscapeToTerminal.setOffText(shiftEsc); + sendEscapeToTerminal.setOnTooltip(Tr::tr("Sends Esc to terminal instead of %1.") + .arg(QGuiApplication::applicationDisplayName())); + sendEscapeToTerminal.setOffTooltip(Tr::tr("Press %1 to send Esc to terminal.").arg(shiftEsc)); + QObject::connect(&sendEscapeToTerminal, + &ToggleAspect::changed, + this, + &TerminalSettings::writeSettings); + lockKeyboard.setSettingsKey("LockKeyboard"); lockKeyboard.setLabelText(Tr::tr("Block shortcuts in terminal")); lockKeyboard.setToolTip( Tr::tr("Keeps Qt Creator shortcuts from interfering with the terminal.")); lockKeyboard.setDefaultValue(true); + lockKeyboard.setIcon(LOCK_KEYBOARD_ICON.icon()); + lockKeyboard.setOffIcon(UNLOCK_KEYBOARD_ICON.icon()); + lockKeyboard.setOnTooltip(Tr::tr("%1 shortcuts are blocked when focus is inside the terminal.") + .arg(qApp->applicationDisplayName())); + lockKeyboard.setOffTooltip( + Tr::tr("%1 shortcuts take precedence.").arg(qApp->applicationDisplayName())); + + QObject::connect(&lockKeyboard, &ToggleAspect::changed, this, &TerminalSettings::writeSettings); + audibleBell.setSettingsKey("AudibleBell"); audibleBell.setLabelText(Tr::tr("Audible bell")); audibleBell.setToolTip(Tr::tr("Makes the terminal beep when a bell " diff --git a/src/plugins/terminal/terminalsettings.h b/src/plugins/terminal/terminalsettings.h index 1400339dd8d..64af55af2f1 100644 --- a/src/plugins/terminal/terminalsettings.h +++ b/src/plugins/terminal/terminalsettings.h @@ -28,9 +28,9 @@ public: Utils::BoolAspect allowBlinkingCursor{this}; - Utils::BoolAspect sendEscapeToTerminal{this}; + Utils::ToggleAspect sendEscapeToTerminal{this}; Utils::BoolAspect audibleBell{this}; - Utils::BoolAspect lockKeyboard{this}; + Utils::ToggleAspect lockKeyboard{this}; Utils::BoolAspect enableMouseTracking{this}; }; diff --git a/src/plugins/terminal/terminalwidget.cpp b/src/plugins/terminal/terminalwidget.cpp index a3e70b77217..c6f0d05b1a5 100644 --- a/src/plugins/terminal/terminalwidget.cpp +++ b/src/plugins/terminal/terminalwidget.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -256,44 +257,57 @@ void TerminalWidget::registerShortcut(Command *cmd) }); } -RegisteredAction TerminalWidget::registerAction(Id commandId, const Context &context) -{ - QAction *action = new QAction; - Command *cmd = ActionManager::registerAction(action, commandId, context); - - registerShortcut(cmd); - - return RegisteredAction(action, [commandId](QAction *a) { - ActionManager::unregisterAction(a, commandId); - delete a; - }); -} - void TerminalWidget::setupActions() { - m_copy = registerAction(Constants::COPY, m_context); - m_paste = registerAction(Constants::PASTE, m_context); - m_close = registerAction(Core::Constants::CLOSE, m_context); - m_clearTerminal = registerAction(Constants::CLEAR_TERMINAL, m_context); - m_clearSelection = registerAction(Constants::CLEARSELECTION, m_context); - m_moveCursorWordLeft = registerAction(Constants::MOVECURSORWORDLEFT, m_context); - m_moveCursorWordRight = registerAction(Constants::MOVECURSORWORDRIGHT, m_context); - m_selectAll = registerAction(Constants::SELECTALL, m_context); + auto make_registered = [this](ActionBuilder &actionBuilder) { + registerShortcut(actionBuilder.command()); - connect(m_copy.get(), &QAction::triggered, this, &TerminalWidget::copyToClipboard); - connect(m_paste.get(), &QAction::triggered, this, &TerminalWidget::pasteFromClipboard); - connect(m_close.get(), &QAction::triggered, this, &TerminalWidget::closeTerminal); - connect(m_clearTerminal.get(), &QAction::triggered, this, &TerminalWidget::clearContents); - connect(m_selectAll.get(), &QAction::triggered, this, &TerminalWidget::selectAll); - connect(m_clearSelection.get(), &QAction::triggered, this, &TerminalWidget::clearSelection); - connect(m_moveCursorWordLeft.get(), - &QAction::triggered, - this, - &TerminalWidget::moveCursorWordLeft); - connect(m_moveCursorWordRight.get(), - &QAction::triggered, - this, - &TerminalWidget::moveCursorWordRight); + return RegisteredAction(actionBuilder.contextAction(), + [cmdId = actionBuilder.command()->id()](QAction *a) { + ActionManager::unregisterAction(a, cmdId); + delete a; + }); + }; + + ActionBuilder copyAction(this, Constants::COPY); + copyAction.setContext(m_context); + copyAction.setOnTriggered(this, &TerminalWidget::copyToClipboard); + m_copy = make_registered(copyAction); + + ActionBuilder pasteAction(this, Constants::PASTE); + pasteAction.setContext(m_context); + pasteAction.setOnTriggered(this, &TerminalWidget::pasteFromClipboard); + m_paste = make_registered(pasteAction); + + ActionBuilder closeAction(this, Core::Constants::CLOSE); + closeAction.setContext(m_context); + closeAction.setOnTriggered(this, &TerminalWidget::closeTerminal); + m_close = make_registered(closeAction); + + ActionBuilder clearTerminalAction(this, Constants::CLEAR_TERMINAL); + clearTerminalAction.setContext(m_context); + clearTerminalAction.setOnTriggered(this, &TerminalWidget::clearContents); + m_clearTerminal = make_registered(clearTerminalAction); + + ActionBuilder clearSelectionAction(this, Constants::CLEARSELECTION); + clearSelectionAction.setContext(m_context); + clearSelectionAction.setOnTriggered(this, &TerminalWidget::clearSelection); + m_clearSelection = make_registered(clearSelectionAction); + + ActionBuilder moveCursorWordLeftAction(this, Constants::MOVECURSORWORDLEFT); + moveCursorWordLeftAction.setContext(m_context); + moveCursorWordLeftAction.setOnTriggered(this, &TerminalWidget::moveCursorWordLeft); + m_moveCursorWordLeft = make_registered(moveCursorWordLeftAction); + + ActionBuilder moveCursorWordRightAction(this, Constants::MOVECURSORWORDRIGHT); + moveCursorWordRightAction.setContext(m_context); + moveCursorWordRightAction.setOnTriggered(this, &TerminalWidget::moveCursorWordRight); + m_moveCursorWordRight = make_registered(moveCursorWordRightAction); + + ActionBuilder selectAllAction(this, Constants::SELECTALL); + selectAllAction.setContext(m_context); + selectAllAction.setOnTriggered(this, &TerminalWidget::selectAll); + m_selectAll = make_registered(selectAllAction); // Ctrl+Q, the default "Quit" shortcut, is a useful key combination in a shell. // It can be used in combination with Ctrl+S to pause a program, and resume it with Ctrl+Q. @@ -303,6 +317,7 @@ void TerminalWidget::setupActions() unlockGlobalAction(Core::Constants::OPTIONS); unlockGlobalAction("Preferences.Terminal.General"); unlockGlobalAction(Core::Constants::FIND_IN_DOCUMENT); + unlockGlobalAction(Core::Constants::LOCATE); } void TerminalWidget::closeTerminal() @@ -607,57 +622,56 @@ bool TerminalWidget::event(QEvent *event) return TerminalView::event(event); } -void TerminalWidget::initActions() +void TerminalWidget::initActions(QObject *parent) { Core::Context context(Utils::Id("TerminalWidget")); - static QAction copy; - static QAction paste; - static QAction clearSelection; - static QAction clearTerminal; - static QAction selectAll; - static QAction moveCursorWordLeft; - static QAction moveCursorWordRight; - static QAction close; + auto keySequence = [](const QChar &key) -> QList { + if (HostOsInfo::isMacHost()) { + return {QKeySequence(QLatin1String("Ctrl+") + key)}; + } else if (HostOsInfo::isLinuxHost()) { + return {QKeySequence(QLatin1String("Ctrl+Shift+") + key)}; + } else if (HostOsInfo::isWindowsHost()) { + return {QKeySequence(QLatin1String("Ctrl+") + key), + QKeySequence(QLatin1String("Ctrl+Shift+") + key)}; + } + }; - copy.setText(Tr::tr("Copy")); - paste.setText(Tr::tr("Paste")); - clearSelection.setText(Tr::tr("Clear Selection")); - clearTerminal.setText(Tr::tr("Clear Terminal")); - selectAll.setText(Tr::tr("Select All")); - moveCursorWordLeft.setText(Tr::tr("Move Cursor Word Left")); - moveCursorWordRight.setText(Tr::tr("Move Cursor Word Right")); - close.setText(Tr::tr("Close Terminal")); + ActionBuilder copyAction(parent, Constants::COPY); + copyAction.setText(Tr::tr("Copy")); + copyAction.setContext(context); + copyAction.setDefaultKeySequences(keySequence('C')); - auto copyCmd = ActionManager::registerAction(©, Constants::COPY, context); - auto pasteCmd = ActionManager::registerAction(&paste, Constants::PASTE, context); - auto selectAllCmd = ActionManager::registerAction(&selectAll, Constants::SELECTALL, context); + ActionBuilder pasteAction(parent, Constants::PASTE); + pasteAction.setText(Tr::tr("Paste")); + pasteAction.setContext(context); + pasteAction.setDefaultKeySequences(keySequence('V')); - if (HostOsInfo::isMacHost()) { - copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+C"))); - pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+V"))); - selectAllCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+A"))); - } else if (HostOsInfo::isLinuxHost()) { - copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+C"))); - pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+V"))); - selectAllCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+A"))); - } else if (HostOsInfo::isWindowsHost()) { - copyCmd->setDefaultKeySequences( - {QKeySequence(QLatin1String("Ctrl+C")), QKeySequence(QLatin1String("Ctrl+Shift+C"))}); - pasteCmd->setDefaultKeySequences( - {QKeySequence(QLatin1String("Ctrl+V")), QKeySequence(QLatin1String("Ctrl+Shift+V"))}); - selectAllCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+A"))); - } + ActionBuilder clearTerminalAction(parent, Constants::CLEAR_TERMINAL); + clearTerminalAction.setText(Tr::tr("Clear Terminal")); + clearTerminalAction.setContext(context); - ActionManager::registerAction(&clearSelection, Constants::CLEARSELECTION, context); + ActionBuilder selectAllAction(parent, Constants::SELECTALL); + selectAllAction.setText(Tr::tr("Select All")); + selectAllAction.setContext(context); + selectAllAction.setDefaultKeySequences(keySequence('A')); - ActionManager::registerAction(&moveCursorWordLeft, Constants::MOVECURSORWORDLEFT, context) - ->setDefaultKeySequences({QKeySequence("Alt+Left")}); + ActionBuilder clearSelectionAction(parent, Constants::CLEARSELECTION); + clearSelectionAction.setText(Tr::tr("Clear Selection")); + clearSelectionAction.setContext(context); - ActionManager::registerAction(&moveCursorWordRight, Constants::MOVECURSORWORDRIGHT, context) - ->setDefaultKeySequences({QKeySequence("Alt+Right")}); + ActionBuilder moveCursorWordLeftAction(parent, Constants::MOVECURSORWORDLEFT); + moveCursorWordLeftAction.setText(Tr::tr("Move Cursor Word Left")); + moveCursorWordLeftAction.setContext(context); + moveCursorWordLeftAction.setDefaultKeySequence({QKeySequence("Alt+Left")}); - ActionManager::registerAction(&clearTerminal, Constants::CLEAR_TERMINAL, context); + ActionBuilder moveCursorWordRightAction(parent, Constants::MOVECURSORWORDRIGHT); + moveCursorWordRightAction.setText(Tr::tr("Move Cursor Word Right")); + moveCursorWordRightAction.setContext(context); + moveCursorWordRightAction.setDefaultKeySequence({QKeySequence("Alt+Right")}); + + ActionBuilder closeAction(parent, Core::Constants::CLOSE); + closeAction.setText(Tr::tr("Close Terminal")); } void TerminalWidget::unlockGlobalAction(const Utils::Id &commandId) diff --git a/src/plugins/terminal/terminalwidget.h b/src/plugins/terminal/terminalwidget.h index 55822b2c7cd..8167e2afe3d 100644 --- a/src/plugins/terminal/terminalwidget.h +++ b/src/plugins/terminal/terminalwidget.h @@ -44,7 +44,7 @@ public: void restart(const Utils::Terminal::OpenTerminalParameters &openParameters); - static void initActions(); + static void initActions(QObject *parent); void unlockGlobalAction(const Utils::Id &commandId); @@ -81,7 +81,6 @@ protected: void setClipboard(const QString &text) override; std::optional toLink(const QString &text) override; - RegisteredAction registerAction(Utils::Id commandId, const Core::Context &context); void registerShortcut(Core::Command *command); void updateCopyState();