[Monodevelop-patches-list] r722 - in trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Widgets: . FileBrowser

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Fri Jan 30 01:02:22 EST 2004


Author: jluke
Date: 2004-01-30 01:02:21 -0500 (Fri, 30 Jan 2004)
New Revision: 722

Added:
   trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Widgets/FileBrowser/
   trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Widgets/FileBrowser/FileBrowser.cs
Log:
a widget to browse files in the ClassBrowser
not quite finished yet


Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Widgets/FileBrowser/FileBrowser.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Widgets/FileBrowser/FileBrowser.cs	2004-01-29 23:52:56 UTC (rev 721)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Widgets/FileBrowser/FileBrowser.cs	2004-01-30 06:02:21 UTC (rev 722)
@@ -0,0 +1,98 @@
+using System;
+using System.IO;
+using Gtk;
+using GtkSharp;
+
+namespace MonoDevelop.Gui.Widgets
+{
+	public class FileBrowser : ScrolledWindow
+	{
+		private static GLib.GType gtype;
+		private TreeView tv;
+		private ListStore store;
+		private string currentDir;
+		private bool ignoreHidden;
+		private string[] files;
+
+		public FileBrowser () : base (GType)
+		{
+			this.VscrollbarPolicy = PolicyType.Automatic;
+			this.HscrollbarPolicy = PolicyType.Automatic;
+			ignoreHidden = true;
+
+			tv = new TreeView ();
+			tv.AppendColumn ("Name", new CellRendererText (), "text", 0);
+			store = new ListStore (typeof (string));
+			currentDir = Environment.GetEnvironmentVariable ("HOME");
+			Populate ();
+			tv.Model = store;
+
+			tv.RowActivated += new RowActivatedHandler (OnRowActivated);
+			tv.Selection.Changed += new EventHandler (OnSelectionChanged);
+
+			this.Add (tv);
+			this.ShowAll ();
+		}
+
+		public bool IgnoreHidden
+		{
+			get { return ignoreHidden; }
+			set { ignoreHidden = value; }
+		}
+
+		public static new GLib.GType GType
+		{
+			get
+			{
+				if (gtype == GLib.GType.Invalid)
+					gtype = RegisterGType (typeof (FileBrowser));
+
+				return gtype;
+			}
+		}
+
+		void Populate ()
+		{
+			store.Clear ();
+			// seems unnecessary
+			// store.AppendValues (".");
+			if (currentDir != "/")
+				store.AppendValues ("..");
+
+			DirectoryInfo di = new DirectoryInfo (currentDir);
+			DirectoryInfo[] dirs = di.GetDirectories ();
+			
+			foreach (DirectoryInfo d in dirs)
+			{
+				if (ignoreHidden)
+				{
+					if (!d.Name.StartsWith ("."))
+						store.AppendValues (d.Name);
+				}
+				else
+				{
+					store.AppendValues (d.Name);
+				}
+			}
+		}
+
+		private void OnSelectionChanged (object o, EventArgs args)
+		{
+			TreeIter iter;
+			TreeModel model;
+			tv.Selection.GetSelected (out model, out iter);
+			string selection = (string) model.GetValue (iter, 0);
+			files = Directory.GetFiles (System.IO.Path.Combine (currentDir, selection));
+		}
+
+		private void OnRowActivated (object o, RowActivatedArgs args)
+		{
+			TreeIter iter;
+			store.GetIter (out iter, args.Path);
+			string file = (string) store.GetValue (iter, 0);
+			currentDir = System.IO.Path.Combine (currentDir, file);
+			Populate ();
+		}
+	}
+}
+




More information about the Monodevelop-patches-list mailing list