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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Apr 24 13:05:38 UTC 2007


Revision: 1841
          http://svn.sourceforge.net/rkward/?rev=1841&view=rev
Author:   tfry
Date:     2007-04-24 06:05:38 -0700 (Tue, 24 Apr 2007)

Log Message:
-----------
Try hard to always keep a window active, and a number of cosmetics

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

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/rkward.cpp	2007-04-24 13:05:38 UTC (rev 1841)
@@ -650,7 +650,7 @@
 void RKWardMainWindow::activateDocumentView () {
 	RK_TRACE (APP);
 
-	RKMDIWindow *window = RKWorkplace::mainWorkplace ()->activeAttachedWindow ();
+	RKMDIWindow *window = RKWorkplace::mainWorkplace ()->view ()->activePage ();
 	if (window) window->activate ();
 }
 
@@ -779,7 +779,7 @@
 void RKWardMainWindow::slotDetachWindow () {
 	RK_TRACE (APP);
 
-	RKWorkplace::mainWorkplace ()->detachWindow (RKWorkplace::mainWorkplace ()->activeAttachedWindow ());
+	RKWorkplace::mainWorkplace ()->detachWindow (RKWorkplace::mainWorkplace ()->activeWindow (RKMDIWindow::Attached));
 }
 
 void RKWardMainWindow::setRStatus (bool busy) {
@@ -854,7 +854,7 @@
 	QString wcaption = RObjectList::getObjectList ()->getWorkspaceURL ().fileName ();
 	if (wcaption.isEmpty ()) wcaption = RObjectList::getObjectList ()->getWorkspaceURL ().prettyURL ();
 	if (wcaption.isEmpty ()) wcaption = i18n ("[Unnamed Workspace]");
-	RKMDIWindow *window = RKWorkplace::mainWorkplace ()->activeAttachedWindow ();
+	RKMDIWindow *window = RKWorkplace::mainWorkplace ()->activeWindow (RKMDIWindow::Attached);
 	if (window) wcaption.append (" - " + window->fullCaption ());
 	KMdiMainFrm::setCaption (wcaption);
 }

Modified: trunk/rkward/rkward/robjectbrowser.cpp
===================================================================
--- trunk/rkward/rkward/robjectbrowser.cpp	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/robjectbrowser.cpp	2007-04-24 13:05:38 UTC (rev 1841)
@@ -197,7 +197,7 @@
 	
 	if (!object) return;
 	if (object == RObjectList::getObjectList ()) return;
-	QWidget *w = RKWorkplace::mainWorkplace ()->activeAttachedWindow ();
+	QWidget *w = RKWorkplace::mainWorkplace ()->activeWindow (RKMDIWindow::Attached);
 	if (!w) return;
 	
 	if (w->inherits ("RKCommandEditorWindow")) {

Modified: trunk/rkward/rkward/windows/rkmdiwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.h	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/windows/rkmdiwindow.h	2007-04-24 13:05:38 UTC (rev 1841)
@@ -40,8 +40,9 @@
 		WorkspaceBrowserWindow=128,
 		SearchHelpWindow=256,
 		PendingJobsWindow=512,
+		DocumentWindow = DataEditorWindow | CommandEditorWindow | OutputWindow | HelpWindow,
 		ToolWindow = ConsoleWindow | CommandLogWindow | WorkspaceBrowserWindow | SearchHelpWindow | PendingJobsWindow,
-		AnyType=DataEditorWindow | CommandEditorWindow | OutputWindow | HelpWindow | ToolWindow
+		AnyType= DocumentWindow | ToolWindow
 	};
 
 	enum State {

Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp	2007-04-24 13:05:38 UTC (rev 1841)
@@ -278,13 +278,16 @@
 	RK_TRACE (APP);
 	RK_ASSERT (windows.find (window) != windows.end ());
 
+	bool tool_window = window->isToolWindow ();
 	window->close (true);		// all the rest should happen in windowDestroyed ()
+	
+	if (tool_window) windowRemoved ();	// for regular windows, this happens in windowDestroyed(), already
 }
 
 void RKWorkplace::closeActiveWindow () {
 	RK_TRACE (APP);
 
-	RKMDIWindow *w = activeAttachedWindow ();
+	RKMDIWindow *w = activeWindow (RKMDIWindow::Attached);
 	if (w) closeWindow (w);
 }
 
@@ -313,17 +316,63 @@
 	RK_TRACE (APP);
 	RKMDIWindow *window = static_cast<RKMDIWindow *> (object);
 
