forked from qt-creator/qt-creator
Terminal: lock/unlock keyboard
We copied QShortCutMap into Qtc to allow us tight control over which shortcuts are "enabled" while the focus is inside a terminal, and the keyboard is "locked" to the Terminal. Locked here means that except for a select few, all key presses are send directly to the terminal and cannot be used to activate other actions. Change-Id: I96cddf753033c0f4e7d806b20085bb4755853117 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "terminalpane.h"
|
||||
|
||||
#include "shellmodel.h"
|
||||
#include "shortcutmap.h"
|
||||
#include "terminalconstants.h"
|
||||
#include "terminalicons.h"
|
||||
#include "terminalsettings.h"
|
||||
@@ -36,9 +37,9 @@ using namespace Core;
|
||||
|
||||
TerminalPane::TerminalPane(QObject *parent)
|
||||
: IOutputPane(parent)
|
||||
, m_context("Terminal.Pane", Core::Constants::C_GLOBAL_CUTOFF)
|
||||
, m_selfContext("Terminal.Pane")
|
||||
{
|
||||
setupContext(m_context, &m_tabWidget);
|
||||
setupContext(m_selfContext, &m_tabWidget);
|
||||
setZoomButtonsEnabled(true);
|
||||
|
||||
connect(this, &IOutputPane::zoomInRequested, this, [this] {
|
||||
@@ -52,6 +53,9 @@ TerminalPane::TerminalPane(QObject *parent)
|
||||
|
||||
initActions();
|
||||
|
||||
m_lockKeyboardButton = new QToolButton();
|
||||
m_lockKeyboardButton->setDefaultAction(&lockKeyboard);
|
||||
|
||||
m_newTerminalButton = new QToolButton();
|
||||
m_newTerminalButton->setDefaultAction(&newTerminal);
|
||||
|
||||
@@ -124,6 +128,14 @@ void TerminalPane::openTerminal(const OpenTerminalParameters ¶meters)
|
||||
}
|
||||
|
||||
const auto terminalWidget = new TerminalWidget(&m_tabWidget, parametersCopy);
|
||||
|
||||
using namespace Constants;
|
||||
terminalWidget->unlockGlobalAction("Coreplugin.OutputPane.minmax");
|
||||
terminalWidget->unlockGlobalAction(Core::Constants::LOCATE);
|
||||
terminalWidget->unlockGlobalAction(NEWTERMINAL);
|
||||
terminalWidget->unlockGlobalAction(NEXTTERMINAL);
|
||||
terminalWidget->unlockGlobalAction(PREVTERMINAL);
|
||||
|
||||
m_tabWidget.setCurrentIndex(m_tabWidget.addTab(terminalWidget, Tr::tr("Terminal")));
|
||||
setupTerminalWidget(terminalWidget);
|
||||
|
||||
@@ -229,6 +241,23 @@ void TerminalPane::initActions()
|
||||
{
|
||||
createShellMenu();
|
||||
|
||||
lockKeyboard.setCheckable(true);
|
||||
lockKeyboard.setChecked(TerminalSettings::instance().lockKeyboard());
|
||||
|
||||
auto updateLockKeyboard = [this](bool locked) {
|
||||
TerminalSettings::instance().lockKeyboard.setValue(locked);
|
||||
if (locked) {
|
||||
lockKeyboard.setIcon(Icons::LOCKED_TOOLBAR.icon());
|
||||
lockKeyboard.setToolTip(Tr::tr("Keyboard shortcuts will be send to the Terminal"));
|
||||
} else {
|
||||
lockKeyboard.setIcon(Icons::UNLOCKED_TOOLBAR.icon());
|
||||
lockKeyboard.setToolTip(Tr::tr("Keyboard shortcuts will be send to Qt Creator"));
|
||||
}
|
||||
};
|
||||
|
||||
updateLockKeyboard(TerminalSettings::instance().lockKeyboard());
|
||||
connect(&lockKeyboard, &QAction::toggled, this, updateLockKeyboard);
|
||||
|
||||
newTerminal.setText(Tr::tr("New Terminal"));
|
||||
newTerminal.setIcon(NEW_TERMINAL_ICON.icon());
|
||||
newTerminal.setToolTip(Tr::tr("Create a new Terminal."));
|
||||
@@ -242,25 +271,22 @@ void TerminalPane::initActions()
|
||||
|
||||
using namespace Constants;
|
||||
|
||||
ActionManager::registerAction(&newTerminal, NEWTERMINAL, m_context)
|
||||
->setDefaultKeySequences({QKeySequence(
|
||||
HostOsInfo::isMacHost() ? QLatin1String("Ctrl+T") : QLatin1String("Ctrl+Shift+T"))});
|
||||
Command *cmd = ActionManager::registerAction(&newTerminal, NEWTERMINAL, m_selfContext);
|
||||
cmd->setDefaultKeySequences({QKeySequence(
|
||||
HostOsInfo::isMacHost() ? QLatin1String("Ctrl+T") : QLatin1String("Ctrl+Shift+T"))});
|
||||
|
||||
ActionManager::registerAction(&nextTerminal, NEXTTERMINAL, m_context)
|
||||
ActionManager::registerAction(&nextTerminal, NEXTTERMINAL, m_selfContext)
|
||||
->setDefaultKeySequences(
|
||||
{QKeySequence("Alt+Tab"),
|
||||
QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+[")
|
||||
: QLatin1String("Ctrl+PgUp"))});
|
||||
|
||||
ActionManager::registerAction(&prevTerminal, PREVTERMINAL, m_context)
|
||||
ActionManager::registerAction(&prevTerminal, PREVTERMINAL, m_selfContext)
|
||||
->setDefaultKeySequences(
|
||||
{QKeySequence("Alt+Shift+Tab"),
|
||||
QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+]")
|
||||
: QLatin1String("Ctrl+PgDown"))});
|
||||
|
||||
m_minMax = TerminalWidget::unlockGlobalAction("Coreplugin.OutputPane.minmax", m_context);
|
||||
m_locate = TerminalWidget::unlockGlobalAction(Core::Constants::LOCATE, m_context);
|
||||
|
||||
connect(&newTerminal, &QAction::triggered, this, [this] { openTerminal({}); });
|
||||
connect(&closeTerminal, &QAction::triggered, this, [this] {
|
||||
removeTab(m_tabWidget.currentIndex());
|
||||
@@ -303,10 +329,11 @@ void TerminalPane::createShellMenu()
|
||||
QList<QWidget *> TerminalPane::toolBarWidgets() const
|
||||
{
|
||||
QList<QWidget *> widgets = IOutputPane::toolBarWidgets();
|
||||
|
||||
widgets.prepend(m_newTerminalButton);
|
||||
widgets.prepend(m_closeTerminalButton);
|
||||
|
||||
return widgets << m_openSettingsButton << m_escSettingButton;
|
||||
return widgets << m_openSettingsButton << m_lockKeyboardButton << m_escSettingButton;
|
||||
}
|
||||
|
||||
QString TerminalPane::displayName() const
|
||||
|
||||
Reference in New Issue
Block a user