[utilities/krusader] /: Added feature which allows Active panel to follow Embedded Terminal working directory.

Toni Asensi Esteve null at kde.org
Sat Jun 18 20:12:24 BST 2022


Git commit c24bb4e78debfed0709989c83697eb84622dbc51 by Toni Asensi Esteve, on behalf of Vyacheslav Mayorov.
Committed on 18/06/2022 at 19:09.
Pushed by asensi into branch 'master'.

Added feature which allows Active panel to follow Embedded Terminal working directory.

ADDED: Active panel follows Embedded Terminal working directory.
GUI: An "Active panel follows Embedded Terminal working directory" option can be chosen.
Revision: https://invent.kde.org/utilities/krusader/-/merge_requests/82

M  +4    -0    doc/konfigurator.docbook
M  +39   -0    krusader/GUI/terminaldock.cpp
M  +4    -0    krusader/GUI/terminaldock.h
M  +2    -1    krusader/Konfigurator/kggeneral.cpp
M  +2    -1    krusader/Panel/listpanel.cpp
M  +2    -0    krusader/defaults.h

https://invent.kde.org/utilities/krusader/commit/c24bb4e78debfed0709989c83697eb84622dbc51

diff --git a/doc/konfigurator.docbook b/doc/konfigurator.docbook
index 43bda96c..3dc73f91 100644
--- a/doc/konfigurator.docbook
+++ b/doc/konfigurator.docbook
@@ -1083,6 +1083,10 @@
         change</guilabel>: if unchecked, there will be no
         <command>cd</command> command sent to the Terminal Emulator
         if the panel folder changes.</para>
+      <para>
+        <guilabel>Active panel follows Embedded Terminal working directory</guilabel>: if unchecked, active panel
+        stays unchanged while the user navigates in the embedded terminal (using cd, popd, etc).
+      </para>
       <para>
 	<guilabel>Toggle Fullscreen Embedded Terminal</guilabel>: if checked,
 	  &krusader; shows fullscreen terminal in
diff --git a/krusader/GUI/terminaldock.cpp b/krusader/GUI/terminaldock.cpp
index 0d3dac6d..6f7ac369 100644
--- a/krusader/GUI/terminaldock.cpp
+++ b/krusader/GUI/terminaldock.cpp
@@ -30,8 +30,11 @@
 #include <KService/KService>
 #include <KWidgetsAddons/KToggleAction>
 #include <KWidgetsAddons/KMessageBox>
+#include <KConfigCore/KConfig>
+#include <KConfigCore/KConfigGroup>
 
 #include "kcmdline.h"
+#include "../defaults.h"
 #include "../kractions.h"
 #include "../krmainwindow.h"
 #include "../krservices.h"
@@ -237,6 +240,11 @@ bool TerminalDock::eventFilter(QObject * watched, QEvent * e)
         }
         break;
     }
+    case QEvent::FocusIn:
+    case QEvent::FocusOut: {
+        onTerminalFocusChanged(e->type() == QEvent::FocusIn);
+        break;
+    }
     default:
         return false;
     }
@@ -274,3 +282,34 @@ void TerminalDock::showEvent(QShowEvent * /*e*/)
     }
 }
 
+void TerminalDock::onTerminalFocusChanged(bool focused)
+{
+    if (konsole_part == nullptr) {
+        return;
+    }
+
+    if (!focused) {
+        disconnect(konsole_part, SIGNAL(currentDirectoryChanged(QString)), nullptr, nullptr);
+        return;
+    }
+
+    const KConfigGroup cfg = krConfig->group("General");
+    if (!cfg.readEntry("Follow Terminal CD", _FollowTerminalCD)) {
+        return;
+    }
+
+    connect(konsole_part, SIGNAL(currentDirectoryChanged(QString)),
+            this, SLOT(currentDirChanged(QString)));
+}
+
+void TerminalDock::currentDirChanged(const QString &terminalPath)
+{
+    const QString panelPath = ACTIVE_PANEL->virtualPath().toLocalFile();
+    if (panelPath == terminalPath) {
+        return;
+    }
+
+    qDebug() << "terminal cwd changed=" << terminalPath << "panelPath=" << panelPath;
+    lastPath = terminalPath;
+    _mainWindow->activePanel()->func->openUrl(QUrl::fromLocalFile(terminalPath));
+}
diff --git a/krusader/GUI/terminaldock.h b/krusader/GUI/terminaldock.h
index b5a0a228..c3c68348 100644
--- a/krusader/GUI/terminaldock.h
+++ b/krusader/GUI/terminaldock.h
@@ -42,11 +42,15 @@ public:
     bool initialise();
     void hideEvent(QHideEvent * e) override;
     void showEvent(QShowEvent * e) override;
