[Monodevelop-patches-list] r635 - in trunk/MonoDevelop/src: Libraries/MonoDevelop.Gui/Tree Main/Base/Gui/Pads/ProjectBrowser Main/Base/Gui/Pads/ProjectBrowser/NodeBuilder Main/Base/Internal/CollectionUtilities

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Sat Jan 24 20:01:07 EST 2004


Author: benm
Date: 2004-01-24 20:01:07 -0500 (Sat, 24 Jan 2004)
New Revision: 635

Modified:
   trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeNode.cs
   trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeView.cs
   trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/NodeBuilder/DefaultDotNetNodeBuilder.cs
   trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/ProjectBrowserView.cs
   trunk/MonoDevelop/src/Main/Base/Internal/CollectionUtilities/Comparers.cs
Log:
use Gtk's native sorting to take care of things. Total cleanup

Modified: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeNode.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeNode.cs	2004-01-24 23:38:25 UTC (rev 634)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeNode.cs	2004-01-25 01:01:07 UTC (rev 635)
@@ -10,6 +10,8 @@
 		private Gdk.Pixbuf image, opened_image, closed_image;
 		private object tag;
 		
+		internal Gtk.TreeRowReference row;
+		
 		public TreeNode() {
 			nodes = new TreeNodeCollection();
 			nodes.TreeNodeCollectionChanged += new TreeNodeCollectionChangedHandler(OnNodesChanged);
@@ -77,16 +79,11 @@
 		
 		public bool IsExpanded {
 			get {
-				if (TreeView != null) {
-					return TreeView.GetRowExpanded(new Gtk.TreePath(TreePath));
-				} else {
-					return false;
-				}
+				return TreeView != null && TreeView.GetRowExpanded (TreePath);
 			}
 			set {
-				if (TreeView != null) {
-					TreeView.ExpandRow(new Gtk.TreePath(TreePath), value);
-				}
+				if (TreeView != null)
+					TreeView.ExpandRow (TreePath, value);
 			}
 		}
 		
@@ -115,12 +112,12 @@
 		
 		public TreeView TreeView {
 			get {
-				if (treeView != null) {
+				if (treeView != null)
 					return treeView;
-				}
-				if (parent == null) {
+				
+				if (parent == null)
 					return null;
-				}
+				
 				return parent.TreeView;
 			}
 		}
@@ -132,9 +129,8 @@
 		}
 		
 		public void Expand() {
-			if (TreeView != null) {
-				TreeView.ExpandToPath(new Gtk.TreePath(TreePath));
-			}
+			if (TreeView != null)
+				TreeView.ExpandToPath (TreePath);
 		}
 		
 		public void EnsureVisible() {
@@ -142,9 +138,8 @@
 		}
 		
 		public void Remove() {
-			if (parent != null) {
+			if (parent != null)
 				parent.Nodes.Remove(this);
-			}
 		}
 
 		internal void SetTreeView(TreeView t) {
@@ -153,50 +148,48 @@
 		
 		private void OnNodeInserted(TreeNode node) {
 			node.parent = this;
-			if (TreeView != null) {
+			if (TreeView != null)
 				TreeView.AddNode(this, node);
-			}
 		}
 
 		private void OnNodeRemoved(TreeNode node) {
-			if (TreeView != null) {
+			if (TreeView != null) 
 				TreeView.RemoveNode(node);
-			}
+			
 			node.parent = null;
 		}
 		
 		private void OnNodesChanged() {
-			if (TreeView != null) {
+			if (TreeView != null)
 				TreeView.OnTreeChanged();
-			}
 		}
 		
-		private string TreePath {
+		internal Gtk.TreeIter TreeIter {
 			get {
-				if (parent == null) {
-					return "0";
-				}
-
-				string ret = parent.TreePath + ":";
-				ret += parent.Nodes.IndexOf(this);
-				return ret;
+				Gtk.TreeIter iter;
+				if (! TreeView.Model.GetIter (out iter, TreePath))
+					throw new Exception("Error calculating iter for " + this.Text);
+				
+				return iter;
 			}
 		}
 		
-		internal Gtk.TreeIter TreeIter {
+		internal Gtk.TreePath TreePath {
 			get {
-				Gtk.TreeIter iter;
-				if (TreeView.Model.GetIterFromString(out iter, TreePath) == false) {
-					throw new Exception("Error calculating iter for path " + TreePath);
-				}
-				return iter;
+				if (TreeView == null)
+					return null;
+				
+				if (row == null || ! row.Valid ())
+					throw new Exception ("RowReference not valid " + this.Text);
+
+				return row.Path;
 			}
 		}
 		
 		public virtual void BeginEdit ()
 		{
 			TreeView.text_render.Editable = TreeView.canEdit;
-			TreeView.SetCursor (new Gtk.TreePath (TreePath), TreeView.complete_column, true);
+			TreeView.SetCursor (TreePath, TreeView.complete_column, true);
 			TreeView.GrabFocus ();
 		}
 		

Modified: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeView.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeView.cs	2004-01-24 23:38:25 UTC (rev 634)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui/Tree/TreeView.cs	2004-01-25 01:01:07 UTC (rev 635)
@@ -3,10 +3,11 @@
 
 namespace MonoDevelop.Gui {
 	public class TreeView: Gtk.TreeView {
-		private Gtk.TreeView view;
-		private Gtk.TreeStore store;
-		private TreeNodeCollection nodes;
-		private bool updating = false;
+		Gtk.TreeView view;
+		Gtk.TreeStore store;
+		TreeNodeCollection nodes;
+		bool updating = false;
+		
 		internal bool canEdit = false;
 		internal Gtk.TreeViewColumn complete_column;
 		internal Gtk.CellRendererText text_render;
@@ -15,7 +16,8 @@
 		{
 		}
 		
-		public TreeView(bool canEdit) {
+		public TreeView (bool canEdit)
+		{
 			/*
 			0 -- Text
 			1 -- Icon
@@ -23,7 +25,7 @@
 			3 -- Expanded Icon
 			4 -- Unexpanded Icon
 			*/
-			store = new Gtk.TreeStore(typeof(string), typeof(Gdk.Pixbuf), typeof(TreeNode), typeof(Gdk.Pixbuf), typeof(Gdk.Pixbuf));
+			store = new Gtk.TreeStore (typeof (string), typeof (Gdk.Pixbuf), typeof (TreeNode), typeof (Gdk.Pixbuf), typeof (Gdk.Pixbuf));
 			this.Model = store;
 			this.canEdit = canEdit;
 
@@ -40,21 +42,27 @@
 			complete_column.AddAttribute (pix_render, "pixbuf-expander-closed", 4);
 			
 			text_render = new Gtk.CellRendererText ();
-			if (canEdit) {
+			if (canEdit)
 				text_render.Edited += new GtkSharp.EditedHandler (HandleOnEdit);
-			}
+			
 			complete_column.PackStart (text_render, true);
 			complete_column.AddAttribute (text_render, "text", 0);
 	
 			AppendColumn (complete_column);
 
-			nodes = new TreeNodeCollection();
-			nodes.TreeNodeCollectionChanged += new TreeNodeCollectionChangedHandler(OnTreeChanged);
-			nodes.NodeInserted += new NodeInsertedHandler(OnNodeInserted);
-			nodes.NodeRemoved += new NodeRemovedHandler(OnNodeRemoved);
+			nodes = new TreeNodeCollection ();
+			nodes.TreeNodeCollectionChanged += new TreeNodeCollectionChangedHandler (OnTreeChanged);
+			nodes.NodeInserted += new NodeInsertedHandler (OnNodeInserted);
+			nodes.NodeRemoved += new NodeRemovedHandler (OnNodeRemoved);
 			
-			TestExpandRow += new GtkSharp.TestExpandRowHandler(OnTestExpandRow);
+			TestExpandRow += new GtkSharp.TestExpandRowHandler (OnTestExpandRow);
 		}
+		
+		public TreeView (bool edit, Gtk.TreeIterCompareFunc cb_compare) : this (edit)
+		{
+			store.SetDefaultSortFunc (cb_compare, IntPtr.Zero, null);
+			store.SetSortColumnId (/* GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID */ -1, Gtk.SortType.Ascending);
+		}
 
 		void HandleOnEdit (object o, GtkSharp.EditedArgs e)
 		{
@@ -85,7 +93,6 @@
 
 		public TreeNode SelectedNode {
 			get {
-				
 				Gtk.TreeModel foo;
 				Gtk.TreeIter iter;
 				if (! Selection.GetSelected (out foo, out iter))
@@ -107,85 +114,149 @@
 			}
 		}
 		
-		public void BeginUpdate() {
+		public void BeginUpdate() 
+		{
 			//updating = true;
 		}
 		
-		public void EndUpdate() {
+		public void EndUpdate ()
+		{
 			//if (updating == true) {
 			//	UpdateStore(store);
 			//}
 			//updating = false;
 
 		}
-				
-		internal void OnTreeChanged() {
-			if (updating == false) {
-				UpdateStore(store);
-			}
+		
+		internal void OnTreeChanged ()
+		{
+			if (updating == false)
+				UpdateStore (store);
 		}
 		
-        internal void UpdateStore(Gtk.TreeStore store) {
-			store.Clear();
+		internal void UpdateStore (Gtk.TreeStore store)
+		{
+			store.Clear ();
 			foreach (TreeNode node in nodes) {
-				Gtk.TreeIter it = store.AppendValues(node.Text, node.Image, node, node.OpenedImage, node.ClosedImage);
-				AddNodesRecursively(store, it, node);
+				Gtk.TreeIter i = Append (node);
+				AddNodesRecursively (store, i, node);
 			}
 		}
 		
-		private void AddNodesRecursively(Gtk.TreeStore store, Gtk.TreeIter it, TreeNode node) {
-			foreach(TreeNode nod in node.Nodes) {
-				Gtk.TreeIter i = store.AppendValues(it, nod.Text, nod.Image, nod, nod.OpenedImage, nod.ClosedImage);
-				AddNodesRecursively(store, i, nod);
+		Gtk.TreeIter Append (Gtk.TreeIter parent, TreeNode new_child)
+		{
+			if (new_child.row != null) {
+				new_child.row.Free ();
+				new_child.row = null;
 			}
+			
+			Gtk.TreeIter it = store.Append (parent);
+			
+			// It is *critical* that we set this first. We will
+			// sort after this call, so we must give as much info
+			// to the sort function as possible.
+			store.SetValue (it, 2, new_child);
+			
+			if (new_child.Text != null)        store.SetValue (it, 0, new_child.Text);
+			if (new_child.Image != null)       store.SetValue (it, 1, new_child.Image);
+			if (new_child.OpenedImage != null) store.SetValue (it, 3, new_child.OpenedImage);
+			if (new_child.ClosedImage != null) store.SetValue (it, 4, new_child.ClosedImage);
+			
+			new_child.row = new Gtk.TreeRowReference (store, store.GetPath (it));
+			
+			return it;
 		}
-
-		internal void AddNode(TreeNode parent, TreeNode child) {
-			if (parent.TreeView != this) {
-				throw new Exception("Wrong tree");
+		
+		Gtk.TreeIter Append (TreeNode new_child)
+		{
+			if (new_child.row != null) {
+				new_child.row.Free ();
+				new_child.row = null;
 			}
-			Gtk.TreeIter i = store.AppendValues(parent.TreeIter, child.Text, child.Image, child, child.OpenedImage, child.ClosedImage);
-			AddNodesRecursively(store, i, child);
+			
+			Gtk.TreeIter it;
+			store.Append (out it);
+			
+			// It is *critical* that we set this first. We will
+			// sort after this call, so we must give as much info
+			// to the sort function as possible.
+			store.SetValue (it, 2, new_child);
+			
+			if (new_child.Text != null)        store.SetValue (it, 0, new_child.Text);
+			if (new_child.Image != null)       store.SetValue (it, 1, new_child.Image);
+			if (new_child.OpenedImage != null) store.SetValue (it, 3, new_child.OpenedImage);
+			if (new_child.ClosedImage != null) store.SetValue (it, 4, new_child.ClosedImage);
+			
+			new_child.row = new Gtk.TreeRowReference (store, store.GetPath (it));
+			
+			return it;
 		}
 		
-		internal void RemoveNode(TreeNode node) {
-			if (node.TreeView != this) {
-				throw new Exception("Wrong tree");
+		private void AddNodesRecursively (Gtk.TreeStore store, Gtk.TreeIter it, TreeNode node)
+		{
+			foreach (TreeNode nod in node.Nodes) {
+				Gtk.TreeIter i = Append (it, nod);
+				AddNodesRecursively (store, i, nod);
 			}
+		}
+
+		internal void AddNode (TreeNode parent, TreeNode child)
+		{
+			if (parent.TreeView != this)
+				throw new Exception ("Wrong tree");
+			
+			Gtk.TreeIter i = Append (parent.TreeIter, child);
+			
+			AddNodesRecursively (store, i, child);
+		}
+		
+		internal void RemoveNode (TreeNode node)
+		{
+			if (node.TreeView != this)
+				throw new Exception ("Wrong tree");
+			
 			Gtk.TreeIter iter = node.TreeIter;
-			store.Remove(ref iter);
+			store.Remove (ref iter);
 		}
 		
-		private void OnNodeInserted(TreeNode node) {
+		private void OnNodeInserted (TreeNode node)
+		{
 			node.treeView = this;
 			node.parent = null;
-			Gtk.TreeIter i = store.AppendValues(node.Text, node.Image, node, node.OpenedImage, node.ClosedImage);
+
+			
+			Gtk.TreeIter i = Append (node);
 			AddNodesRecursively(store, i, node);
 		}
 
-		private void OnNodeRemoved(TreeNode node) {
-			RemoveNode(node);
+		private void OnNodeRemoved (TreeNode node)
+		{
+			RemoveNode (node);
 			node.parent = null;
 			node.treeView = null;
+			if (node.row != null) {
+				node.row.Free ();
+				node.row = null;
+			}
 		}
 		
-		private TreeNode GetNodeByIter(Gtk.TreeIter iter) {
+		private TreeNode GetNodeByIter (Gtk.TreeIter iter)
+		{
 			TreeNode ret = (TreeNode)store.GetValue(iter, 2);
 			return ret;
 		}
 		
-		private void OnTestExpandRow(object sender, GtkSharp.TestExpandRowArgs args) {
-			TreeNode node = GetNodeByIter(args.Iter);
-			TreeViewCancelEventArgs e = new TreeViewCancelEventArgs(node);
-			OnBeforeExpand(e);
-			if (e.Cancel == true || node.Nodes.Count == 0) {
-				args.RetVal = true;
-			} else {
-				args.RetVal = false;
-			}
+		private void OnTestExpandRow (object sender, GtkSharp.TestExpandRowArgs args)
+		{
+			TreeNode node = GetNodeByIter (args.Iter);
+			TreeViewCancelEventArgs e = new TreeViewCancelEventArgs (node);
+			OnBeforeExpand (e);
+			
+			args.RetVal = (e.Cancel == true || node.Nodes.Count == 0);
 		}
 		
-		protected virtual void OnBeforeExpand(TreeViewCancelEventArgs e) {
+		protected virtual void OnBeforeExpand (TreeViewCancelEventArgs e)
+		{
 			// Nothing
 		}
 	}
@@ -194,7 +265,8 @@
 		private TreeNode node;
 		private bool cancel = false;
 		
-		public TreeViewCancelEventArgs(TreeNode node) {
+		public TreeViewCancelEventArgs (TreeNode node)
+		{
 			this.node = node;
 		}
 		

Modified: trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/NodeBuilder/DefaultDotNetNodeBuilder.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/NodeBuilder/DefaultDotNetNodeBuilder.cs	2004-01-24 23:38:25 UTC (rev 634)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/NodeBuilder/DefaultDotNetNodeBuilder.cs	2004-01-25 01:01:07 UTC (rev 635)
@@ -202,9 +202,6 @@
 			*/
 
 			InitializeReferences(referenceNode, project);
-			SortUtility.QuickSort(referenceNode.Nodes, TreeNodeComparer.ProjectNode);
-			SortUtility.QuickSort(resourceNode.Nodes, TreeNodeComparer.ProjectNode);
-			SortUtility.QuickSort(projectNode.Nodes, TreeNodeComparer.ProjectNode);
 			return projectNode;
 		}
 
@@ -250,7 +247,7 @@
 							newNode.ContextmenuAddinTreePath = FileNode.ProjectFileContextMenuPath;
 							//parentNode.Nodes.Add(newNode);
 							
-							SortUtility.SortedInsert(newNode, currentPathNode1.Nodes, TreeNodeComparer.ProjectNode);
+							currentPathNode1.Nodes.Add (newNode);
 							break;
 					}
 					break;
@@ -279,7 +276,7 @@
 								newFolderNode.OpenedImage = resourceService.GetBitmap("Icons.16x16.OpenFolderBitmap");
 								newFolderNode.ClosedImage = resourceService.GetBitmap("Icons.16x16.ClosedFolderBitmap");
 							}
-							SortUtility.SortedInsert(newFolderNode, currentPathNode.Nodes, TreeNodeComparer.ProjectNode);
+							currentPathNode.Nodes.Add(newFolderNode);
 						}
 					}
 					break;
@@ -297,7 +294,7 @@
 						newFolderNode.ClosedImage = resourceService.GetBitmap("Icons.16x16.ClosedWebReferenceFolder");
 
 						string parentDirectory = Path.GetFileName(directoryName);
-						projectNode.Nodes.Insert(2, newFolderNode);
+						projectNode.Nodes.Add (newFolderNode);
 					}
 					break;
 				case Subtype.WebForm:
@@ -312,7 +309,7 @@
 						newNode.ContextmenuAddinTreePath = FileNode.ProjectFileContextMenuPath;
 						//parentNode.Nodes.Add(newNode);
 						
-						SortUtility.SortedInsert(newNode, currentPathNode1.Nodes, TreeNodeComparer.ProjectNode);
+						currentPathNode1.Nodes.Add (newNode);
 						// codeBehind?
 					}
 
@@ -330,7 +327,7 @@
 						newNode.ContextmenuAddinTreePath = FileNode.ProjectFileContextMenuPath;
 						//parentNode.Nodes.Add(newNode);
 						
-						SortUtility.SortedInsert(newNode, currentPathNode1.Nodes, TreeNodeComparer.ProjectNode);
+						currentPathNode1.Nodes.Add (newNode);
 					}
 
 					break;
@@ -391,7 +388,7 @@
 				if (node == null) {
 					if (create) {
 						DirectoryNode newFolderNode  = new DirectoryNode(fileUtilityService.GetDirectoryNameWithSeparator(ConstructFolderName(curpathnode)) + path);
-						SortUtility.SortedInsert(newFolderNode, curpathnode.Nodes, TreeNodeComparer.ProjectNode);
+						curpathnode.Nodes.Add (newFolderNode);
 						curpathnode = newFolderNode;
 						continue;
 					} else {
@@ -454,7 +451,6 @@
 
 				parentNode.Nodes.Add(newReferenceNode);
 			}
-			parentNode.Sort (TreeNodeComparer.ProjectNode);
 		}
 		
 	}

Modified: trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/ProjectBrowserView.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/ProjectBrowserView.cs	2004-01-24 23:38:25 UTC (rev 634)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Pads/ProjectBrowser/ProjectBrowserView.cs	2004-01-25 01:01:07 UTC (rev 635)
@@ -86,7 +86,7 @@
 			//projectBrowserImageList = new ImageList();
 			//projectBrowserImageList.ColorDepth = ColorDepth.Depth32Bit;
 		}
-		public ProjectBrowserView() : base (true)
+		public ProjectBrowserView() : base (true, TreeNodeComparer.GtkProjectNode)
 		{
 			//LabelEdit     = true;
 			//AllowDrop     = true;
@@ -129,7 +129,8 @@
 			DisposeProjectNodes();
 			Nodes.Clear();
 			TreeNode treeNode = BuildCombineTreeNode(combine);
-			SortUtility.SortedInsert(treeNode, Nodes, TreeNodeComparer.ProjectNode);
+			Nodes.Add (treeNode);
+			
 			combine.StartupPropertyChanged += new EventHandler(StartupPropertyChanged);
 			StartupPropertyChanged(null, null);
 			// .NET bugfix : have to expand the node to ensure the refresh
@@ -189,11 +190,6 @@
 			// we set the label ourself
 			((AbstractBrowserNode) node).AfterLabelEdit (new_text);
 			
-			if (node.Parent != null)
-				node.Parent.Sort (TreeNodeComparer.ProjectNode);
-			
-			node.EnsureVisible();
-			
 			// save changes
 			IProjectService projectService = (IProjectService) ServiceManager.Services.GetService (typeof(IProjectService));
 			projectService.SaveCombine();
@@ -321,11 +317,9 @@
 				} else {
 					node = BuildCombineTreeNode((Combine)entry.Entry);
 				}
-				combineNode.Nodes.Add(node);
+				combineNode.Nodes.Add (node);
 			}
 			
-			combineNode.Sort (TreeNodeComparer.ProjectNode);
-			
 			return combineNode;
 		}
 
@@ -614,7 +608,8 @@
 			}
 
 			AbstractBrowserNode pbn = new FileNode(fInfo);
-			SortUtility.SortedInsert(pbn, newparent.Nodes, TreeNodeComparer.ProjectNode);
+			newparent.Nodes.Add (pbn);
+			
 			pbn.EnsureVisible();
 			projectService.SaveCombine();
 		}

Modified: trunk/MonoDevelop/src/Main/Base/Internal/CollectionUtilities/Comparers.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Internal/CollectionUtilities/Comparers.cs	2004-01-24 23:38:25 UTC (rev 634)
+++ trunk/MonoDevelop/src/Main/Base/Internal/CollectionUtilities/Comparers.cs	2004-01-25 01:01:07 UTC (rev 635)
@@ -106,6 +106,32 @@
 		
 		public static IComparer Default    = new TreeNodeComparer();
 		public static IComparer ProjectNode = new ProjectNodeComparer();
+		public static Gtk.TreeIterCompareFunc GtkProjectNode = new Gtk.TreeIterCompareFunc (GtkProjectNodeComparer);
+			
+		static int GtkProjectNodeComparer (Gtk.TreeModel model, Gtk.TreeIter a, Gtk.TreeIter b)
+		{
+			Gtk.TreeStore ts = (Gtk.TreeStore) model;
+			TreeNode x = (TreeNode) ts.GetValue (a, 2);
+			TreeNode y = (TreeNode) ts.GetValue (b, 2);
+			
+			if (x.GetType () == y.GetType ()) {
+				if (x is NamedFolderNode) {
+					return ((NamedFolderNode)x).SortPriority - ((NamedFolderNode)y).SortPriority;
+				}
+				return x.Text.CompareTo(y.Text);
+			}
+			if (x is FileNode) {
+				return 1;
+			} else if (y is FileNode) {
+				return -1;
+			}
+			if (x is DirectoryNode) {
+				return 1;
+			} else if (y is DirectoryNode) {
+				return -1;
+			}
+			return x.Text.CompareTo(y.Text);
+		}
 		
 		protected TreeNodeComparer() {}
 		




More information about the Monodevelop-patches-list mailing list