[rkward] /: File browser tool window follows current working directory (while showing current working directory)

Thomas Friedrichsmeier null at kde.org
Sun Apr 22 08:28:31 UTC 2018


Git commit ec179e24b74d512618fe239a233fa392b902a6d6 by Thomas Friedrichsmeier.
Committed on 22/04/2018 at 08:28.
Pushed by tfry into branch 'master'.

File browser tool window follows current working directory (while showing current working directory)

M  +1    -0    ChangeLog
M  +2    -2    rkward/rbackend/rkrinterface.cpp
M  +3    -1    rkward/rbackend/rkrinterface.h
M  +1    -0    rkward/rkward.cpp
M  +14   -5    rkward/windows/rkfilebrowser.cpp
M  +4    -4    rkward/windows/rkfilebrowser.h

https://commits.kde.org/rkward/ec179e24b74d512618fe239a233fa392b902a6d6

diff --git a/ChangeLog b/ChangeLog
index 82ec0b69..6d321fee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 --- Version 0.7.1 - UNRELEASED
+- File browser tool window follows changes in current working directory (while showing current working directory)
 - Show focus indication in highlighted item color (usually blue), instead of hardcoded red
 - On Mac, do not attempt to start DBus, if it is already running
 - Fix most compiler warnings
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index 514e2494..1bab396b 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -2,7 +2,7 @@
                           rkrinterface.cpp  -  description
                              -------------------
     begin                : Fri Nov 1 2002
