Re: [Mono-dev] [Patch] TreeView, TreeNode, TreeNodeCollection

2007-01-20 Thread Alan McGovern

Heya,

I'm on holidays in italy right now, so i havent had a chance to work on
stuff for the last week. I'll be home again tomorrow, so there should be a
patch ready (including nunits) by next saturday, all going well.

Alan.

On 1/20/07, Jonathan Pobst [EMAIL PROTECTED] wrote:


Hey Alan, I haven't seen you around in a while and wanted to make sure
TreeNode.Name got into 1.2.3 due to how high it appears on the moma
reports, so I committed that part of your patch and wrote the relevant
test.

I'm not writing the tests for the collection part, so I'll need those
before I commit the other stuff.  :)

Obviously, the performance concerns are valid, but I'll take an
inefficient implementation over no implementation if you are unable to
make it use something better than a linear search.

Also, have you made any headway on the TreeNode ContextMenu(Strip)
stuff?  It also shows pretty high on moma, so if you don't have time to
do that, I'll probably write it.

Thanks!
jpobst


Alan McGovern wrote:
 Hi,

 This is my first patch, so i want to make sure that everything is
 alright before i go committing. I will provide NUnit tests for the new
 functionality (i'll post the tests here) if everything looks good with
 the patch.

 I just implemented some of the .NET 2.0 methods which are missing which
 i would like to have. They're nothing major. Also, how would i go about
 implementing the ContextMenu stuff. Is there an example of how i can do
 this? I'm not 100% sure how to do it :p


 

 Index:
C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
 ===
 ---
C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
(revision 69123)
 +++
C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
(working copy)
 @@ -54,6 +54,9 @@

   internal IntPtr handle;

 +#if NET_2_0
 + private string name = string.Empty;
 +#endif
   #endregion  // Fields

   #region Internal Constructors
 @@ -352,6 +355,18 @@
   }
   }

 +#if NET_2_0
 + public string Name
 + {
 + get { return this.name; }
 + set
 + {
 + // Value should never be null as per spec
 + this.name = (value == null) ? string.Empty: 
value;
 + }
 + }
 +#endif
 +
   public TreeNode NextNode {
   get {
   if (parent == null)
 Index:
C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
 ===
 ---
C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
(revision 69123)
 +++
C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
(working copy)
 @@ -95,6 +95,20 @@
   }
   }

 + #if NET_2_0
 + public virtual TreeNode this[string key]
 + {
 + get
 + {
 + if(string.IsNullOrEmpty(key))
 + return null;
 +
 + int index = IndexOfKey(key);
 + return (index == -1) ? null : this[index];
 + }
 + }
 + #endif
 +
   public virtual TreeNode Add (string text)
   {
   TreeNode res = new TreeNode (text);
 @@ -442,6 +456,43 @@
   return (res == 0 ? l.Index - r.Index :
res);
   }
   }
 +
 +#if NET_2_0
 + public virtual int IndexOfKey(string key)
 + {
 + if (string.IsNullOrEmpty(key))
 + return -1;
 +
 + // We do a case insensitive comparison to
find the key
 + for (int i = 0; i  nodes.Count; i++)
 + if (string.Equals(nodes.Name, name,
StringComparison.CurrentCultureIgnoreCase))
 + return i;
 +
 + return -1;
 +}
 +
 + public virtual bool ContainsKey(string name)
 + {
 + return (IndexOfKey(name) != -1);
 + }
 +
 +
 + public virtual void RemoveByKey(string key)
 + {
 + int index = -1;
 + for (int i = 0; i  nodes.Count; i++)
 + {
 + if (!string.Equals(nodes[i].Name,key,
StringComparison.CurrentCultureIgnoreCase))
 + continue;
 +
 +   

[Mono-dev] [Patch] TreeView, TreeNode, TreeNodeCollection

2007-01-09 Thread Alan McGovern

Hi,

This is my first patch, so i want to make sure that everything is alright
before i go committing. I will provide NUnit tests for the new functionality
(i'll post the tests here) if everything looks good with the patch.

I just implemented some of the .NET 2.0 methods which are missing which i
would like to have. They're nothing major. Also, how would i go about
implementing the ContextMenu stuff. Is there an example of how i can do
this? I'm not 100% sure how to do it :p
Index: C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
===
--- C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs	(revision 69123)
+++ C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs	(working copy)
@@ -54,6 +54,9 @@
 
 		internal IntPtr handle;
 		
+#if NET_2_0
+		private string name = string.Empty;
+#endif
 		#endregion	// Fields
 
 		#region Internal Constructors		
@@ -352,6 +355,18 @@
 			}
 		}
 
+#if NET_2_0
+		public string Name
+		{
+			get { return this.name; }
+			set
+			{
+// Value should never be null as per spec
+this.name = (value == null) ? string.Empty : value;
+			}
+		}
+#endif
+
 		public TreeNode NextNode {
 			get {
 if (parent == null)
Index: C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
===
--- C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs	(revision 69123)
+++ C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs	(working copy)
@@ -95,6 +95,20 @@
 			}
 		}
 
+		#if NET_2_0
+		public virtual TreeNode this[string key]
+		{
+			get
+			{
+if(string.IsNullOrEmpty(key))
+		return null;
+
+int index = IndexOfKey(key);
+return (index == -1) ? null : this[index];
+			}
+		}
+		#endif
+
 		public virtual TreeNode Add (string text)
 		{
 			TreeNode res = new TreeNode (text);
@@ -442,6 +456,43 @@
 return (res == 0 ? l.Index - r.Index : res);
 			}
 		}
