forked from qt-creator/qt-creator
Terminal: Refactor actions
Change actions to use ActionBuilder and use ToggleAspects for tool buttons. Change-Id: I0f4a58c3a98cb2804e3d387ea02cac043bd71ae7 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
namespace Terminal::Constants {
|
namespace Terminal::Constants {
|
||||||
constexpr char NEWTERMINAL[] = "Terminal.NewTerminal";
|
constexpr char NEWTERMINAL[] = "Terminal.NewTerminal";
|
||||||
|
constexpr char CLOSETERMINAL[] = "Terminal.CloseTerminal";
|
||||||
constexpr char NEXTTERMINAL[] = "Terminal.NextTerminal";
|
constexpr char NEXTTERMINAL[] = "Terminal.NextTerminal";
|
||||||
constexpr char PREVTERMINAL[] = "Terminal.PrevTerminal";
|
constexpr char PREVTERMINAL[] = "Terminal.PrevTerminal";
|
||||||
constexpr char MINMAX[] = "Terminal.MinMax";
|
constexpr char MINMAX[] = "Terminal.MinMax";
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
#include "terminalpane.h"
|
#include "terminalpane.h"
|
||||||
|
|
||||||
#include "shellmodel.h"
|
#include "shellmodel.h"
|
||||||
#include "shortcutmap.h"
|
|
||||||
#include "terminalconstants.h"
|
#include "terminalconstants.h"
|
||||||
#include "terminalicons.h"
|
#include "terminalicons.h"
|
||||||
#include "terminalsettings.h"
|
#include "terminalsettings.h"
|
||||||
@@ -15,7 +14,6 @@
|
|||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/locator/locatorconstants.h>
|
|
||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
@@ -57,13 +55,16 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
currentTerminal()->zoomOut();
|
currentTerminal()->zoomOut();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createShellMenu();
|
||||||
initActions();
|
initActions();
|
||||||
|
|
||||||
m_newTerminalButton = new QToolButton();
|
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 = new QToolButton();
|
||||||
m_closeTerminalButton->setDefaultAction(&closeTerminal);
|
m_closeTerminalButton->setDefaultAction(m_closeTerminalAction);
|
||||||
|
|
||||||
m_openSettingsButton = new QToolButton();
|
m_openSettingsButton = new QToolButton();
|
||||||
m_openSettingsButton->setToolTip(Tr::tr("Configure..."));
|
m_openSettingsButton->setToolTip(Tr::tr("Configure..."));
|
||||||
@@ -73,66 +74,11 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
ICore::showOptionsDialog("Terminal.General");
|
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 = new QToolButton();
|
||||||
m_escSettingButton->setCheckable(true);
|
m_escSettingButton->setDefaultAction(settings().sendEscapeToTerminal.action());
|
||||||
|
|
||||||
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_lockKeyboardButton = new QToolButton();
|
m_lockKeyboardButton = new QToolButton();
|
||||||
m_lockKeyboardButton->setCheckable(true);
|
m_lockKeyboardButton->setDefaultAction(m_toggleKeyboardLockAction);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalPane::~TerminalPane() {}
|
TerminalPane::~TerminalPane() {}
|
||||||
@@ -164,7 +110,6 @@ void TerminalPane::openTerminal(const OpenTerminalParameters ¶meters)
|
|||||||
|
|
||||||
using namespace Constants;
|
using namespace Constants;
|
||||||
terminalWidget->unlockGlobalAction("Coreplugin.OutputPane.minmax");
|
terminalWidget->unlockGlobalAction("Coreplugin.OutputPane.minmax");
|
||||||
terminalWidget->unlockGlobalAction(Core::Constants::LOCATE);
|
|
||||||
terminalWidget->unlockGlobalAction(NEWTERMINAL);
|
terminalWidget->unlockGlobalAction(NEWTERMINAL);
|
||||||
terminalWidget->unlockGlobalAction(NEXTTERMINAL);
|
terminalWidget->unlockGlobalAction(NEXTTERMINAL);
|
||||||
terminalWidget->unlockGlobalAction(PREVTERMINAL);
|
terminalWidget->unlockGlobalAction(PREVTERMINAL);
|
||||||
@@ -281,55 +226,51 @@ void TerminalPane::setupTerminalWidget(TerminalWidget *terminal)
|
|||||||
|
|
||||||
void TerminalPane::initActions()
|
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;
|
using namespace Constants;
|
||||||
|
|
||||||
Command *cmd = ActionManager::registerAction(&newTerminal, NEWTERMINAL, m_selfContext);
|
ActionBuilder newTerminalAction(this, NEWTERMINAL);
|
||||||
cmd->setDefaultKeySequences({QKeySequence(
|
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"))});
|
HostOsInfo::isMacHost() ? QLatin1String("Ctrl+T") : QLatin1String("Ctrl+Shift+T"))});
|
||||||
|
newTerminalAction.setOnTriggered(this, [this] { openTerminal({}); });
|
||||||
|
m_newTerminalAction = newTerminalAction.commandAction();
|
||||||
|
|
||||||
ActionManager::registerAction(&nextTerminal, NEXTTERMINAL, m_selfContext)
|
ActionBuilder closeTerminalAction(this, CLOSETERMINAL);
|
||||||
->setDefaultKeySequences(
|
closeTerminalAction.setText(Tr::tr("Close Terminal"));
|
||||||
{QKeySequence("Alt+Tab"),
|
closeTerminalAction.setIcon(CLOSE_TERMINAL_ICON.icon());
|
||||||
QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+[")
|
closeTerminalAction.setToolTip(Tr::tr("Close the current Terminal."));
|
||||||
: QLatin1String("Ctrl+PgUp"))});
|
closeTerminalAction.setOnTriggered(this, [this] { removeTab(m_tabWidget.currentIndex()); });
|
||||||
|
m_closeTerminalAction = closeTerminalAction.commandAction();
|
||||||
|
|
||||||
ActionManager::registerAction(&prevTerminal, PREVTERMINAL, m_selfContext)
|
ActionBuilder nextTerminalAction(this, NEXTTERMINAL);
|
||||||
->setDefaultKeySequences(
|
nextTerminalAction.setText(Tr::tr("Next Terminal"));
|
||||||
{QKeySequence("Alt+Shift+Tab"),
|
nextTerminalAction.setDefaultKeySequences(
|
||||||
QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+]")
|
{QKeySequence("Alt+Tab"),
|
||||||
: QLatin1String("Ctrl+PgDown"))});
|
QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+[")
|
||||||
|
: QLatin1String("Ctrl+PgUp"))});
|
||||||
ActionManager::registerAction(&toggleKeyboardLock,
|
nextTerminalAction.setOnTriggered(this, [this] {
|
||||||
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] {
|
|
||||||
if (canNavigate())
|
if (canNavigate())
|
||||||
goToNext();
|
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())
|
if (canPrevious())
|
||||||
goToPrev();
|
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()
|
void TerminalPane::createShellMenu()
|
||||||
|
@@ -62,11 +62,9 @@ private:
|
|||||||
QToolButton *m_escSettingButton{nullptr};
|
QToolButton *m_escSettingButton{nullptr};
|
||||||
QToolButton *m_lockKeyboardButton{nullptr};
|
QToolButton *m_lockKeyboardButton{nullptr};
|
||||||
|
|
||||||
QAction newTerminal;
|
QAction *m_newTerminalAction{nullptr};
|
||||||
QAction nextTerminal;
|
QAction *m_closeTerminalAction{nullptr};
|
||||||
QAction prevTerminal;
|
QAction *m_toggleKeyboardLockAction{nullptr};
|
||||||
QAction closeTerminal;
|
|
||||||
QAction toggleKeyboardLock;
|
|
||||||
|
|
||||||
QMenu m_shellMenu;
|
QMenu m_shellMenu;
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ public:
|
|||||||
m_terminalPane = new TerminalPane;
|
m_terminalPane = new TerminalPane;
|
||||||
ExtensionSystem::PluginManager::addObject(m_terminalPane);
|
ExtensionSystem::PluginManager::addObject(m_terminalPane);
|
||||||
|
|
||||||
TerminalWidget::initActions();
|
TerminalWidget::initActions(this);
|
||||||
|
|
||||||
auto enable = [this] {
|
auto enable = [this] {
|
||||||
Utils::Terminal::Hooks::instance()
|
Utils::Terminal::Hooks::instance()
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "terminalsettings.h"
|
#include "terminalsettings.h"
|
||||||
|
|
||||||
|
#include "terminalicons.h"
|
||||||
#include "terminaltr.h"
|
#include "terminaltr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QFontComboBox>
|
#include <QFontComboBox>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
@@ -486,12 +488,34 @@ TerminalSettings::TerminalSettings()
|
|||||||
"instead of closing the terminal."));
|
"instead of closing the terminal."));
|
||||||
sendEscapeToTerminal.setDefaultValue(false);
|
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.setSettingsKey("LockKeyboard");
|
||||||
lockKeyboard.setLabelText(Tr::tr("Block shortcuts in terminal"));
|
lockKeyboard.setLabelText(Tr::tr("Block shortcuts in terminal"));
|
||||||
lockKeyboard.setToolTip(
|
lockKeyboard.setToolTip(
|
||||||
Tr::tr("Keeps Qt Creator shortcuts from interfering with the terminal."));
|
Tr::tr("Keeps Qt Creator shortcuts from interfering with the terminal."));
|
||||||
lockKeyboard.setDefaultValue(true);
|
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.setSettingsKey("AudibleBell");
|
||||||
audibleBell.setLabelText(Tr::tr("Audible bell"));
|
audibleBell.setLabelText(Tr::tr("Audible bell"));
|
||||||
audibleBell.setToolTip(Tr::tr("Makes the terminal beep when a bell "
|
audibleBell.setToolTip(Tr::tr("Makes the terminal beep when a bell "
|
||||||
|
@@ -28,9 +28,9 @@ public:
|
|||||||
|
|
||||||
Utils::BoolAspect allowBlinkingCursor{this};
|
Utils::BoolAspect allowBlinkingCursor{this};
|
||||||
|
|
||||||
Utils::BoolAspect sendEscapeToTerminal{this};
|
Utils::ToggleAspect sendEscapeToTerminal{this};
|
||||||
Utils::BoolAspect audibleBell{this};
|
Utils::BoolAspect audibleBell{this};
|
||||||
Utils::BoolAspect lockKeyboard{this};
|
Utils::ToggleAspect lockKeyboard{this};
|
||||||
|
|
||||||
Utils::BoolAspect enableMouseTracking{this};
|
Utils::BoolAspect enableMouseTracking{this};
|
||||||
};
|
};
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include <coreplugin/fileutils.h>
|
#include <coreplugin/fileutils.h>
|
||||||
#include <coreplugin/find/textfindconstants.h>
|
#include <coreplugin/find/textfindconstants.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/locator/locatorconstants.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
@@ -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()
|
void TerminalWidget::setupActions()
|
||||||
{
|
{
|
||||||
m_copy = registerAction(Constants::COPY, m_context);
|
auto make_registered = [this](ActionBuilder &actionBuilder) {
|
||||||
m_paste = registerAction(Constants::PASTE, m_context);
|
registerShortcut(actionBuilder.command());
|
||||||
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);
|
|
||||||
|
|
||||||
connect(m_copy.get(), &QAction::triggered, this, &TerminalWidget::copyToClipboard);
|
return RegisteredAction(actionBuilder.contextAction(),
|
||||||
connect(m_paste.get(), &QAction::triggered, this, &TerminalWidget::pasteFromClipboard);
|
[cmdId = actionBuilder.command()->id()](QAction *a) {
|
||||||
connect(m_close.get(), &QAction::triggered, this, &TerminalWidget::closeTerminal);
|
ActionManager::unregisterAction(a, cmdId);
|
||||||
connect(m_clearTerminal.get(), &QAction::triggered, this, &TerminalWidget::clearContents);
|
delete a;
|
||||||
connect(m_selectAll.get(), &QAction::triggered, this, &TerminalWidget::selectAll);
|
});
|
||||||
connect(m_clearSelection.get(), &QAction::triggered, this, &TerminalWidget::clearSelection);
|
};
|
||||||
connect(m_moveCursorWordLeft.get(),
|
|
||||||
&QAction::triggered,
|
ActionBuilder copyAction(this, Constants::COPY);
|
||||||
this,
|
copyAction.setContext(m_context);
|
||||||
&TerminalWidget::moveCursorWordLeft);
|
copyAction.setOnTriggered(this, &TerminalWidget::copyToClipboard);
|
||||||
connect(m_moveCursorWordRight.get(),
|
m_copy = make_registered(copyAction);
|
||||||
&QAction::triggered,
|
|
||||||
this,
|
ActionBuilder pasteAction(this, Constants::PASTE);
|
||||||
&TerminalWidget::moveCursorWordRight);
|
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.
|
// 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.
|
// 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(Core::Constants::OPTIONS);
|
||||||
unlockGlobalAction("Preferences.Terminal.General");
|
unlockGlobalAction("Preferences.Terminal.General");
|
||||||
unlockGlobalAction(Core::Constants::FIND_IN_DOCUMENT);
|
unlockGlobalAction(Core::Constants::FIND_IN_DOCUMENT);
|
||||||
|
unlockGlobalAction(Core::Constants::LOCATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalWidget::closeTerminal()
|
void TerminalWidget::closeTerminal()
|
||||||
@@ -607,57 +622,56 @@ bool TerminalWidget::event(QEvent *event)
|
|||||||
return TerminalView::event(event);
|
return TerminalView::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalWidget::initActions()
|
void TerminalWidget::initActions(QObject *parent)
|
||||||
{
|
{
|
||||||
Core::Context context(Utils::Id("TerminalWidget"));
|
Core::Context context(Utils::Id("TerminalWidget"));
|
||||||
|
|
||||||
static QAction copy;
|
auto keySequence = [](const QChar &key) -> QList<QKeySequence> {
|
||||||
static QAction paste;
|
if (HostOsInfo::isMacHost()) {
|
||||||
static QAction clearSelection;
|
return {QKeySequence(QLatin1String("Ctrl+") + key)};
|
||||||
static QAction clearTerminal;
|
} else if (HostOsInfo::isLinuxHost()) {
|
||||||
static QAction selectAll;
|
return {QKeySequence(QLatin1String("Ctrl+Shift+") + key)};
|
||||||
static QAction moveCursorWordLeft;
|
} else if (HostOsInfo::isWindowsHost()) {
|
||||||
static QAction moveCursorWordRight;
|
return {QKeySequence(QLatin1String("Ctrl+") + key),
|
||||||
static QAction close;
|
QKeySequence(QLatin1String("Ctrl+Shift+") + key)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
copy.setText(Tr::tr("Copy"));
|
ActionBuilder copyAction(parent, Constants::COPY);
|
||||||
paste.setText(Tr::tr("Paste"));
|
copyAction.setText(Tr::tr("Copy"));
|
||||||
clearSelection.setText(Tr::tr("Clear Selection"));
|
copyAction.setContext(context);
|
||||||
clearTerminal.setText(Tr::tr("Clear Terminal"));
|
copyAction.setDefaultKeySequences(keySequence('C'));
|
||||||
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"));
|
|
||||||
|
|
||||||
auto copyCmd = ActionManager::registerAction(©, Constants::COPY, context);
|
ActionBuilder pasteAction(parent, Constants::PASTE);
|
||||||
auto pasteCmd = ActionManager::registerAction(&paste, Constants::PASTE, context);
|
pasteAction.setText(Tr::tr("Paste"));
|
||||||
auto selectAllCmd = ActionManager::registerAction(&selectAll, Constants::SELECTALL, context);
|
pasteAction.setContext(context);
|
||||||
|
pasteAction.setDefaultKeySequences(keySequence('V'));
|
||||||
|
|
||||||
if (HostOsInfo::isMacHost()) {
|
ActionBuilder clearTerminalAction(parent, Constants::CLEAR_TERMINAL);
|
||||||
copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+C")));
|
clearTerminalAction.setText(Tr::tr("Clear Terminal"));
|
||||||
pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+V")));
|
clearTerminalAction.setContext(context);
|
||||||
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")));
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
ActionBuilder clearSelectionAction(parent, Constants::CLEARSELECTION);
|
||||||
->setDefaultKeySequences({QKeySequence("Alt+Left")});
|
clearSelectionAction.setText(Tr::tr("Clear Selection"));
|
||||||
|
clearSelectionAction.setContext(context);
|
||||||
|
|
||||||
ActionManager::registerAction(&moveCursorWordRight, Constants::MOVECURSORWORDRIGHT, context)
|
ActionBuilder moveCursorWordLeftAction(parent, Constants::MOVECURSORWORDLEFT);
|
||||||
->setDefaultKeySequences({QKeySequence("Alt+Right")});
|
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)
|
void TerminalWidget::unlockGlobalAction(const Utils::Id &commandId)
|
||||||
|
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
void restart(const Utils::Terminal::OpenTerminalParameters &openParameters);
|
void restart(const Utils::Terminal::OpenTerminalParameters &openParameters);
|
||||||
|
|
||||||
static void initActions();
|
static void initActions(QObject *parent);
|
||||||
|
|
||||||
void unlockGlobalAction(const Utils::Id &commandId);
|
void unlockGlobalAction(const Utils::Id &commandId);
|
||||||
|
|
||||||
@@ -81,7 +81,6 @@ protected:
|
|||||||
void setClipboard(const QString &text) override;
|
void setClipboard(const QString &text) override;
|
||||||
std::optional<TerminalView::Link> toLink(const QString &text) override;
|
std::optional<TerminalView::Link> toLink(const QString &text) override;
|
||||||
|
|
||||||
RegisteredAction registerAction(Utils::Id commandId, const Core::Context &context);
|
|
||||||
void registerShortcut(Core::Command *command);
|
void registerShortcut(Core::Command *command);
|
||||||
|
|
||||||
void updateCopyState();
|
void updateCopyState();
|
||||||
|
Reference in New Issue
Block a user