-    copyright            : (C) 2002-2017 by Thomas Friedrichsmeier
+    copyright            : (C) 2002-2018 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -564,7 +564,7 @@ QStringList RInterface::processPlainGenericRequest (const QStringList &calllist)
 	} else if (call == "wdChange") {
 		// in case of separate processes, apply new working directory in frontend, too.
 		QDir::setCurrent (calllist.value (1));
-		RKWardMainWindow::getMain ()->updateCWD ();
+		emit (backendWorkdirChanged());
 	} else if (call == "highlightRCode") {
 		return (QStringList (RKCommandHighlighter::commandToHTML (calllist.value (1))));
 	} else if (call == "quit") {
diff --git a/rkward/rbackend/rkrinterface.h b/rkward/rbackend/rkrinterface.h
index fa286286..15be279b 100644
--- a/rkward/rbackend/rkrinterface.h
+++ b/rkward/rbackend/rkrinterface.h
@@ -2,7 +2,7 @@
                           rkrinterface.h  -  description
                              -------------------
     begin                : Fri Nov 1 2002
-    copyright            : (C) 2002 - 2017 by Thomas Friedrichsmeier
+    copyright            : (C) 2002 - 2018 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -136,6 +136,8 @@ friend class RCommand;
 protected:
 	void handleRequest (RBackendRequest *request);
 	void rCommandDone (RCommand *command) override;
+signals:
+	void backendWorkdirChanged();
 };
 
 /**
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 47d447ac..3964ba8e 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -269,6 +269,7 @@ void RKWardMainWindow::doPostInit () {
 	// around on the bus in this case.
 
 	updateCWD ();
+	connect (RKGlobals::rInterface (), &RInterface::backendWorkdirChanged, this, &RKWardMainWindow::updateCWD);
 	setCaption (QString ());	// our version of setCaption takes care of creating a correct caption, so we do not need to provide it here
 }
 
diff --git a/rkward/windows/rkfilebrowser.cpp b/rkward/windows/rkfilebrowser.cpp
index 3531c02a..b5f43017 100644
--- a/rkward/windows/rkfilebrowser.cpp
+++ b/rkward/windows/rkfilebrowser.cpp
@@ -39,6 +39,8 @@
 #include <QInputDialog>
 
 #include "rkworkplace.h"
+#include "../rkglobals.h"
+#include "../rbackend/rkrinterface.h"
 #include "../rkward.h"
 #include "../misc/rkdummypart.h"
 
@@ -83,10 +85,7 @@ void RKFileBrowser::showEvent (QShowEvent *e) {
 	}
 
 	RKMDIWindow::showEvent (e);
-}
-
-void RKFileBrowser::currentWDChanged () {
-	RK_TRACE (APP);
+	real_widget->syncToWD();
 }
 
 /////////////////// RKFileBrowserWidget ////////////////////
@@ -124,7 +123,7 @@ RKFileBrowserWidget::RKFileBrowserWidget (QWidget *parent) : QWidget (parent) {
 	toolbar->addAction (dir->actionCollection ()->action ("home"));
 	QAction* action = new QAction (QIcon::fromTheme ("folder-sync"), i18n ("Working directory"), this);
 	action->setToolTip (action->text ());
-	connect(action, &QAction::triggered, this, [=] () { setURL (QUrl::fromLocalFile (QDir::currentPath ())); });
+	connect(action, &QAction::triggered, this, [=] () { follow_working_directory = true; syncToWD(); });
 	toolbar->addAction (action);
 	toolbar->addSeparator ();
 	toolbar->addAction (dir->actionCollection ()->action ("short view"));
@@ -143,6 +142,7 @@ RKFileBrowserWidget::RKFileBrowserWidget (QWidget *parent) : QWidget (parent) {
 	connect (urlbox, &KUrlComboBox::urlActivated, this, &RKFileBrowserWidget::urlChangedInCombo);
 
 	connect (dir, &KDirOperator::fileSelected, this, &RKFileBrowserWidget::fileActivated);
+	connect (RKGlobals::rInterface (), &RInterface::backendWorkdirChanged, this, &RKFileBrowserWidget::syncToWD);
 
 	setURL (QUrl::fromLocalFile (QDir::currentPath ()));
 }
@@ -151,6 +151,13 @@ RKFileBrowserWidget::~RKFileBrowserWidget () {
 	RK_TRACE (APP);
 }
 
+void RKFileBrowserWidget::syncToWD () {
+	RK_TRACE (APP);
+
+	if (!follow_working_directory) return;
+	if (isVisible()) setURL (QUrl::fromLocalFile (QDir::currentPath ()));
+}
+
 void RKFileBrowserWidget::rename () {
 	RK_TRACE (APP);
 
@@ -202,12 +209,14 @@ void RKFileBrowserWidget::setURL (const QUrl &url) {
 
 	urlbox->setUrl (url);
 	dir->setUrl (url, true);
+	follow_working_directory = (url.path() == QDir::currentPath ());
 }
 
 void RKFileBrowserWidget::urlChangedInView (const QUrl &url) {
 	RK_TRACE (APP);
 
 	urlbox->setUrl (url);
+	follow_working_directory = (url.path() == QDir::currentPath ());
 }
 
 void RKFileBrowserWidget::stringChangedInCombo (const QString &url) {
diff --git a/rkward/windows/rkfilebrowser.h b/rkward/windows/rkfilebrowser.h
index b38f9d91..a95b5298 100644
--- a/rkward/windows/rkfilebrowser.h
+++ b/rkward/windows/rkfilebrowser.h
@@ -2,7 +2,7 @@
                           rkfilebrowser  -  description
                              -------------------
     begin                : Thu Apr 26 2007
-    copyright            : (C) 2007-2016 by Thomas Friedrichsmeier
+    copyright            : (C) 2007-2018 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -41,8 +41,6 @@ public:
 /** reimplemented to create the real file browser widget only when the file browser is shown for the first time */
 	void showEvent (QShowEvent *e) override;
 	static RKFileBrowser *getMainBrowser() { return main_browser; };
-public slots:
-	void currentWDChanged ();
 private:
 	RKFileBrowserWidget *real_widget;
 	QWidget *layout_widget;
@@ -51,7 +49,7 @@ friend class RKWardMainWindow;
 };
 
 /** The internal widget used in RKFileBrowser 
-TODO: KDE4: check whether there is a ready widget for this. Much of the implementation is a modified copy from Kate / kdevelop.
+Much of the implementation is a modified copy from Kate / kdevelop.
 */
 class RKFileBrowserWidget : public QWidget {
 	Q_OBJECT
@@ -69,6 +67,7 @@ public slots:
 	void saveConfig ();
 	void contextMenuHook (const KFileItem &item, QMenu *menu);
 	void rename ();
+	void syncToWD ();
 private:
 	QList<QAction*> added_service_actions;
 	KDirOperator *dir;
@@ -76,6 +75,7 @@ private:
 	KFileItemActions *fi_actions;
 	QAction *rename_action;
 	QUrl context_menu_url;
+	bool follow_working_directory;
 };
 
 #endif



More information about the rkward-tracker mailing list