[Monodevelop-patches-list] r2285 - trunk/MonoDevelop/Unused/Gdl

John Luke <jluke@cfl.rr.com> jluke at mono-cvs.ximian.com
Wed Mar 2 18:37:26 EST 2005


Author: jluke
Date: 2005-03-02 18:37:26 -0500 (Wed, 02 Mar 2005)
New Revision: 2285

Added:
   trunk/MonoDevelop/Unused/Gdl/TODO
Modified:
   trunk/MonoDevelop/Unused/Gdl/DockLayout.cs
   trunk/MonoDevelop/Unused/Gdl/DockPlacement.cs
   trunk/MonoDevelop/Unused/Gdl/GdlDockTest.cs
   trunk/MonoDevelop/Unused/Gdl/Makefile
Log:
flush


Modified: trunk/MonoDevelop/Unused/Gdl/DockLayout.cs
===================================================================
--- trunk/MonoDevelop/Unused/Gdl/DockLayout.cs	2005-03-02 02:20:07 UTC (rev 2284)
+++ trunk/MonoDevelop/Unused/Gdl/DockLayout.cs	2005-03-02 23:37:26 UTC (rev 2285)
@@ -1,156 +1,420 @@
 using System;
 using System.Collections;
+using System.IO;
 using System.Xml;
