From 9673dc7cd4b21775efd98ad7a335006674d0e77c Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 2 Mar 2023 18:13:27 +0100 Subject: [PATCH] Terminal: New terminal and switch between terminals shortcuts On macOS: * new terminal Ctrl+T * next terminal Ctrl+Shift+] * prev terminal Ctrl+Shift+[ On Windows / Linux * new terminal Ctrl+Shift+T * next terminal Ctrl+PgUp * prev terminal Ctrl+PgDown Change-Id: I5626816cd18fd7a6d2b1cea5eea835a40b0c1029 Reviewed-by: Marcus Tillmanns --- src/plugins/terminal/terminalpane.cpp | 35 ++++++++++++++++++++++++--- src/plugins/terminal/terminalpane.h | 2 ++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/plugins/terminal/terminalpane.cpp b/src/plugins/terminal/terminalpane.cpp index 9eedfb3cce5..b93bdd3a5e9 100644 --- a/src/plugins/terminal/terminalpane.cpp +++ b/src/plugins/terminal/terminalpane.cpp @@ -64,11 +64,28 @@ TerminalPane::TerminalPane(QObject *parent) }); m_newTerminal.setMenu(shellMenu); + m_newTerminal.setShortcut(QKeySequence( + HostOsInfo::isMacHost() ? QLatin1String("Ctrl+T") : QLatin1String("Ctrl+Shift+T"))); m_newTerminalButton->setDefaultAction(&m_newTerminal); m_closeTerminalButton = new QToolButton(); m_closeTerminalButton->setDefaultAction(&m_closeTerminal); + + m_nextTerminal.setShortcut(QKeySequence(HostOsInfo::isMacHost() ? QLatin1String("Ctrl+Shift+[") + : QLatin1String("Ctrl+PgUp"))); + m_prevTerminal.setShortcut(QKeySequence(HostOsInfo::isMacHost() + ? QLatin1String("Ctrl+Shift+]") + : QLatin1String("Ctrl+PgDown"))); + + connect(&m_nextTerminal, &QAction::triggered, this, [this] { + if (canNavigate()) + goToNext(); + }); + connect(&m_prevTerminal, &QAction::triggered, this, [this] { + if (canPrevious()) + goToPrev(); + }); } void TerminalPane::openTerminal(const Utils::Terminal::OpenTerminalParameters ¶meters) @@ -148,6 +165,8 @@ void TerminalPane::setupTerminalWidget(TerminalWidget *terminal) if (!terminal->shellName().isEmpty()) setTabText(terminal); + + terminal->addActions({&m_newTerminal, &m_nextTerminal, &m_prevTerminal}); } QList TerminalPane::toolBarWidgets() const @@ -202,23 +221,31 @@ bool TerminalPane::canNavigate() const bool TerminalPane::canNext() const { - return m_tabWidget->count() > 1 && m_tabWidget->currentIndex() < m_tabWidget->count() - 1; + return m_tabWidget->count() > 1; } bool TerminalPane::canPrevious() const { - return m_tabWidget->count() > 1 && m_tabWidget->currentIndex() > 0; + return m_tabWidget->count() > 1; } void TerminalPane::goToNext() { - m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() + 1); + int nextIndex = m_tabWidget->currentIndex() + 1; + if (nextIndex >= m_tabWidget->count()) + nextIndex = 0; + + m_tabWidget->setCurrentIndex(nextIndex); emit navigateStateUpdate(); } void TerminalPane::goToPrev() { - m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() - 1); + int prevIndex = m_tabWidget->currentIndex() - 1; + if (prevIndex < 0) + prevIndex = m_tabWidget->count() - 1; + + m_tabWidget->setCurrentIndex(prevIndex); emit navigateStateUpdate(); } diff --git a/src/plugins/terminal/terminalpane.h b/src/plugins/terminal/terminalpane.h index 838fb3376ad..f748c70e717 100644 --- a/src/plugins/terminal/terminalpane.h +++ b/src/plugins/terminal/terminalpane.h @@ -53,6 +53,8 @@ private: QAction m_newTerminal; QAction m_closeTerminal; + QAction m_nextTerminal; + QAction m_prevTerminal; }; } // namespace Terminal