+	// WARNING: the window is dead. Don't call any functions on it.
+
 	RK_ASSERT (windows.find (window) != windows.end ());
-	if (window->isAttached ()) view ()->removePage (window, true);
+	if (view ()->hasPage (window)) view ()->removePage (window, true);
 	windows.remove (window);
+
+	windowRemoved ();
 }
 
-RKMDIWindow *RKWorkplace::activeAttachedWindow () {
+void RKWorkplace::windowRemoved () {
 	RK_TRACE (APP);
 
+	if (activeWindow (RKMDIWindow::AnyWindowState) != 0) return;	// something already active
+
+	// try to activate an attached document window, first
+	RKMDIWindow *window = view ()->activePage ();
+	if (window) {
+		window->activate (true);
+		return;
+	}
+
+	// some document window in the history? Try that.
+	if (history->haveNext ()) {
+		history->next ();
+		return;
+	} else if (history->havePrev ()) {
+		history->prev ();
+		return;
+	}
+
+	// now try to activate an attached (tool) window, if one is visible
+	for (RKWorkplaceObjectList::const_iterator it = windows.constBegin (); it != windows.constEnd (); ++it) {
+		if ((*it)->isAttached ()) {
+			if ((*it)->isVisible ()) {
+				(*it)->activate (true);
+				return;
+			}
+		}
+	}
+
+	// nothing, yet? Try *any* visible window
+	for (RKWorkplaceObjectList::const_iterator it = windows.constBegin (); it != windows.constEnd (); ++it) {
+		if ((*it)->isVisible ()) {
+			(*it)->activate (true);
+			return;
+		}
+	}
+
+	// give up
+}
+
+RKMDIWindow *RKWorkplace::activeWindow (RKMDIWindow::State state) {
+	RK_TRACE (APP);
+
 	RKMDIWindow *ret = 0;
 	for (RKWorkplaceObjectList::const_iterator it = windows.constBegin (); it != windows.constEnd (); ++it) {
-		if (!(*it)->isAttached()) continue;
+		if (!(state & ((*it)->state))) continue;
 
 		if ((*it)->isActive ()) {
 			ret = *it;

Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/windows/rkworkplace.h	2007-04-24 13:05:38 UTC (rev 1841)
@@ -84,8 +84,8 @@
 	void attachWindow (RKMDIWindow *window);
 /** Dettach a window (it is removed from the view (), and placed in a top-level DetachedWindowContainer instead. */
 	void detachWindow (RKMDIWindow *window, bool was_attached=true);
-/** @returns a pointer to the current window. Detached windows are not considered, only those attached to the workplace(view) */
-	RKMDIWindow *activeAttachedWindow ();
+/** @returns a pointer to the current window. state specifies, which windows should be considered. */
+	RKMDIWindow *activeWindow (RKMDIWindow::State state);
 
 /** Opens a new script editor
 @param url URL to load. Default option is to open an empty document
@@ -167,6 +167,8 @@
 	void addWindow (RKMDIWindow *window, bool attached=true);
 /** static pointer to the workplace. @See mainWorkplace () */
 	static RKWorkplace *main_workplace;
+/** a window was removed. Try to activate some other window. */
+	void windowRemoved ();
 
 	void restoreWorkplaceItem (const QString &desc);
 	RKMDIWindowHistory *history;

Modified: trunk/rkward/rkward/windows/rkworkplaceview.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplaceview.cpp	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/windows/rkworkplaceview.cpp	2007-04-24 13:05:38 UTC (rev 1841)
@@ -129,6 +129,10 @@
 	setPage (id);		// active new window
 }
 
+bool RKWorkplaceView::hasPage (RKMDIWindow *widget) {
+	return (idOfWidget (widget) != -1);
+}
+
 void RKWorkplaceView::removePage (RKMDIWindow *widget, bool destroyed) {
 	RK_TRACE (APP);
 

Modified: trunk/rkward/rkward/windows/rkworkplaceview.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplaceview.h	2007-04-24 12:00:24 UTC (rev 1840)
+++ trunk/rkward/rkward/windows/rkworkplaceview.h	2007-04-24 13:05:38 UTC (rev 1841)
@@ -41,6 +41,8 @@
 /** remove the given window to the view
 @param destroyed if the window is already destroyed, set this to true */
 	void removePage (RKMDIWindow *widget, bool destroyed=false);
+/** does this window exist in the view? */
+	bool hasPage (RKMDIWindow *widget);
 
 /** activate the given window */
 	void setActivePage (RKMDIWindow *widget);


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