+
+#if NET_2_0
+		public virtual int IndexOfKey(string key)
+		{
+			if (string.IsNullOrEmpty(key))
+return -1;
+
+// We do a case insensitive comparison to find the key
+			for (int i = 0; i  nodes.Count; i++)
+if (string.Equals(nodes.Name, name, StringComparison.CurrentCultureIgnoreCase))
+	return i;
+
+			return -1;
+}
+
+		public virtual bool ContainsKey(string name)
+		{
+			return (IndexOfKey(name) != -1);
+		}
+
+
+		public virtual void RemoveByKey(string key)
+		{
+			int index = -1;
+			for (int i = 0; i  nodes.Count; i++)
+			{
+if (!string.Equals(nodes[i].Name,key, StringComparison.CurrentCultureIgnoreCase))
+	continue;
+
+index = i;
+break;
+			}
+
+			if (index != -1)
+RemoveAt(index);
+		}
+#endif
 	}
 }
 
Index: C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs
===
--- C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs	(revision 69123)
+++ C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs	(working copy)
@@ -549,6 +549,15 @@
 			return root_node.GetNodeCount (include_subtrees);
 		}
 
+		#if NET_2_0
+		public void Sort()
+		{
+			// Just call the pre-existing methods to sort the treeview.
+			// I assume it'll sort correctly.
+			this.Sorted = true;
+		}
+#endif
+
 		public override string ToString () {
 			int count = Nodes.Count;
 			if (count = 0)
Index: C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===
--- C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog	(revision 69123)
+++ C:/programming/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2007-1-09 Alan McGovern [EMAIL PROTECTED]
+	* TreeNode.cs
+	* TreeView.cs
+	* TreeNodeCollection.cs
+	- Added some new .NET 2.0 methods
+
 2006-12-06  Jackson Harper  [EMAIL PROTECTED]
 
 	* TextControl.cs: Make this operation undoable.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] TreeView, TreeNode, TreeNodeCollection

2007-01-09 Thread Robert Jordan
Hi Alan,

Alan McGovern wrote:
 This is my first patch, so i want to make sure that everything is alright
 before i go committing. I will provide NUnit tests for the new 
 functionality
 (i'll post the tests here) if everything looks good with the patch.

You should write and test the unit tests on MS.NET even before
starting to code, because MS.NET's docs are often incomplete.

 +#if NET_2_0
 + public virtual int IndexOfKey(string key)
 + {
 + if (string.IsNullOrEmpty(key))
 + return -1;
 +
 + // We do a case insensitive comparison to find 
 the key
 + for (int i = 0; i  nodes.Count; i++)
 + if (string.Equals(nodes.Name, name, 
 StringComparison.CurrentCultureIgnoreCase))

Does MS.NET really perform a culture-variant comparison?

Also, that's a linear scan. How does MS.NET perform? You may want to
write a test that creates 100 nodes and that removes them by
name. If it's an almost instant operation on MS.NET, they are probably
optimizing the lookup using a non-linear (hash table, sorted
list) data type.

 + public virtual void RemoveByKey(string key)
 + {
 + int index = -1;
 + for (int i = 0; i  nodes.Count; i++)
 + {
 + if (!string.Equals(nodes[i].Name,key, 
 StringComparison.CurrentCultureIgnoreCase))
 + continue;
 +
 + index = i;
 + break;
 + }

Ditto. Additionally, what happens on MS.NET if you remove the
String.Empty key? What happens if the collection has duplicate keys?
Will be the keys deleted all together or just the first/last/random
occurrence?

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] TreeView, TreeNode, TreeNodeCollection

2007-01-09 Thread Carlos Alberto Cortez

 
  +   public virtual void RemoveByKey(string key)
  +   {
  +   int index = -1;
  +   for (int i = 0; i  nodes.Count; i++)
  +   {
  +   if (!string.Equals(nodes[i].Name,key, 
  StringComparison.CurrentCultureIgnoreCase))
  +   continue;
  +
  +   index = i;
  +   break;
  +   }
 
 Ditto. Additionally, what happens on MS.NET if you remove the
 String.Empty key? What happens if the collection has duplicate keys?
 Will be the keys deleted all together or just the first/last/random
 occurrence?

As far as I can tell, RemoveByKey behaves just like the other
Key-related methods, so when passing a null or empty string it should do
nothing.

Also, when having duplicate keys, the method should remove the first
occurrence (at least that happens with ListView related collections, for
example).

Anyway, the best thing do do, as Robert said, is to write tests.

Carlos.




___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list