]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add action for focusing Terminal Panel
authorNate Graham <nate@kde.org>
Wed, 20 Mar 2019 22:06:28 +0000 (23:06 +0100)
committerNate Graham <nate@kde.org>
Thu, 5 Dec 2019 22:53:19 +0000 (15:53 -0700)
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

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinpart.rc
src/dolphinui.rc
src/panels/terminal/terminalpanel.cpp
src/panels/terminal/terminalpanel.h

index 54cd1f0ef9d8a5bb6b9ae49838f94c447c6d7858..30c903bb5ec92d156dd0ae36664330bd61e3fba4 100644 (file)
@@ -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()
 {
index 0520e1091ebe0b0a7d2ad06d94cf3e11f7f4f75c..940a03d83d13623eeb414450858d1b8d21044e6e 100644 (file)
@@ -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();
 
index afd3838e3b5018417e0e622a9854d1fa101ea454..df152fb20e4a30ebba0e234c747321f2ff3e7eeb 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphinpart" version="14" translationDomain="dolphin">
+<kpartgui name="dolphinpart" version="15" translationDomain="dolphin">
  <MenuBar>
   <Menu name="edit"><text>&amp;Edit</text>
    <Action name="new_menu"/>
@@ -39,6 +39,7 @@
   </Menu>
   <Menu name="tools"><text context="@title:menu">Tools</text>
     <Action name="open_terminal"/>
+    <Action name="focus_terminal_panel"/>
     <Action name="find_file" />
     <Action name="show_filter_bar" />
     <Action name="compare_files" />
index 4de1c609c7d4c35b255409d53d9f7ff701a9c75b..e1bb9ee58daa0ad0c8b2f556a1a7358d96a4ce6b 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="28">
+<kpartgui name="dolphin" version="29">
     <MenuBar>
         <Menu name="file">
             <Action name="new_menu" />
@@ -56,6 +56,7 @@
             <Action name="show_filter_bar" />
             <Action name="open_preferred_search_tool" />
             <Action name="open_terminal" />
+            <Action name="focus_terminal_panel"/>
             <Action name="compare_files" />
             <Action name="change_remote_encoding" />
         </Menu>
index 86974d200e4d23190222367c07b86d226037e813..861afebee0330fa2fd5c9ffc4917630a29809f6b 100644 (file)
@@ -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();
+}
index f5d66e548ece30e5ed2fa4aaea250f2fa049f559..6ab205fe32cb01828dff012bdfb49e6b8d59ad5e 100644 (file)
@@ -56,6 +56,7 @@ public:
     void goHome();
     QString currentWorkingDirectory();
     bool isHiddenInVisibleWindow() const;
+    bool terminalHasFocus() const;
     bool hasProgramRunning() const;
     QString runningProgramName() const;