-using System.Xml.Serialization;
 using Gtk;
 
 namespace Gdl
 {
 	public class DockLayout
 	{
-		DockMaster master;
-		Widget itemsui;
-		Widget layoutsui;
-		ArrayList layouts;
-		bool dirty;
 		XmlDocument doc;
+		ListStore itemsModel;
+		ListStore layoutsModel;
+		bool dirty = false;
+		bool idleSavePending = false;
 
+		Widget itemsUI, layoutsUI;
+		DockMaster master = null;
+		ArrayList layouts;
+
 		public DockLayout (Dock dock)
 		{
 			layouts = new ArrayList ();
 			this.Attach (dock.Master);
 		}
-		
-		public DockMaster Master {
-			get { return master; }
-			set { master = value; }
-		}
-		
-		public bool IsDirty {
+
+		public Widget ItemsUI {
 			get {
-				return dirty;
+				if (itemsUI == null)
+					itemsUI = ConstructItemsUI ();
+				return itemsUI;
 			}
 		}
-		
-		public Widget ItemsUi { 
-			get {
-				return itemsui;
-			}
+
+		public ArrayList Layouts {
+			get { return layouts; }
 		}
-		
-		public Widget LayoutsUi { 
+
+		public Widget LayoutsUI {
 			get {
-				return layoutsui;
+				if (layoutsUI == null)
+					layoutsUI = ConstructLayoutsUI ();
+				return layoutsUI;
 			}
 		}
 
-		public string[] Layouts {
-			get {
-				return layouts.ToArray (typeof (string)) as string[];
-			}
+		public DockMaster Master {
+			get { return master; }
+			set { master = value; }
 		}
-		
+
+		public Widget UI {
+			get { return ConstructUI ();}
+		}
+
+        // true if the layouts have changed and need to be saved to a file
+		public bool IsDirty {
+			get { return dirty; }
+		}
+
 		public void Attach (DockMaster master)
 		{
-			if (this.master != null)
-				master.LayoutChanged -= OnLayoutChanged;
+			if (master == null)
+				return;
 
+			master.LayoutChanged -= OnLayoutChanged;
+
+			if (itemsModel != null)
+				itemsModel.Clear ();
+
 			this.master = master;
 			master.LayoutChanged += OnLayoutChanged;
+			UpdateItemsModel ();
 		}
-		
+
 		public void DeleteLayout (string name)
 		{
+			// dont allow deletion of default layout
+			if (name == null || name == "__default__")
+				return;
+
+			XmlNode node = FindLayout (name);
+			if (node != null) {
+				doc.RemoveChild (node);
+				dirty = true;
+				// notify dirty
+			}
 		}
-	
-		public void LoadLayout (string newLayout)
+
+		public void Dump ()
 		{
+			XmlTextWriter writer = new XmlTextWriter (Console.Out);
+			writer.Formatting = Formatting.Indented;
+			doc.WriteTo (writer);
 		}
-		
-		public void LoadFromFile (string configFile)
+
+		public bool LoadFromFile (string file)
 		{
-			doc = new XmlDocument ();
-			doc.Load (configFile);
-			XmlNodeList nodes = doc.SelectNodes ("/dock-layout/layout");
-			foreach (XmlNode n in nodes)
-				LoadLayout (n);
+			if (doc != null) {
+				doc = null;
+				dirty = false;
+				// notify dirty
+			}
+
+			if (File.Exists (file))
+			{
+				doc = new XmlDocument ();
+				doc.Load (file);
+				// minimum validation: test root element
+				if (doc.SelectSingleNode ("/dock-layout") != null) {
+					UpdateLayoutsModel ();
+					return true;
+				}
+				else {
+					doc = null;	
+				}
+			}
+
+			return false;
 		}
 
-		void LoadLayout (XmlNode node)
+		public bool LoadLayout (string name)
 		{
-			layouts.Add (node.Attributes["name"].Value);
-			LoadDock (node["dock"]);
+			if (doc == null || master == null)
+				return false;
+
+			if (name == null || name.Length < 1)
+				name = "__default__";
+
+			XmlNode node = FindLayout (name);
+			if (node == null)
+				node = FindLayout (null);
+			
+			if (node == null)
+				return false;
+
+			Load (node);
+			return true;
 		}
 
-		void LoadDock (XmlNode node)
+		public void RunManager ()
 		{
-			Dock dock = new Dock ();
-			foreach (XmlNode child in node.ChildNodes)
+			if (master == null)
+				return;
+
+			Widget container = ConstructUI ();
+			if (container == null)
+				return;
+
+			Widget parent = master.Controller;
+			if (parent != null)
+				parent = parent.Toplevel;
+
+			Dialog dialog = new Dialog ();
+			dialog.Title = "Layout management";
+			dialog.TransientFor = parent as Window;
+			dialog.AddButton (Gtk.Stock.Close, Gtk.ResponseType.Close);
+			dialog.SetDefaultSize (-1, 300);
+			dialog.VBox.Add (container);
+			dialog.Run ();
+			dialog.Destroy ();
+		}
+
+		public void SaveLayout (string name)
+		{
+			if (master == null)
+				return;
+
+			if (doc == null)
+				BuildDoc ();
+
+			if (name == null || name.Length < 1)
+				name = "__default__";
+
+			// delete any previous node with the same name
+			XmlNode node = FindLayout (name);
+			if (node != null)
+				doc.RemoveChild (node);
+
+			// create the new node
+			doc.CreateNode (XmlNodeType.Element, "layout", null);
+			// FIXME:set name attribute to name
+
+			// save the layout
+			Save (node);
+			dirty = true;
+			// notify dirty
+		}
+
+		public bool SaveToFile (string file)
+		{
+			if (file == null)
+				return false;
+
+			// if there is still no xml doc, create an empty one
+			if (doc == null)
+				BuildDoc ();
+
+			XmlTextWriter writer = new XmlTextWriter (file, System.Text.Encoding.UTF8);
+			writer.Formatting = Formatting.Indented;
+			doc.WriteTo (writer);
+			dirty = false;
+			// notify dirty
+			return true;
+		}
+
+		void BuildModels ()
+		{
+			// NAME, SHOW, LOCKED, ITEM
+			itemsModel = new ListStore (typeof (string), typeof (bool), typeof (bool), typeof (DockItem));
+			itemsModel.SetSortColumnId (0, SortType.Ascending);
+			layoutsModel = new ListStore (typeof (string), typeof (bool));
+			layoutsModel.SetSortColumnId (0, SortType.Ascending);
+		}
+
+		void BuildDoc ()
+		{
+			doc = new XmlDocument ();
+			doc.CreateXmlDeclaration ("1.0", null, null);
+			doc.CreateNode (XmlNodeType.Element, "dock-layout", null);
+		}
+
+		XmlNode FindLayout (string name)
+		{
+			if (doc == null)
+				return null;
+
+			foreach (XmlNode n in doc.SelectNodes ("/dock-layout/layout"))
 			{
-				switch (child.Name) {
-					case "notebook":
-						LoadNotebook (child);
-						break;
-					default:
-						Console.WriteLine (child.Name);
-						break;
-				}
-			}	
+				if (n.Attributes["name"].Value == name)
+					return n;
+			}
+
+			return null;
 		}
 
-		void LoadNotebook (XmlNode node)
+		void UpdateItemsModel ()
 		{
-			DockNotebook notebook = new DockNotebook ();
-			notebook.Orientation = node.Attributes ["orientation"].Value == "vertical" ? Orientation.Vertical : Orientation.Horizontal;
-			notebook.Page = int.Parse (node.Attributes ["page"].Value);
+			if (itemsModel == null || master == null)
+				return;
 
-			foreach (XmlNode child in node.ChildNodes)
-			{
-				switch (child.Name) {
-					case "item":
-						LoadItem (child);
-						break;
-					default:
-						Console.WriteLine (child.Name);
-						break;
+			// build items list
+			ArrayList items = new ArrayList ();
+    		//gdl_dock_master_foreach (master, BuildList, out items);
+			foreach (object o in master.DockObjects) {
+				if (o is DockItem)
+					items.Add (o);
+			}
+
+			TreeIter iter;
+			// update items model data after a layout load
+    		if (itemsModel.GetIterFirst (out iter)) {
+				bool valid = true;
+				while (valid) {
+					DockItem item = itemsModel.GetValue (iter, 3) as DockItem;
+					if (item != null) {
+                		// look for the object in the items list
+						foreach (DockItem di in items)
+						{
+                    		// found, update data
+							if (item == di) {
+								itemsModel.SetValue (iter, 0, item.Name);
+								itemsModel.SetValue (iter, 1, item.IsAttached);
+								itemsModel.SetValue (iter, 2, item.Locked);
+							}
+
+                    		// remove the item from the linked list and keep on walking the model
+							items.Remove (di);
+                    		valid = itemsModel.IterNext (ref iter);
+						}
+					}
+					else {
+                		// not a valid row
+                		valid = itemsModel.Remove (ref iter);
+					}
 				}
-			}	
+			}
+
+			// add any remaining objects
+			foreach (DockItem ditem in items)
+				itemsModel.AppendValues (ditem.Name, ditem.IsAttached, ditem.Locked, ditem);
 		}
 
-		void LoadItem (XmlNode node)
+		void UpdateLayoutsModel ()
 		{
-			string name = node.Attributes ["name"].Value;
-			string locked = node.Attributes ["locked"].Value;
-			DockItem item = new DockItem (name, name, DockItemBehavior.Normal);
-			item.Orientation = node.Attributes ["orientation"].Value == "vertical" ? Orientation.Vertical : Orientation.Horizontal;
+			if (master == null || layoutsModel == null)
+				return;
+
+			// build layouts list
+			layoutsModel.Clear ();
+    		ArrayList items = this.Layouts;
+			foreach (string s in items)
+				layoutsModel.AppendValues (s, true);
 		}
-		
-		public void RunManager ()
+
+		Notebook ConstructUI ()
 		{
+			Notebook notebook = new Notebook ();
+			notebook.Show ();
+
+			Widget child;
+
+			child = ConstructItemsUI ();
+			if (child != null)
+				notebook.AppendPage (child, new Label ("Items"));
+
+			child = ConstructLayoutsUI ();
+			if (child != null)
+				notebook.AppendPage (child, new Label ("Layouts"));
+
+			notebook.CurrentPage = 0;
+			return notebook;
 		}
-		
-		public void SaveLayout (string currentLayout)
+
+		Widget ConstructItemsUI ()
 		{
+			return null;
 		}
-		
-		public void SaveToFile (string file)
+
+		Widget ConstructLayoutsUI ()
 		{
-			XmlTextWriter writer = new XmlTextWriter (file, System.Text.Encoding.UTF8);
-			writer.Formatting = Formatting.Indented;
-			doc.WriteTo (writer);
+			return null;
 		}
 
-		public void Dump ()
+		Glade.XML LoadInterface (string topWidget)
 		{
-			XmlTextWriter writer = new XmlTextWriter (Console.Out);
-			writer.Formatting = Formatting.Indented;
-			doc.WriteTo (writer);
+			return null;
 		}
 
+		DockObject SetupObject (DockMaster master, XmlNode node)
+		{
+			return null;
+		}
+
+		void RecursiveBuild (XmlNode parentNode, DockObject parent)
+		{
+		}
+
+		void ForeachDetach (DockObject obj)
+		{
+			obj.Detach (true);
+		}
+
+		void ForeachToplevelDetach (DockObject obj)
+		{
+			//((Container)obj).Foreach (ForeachDetach);
+		}
+
+		void Load (XmlNode node)
+		{
+			if (node == null)
+				return;
+
+			// start by detaching all items from the toplevels
+			//gdl_dock_master_foreach_toplevel (master, TRUE, (GFunc) gdl_dock_layout_foreach_toplevel_detach, NULL);
+
+			RecursiveBuild (node, null);
+		}
+
+		void ForeachObjectSave (DockObject obj)
+		{
+		}
+
+		void AddPlaceholder (DockObject obj, Hashtable placeholders)
+		{
+			if (obj is DockPlaceholder) {
+			}
+		}
+
+		void Save (XmlNode node)
+		{
+		}
+
+		bool IdleSave ()
+		{
+			//SaveLayout (this);
+			idleSavePending = false;
+			return false;
+		}
+
 		void OnLayoutChanged (object sender, EventArgs a)
 		{
-			Console.WriteLine ("layout changed");
+			UpdateItemsModel ();
+
+			if (!idleSavePending) {
+				GLib.Idle.Add (IdleSave);
+				idleSavePending = true;
+			}
 		}
+
+		void LoadLayoutCb (object sender, EventArgs a)
+		{
+		}
+
+		void DeleteLayoutCb (object sender, EventArgs a)
+		{
+		}
+
+		void ShowToggledCb (object sender, EventArgs a)
+		{
+		}
+
+		void AllLockedToggledCb (object sender, EventArgs a)
+		{
+		}
+
+		void LayoutUIDestroyed (object sender, EventArgs a)
+		{
+		}
+
+		void MasterLockedNotifyCb (object sender, EventArgs a)
+		{
+		}
+
+		void CellEditedCb (object sender, EventArgs a)
+		{
+		}
 	}
 }
 

Modified: trunk/MonoDevelop/Unused/Gdl/DockPlacement.cs
===================================================================
--- trunk/MonoDevelop/Unused/Gdl/DockPlacement.cs	2005-03-02 02:20:07 UTC (rev 2284)
+++ trunk/MonoDevelop/Unused/Gdl/DockPlacement.cs	2005-03-02 23:37:26 UTC (rev 2285)
@@ -1,13 +1,10 @@
-// This file was generated by the Gtk# code generator.
-// Any changes made will be lost if regenerated.
+using System;
 
-namespace Gdl {
-
-	using System;
-
-#region Autogenerated code
-	public enum DockPlacement {
-
+namespace Gdl
+{
+	[Serializable]
+	public enum DockPlacement
+	{
 		None,
 		Top,
 		Bottom,
@@ -16,5 +13,5 @@
 		Center,
 		Floating,
 	}
-#endregion
 }
+

Modified: trunk/MonoDevelop/Unused/Gdl/GdlDockTest.cs
===================================================================
--- trunk/MonoDevelop/Unused/Gdl/GdlDockTest.cs	2005-03-02 02:20:07 UTC (rev 2284)
+++ trunk/MonoDevelop/Unused/Gdl/GdlDockTest.cs	2005-03-02 23:37:26 UTC (rev 2285)
@@ -113,6 +113,7 @@
 	private void OnDumpXML (object o, EventArgs args)
 	{
 		layout.Dump ();
+		Console.WriteLine ();
 	}
 	
 	private void OnAppDelete (object o, DeleteEventArgs args)

Modified: trunk/MonoDevelop/Unused/Gdl/Makefile
===================================================================
--- trunk/MonoDevelop/Unused/Gdl/Makefile	2005-03-02 02:20:07 UTC (rev 2284)
+++ trunk/MonoDevelop/Unused/Gdl/Makefile	2005-03-02 23:37:26 UTC (rev 2285)
@@ -30,7 +30,7 @@
 	rm -f $(TEST) $(TEST).mdb
 
 $(GDL): $(FILES)
-	$(CSC) -out:$@ -target:library $(FILES) -pkg:gtk-sharp-2.0
+	$(CSC) -out:$@ -target:library $(FILES) -pkg:gtk-sharp-2.0 -pkg:glade-sharp-2.0
 
 $(TEST) : GdlDockTest.cs $(GDL)
 	$(CSC) -out:$@ -r:$(GDL) -pkg:gtk-sharp-2.0 GdlDockTest.cs -codepage:utf8

Added: trunk/MonoDevelop/Unused/Gdl/TODO
===================================================================
--- trunk/MonoDevelop/Unused/Gdl/TODO	2005-03-02 02:20:07 UTC (rev 2284)
+++ trunk/MonoDevelop/Unused/Gdl/TODO	2005-03-02 23:37:26 UTC (rev 2285)
@@ -0,0 +1,4 @@
+ - layout code
+ - restore size/position on de-iconify?
+ - fix:
+(<unknown>:21016): Gtk-CRITICAL **: gtk_widget_send_expose: assertion `GTK_WIDGET_REALIZED (widget)' failed




More information about the Monodevelop-patches-list mailing list