[rkward-cvs] SF.net SVN: rkward: [1855] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Apr 27 13:32:44 UTC 2007


Revision: 1855
          http://svn.sourceforge.net/rkward/?rev=1855&view=rev
Author:   tfry
Date:     2007-04-27 06:32:43 -0700 (Fri, 27 Apr 2007)

Log Message:
-----------
make file browser marginally useful

Modified Paths:
--------------
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/windows/rkfilebrowser.cpp
    trunk/rkward/rkward/windows/rkfilebrowser.h

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2007-04-26 20:52:58 UTC (rev 1854)
+++ trunk/rkward/rkward/rkward.cpp	2007-04-27 13:32:43 UTC (rev 1855)
@@ -67,6 +67,7 @@
 #include "windows/rkcommandlog.h"
 #include "windows/rkhelpsearchwindow.h"
 #include "windows/rktoplevelwindowgui.h"
+#include "windows/rkfilebrowser.h"
 #include "rkconsole.h"
 #include "debug.h"
 
@@ -213,6 +214,11 @@
 	RObjectBrowser::mainBrowser ()->setToolWrapper (addToolWindow(RObjectBrowser::mainBrowser (), KDockWidget::DockLeft, getMainDockWidget(), 30, i18n ("Existing objects in your workspace."), i18n ("Workspace")));
 	RKWorkplace::mainWorkplace ()->registerToolWindow (RObjectBrowser::mainBrowser ());
 
+	RKFileBrowser *file_browser = new RKFileBrowser (0, true, "file_browser");
+	file_browser->setIcon (SmallIcon ("fileopen"));
+	file_browser->setToolWrapper (addToolWindow (file_browser, KDockWidget::DockLeft, getMainDockWidget (), 10, i18n ("File-system Browser"), i18n ("Files")));
+	RKWorkplace::mainWorkplace ()->registerToolWindow (file_browser);
+
 	RControlWindow::getControl ()->setCaption (i18n ("Pending Jobs"));
 	RControlWindow::getControl ()->setToolWrapper (addToolWindow (RControlWindow::getControl (), KDockWidget::DockBottom, getMainDockWidget (), 10));
 	RKWorkplace::mainWorkplace ()->registerToolWindow (RControlWindow::getControl ());

Modified: trunk/rkward/rkward/windows/rkfilebrowser.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkfilebrowser.cpp	2007-04-26 20:52:58 UTC (rev 1854)
+++ trunk/rkward/rkward/windows/rkfilebrowser.cpp	2007-04-27 13:32:43 UTC (rev 1855)
@@ -18,11 +18,17 @@
 #include "rkfilebrowser.h"
 
 #include <kdiroperator.h>
+#include <kurlcombobox.h>
+#include <kurlcompletion.h>
+#include <ktoolbar.h>
+#include <krun.h>
 
 #include <qdir.h>
 #include <qlayout.h>
 #include <qvbox.h>
+#include <qlistbox.h>
 
+#include "rkworkplace.h"
 #include "../misc/rkdummypart.h"
 
 #include "../debug.h"
@@ -33,11 +39,11 @@
 	real_widget = 0;
 
 	QVBoxLayout *layout = new QVBoxLayout (this);
-	wrapper = new QVBox (this);
-	wrapper->setFocusPolicy (QWidget::StrongFocus);
-	layout->addWidget (wrapper);
+	layout_widget = new QVBox (this);
+	layout->addWidget (layout_widget);
+	layout_widget->setFocusPolicy (QWidget::StrongFocus);
 
-	RKDummyPart *part = new RKDummyPart (this, wrapper);
+	RKDummyPart *part = new RKDummyPart (this, layout_widget);
 	setPart (part);
 	initializeActivationSignals ();
 }
@@ -48,27 +54,16 @@
 	hide ();
 }
 
-void RKFileBrowser::hide () {
-	RK_TRACE (APP);
-
-	if (real_widget) {
-		real_widget->close (false);
-	}
-}
-
 void RKFileBrowser::show () {
 	RK_TRACE (APP);
 
 	if (!real_widget) {
 		RK_DO (qDebug ("creating file browser"), APP, DL_INFO);
 
-		real_widget = new KDirOperator (QDir::currentDirPath (), wrapper);
-		real_widget->setView(KFile::Default);
-		real_widget->setPreviewWidget (0);
-		wrapper->setFocusProxy (real_widget);
+		real_widget = new RKFileBrowserWidget (layout_widget);
+		layout_widget->setFocusProxy (real_widget);
 	}
 
-	real_widget->show ();
 	RKMDIWindow::show ();
 }
 
@@ -76,4 +71,98 @@
 	RK_TRACE (APP);
 }
 