+    void onTerminalFocusChanged(bool focused);
     inline KParts::Part* part() {
         return konsole_part;
     }
+
 private slots:
     void killTerminalEmulator();
+    void currentDirChanged(const QString& terminalPath);
+
 private:
     KrMainWindow *_mainWindow;
     QString lastPath;                       // path of the last sendCd
diff --git a/krusader/Konfigurator/kggeneral.cpp b/krusader/Konfigurator/kggeneral.cpp
index 318590dd..0dd74b97 100644
--- a/krusader/Konfigurator/kggeneral.cpp
+++ b/krusader/Konfigurator/kggeneral.cpp
@@ -271,8 +271,9 @@ void KgGeneral::createGeneralTab()
 
     KONFIGURATOR_CHECKBOX_PARAM terminal_settings[] = { //   cfg_class  cfg_name     default        text            restart tooltip
         {"General", "Send CDs", _SendCDs, i18n("Embedded Terminal sends Chdir on panel change"), false, i18n("When checked, whenever the panel is changed (for example, by pressing Tab), Krusader changes the current folder in the embedded terminal.") },
+        {"General", "Follow Terminal CD", _FollowTerminalCD, i18n("Active panel follows Embedded Terminal working directory"), false, i18n("When checked, whenever terminal working directory is changed (for example, by executing 'cd' or 'popd' command), Krusader changes the current folder of active panel.") },
     };
-    cbs = createCheckBoxGroup(1, 0, terminal_settings, 1 /*count*/, terminalGrp, PAGE_GENERAL);
+    cbs = createCheckBoxGroup(1, 0, terminal_settings, 2 /*count*/, terminalGrp, PAGE_GENERAL);
     terminalGrid->addWidget(cbs, 2, 0, 1, 2);
 
 
diff --git a/krusader/Panel/listpanel.cpp b/krusader/Panel/listpanel.cpp
index 0b1077f0..dde22a25 100644
--- a/krusader/Panel/listpanel.cpp
+++ b/krusader/Panel/listpanel.cpp
@@ -77,6 +77,7 @@
 #include "../GUI/dirhistorybutton.h"
 #include "../GUI/kcmdline.h"
 #include "../GUI/mediabutton.h"
+#include "../GUI/terminaldock.h"
 #include "../MountMan/kmountman.h"
 #include "../UserAction/useractionpopupmenu.h"
 
@@ -744,7 +745,7 @@ void ListPanel::slotStartUpdate(bool directoryChange)
     const QUrl currentUrl = virtualPath();
     if (directoryChange) {
 
-        if (this == ACTIVE_PANEL) {
+        if (this == ACTIVE_PANEL && !MAIN_VIEW->terminalDock()->hasFocus()) {
             slotFocusOnMe();
         }
 
diff --git a/krusader/defaults.h b/krusader/defaults.h
index be5a6fdf..5a720599 100644
--- a/krusader/defaults.h
+++ b/krusader/defaults.h
@@ -115,6 +115,8 @@
 #define _Terminal      "konsole --separate"
 // Send CDs ///////////
 #define _SendCDs  true
+// Follow Terminal CD ///////////
+#define _FollowTerminalCD  true
 // Editor /////////////
 #define _Editor        "internal editor"
 // Use Okteta as Hex viewer ///////


More information about the kde-doc-english mailing list