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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Feb 19 12:03:14 UTC 2007


Revision: 1413
          http://svn.sourceforge.net/rkward/?rev=1413&view=rev
Author:   tfry
Date:     2007-02-19 04:03:13 -0800 (Mon, 19 Feb 2007)

Log Message:
-----------
Integrate tool windows into RKMDIWindow framework. Part I. Seems to work for console

Modified Paths:
--------------
    trunk/rkward/rkward/rkconsole.cpp
    trunk/rkward/rkward/rkconsole.h
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/rkward.h
    trunk/rkward/rkward/windows/rkmdiwindow.cpp
    trunk/rkward/rkward/windows/rkmdiwindow.h
    trunk/rkward/rkward/windows/rkworkplace.cpp
    trunk/rkward/rkward/windows/rkworkplace.h

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/rkconsole.cpp	2007-02-19 12:03:13 UTC (rev 1413)
@@ -47,7 +47,7 @@
 // static
 RKConsole* RKConsole::main_console = 0;
 
-RKConsole::RKConsole () : QWidget (0) {
+RKConsole::RKConsole (QWidget *parent, bool tool_window, char *name) : RKMDIWindow (parent, RKMDIWindow::ConsoleWindow, tool_window, name) {
 	RK_TRACE (APP);
 
 	QVBoxLayout *layout = new QVBoxLayout (this);
@@ -153,6 +153,11 @@
 	RKSettingsModuleConsole::saveCommandHistory (commands_history);
 }
 
+KParts::Part *RKConsole::getPart () {
+	RK_TRACE (APP);
+	return part;
+}
+
 void RKConsole::setRHighlighting () {
 	// set syntax-highlighting for R
 	int modes_count = doc->hlModeCount ();
@@ -666,7 +671,6 @@
 
 	QString command = cleanedSelection ();
 	pipeUserCommand (new RCommand (command, RCommand::User));
-	setFocus ();
 }
 
 void RKConsole::showContextHelp () {
@@ -707,7 +711,7 @@
 void RKConsole::pipeCommandThroughConsoleLocal (RCommand *command) {
 	RK_TRACE (APP);
 
-	emit (raiseWindow ());
+	activate (false);
 	if (isBusy () || (!currentCommand ().isEmpty ())) {
 		int res = KMessageBox::questionYesNo (this, i18n ("You have configured RKWrad to run script commands through the console. However, the console is currently busy (either a command is running, or you have started to enter text in the console). Do you want to bypass the console this one time, or do you want to try again later?"), i18n ("Console is busy"), KGuiItem (i18n ("Bypass console")), KGuiItem (i18n ("Cancel")));
 		if (res == KMessageBox::Yes) {

Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/rkconsole.h	2007-02-19 12:03:13 UTC (rev 1413)
@@ -27,6 +27,7 @@
 
 #include "rbackend/rcommandreceiver.h"
 #include "windows/rkcommandeditorwindow.h"
+#include "windows/rkmdiwindow.h"
 
 class QStringList;
 class KAction;
@@ -46,11 +47,11 @@
 @author Pierre Ecochard
 **/
 
-class RKConsole : public QWidget, public RCommandReceiver, public RKScriptContextProvider {
+class RKConsole : public RKMDIWindow, public RCommandReceiver, public RKScriptContextProvider {
 Q_OBJECT
 public:
 /** Constructor. */
-	RKConsole ();
+	RKConsole (QWidget *parent, bool tool_window, char *name=0);
 /** Destructor */
 	~RKConsole ();
 
@@ -77,9 +78,7 @@
 /** Run a user command (through console, if applicable */
 	static void pipeUserCommand (RCommand *command);
 
-	RKConsolePart *getPart () { return part; };
-signals:
-	void raiseWindow ();
+	KParts::Part *getPart ();
 protected:
 /** Handle keystrokes before they reach the kate-part. Return TRUE if we want the kate-part to ignore it
 \param e the QKeyEvent */

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/rkward.cpp	2007-02-19 12:03:13 UTC (rev 1413)
@@ -208,12 +208,10 @@
 	addToolWindow (RKGlobals::rcontrol, KDockWidget::DockBottom, getMainDockWidget (), 10);
 	RKGlobals::rcontrol->hide ();		// this line is important! RControlWindow must do some initializations on first show, and be hidden until then.
 
-	RKConsole *console = new RKConsole ();
+	RKConsole *console = new RKConsole (0, true, "r_console");
 	console->setIcon (SmallIcon ("konsole"));
-	console->setName ("r_console");
-	console_view = addToolWindow (console, KDockWidget::DockBottom, getMainDockWidget (), 10);
-	connect (console, SIGNAL (raiseWindow ()), this, SLOT (raiseConsole ()));
-	partManager ()->addPart (console->getPart (), false);
+	console->setToolWrapper (addToolWindow (console, KDockWidget::DockBottom, getMainDockWidget (), 10));
+	RKWorkplace::mainWorkplace ()->registerToolWindow (console);
 	RKConsole::setMainConsole (console);
 	
 	RKGlobals::helpdlg = new KHelpDlg (0);
@@ -549,15 +547,6 @@
 	}
 }
 
-void RKWardMainWindow::raiseConsole () {
-	RK_TRACE (APP);
-	console_view->show ();
-	KMdiChildView *window = activeWindow ();
-	if (window) {
-		window->activate ();
-	}
-}
-
 void RKWardMainWindow::invokeRHelp () {
 	RK_TRACE (APP);
 

Modified: trunk/rkward/rkward/rkward.h
===================================================================
--- trunk/rkward/rkward/rkward.h	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/rkward.h	2007-02-19 12:03:13 UTC (rev 1413)
@@ -136,8 +136,6 @@
 	void showAboutApplication ();
 	/** raises the watch window */
 	void raiseWatch ();
-	/** raises the console window */
-	void raiseConsole ();
 	/** creates a new (empty) data.frame */
 	void slotNewDataFrame ();
 	/** open a file and load it into the document*/
@@ -225,7 +223,6 @@
 	KAction* configure;
 
 	KMdiToolViewAccessor *watch_view;
-	KMdiToolViewAccessor *console_view;
 	KMdiToolViewAccessor *search_help_view;
 	
 	friend class RKSettingsModule;

Modified: trunk/rkward/rkward/windows/rkmdiwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.cpp	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/windows/rkmdiwindow.cpp	2007-02-19 12:03:13 UTC (rev 1413)
@@ -2,7 +2,7 @@
                           rkmdiwindow  -  description
                              -------------------
     begin                : Tue Sep 26 2006
-    copyright            : (C) 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -17,16 +17,20 @@
 
 #include "rkmdiwindow.h"
 
+#include <qapplication.h>
+
 #include "rkworkplace.h"
 #include "rkworkplaceview.h"
 
 #include "../debug.h"
 
-RKMDIWindow::RKMDIWindow (QWidget *parent, Type type) : QWidget (parent) {
+RKMDIWindow::RKMDIWindow (QWidget *parent, Type type, bool tool_window, char *name) : QWidget (parent, name) {
 	RK_TRACE (APP);
 
 	RKMDIWindow::type = type;
-	state = Attached;
+	if (tool_window) state = ToolWindow;
+	else state = Attached;
+	wrapper = 0;
 }
 
 RKMDIWindow::~RKMDIWindow () {
@@ -52,15 +56,54 @@
 	emit (captionChanged (this));
 }
 
-void RKMDIWindow::activate () {
+void RKMDIWindow::activate (bool with_focus) {
 	RK_TRACE (APP);
 
-	if (isAttached ()) {
-		RKWorkplace::mainWorkplace ()->view ()->setActivePage (this);
+	// WORKAROUND for KMDI: it will always grab focus, so we need to make sure to release it again, if needed
+	QWidget *old_focus = qApp->focusWidget ();
+
+	if (isToolWindow ()) {
+		RK_ASSERT (wrapper);
+		wrapper->wrapperWidget ()->topLevelWidget ()->show ();
+		wrapper->wrapperWidget ()->topLevelWidget ()->raise ();
+		wrapper->show ();
 	} else {
-		topLevelWidget ()->show ();
-		topLevelWidget ()->raise ();
+		if (isAttached ()) {
+			RKWorkplace::mainWorkplace ()->view ()->setActivePage (this);
+		} else {
+			topLevelWidget ()->show ();
+			topLevelWidget ()->raise ();
+		}
 	}
+
+	if (with_focus) setFocus ();
+	else {
+		if (old_focus) old_focus->setFocus ();
+	}
 }
 
+bool RKMDIWindow::close (bool also_delete) {
+	RK_TRACE (APP);
+
+	if (isToolWindow ()) {
+		RK_ASSERT (wrapper);
+		wrapper->hide ();
+		return true;
+	}
+
+	return QWidget::close (also_delete);
+}
+
+void RKMDIWindow::prepareToBeAttached () {
+	RK_TRACE (APP);
+
+	RK_ASSERT (!isToolWindow ());
+}
+
+void RKMDIWindow::prepareToBeDetached () {
+	RK_TRACE (APP);
+
+	RK_ASSERT (!isToolWindow ());
+}
+
 #include "rkmdiwindow.moc"

Modified: trunk/rkward/rkward/windows/rkmdiwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.h	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/windows/rkmdiwindow.h	2007-02-19 12:03:13 UTC (rev 1413)
@@ -2,7 +2,7 @@
                           rkmdiwindow  -  description
                              -------------------
     begin                : Tue Sep 26 2006
-    copyright            : (C) 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -21,6 +21,7 @@
 #include <qwidget.h>
 
 #include <kparts/part.h>
+#include <kmdimainfrm.h>
 
 class RKWorkplace;
 
@@ -34,23 +35,30 @@
 		OutputWindow=4,
 		HelpWindow=8,
 		X11Window=16,
-		AnyType=DataEditorWindow | CommandEditorWindow | OutputWindow | HelpWindow
+		ConsoleWindow=32,
+		CommandLogWindow=64,
+		WorkspaceBrowserWindow=128,
+		SearchHelpWindow=256,
+		PendingJobsWindow=512,
+		AnyType=DataEditorWindow | CommandEditorWindow | OutputWindow | HelpWindow | ConsoleWindow | CommandLogWindow | WorkspaceBrowserWindow | SearchHelpWindow | PendingJobsWindow
 	};
 
 	enum State {
 		Attached=1,
 		Detached=2,
-		AnyState=Attached | Detached
+		AnyNormalWindow=Attached | Detached,
+		ToolWindow=4,
+		AnyWindowState=AnyNormalWindow | ToolWindow
 	};
 protected:
 /** constructor
 @param parent parent widget
 @param type Type of window */
-	RKMDIWindow (QWidget *parent, Type type);
+	RKMDIWindow (QWidget *parent, Type type, bool tool_window=false, char *name=0);
 	virtual ~RKMDIWindow ();
 public:
 /** @returns true, if the window's document was modified (and would need to be saved) */
-	virtual bool isModified () = 0;
+	virtual bool isModified () { return false; };
 /** @returns A long / complete caption. Default implementation simply calls shortCaption () */
 	virtual QString fullCaption ();
 /** @returns A short caption (e.g. only the filename without the path). Default implementation simply calls QWidget::caption () */
@@ -59,18 +67,25 @@
 	virtual KParts::Part *getPart () = 0;
 /** This is used in RKWorkplace::saveWorkplace () to save the info about the workplace. Make sure to add corresponding code to RKWorkplace::restoreWorkplace (), so your window(s) get restored when loading a Workspace
 @returns An internal descriptive string. */
-	virtual QString getDescription () = 0;
+	virtual QString getDescription () { return QString (); };
 /** Reimplemented from QWidget::setCaption () to emit the signal captionChanged () when the caption is changed. */
 	void setCaption (const QString &caption);
 /** Is this window attached (or detached)?
 @returns true if attached, false if detached */
 	bool isAttached () { return (state == Attached); };
-/** Activate (raise) this window, regardless of whether it is attached or detached */
-	void activate ();
-/** If your mdi window should perform any adjustments before being attached, reimplement this function */
-	virtual void prepareToBeAttached () {};
-/** If your mdi window should perform any adjustments before being detached, reimplement this function */
-	virtual void prepareToBeDetached () {};
+/** Is this a tool window? */
+	bool isToolWindow () { return (state == ToolWindow); };
+/** Activate (raise) this window, regardless of whether it is attached or detached
+ at param with_focus Should the window also get keyboard focus? */
+	void activate (bool with_focus=true);
+/** If your mdi window should perform any adjustments before being attached, reimplement this function. Default implementation does nothing, but raises an assert, if this is a tool window */
+	virtual void prepareToBeAttached ();
+/** If your mdi window should perform any adjustments before being detached, reimplement this function. Default implementation does nothing, but raises an assert, if this is a tool window */
+	virtual void prepareToBeDetached ();
+/** Tool windows will only hide themselves, and ignore the also_delete flag */
+	virtual bool close (bool also_delete);
+/** For tool windows only (and perhaps for KDE3 only): set the wrapper widget that should be shown/raised on activation */
+	void setToolWrapper (KMdiToolViewAccessor *wrapper_widget) { wrapper = wrapper_widget; };
 signals:
 /** This signal is emitted, whenever the window caption was changed.
 @param RKMDIWindow* a pointer to this window */
@@ -82,6 +97,7 @@
 private:
 /** state of this window (attached / detached). This is usually set from the RKWorkplace */
 	State state;
+	KMdiToolViewAccessor *wrapper;
 };
 
 #endif

Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp	2007-02-19 12:03:13 UTC (rev 1413)
@@ -65,9 +65,11 @@
 	RK_TRACE (APP);
 	RK_ASSERT (windows.find (window) != windows.end ());		// This should not happen for now.
 
-	window->prepareToBeAttached ();
-	window->state = RKMDIWindow::Attached;
-	view ()->addPage (window);
+	if (!window->isToolWindow ()) {
+		window->prepareToBeAttached ();
+		window->state = RKMDIWindow::Attached;
+		view ()->addPage (window);
+	}
 
 	RK_ASSERT (window->getPart ());
 	RKWardMainWindow::getMain ()->partManager ()->addPart (window->getPart ());
@@ -100,6 +102,13 @@
 	else detachWindow (window, false);
 }
 
+void RKWorkplace::registerToolWindow (RKMDIWindow *window) {
+	RK_TRACE (APP);
+
+	RK_ASSERT (window->isToolWindow ());
+	addWindow (window, true);
+}
+
 bool RKWorkplace::openScriptEditor (const KURL &url, bool use_r_highlighting, bool read_only, const QString &force_caption) {
 	RK_TRACE (APP);
 
@@ -140,7 +149,7 @@
 	}
 
 	if (only_once) {
-		RKWorkplaceObjectList help_windows = getObjectList (RKMDIWindow::HelpWindow, RKMDIWindow::AnyState);
+		RKWorkplaceObjectList help_windows = getObjectList (RKMDIWindow::HelpWindow, RKMDIWindow::AnyWindowState);
 		for (RKWorkplaceObjectList::const_iterator it = help_windows.constBegin (); it != help_windows.constEnd (); ++it) {
 			if (static_cast<RKHelpWindow *> (*it)->url ().equals (url, true)) {
 				(*it)->activate ();

Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h	2007-02-18 15:31:01 UTC (rev 1412)
+++ trunk/rkward/rkward/windows/rkworkplace.h	2007-02-19 12:03:13 UTC (rev 1413)
@@ -50,7 +50,7 @@
 /** Returns a list of all windows in the workplace. */
 	RKWorkplaceObjectList getObjectList () { return windows; };
 /** Returns a list of all windows with a given type and state */
-	RKWorkplaceObjectList getObjectList (int type, int state=RKMDIWindow::AnyState);
+	RKWorkplaceObjectList getObjectList (int type, int state=RKMDIWindow::AnyWindowState);
 
 /** Attach an already created window. */
 	void attachWindow (RKMDIWindow *window);
@@ -98,7 +98,7 @@
 /** Closes all windows of the given type(s). Default call (no arguments) closes all windows
 @param type: A bitwise OR of RKWorkplaceObjectType
 @param state: A bitwise OR of RKWorkplaceObjectState */
-	void closeAll (int type=RKMDIWindow::AnyType, int state=RKMDIWindow::AnyState);
+	void closeAll (int type=RKMDIWindow::AnyType, int state=RKMDIWindow::AnyWindowState);
 
 /** Write a description of all current windows to the R backend. This can later be read by restoreWorkplace (). Has no effect, if RKSettingsModuleGeneral::workplaceSaveMode () != RKSettingsModuleGeneral::SaveWorkplaceWithWorkspace
 @param chain command chain to place the command in */
@@ -120,6 +120,7 @@
 /** In the current design there is only ever one workplace. Use this static function to reference it.
 @returns a pointer to the workplace */
 	static RKWorkplace *mainWorkplace () { return main_workplace; };
+	void registerToolWindow (RKMDIWindow *window);
 signals:
 /** TODO: For future expansion. This signal is neither emitted nor used so far. It could be used to deactivate some options in the "Window" menu. Or maybe it can be removed? */
 	void lastWindowClosed ();


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