From: Nate Graham Date: Wed, 20 Mar 2019 22:06:28 +0000 (+0100) Subject: Add action for focusing Terminal Panel X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/69838a1cdd6a10d9d6ca6572962c438a97d46b36 Add action for focusing Terminal Panel Summary: Add an action for focusing and de-focusing the Terminal Panel. FEATURE: 185096 FIXED-IN 20.04.0 Test Plan: - Hit {key Ctrl Shift F4} or click {nav Tools > Focus Terminal Panel} or {nav Control > Tools > Focus Terminal Panel} - If the Terminal Panel was closed, it opens and gains focus - If the Terminal Panel was open but unfocused, it gains focus - If the Terminal Panel was open and focused, focus returns to the view {F6630289, size=full} Reviewers: #dolphin, elvisangelaccio, rominf Reviewed By: #dolphin, elvisangelaccio, rominf Subscribers: kfm-devel, elvisangelaccio, rkflx, ngraham, #dolphin Tags: #dolphin Differential Revision: https://phabricator.kde.org/D10959 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 54cd1f0ef..30c903bb5 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1554,6 +1554,12 @@ void DolphinMainWindow::setupActions() openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts"))); actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4); connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal); + + QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel")); + focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel")); + focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels"))); + actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL + Qt::SHIFT + Qt::Key_F4); + connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel); } #endif @@ -2305,6 +2311,22 @@ bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event) return false; } +void DolphinMainWindow::focusTerminalPanel() +{ + if (m_terminalPanel->isVisible()) { + if (m_terminalPanel->terminalHasFocus()) { + m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason); + actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel")); + } else { + m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason); + actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel")); + } + } else { + actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); + actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel")); + } +} + DolphinMainWindow::UndoUiInterface::UndoUiInterface() : KIO::FileUndoManager::UiInterface() { diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 0520e1091..940a03d83 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -365,6 +365,9 @@ private slots: /** Opens a terminal window for the current location. */ void openTerminal(); + /** Focus a Terminal Panel. */ + void focusTerminalPanel(); + /** Opens the settings dialog for Dolphin. */ void editSettings(); diff --git a/src/dolphinpart.rc b/src/dolphinpart.rc index afd3838e3..df152fb20 100644 --- a/src/dolphinpart.rc +++ b/src/dolphinpart.rc @@ -1,5 +1,5 @@ - + &Edit @@ -39,6 +39,7 @@ Tools + diff --git a/src/dolphinui.rc b/src/dolphinui.rc index 4de1c609c..e1bb9ee58 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -1,5 +1,5 @@ - + @@ -56,6 +56,7 @@ + diff --git a/src/panels/terminal/terminalpanel.cpp b/src/panels/terminal/terminalpanel.cpp index 86974d200..861afebee 100644 --- a/src/panels/terminal/terminalpanel.cpp +++ b/src/panels/terminal/terminalpanel.cpp @@ -147,6 +147,7 @@ void TerminalPanel::showEvent(QShowEvent* event) if (m_konsolePart) { connect(m_konsolePart, &KParts::ReadOnlyPart::destroyed, this, &TerminalPanel::terminalExited); m_terminalWidget = m_konsolePart->widget(); + setFocusProxy(m_terminalWidget); m_layout->addWidget(m_terminalWidget); if (m_konsolePartMissingMessage) { m_layout->removeWidget(m_konsolePartMissingMessage); @@ -263,3 +264,8 @@ void TerminalPanel::slotKonsolePartCurrentDirectoryChanged(const QString& dir) const QUrl url(QUrl::fromLocalFile(dir)); emit changeUrl(url); } + +bool TerminalPanel::terminalHasFocus() const +{ + return m_terminalWidget->hasFocus(); +} diff --git a/src/panels/terminal/terminalpanel.h b/src/panels/terminal/terminalpanel.h index f5d66e548..6ab205fe3 100644 --- a/src/panels/terminal/terminalpanel.h +++ b/src/panels/terminal/terminalpanel.h @@ -56,6 +56,7 @@ public: void goHome(); QString currentWorkingDirectory(); bool isHiddenInVisibleWindow() const; + bool terminalHasFocus() const; bool hasProgramRunning() const; QString runningProgramName() const;