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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue May 8 12:46:31 UTC 2007


Revision: 1883
          http://svn.sourceforge.net/rkward/?rev=1883&view=rev
Author:   tfry
Date:     2007-05-08 05:46:31 -0700 (Tue, 08 May 2007)

Log Message:
-----------
More delayed initialization of the workspace browser

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/robjectbrowser.cpp
    trunk/rkward/rkward/robjectbrowser.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-05-08 12:00:15 UTC (rev 1882)
+++ trunk/rkward/ChangeLog	2007-05-08 12:46:31 UTC (rev 1883)
@@ -1,4 +1,5 @@
-- support for including files and snippets in xml files		TODO: document, use
+- create the workspace browser only when it is first shown
+- support for including files and snippets in xml files		TODO: use more
 - all file selection line edits gain filename-completion
 - add a basic file selector window
 - show the focus indication (thin red border) also for detached windows

Modified: trunk/rkward/rkward/robjectbrowser.cpp
===================================================================
--- trunk/rkward/rkward/robjectbrowser.cpp	2007-05-08 12:00:15 UTC (rev 1882)
+++ trunk/rkward/rkward/robjectbrowser.cpp	2007-05-08 12:46:31 UTC (rev 1883)
@@ -23,6 +23,7 @@
 #include <qcheckbox.h>
 #include <qradiobutton.h>
 #include <qbuttongroup.h>
+#include <qvbox.h>
 
 #include <klocale.h>
 #include <kinputdialog.h>
@@ -49,8 +50,57 @@
 
 RObjectBrowser::RObjectBrowser (QWidget *parent, bool tool_window, char *name) : RKMDIWindow (parent, WorkspaceBrowserWindow, tool_window, name) {
 	RK_TRACE (APP);
-	setPart (new RKDummyPart (0, this));
+
+	internal = 0;
+	locked = true;
+
+	QVBoxLayout *layout = new QVBoxLayout (this);
+	layout_widget = new QVBox (this);
+	layout->addWidget (layout_widget);
+	layout_widget->setFocusPolicy (QWidget::StrongFocus);
+
+	RKDummyPart *part = new RKDummyPart (this, layout_widget);
+	setPart (part);
 	initializeActivationSignals ();
+}
+
+RObjectBrowser::~RObjectBrowser () {
+	RK_TRACE (APP);
+}
+
+void RObjectBrowser::unlock () {
+	RK_TRACE (APP);
+
+	locked = false;
+	if (isShown ()) {
+		initialize ();
+	}
+}
+
+void RObjectBrowser::show () {
+	RK_TRACE (APP);
+
+	initialize ();
+	RKMDIWindow::show ();
+}
+
+void RObjectBrowser::initialize () {
+	RK_TRACE (APP);
+
+	if (internal) return;
+	if (locked) return;
+
+	RK_DO (qDebug ("creating workspace browser"), APP, DL_INFO);
+
+	internal = new RObjectBrowserInternal (layout_widget);
+	layout_widget->setFocusProxy (internal);
+	setMinimumSize (internal->minimumSize ());
+}
+
+
+///////////////////////// RObjectBrowserInternal /////////////////////////////
+RObjectBrowserInternal::RObjectBrowserInternal (QWidget *parent) : QWidget (parent) {
+	RK_TRACE (APP);
 	setFocusPolicy (QWidget::ClickFocus);
 
 	QVBoxLayout *vbox = new QVBoxLayout (this);
@@ -78,60 +128,40 @@
 	
 	resize (minimumSizeHint ().expandedTo (QSize (400, 480)));
 
-	initialized = false;
-	locked = true;
+	list_view->initialize ();
+	connect (update_button, SIGNAL (clicked ()), this, SLOT (updateButtonClicked ()));
 }
 