+
+
+RKFileBrowserWidget::RKFileBrowserWidget (QWidget *parent) : QVBox (parent) {
+	RK_TRACE (APP);
+
+	KToolBar *toolbar = new KToolBar (this);
+	toolbar->setIconSize (16);
+
+	urlbox = new KURLComboBox (KURLComboBox::Directories, true, this);
+	KURLCompletion* cmpl = new KURLCompletion (KURLCompletion::DirCompletion);
+	urlbox->setCompletionObject (cmpl);
+	urlbox->setAutoDeleteCompletionObject (true);
+	urlbox->setSizePolicy (QSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed));
+	urlbox->listBox ()->installEventFilter (this);
+
+	dir = new KDirOperator (KURL (), this);
+	dir->setView(KFile::Simple);
+	dir->setPreviewWidget (0);
+
+	dir->actionCollection ()->action ("up")->plug (toolbar);
+	dir->actionCollection ()->action ("back")->plug (toolbar);
+	dir->actionCollection ()->action ("forward")->plug (toolbar);
+	dir->actionCollection ()->action ("home")->plug (toolbar);
+	dir->actionCollection ()->action ("short view")->plug (toolbar);
+	dir->actionCollection ()->action ("detailed view")->plug (toolbar);
+
+	connect (dir, SIGNAL (urlEntered (const KURL &)), this, SLOT (urlChangedInView (const KURL &)));
+	connect (urlbox, SIGNAL (returnPressed (const QString &)), this, SLOT (urlChangedInCombo (const QString &)));
+	connect (urlbox, SIGNAL (urlActivated (const KURL&)), this, SLOT (urlChangedInCombo (const KURL&)));
+
+	connect (dir, SIGNAL (fileSelected (const KFileItem*)), this, SLOT (fileActivated (const KFileItem*)));
+
+	setURL (QDir::currentDirPath ());
+}
+
+RKFileBrowserWidget::~RKFileBrowserWidget () {
+	RK_TRACE (APP);
+}
+
+void RKFileBrowserWidget::setURL (const QString &url) {
+	RK_TRACE (APP);
+
+	urlbox->setURL (url);
+	dir->setURL (url, true);
+}
+
+void RKFileBrowserWidget::urlChangedInView (const KURL &url) {
+	RK_TRACE (APP);
+
+	urlbox->setURL (url);
+}
+
+void RKFileBrowserWidget::urlChangedInCombo (const QString &url) {
+	RK_TRACE (APP);
+
+	dir->setURL (url, true);
+}
+
+void RKFileBrowserWidget::urlChangedInCombo (const KURL &url) {
+	RK_TRACE (APP);
+
+	dir->setURL (url, true);
+}
+
+bool RKFileBrowserWidget::eventFilter (QObject *watched, QEvent *e) {
+	// don't trace
+
+	// fix size of popup (copied from katefileselector.cpp)
+	QListBox *lb = urlbox->listBox ();
+	if (watched == lb && e->type() == QEvent::Show) {
+		int add = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0;
+		int w = QMIN (topLevelWidget ()->width(), lb->contentsWidth() + add);
+		lb->resize (w, lb->height());
+	}
+	return QWidget::eventFilter (watched, e);
+}
+
+void RKFileBrowserWidget::fileActivated (const KFileItem *item) {
+	RK_TRACE (APP);
+
+	RK_ASSERT (item);
+
+	QString mimetype = item->mimetype ();
+	if (mimetype.startsWith ("text/")) {
+		if (mimetype == "text/html") {
+			RKWorkplace::mainWorkplace ()->openHelpWindow (item->url (), true);
+		} else {
+			RKWorkplace::mainWorkplace ()->openScriptEditor (item->url ());
+		}
+	} else {
+		new KRun (item->url (), item->mode (), item->isLocalFile ());
+	}
+}
+
 #include "rkfilebrowser.moc"

Modified: trunk/rkward/rkward/windows/rkfilebrowser.h
===================================================================
--- trunk/rkward/rkward/windows/rkfilebrowser.h	2007-04-26 20:52:58 UTC (rev 1854)
+++ trunk/rkward/rkward/windows/rkfilebrowser.h	2007-04-27 13:32:43 UTC (rev 1855)
@@ -20,9 +20,14 @@
 
 #include "rkmdiwindow.h"
 
+#include <qvbox.h>
+
 class KDirOperator;
-class QVBox;
+class RKFileBrowserWidget;
+class KURLComboBox;
+class KFileItem;
 
+/** The file browser (tool) window. In order to save some startup time, the file browser is not really created until it is first shown. Hence, this is mostly just a wrapper around RKFileBrowserWidget */
 class RKFileBrowser : public RKMDIWindow {
 	Q_OBJECT
 public:
@@ -31,13 +36,32 @@
 
 /** reimplemented to create the real file browser widget only when the file browser is shown for the first time */
 	void show ();
-/** reimplemented to call close on the browser widget */
-	void hide ();
 public slots:
 	void currentWDChanged ();
 private:
-	KDirOperator *real_widget;
-	QVBox *wrapper;
+	RKFileBrowserWidget *real_widget;
+	QVBox *layout_widget;
 };
 
+/** 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.
+*/
+class RKFileBrowserWidget : public QVBox {
+	Q_OBJECT
+public:
+	RKFileBrowserWidget (QWidget *widget);
+	~RKFileBrowserWidget ();
+
+	bool eventFilter (QObject *watched, QEvent *e);
+	void setURL (const QString &url);
+public slots:
+	void urlChangedInView (const KURL &url);
+	void urlChangedInCombo (const QString &url);
+	void urlChangedInCombo (const KURL &url);
+	void fileActivated (const KFileItem *item);
+private:
+	KDirOperator *dir;
+	KURLComboBox *urlbox;
+};
+
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list