From 696c9c657336356770cfff65db53271296781bca Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 21 Jan 2005 01:01:51 +0000 Subject: Initial checkin --- About.cs | 172 ++++++++++++++++++++++ AssemblyInfo.cs | 33 +++++ DirectoryCollection.cs | 340 +++++++++++++++++++++++++++++++++++++++++++ GPL.cs | 94 ++++++++++++ MenuTree.cs | 163 +++++++++++++++++++++ Noddybox.GUI.About.resources | Bin 0 -> 5189 bytes Noddybox.GUI.GPL.resources | Bin 0 -> 3419 bytes Noddybox.GUI.cmbx | 16 ++ Noddybox.GUI.prjx | 32 ++++ Noddybox.GUI.resources | Bin 0 -> 18681 bytes NodeTree.cs | 141 ++++++++++++++++++ 11 files changed, 991 insertions(+) create mode 100644 About.cs create mode 100644 AssemblyInfo.cs create mode 100644 DirectoryCollection.cs create mode 100644 GPL.cs create mode 100644 MenuTree.cs create mode 100644 Noddybox.GUI.About.resources create mode 100644 Noddybox.GUI.GPL.resources create mode 100644 Noddybox.GUI.cmbx create mode 100644 Noddybox.GUI.prjx create mode 100644 Noddybox.GUI.resources create mode 100644 NodeTree.cs diff --git a/About.cs b/About.cs new file mode 100644 index 0000000..6e03d83 --- /dev/null +++ b/About.cs @@ -0,0 +1,172 @@ +// Noddybox.GUI - various GUI support routines +// Copyright (C) 2004 Ian Cowburn +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// $Id$ +// +using System; +using System.Windows.Forms; +using System.Text; +using System.Resources; +using System.Reflection; + +namespace Noddybox.GUI +{ + /// + /// Generic Noddybox About/Help box + /// + public class About : System.Windows.Forms.Form + { + private System.Windows.Forms.Label m_helpLabel; + private System.Windows.Forms.Button m_gplButton; + private System.Windows.Forms.RichTextBox m_help; + private System.Windows.Forms.Label m_gpl; + private System.Windows.Forms.Button m_ok; + + /// + /// Displays an about box, with a button to display the GPL (or optionally + /// the GPL in the help window). + /// + /// The title of the program + /// Help file. Set to null to display the GPL instead. + public About(string title, string rtf_help) + { + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + + StringBuilder s=new StringBuilder(); + + Text=title; + + s.Append("This program is distributed in the hope that it will be useful, "); + s.Append("but WITHOUT ANY WARRANTY; without even the implied warranty of "); + s.Append("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "); + s.Append("GNU General Public License for more details."); + + m_gpl.Text=s.ToString(); + + if (rtf_help!=null) + { + m_help.Rtf=rtf_help; + } + else + { + m_gplButton.Hide(); + m_helpLabel.Text="GNU General Public License:"; + + ResourceManager mgr=new ResourceManager("Noddybox.GUI", + Assembly.GetExecutingAssembly()); + + byte[] gpl=(byte[])mgr.GetObject("GPL"); + + m_help.Text=new ASCIIEncoding().GetString(gpl); + } + } + + #region Windows Forms Designer generated code + /// + /// This method is required for Windows Forms designer support. + /// Do not change the method contents inside the source code editor. The Forms designer might + /// not be able to load this method if it was changed manually. + /// + private void InitializeComponent() { + this.m_ok = new System.Windows.Forms.Button(); + this.m_gpl = new System.Windows.Forms.Label(); + this.m_help = new System.Windows.Forms.RichTextBox(); + this.m_gplButton = new System.Windows.Forms.Button(); + this.m_helpLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // m_ok + // + this.m_ok.Location = new System.Drawing.Point(424, 368); + this.m_ok.Name = "m_ok"; + this.m_ok.Size = new System.Drawing.Size(88, 24); + this.m_ok.TabIndex = 2; + this.m_ok.Text = "OK"; + this.m_ok.Click += new System.EventHandler(this.OnOK); + // + // m_gpl + // + this.m_gpl.Location = new System.Drawing.Point(72, 8); + this.m_gpl.Name = "m_gpl"; + this.m_gpl.Size = new System.Drawing.Size(392, 56); + this.m_gpl.TabIndex = 0; + // + // m_help + // + this.m_help.BackColor = System.Drawing.SystemColors.Window; + this.m_help.Cursor = System.Windows.Forms.Cursors.Default; + this.m_help.Location = new System.Drawing.Point(8, 96); + this.m_help.Name = "m_help"; + this.m_help.ReadOnly = true; + this.m_help.Size = new System.Drawing.Size(504, 264); + this.m_help.TabIndex = 9; + this.m_help.Text = ""; + // + // m_gplButton + // + this.m_gplButton.Location = new System.Drawing.Point(8, 368); + this.m_gplButton.Name = "m_gplButton"; + this.m_gplButton.Size = new System.Drawing.Size(192, 24); + this.m_gplButton.TabIndex = 10; + this.m_gplButton.Text = "View GNU General Public License"; + this.m_gplButton.Click += new System.EventHandler(this.OnGPL); + // + // m_helpLabel + // + this.m_helpLabel.Location = new System.Drawing.Point(8, 80); + this.m_helpLabel.Name = "m_helpLabel"; + this.m_helpLabel.Size = new System.Drawing.Size(504, 16); + this.m_helpLabel.TabIndex = 8; + this.m_helpLabel.Text = "Help:"; + // + // About + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); + this.ClientSize = new System.Drawing.Size(522, 399); + this.Controls.Add(this.m_gplButton); + this.Controls.Add(this.m_help); + this.Controls.Add(this.m_helpLabel); + this.Controls.Add(this.m_ok); + this.Controls.Add(this.m_gpl); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "About"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "About"; + this.ResumeLayout(false); + } + #endregion + + + void OnOK(object sender, System.EventArgs e) + { + Close(); + } + void OnGPL(object sender, System.EventArgs e) + { + GPL gpl=new GPL(); + + gpl.ShowDialog(); + } + + } +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..0ee34bd --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,33 @@ +// $Id$ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("Noddybox.GUI")] +[assembly: AssemblyDescription("General purpose GUI routines")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright (c) 2004 Ian Cowburn")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes specify the key for the sign of your assembly. See the +// .NET Framework documentation for more information about signing. +// This is not required, if you don't want signing let these attributes like they're. +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] diff --git a/DirectoryCollection.cs b/DirectoryCollection.cs new file mode 100644 index 0000000..fa29506 --- /dev/null +++ b/DirectoryCollection.cs @@ -0,0 +1,340 @@ +// Noddybox.GUI - various GUI support routines +// Copyright (C) 2004 Ian Cowburn +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// $Id$ +// +using System; +using System.Collections; + +namespace Noddybox.GUI +{ + /// + /// Provides a collection to a directory type structure + /// + public sealed class DirectoryCollection : IEnumerable, IEnumerator + { + // -------------------------------- + // PUBLIC + // -------------------------------- + + /// + /// Construct a DirectoryCollection + /// + public DirectoryCollection() + { + m_dirsep='/'; + m_table=new Hashtable(); + m_iter_list=null; + } + + /// + /// Sets the path seperator (default '/'). + /// + public char Seperator + { + get {return m_dirsep;} + set {m_dirsep=value;} + } + + /// + /// Adds an item + /// + /// The path to the item + /// The item to add + public void Add(string path, object tag) + { + CheckPath(path,false); + + if (IsRoot(path)) + { + m_root=new DirNode(); + m_root.Tag=tag; + m_table[path]=m_root; + } + else + { + string parent=Parent(path); + + CheckPath(parent,true); + + m_table[path]=new DirNode(Locate(parent),path,tag); + } + } + + /// + /// Gets an item. + /// + /// The path to the item + /// The item + public object Get(string path) + { + CheckPath(path,true); + + DirNode n=(DirNode)m_table[path]; + + return n.Tag; + } + + /// + /// Gets the parent item. + /// + /// The path whose parent you want + /// The parent item + public object GetParent(string path) + { + if (IsRoot(path)) + { + throw new ArgumentException("Root has no parent"); + } + + CheckPath(path,true); + + DirNode n=(DirNode)m_table[path]; + + return n.Parent.Tag; + } + + /// + /// Recursively remove a section of the directory structure + /// + /// The path to remove + public void Remove(string path) + { + CheckPath(path,true); + + if (IsRoot(path)) + { + m_table.Clear(); + m_root=null; + } + else + { + DirNode n=Locate(path); + + n.Parent.Children.Remove(n); + n.Parent=null; + + m_table.Remove(path); + } + } + + /// + /// Returns true if the supplied path is the directory root. + /// + /// The path to check + /// True is path is root + public bool IsRoot(string path) + { + return (path.Length==1 && path[0]==m_dirsep); + } + + /// + /// Gets an enumerator + /// + /// The enumerator + public IEnumerator GetEnumerator() + { + Reset(); + return this; + } + + /// + /// Get the current object from the enumerator + /// + public object Current + { + get + { + if (m_iter_list==null) + { + throw new InvalidOperationException(); + } + + DirNode t=(DirNode)m_iter_list[m_iter_index]; + return t.Tag; + } + } + + /// + /// Reset the enumerator to the start of the collection. + /// + public void Reset() + { + m_iter_index=-1; + FlattenTree(); + } + + /// + /// Move the enumerator to the next item. + /// + /// True if there are more objects to enumerate over + public bool MoveNext() + { + m_iter_index++; + + if (m_iter_index>=m_iter_list.Count) + { + m_iter_list=null; + } + + return m_iter_list!=null; + } + + + // -------------------------------- + // PRIVATE + // -------------------------------- + + private DirNode m_root; + private Hashtable m_table; + + private char m_dirsep; + + private ArrayList m_iter_list; + private int m_iter_index; + + private void FlattenTree() + { + m_iter_list=new ArrayList(); + FlattenTree(m_root); + } + + private void FlattenTree(DirNode n) + { + m_iter_list.Add(n); + + foreach (DirNode dn in n.Children) + { + FlattenTree(dn); + } + } + + private void CheckPath(string path, bool must_exist) + { + if (path.Length==0 || path[0]!=m_dirsep) + { + throw new ArgumentException("Invalid path format: "+path); + } + + if (path.Length>1 && path.EndsWith(m_dirsep+"")) + { + throw new ArgumentException("Invalid path format: "+path); + } + + if (must_exist) + { + if (!m_table.ContainsKey(path)) + { + throw new ArgumentException(path+" does not exist"); + } + } + else + { + if (m_table.ContainsKey(path)) + { + throw new ArgumentException(path+" already exists"); + } + } + } + + private string Parent(string path) + { + int i=path.LastIndexOf(m_dirsep); + + if (i==0) + { + return "/"; + } + else + { + return path.Substring(0,i); + } + } + + + private string Name(string path) + { + int i=path.LastIndexOf(m_dirsep); + + return path.Substring(i+1); + } + + private DirNode Locate(string path) + { + return (DirNode)m_table[path]; + } + + private class DirNode + { + public DirNode() + { + m_children=new ArrayList(); + m_parent=null; + } + + public DirNode(DirNode parent, string path, object tag) + { + m_children=new ArrayList(); + m_path=path; + m_tag=tag; + m_parent=parent; + + m_parent.m_children.Add(this); + } + + public string Path + { + get {return m_path;} + set {m_path=value;} + } + + public object Tag + { + get {return m_tag;} + set {m_tag=value;} + } + + public ArrayList Children + { + get {return m_children;} + } + + public DirNode Parent + { + get {return m_parent;} + set {m_parent=value;} + } + + override public bool Equals(object o) + { + DirNode n=(DirNode)o; + + return n.m_path==m_path; + } + + override public int GetHashCode() + { + return m_path.GetHashCode(); + } + + private DirNode m_parent; + private string m_path; + private object m_tag; + private ArrayList m_children; + } + } +} diff --git a/GPL.cs b/GPL.cs new file mode 100644 index 0000000..cdb1a51 --- /dev/null +++ b/GPL.cs @@ -0,0 +1,94 @@ +// Noddybox.GUI - various GUI support routines +// Copyright (C) 2004 Ian Cowburn +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// $Id$ +// +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Text; +using System.Resources; +using System.Reflection; + +namespace Noddybox.GUI +{ + /// + /// Displays the GPL. + /// + internal class GPL : System.Windows.Forms.Form + { + private System.Windows.Forms.RichTextBox m_gpl; + + /// + /// Constructs the GPL License form + /// + public GPL() + { + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + + ResourceManager mgr=new ResourceManager("Noddybox.GUI", + Assembly.GetExecutingAssembly()); + + byte[] gpl=(byte[])mgr.GetObject("GPL"); + + if (gpl!=null) + { + m_gpl.Text=new ASCIIEncoding().GetString(gpl); + } + else + { + m_gpl.Text="Failed to read LICENSE from resources!"; + } + + } + + #region Windows Forms Designer generated code + /// + /// This method is required for Windows Forms designer support. + /// Do not change the method contents inside the source code editor. The Forms designer might + /// not be able to load this method if it was changed manually. + /// + private void InitializeComponent() { + this.m_gpl = new System.Windows.Forms.RichTextBox(); + this.SuspendLayout(); + // + // m_gpl + // + this.m_gpl.Dock = System.Windows.Forms.DockStyle.Fill; + this.m_gpl.Location = new System.Drawing.Point(0, 0); + this.m_gpl.Name = "m_gpl"; + this.m_gpl.Size = new System.Drawing.Size(576, 352); + this.m_gpl.TabIndex = 0; + this.m_gpl.Text = "GPL"; + // + // GPL + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); + this.ClientSize = new System.Drawing.Size(576, 352); + this.Controls.Add(this.m_gpl); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + this.Name = "GPL"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "GNU General Public License Version 2"; + this.ResumeLayout(false); + } + #endregion + } +} diff --git a/MenuTree.cs b/MenuTree.cs new file mode 100644 index 0000000..10033a0 --- /dev/null +++ b/MenuTree.cs @@ -0,0 +1,163 @@ +// Noddybox.GUI - various GUI support routines +// Copyright (C) 2004 Ian Cowburn +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// $Id$ +// +using System; +using System.Windows.Forms; + +namespace Noddybox.GUI +{ + /// + /// Provides a directorey based interface to creating a Menu + /// + public class MenuTree + { + // -------------------------------- + // PUBLIC + // -------------------------------- + + /// + /// Constructs the pathed Menu + /// + /// The GUI object to manage + public MenuTree(Menu m) + { + m_defHandler=null; + m_dir=new DirectoryCollection(); + m_dir.Add("/",m); + } + + /// + /// The default event handler for menu items. + /// + public EventHandler DefaultHandler + { + set {m_defHandler = value;} + } + + /// + /// Adds a menu item + /// + /// The path to the item + /// The text to put in the menu item + public void Add(string path, string name) + { + if (m_defHandler!=null) + { + Add(path,new MenuItem(name,m_defHandler)); + } + else + { + Add(path,new MenuItem(name)); + } + } + + /// + /// Adds a menu item + /// + /// The path to the item + /// The text to put in the menu item + /// The event handler to associate with the menu item + public void Add(string path, string name, EventHandler handler) + { + Add(path,new MenuItem(name,handler)); + } + + /// + /// Adds a menu item + /// + /// The path to the item + /// The menu item + public void Add(string path, MenuItem item) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot set the root element"); + } + + m_dir.Add(path,item); + + object o=m_dir.GetParent(path); + + if (o is MenuItem) + { + MenuItem m=(MenuItem)o; + + m.MenuItems.Add(item); + } + else + { + Menu m=(Menu)o; + + m.MenuItems.Add(item); + } + } + + /// + /// Gets a menu item + /// + /// The path to the menu item + /// The MenuItem object + public MenuItem Get(string path) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot get the root element"); + } + + return (MenuItem)m_dir.Get(path); + } + + /// + /// Removes a section of the menu recursively + /// + /// The path to remove + public void Remove(string path) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot remove the root element"); + } + + object o=m_dir.GetParent(path); + MenuItem item=(MenuItem)m_dir.Get(path); + + m_dir.Remove(path); + + if (o is MenuItem) + { + MenuItem m=(MenuItem)o; + + m.MenuItems.Remove(item); + } + else + { + Menu m=(Menu)o; + + m.MenuItems.Remove(item); + } + } + + // -------------------------------- + // PRIVATE + // -------------------------------- + + private DirectoryCollection m_dir; + private EventHandler m_defHandler; + } +} diff --git a/Noddybox.GUI.About.resources b/Noddybox.GUI.About.resources new file mode 100644 index 0000000..c43cc20 Binary files /dev/null and b/Noddybox.GUI.About.resources differ diff --git a/Noddybox.GUI.GPL.resources b/Noddybox.GUI.GPL.resources new file mode 100644 index 0000000..5b85d43 Binary files /dev/null and b/Noddybox.GUI.GPL.resources differ diff --git a/Noddybox.GUI.cmbx b/Noddybox.GUI.cmbx new file mode 100644 index 0000000..1d1a65b --- /dev/null +++ b/Noddybox.GUI.cmbx @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Noddybox.GUI.prjx b/Noddybox.GUI.prjx new file mode 100644 index 0000000..2bbec56 --- /dev/null +++ b/Noddybox.GUI.prjx @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Noddybox.GUI.resources b/Noddybox.GUI.resources new file mode 100644 index 0000000..548f3eb Binary files /dev/null and b/Noddybox.GUI.resources differ diff --git a/NodeTree.cs b/NodeTree.cs new file mode 100644 index 0000000..6d4a145 --- /dev/null +++ b/NodeTree.cs @@ -0,0 +1,141 @@ +// Noddybox.GUI - various GUI support routines +// Copyright (C) 2004 Ian Cowburn +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// $Id$ +// +using System; +using System.Windows.Forms; + +namespace Noddybox.GUI +{ + /// + /// Provides a directory based interface to creating a TreeView + /// + public class NodeTree + { + // -------------------------------- + // PUBLIC + // -------------------------------- + + /// + /// Constructs the pathed Tree + /// + /// The GUI object to manage + public NodeTree(TreeView tree) + { + m_dir=new DirectoryCollection(); + m_tree=tree; + + m_dir.Add("/",m_tree.Nodes); + } + + /// + /// Adds a node + /// + /// The path to the node + /// The text to put in the node + /// The tag to associate with the node + public void Add(string path, string name, object tag) + { + Add(path,new TreeNode(name),tag); + } + + /// + /// Adds a node + /// + /// The path to the node + /// The Node to put there + /// The tag to associate with node + public void Add(string path, TreeNode node, object tag) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot set the root element"); + } + + node.Tag=tag; + m_dir.Add(path,node); + + object o=m_dir.GetParent(path); + + if (o is TreeNodeCollection) + { + TreeNodeCollection n=(TreeNodeCollection)o; + + n.Add(node); + } + else + { + TreeNode n=(TreeNode)o; + + n.Nodes.Add(node); + } + } + + /// + /// Gets a node + /// + /// The path to the node + /// The TreeNode object + public TreeNode Get(string path) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot get the root element"); + } + + return (TreeNode)m_dir.Get(path); + } + + /// + /// Removes a section of the tree recursively + /// + /// The path to remove + public void Remove(string path) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot remove the root element"); + } + + object o=m_dir.GetParent(path); + TreeNode node=(TreeNode)m_dir.Get(path); + + m_dir.Remove(path); + + if (o is TreeNodeCollection) + { + TreeNodeCollection n=(TreeNodeCollection)o; + + n.Remove(node); + } + else + { + TreeNode n=(TreeNode)o; + + n.Nodes.Remove(node); + } + } + + // -------------------------------- + // PRIVATE + // -------------------------------- + + private DirectoryCollection m_dir; + private TreeView m_tree; + } +} -- cgit v1.2.3