-RObjectBrowser::~RObjectBrowser () {
+RObjectBrowserInternal::~RObjectBrowserInternal () {
 	RK_TRACE (APP);
 }
 
-void RObjectBrowser::focusInEvent (QFocusEvent *e) {
+void RObjectBrowserInternal::focusInEvent (QFocusEvent *e) {
 	RK_TRACE (APP);
 
 	list_view->setFocus ();
 	if (e->reason () != QFocusEvent::Mouse) {
 		list_view->setObjectCurrent (RObjectList::getGlobalEnv (), true);
 	}
-	initialize ();
 }
 
-void RObjectBrowser::unlock () {
+void RObjectBrowserInternal::updateButtonClicked () {
 	RK_TRACE (APP);
-
-	locked = false;
-	if (hasFocus ()) initialize ();
-}
-
-void RObjectBrowser::initialize () {
-	RK_TRACE (APP);
-	if (initialized) return;
-	if (locked) return;
-
-	list_view->initialize ();
-	
-	connect (update_button, SIGNAL (clicked ()), this, SLOT (updateButtonClicked ()));
-
-	initialized = true;
-}
-
-void RObjectBrowser::updateButtonClicked () {
-	RK_TRACE (APP);
 	RObjectList::getObjectList ()->updateFromR (0);
 }
 
-void RObjectBrowser::popupHelp () {
+void RObjectBrowserInternal::popupHelp () {
 	RK_TRACE (APP);
 
 	if (list_view->menuObject ()) RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (list_view->menuObject ()->getShortName ());
 }
 
-void RObjectBrowser::popupEdit () {
+void RObjectBrowserInternal::popupEdit () {
 	RK_TRACE (APP);
 	if (list_view->menuObject ()) RKWorkplace::mainWorkplace ()->editObject (list_view->menuObject ());
 }
 
-void RObjectBrowser::popupCopy () {
+void RObjectBrowserInternal::popupCopy () {
 	RK_TRACE (APP);
 
 	bool ok;
@@ -146,7 +176,7 @@
 	}
 }
 
-void RObjectBrowser::popupCopyToGlobalEnv () {
+void RObjectBrowserInternal::popupCopyToGlobalEnv () {
 	RK_TRACE (APP);
 
 	RObject *object = list_view->menuObject ();
@@ -157,18 +187,18 @@
 	RKGlobals::rInterface ()->issueCommand (RObject::rQuote (valid) + " <- " + object->getFullName (), RCommand::App | RCommand::ObjectListUpdate);
 }
 
-void RObjectBrowser::popupView () {
+void RObjectBrowserInternal::popupView () {
 	RK_TRACE (APP);
 	RKWorkplace::mainWorkplace ()->flushAllData ();
 	new RObjectViewer (0, list_view->menuObject ());
 }
 
-void RObjectBrowser::popupDelete () {
+void RObjectBrowserInternal::popupDelete () {
 	RK_TRACE (APP);
 	RKGlobals::tracker ()->removeObject (list_view->menuObject ());
 }
 
-void RObjectBrowser::popupRename () {
+void RObjectBrowserInternal::popupRename () {
 	RK_TRACE (APP);
 	bool ok;
 	QString name = KInputDialog::getText (i18n ("Rename object"), i18n ("Enter the new name"), list_view->menuObject ()->getShortName (), &ok, this);
@@ -180,7 +210,7 @@
 	}
 }
 
-void RObjectBrowser::contextMenuCallback (RKListViewItem *, bool *) {
+void RObjectBrowserInternal::contextMenuCallback (RKListViewItem *, bool *) {
 	RK_TRACE (APP);
 	RObject *object = list_view->menuObject ();
 	QPopupMenu *menu = list_view->contextMenu ();
@@ -206,7 +236,7 @@
 	menu->setItemVisible (Delete, object->canRemove ());
 }
 
-void RObjectBrowser::slotListDoubleClicked (QListViewItem *item, const QPoint &, int) {
+void RObjectBrowserInternal::slotListDoubleClicked (QListViewItem *item, const QPoint &, int) {
 	RK_TRACE (APP);
 	RObject *object = list_view->findItemObject (static_cast<RKListViewItem*> (item));
 	

Modified: trunk/rkward/rkward/robjectbrowser.h
===================================================================
--- trunk/rkward/rkward/robjectbrowser.h	2007-05-08 12:00:15 UTC (rev 1882)
+++ trunk/rkward/rkward/robjectbrowser.h	2007-05-08 12:46:31 UTC (rev 1883)
@@ -30,22 +30,47 @@
 class QPopupMenu;
 class RObject;
 class RKCommandEditorWindow;
+class RObjectBrowserInternal;
+class QVBox;
 
 /**
 This widget provides a browsable list of all objects in the R workspace
 
+Note: Most actual functionality is realized in RObjectBrowserInternal, which is created as soon as the RObjectBrowser is shown for the first time.
+
 @author Thomas Friedrichsmeier
 */
 class RObjectBrowser : public RKMDIWindow {
-Q_OBJECT
 public:
 	RObjectBrowser (QWidget *parent, bool tool_window, char *name=0);
 	~RObjectBrowser ();
+	void unlock ();
+	static RObjectBrowser *mainBrowser () { return object_browser; };
+/** reimplemented to create the real file browser widget only when the file browser is shown for the first time */
+	void show ();
+private:
+	RObjectBrowserInternal *internal;
+	QVBox *layout_widget;
 
+	bool locked;
+	friend class RKWardMainWindow;
+	static RObjectBrowser *object_browser;
+	void initialize ();
+};
+
+/**
+Provides most of the functionality of RObjectBrowser
+
+ at author Thomas Friedrichsmeier
+*/
+class RObjectBrowserInternal : public QWidget {
+Q_OBJECT
+public:
+	RObjectBrowserInternal (QWidget *parent);
+	~RObjectBrowserInternal ();
+
 	enum PopupItems { Help=1, Edit=2, View=3, Rename=4, Copy=5, CopyToGlobalEnv=6, Delete=7 };
-	static RObjectBrowser *mainBrowser () { return object_browser; };
-	void unlock ();
-public slots:
+private slots:
 	void updateButtonClicked ();
 	void contextMenuCallback (RKListViewItem *item, bool *suppress);
 	
@@ -65,12 +90,6 @@
 private:
 	QPushButton *update_button;
 	RKObjectListView *list_view;
-	bool initialized;
-	bool locked;
-
-	void initialize ();
-	friend class RKWardMainWindow;
-	static RObjectBrowser *object_browser;
 };
 
 /** This class provides a widget to switch quickly between the most important RKObjectListViewSettings */


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