diff options
author | Ian C <ianc@noddybox.co.uk> | 2005-01-21 01:01:51 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2005-01-21 01:01:51 +0000 |
commit | 696c9c657336356770cfff65db53271296781bca (patch) | |
tree | c3e84134457ab6d0c8ae620735ea0535ec1968b4 | |
parent | 5c9feb641be08a26b687cf7147b95bd483eb067a (diff) |
Initial checkin
-rw-r--r-- | About.cs | 172 | ||||
-rw-r--r-- | AssemblyInfo.cs | 33 | ||||
-rw-r--r-- | DirectoryCollection.cs | 340 | ||||
-rw-r--r-- | GPL.cs | 94 | ||||
-rw-r--r-- | MenuTree.cs | 163 | ||||
-rw-r--r-- | Noddybox.GUI.About.resources | bin | 0 -> 5189 bytes | |||
-rw-r--r-- | Noddybox.GUI.GPL.resources | bin | 0 -> 3419 bytes | |||
-rw-r--r-- | Noddybox.GUI.cmbx | 16 | ||||
-rw-r--r-- | Noddybox.GUI.prjx | 32 | ||||
-rw-r--r-- | Noddybox.GUI.resources | bin | 0 -> 18681 bytes | |||
-rw-r--r-- | NodeTree.cs | 141 |
11 files changed, 991 insertions, 0 deletions
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 +{ + /// <summary> + /// Generic Noddybox About/Help box + /// </summary> + 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; + + /// <summary> + /// Displays an about box, with a button to display the GPL (or optionally + /// the GPL in the help window). + /// </summary> + /// <param name="title">The title of the program</param> + /// <param name="rtf_help">Help file. Set to null to display the GPL instead.</param> + 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 + /// <summary> + /// 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. + /// </summary> + 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 +{ + /// <summary> + /// Provides a collection to a directory type structure + /// </summary> + public sealed class DirectoryCollection : IEnumerable, IEnumerator + { + // -------------------------------- + // PUBLIC + // -------------------------------- + + /// <summary> + /// Construct a DirectoryCollection + /// </summary> + public DirectoryCollection() + { + m_dirsep='/'; + m_table=new Hashtable(); + m_iter_list=null; + } + + /// <summary> + /// Sets the path seperator (default '/'). + /// </summary> + public char Seperator + { + get {return m_dirsep;} + set {m_dirsep=value;} + } + + /// <summary> + /// Adds an item + /// </summary> + /// <param name="path">The path to the item</param> + /// <param name="tag">The item to add</param> + 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); + } + } + + /// <summary> + /// Gets an item. + /// </summary> + /// <param name="path">The path to the item</param> + /// <returns>The item</returns> + public object Get(string path) + { + CheckPath(path,true); + + DirNode n=(DirNode)m_table[path]; + + return n.Tag; + } + + /// <summary> + /// Gets the parent item. + /// </summary> + /// <param name="path">The path whose parent you want</param> + /// <returns>The parent item</returns> + 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; + } + + /// <summary> + /// Recursively remove a section of the directory structure + /// </summary> + /// <param name="path">The path to remove</param> + 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); + } + } + + /// <summary> + /// Returns true if the supplied path is the directory root. + /// </summary> + /// <param name="path">The path to check</param> + /// <returns>True is path is root</returns> + public bool IsRoot(string path) + { + return (path.Length==1 && path[0]==m_dirsep); + } + + /// <summary> + /// Gets an enumerator + /// </summary> + /// <returns>The enumerator</returns> + public IEnumerator GetEnumerator() + { + Reset(); + return this; + } + + /// <summary> + /// Get the current object from the enumerator + /// </summary> + public object Current + { + get + { + if (m_iter_list==null) + { + throw new InvalidOperationException(); + } + + DirNode t=(DirNode)m_iter_list[m_iter_index]; + return t.Tag; + } + } + + /// <summary> + /// Reset the enumerator to the start of the collection. + /// </summary> + public void Reset() + { + m_iter_index=-1; + FlattenTree(); + } + + /// <summary> + /// Move the enumerator to the next item. + /// </summary> + /// <returns>True if there are more objects to enumerate over</returns> + 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; + } + } +} @@ -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 +{ + /// <summary> + /// Displays the GPL. + /// </summary> + internal class GPL : System.Windows.Forms.Form + { + private System.Windows.Forms.RichTextBox m_gpl; + + /// <summary> + /// Constructs the GPL License form + /// </summary> + 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 + /// <summary> + /// 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. + /// </summary> + 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 +{ + /// <summary> + /// Provides a directorey based interface to creating a Menu + /// </summary> + public class MenuTree + { + // -------------------------------- + // PUBLIC + // -------------------------------- + + /// <summary> + /// Constructs the pathed Menu + /// </summary> + /// <param name="m">The GUI object to manage</param> + public MenuTree(Menu m) + { + m_defHandler=null; + m_dir=new DirectoryCollection(); + m_dir.Add("/",m); + } + + /// <summary> + /// The default event handler for menu items. + /// </summary> + public EventHandler DefaultHandler + { + set {m_defHandler = value;} + } + + /// <summary> + /// Adds a menu item + /// </summary> + /// <param name="path">The path to the item</param> + /// <param name="name">The text to put in the menu item</param> + public void Add(string path, string name) + { + if (m_defHandler!=null) + { + Add(path,new MenuItem(name,m_defHandler)); + } + else + { + Add(path,new MenuItem(name)); + } + } + + /// <summary> + /// Adds a menu item + /// </summary> + /// <param name="path">The path to the item</param> + /// <param name="name">The text to put in the menu item</param> + /// <param name="handler">The event handler to associate with the menu item</param> + public void Add(string path, string name, EventHandler handler) + { + Add(path,new MenuItem(name,handler)); + } + + /// <summary> + /// Adds a menu item + /// </summary> + /// <param name="path">The path to the item</param> + /// <param name="item">The menu item</param> + 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); + } + } + + /// <summary> + /// Gets a menu item + /// </summary> + /// <param name="path">The path to the menu item</param> + /// <returns>The MenuItem object</returns> + public MenuItem Get(string path) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot get the root element"); + } + + return (MenuItem)m_dir.Get(path); + } + + /// <summary> + /// Removes a section of the menu recursively + /// </summary> + /// <param name="path">The path to remove</param> + 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 Binary files differnew file mode 100644 index 0000000..c43cc20 --- /dev/null +++ b/Noddybox.GUI.About.resources diff --git a/Noddybox.GUI.GPL.resources b/Noddybox.GUI.GPL.resources Binary files differnew file mode 100644 index 0000000..5b85d43 --- /dev/null +++ b/Noddybox.GUI.GPL.resources 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 @@ +<Combine fileversion="1.0" name="Noddybox.GUI" description=""> + <StartMode startupentry="Noddybox.GUI" single="True"> + <Execute entry="Noddybox.GUI" type="None" /> + </StartMode> + <Entries> + <Entry filename=".\.\Noddybox.GUI.prjx" /> + </Entries> + <Configurations active="Debug"> + <Configuration name="Release"> + <Entry name="Noddybox.GUI" configurationname="Debug" build="False" /> + </Configuration> + <Configuration name="Debug"> + <Entry name="Noddybox.GUI" configurationname="Debug" build="False" /> + </Configuration> + </Configurations> +</Combine>
\ 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 @@ +<Project name="Noddybox.GUI" standardNamespace="Noddybox.GUI" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#"> + <Contents> + <File name=".\MenuTree.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\NodeTree.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\DirectoryCollection.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\About.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Noddybox.GUI.About.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> + <File name=".\Noddybox.GUI.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> + <File name=".\GPL.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Noddybox.GUI.GPL.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> + </Contents> + <References /> + <DeploymentInformation target="" script="" strategy="File" /> + <Configuration runwithwarnings="False" name="Debug"> + <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="Standard" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="True" win32Icon="" noconfig="False" nostdlib="False" /> + <Execution commandlineparameters="" consolepause="False" /> + <Output directory=".\bin\Debug" assembly="Noddybox.GUI" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" /> + </Configuration> + <Configurations active="Debug"> + <Configuration runwithwarnings="False" name="Debug"> + <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="Standard" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="True" win32Icon="" noconfig="False" nostdlib="False" /> + <Execution commandlineparameters="" consolepause="False" /> + <Output directory=".\bin\Debug" assembly="Noddybox.GUI" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" /> + </Configuration> + <Configuration runwithwarnings="True" name="Release"> + <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="Library" definesymbols="" generatexmldocumentation="True" win32Icon="" noconfig="False" nostdlib="False" /> + <Execution commandlineparameters="" consolepause="False" /> + <Output directory=".\bin\Release" assembly="Noddybox.GUI" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" /> + </Configuration> + </Configurations> +</Project>
\ No newline at end of file diff --git a/Noddybox.GUI.resources b/Noddybox.GUI.resources Binary files differnew file mode 100644 index 0000000..548f3eb --- /dev/null +++ b/Noddybox.GUI.resources 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 +{ + /// <summary> + /// Provides a directory based interface to creating a TreeView + /// </summary> + public class NodeTree + { + // -------------------------------- + // PUBLIC + // -------------------------------- + + /// <summary> + /// Constructs the pathed Tree + /// </summary> + /// <param name="tree">The GUI object to manage</param> + public NodeTree(TreeView tree) + { + m_dir=new DirectoryCollection(); + m_tree=tree; + + m_dir.Add("/",m_tree.Nodes); + } + + /// <summary> + /// Adds a node + /// </summary> + /// <param name="path">The path to the node</param> + /// <param name="name">The text to put in the node</param> + /// <param name="tag">The tag to associate with the node</param> + public void Add(string path, string name, object tag) + { + Add(path,new TreeNode(name),tag); + } + + /// <summary> + /// Adds a node + /// </summary> + /// <param name="path">The path to the node</param> + /// <param name="node">The Node to put there</param> + /// <param name="tag">The tag to associate with node</param> + 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); + } + } + + /// <summary> + /// Gets a node + /// </summary> + /// <param name="path">The path to the node</param> + /// <returns>The TreeNode object</returns> + public TreeNode Get(string path) + { + if (m_dir.IsRoot(path)) + { + throw new ArgumentException("Cannot get the root element"); + } + + return (TreeNode)m_dir.Get(path); + } + + /// <summary> + /// Removes a section of the tree recursively + /// </summary> + /// <param name="path">The path to remove</param> + 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; + } +} |