[Monodevelop-patches-list] r2041 - in trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets: . FileSelector

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Wed Dec 1 00:51:55 EST 2004


Author: jluke
Date: 2004-12-01 00:51:55 -0500 (Wed, 01 Dec 2004)
New Revision: 2041

Modified:
   trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/ChangeLog
   trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/FileSelector/FileSelector.cs
Log:
2004-12-01  John Luke  <john.luke at gmail.com>

        * FileSelector/FileSelector.cs: improve this to take advantage
        of the FileChooser and remove my old hacks that were likely buggy
        use a switch for adding the buttons
        add ~/Projects as a MD specific bookmark



Modified: trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/ChangeLog	2004-11-26 05:50:07 UTC (rev 2040)
+++ trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/ChangeLog	2004-12-01 05:51:55 UTC (rev 2041)
@@ -1,3 +1,10 @@
+2004-12-01  John Luke  <john.luke at gmail.com>
+
+	* FileSelector/FileSelector.cs: improve this to take advantage
+	of the FileChooser and remove my old hacks that were likely buggy
+	use a switch for adding the buttons
+	add ~/Projects as a MD specific bookmark
+
 2004-10-29  Todd Berman  <tberman at off.net>
 
 	* FileSelector/FileSelector.cs: Add proper Save buttons.

Modified: trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/FileSelector/FileSelector.cs
===================================================================
--- trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/FileSelector/FileSelector.cs	2004-11-26 05:50:07 UTC (rev 2040)
+++ trunk/MonoDevelop/Core/src/Libraries/MonoDevelop.Gui.Widgets/FileSelector/FileSelector.cs	2004-12-01 05:51:55 UTC (rev 2041)
@@ -1,5 +1,4 @@
 using System;
-using System.IO;
 using Gtk;
 
 using MonoDevelop.Services;
@@ -7,13 +6,9 @@
 
 namespace MonoDevelop.Gui.Widgets
 {
-	// basically just to remember the last directory
-	// we could do some if GTK2.4 then use new FileChooser
-	// but that is probably to be hacky at best
 	public class FileSelector : FileChooserDialog
 	{
 		const string LastPathProperty = "MonoDevelop.FileSelector.LastPath";
-		string lastPath;
 		PropertyService propertyService = (PropertyService) ServiceManager.GetService (typeof (PropertyService));
 
 		public FileSelector () : base (GettextCatalog.GetString ("Open file ..."), null, FileChooserAction.Open)
@@ -32,61 +27,43 @@
 
 		public FileSelector (string title, FileChooserAction action) : base (title, null, action)
 		{
-			if (action == FileChooserAction.SelectFolder) {
-				AddButton (Gtk.Stock.Cancel, ResponseType.Cancel);
-				AddButton ("Select Folder", ResponseType.Ok);
-			} else if (action == FileChooserAction.Save) {
-				AddButton (Gtk.Stock.Cancel, ResponseType.Cancel);
-				AddButton (Gtk.Stock.Save, ResponseType.Ok);
+			switch (action) {
+				case FileChooserAction.SelectFolder:
+					AddButton (Gtk.Stock.Cancel, ResponseType.Cancel);
+					AddButton ("Select Folder", ResponseType.Ok);
+					break;
+				case FileChooserAction.Save:
+					AddButton (Gtk.Stock.Cancel, ResponseType.Cancel);
+					AddButton (Gtk.Stock.Save, ResponseType.Ok);
+					break;
+				default:
+					break;
 			}
+
 			CommonSetup ();
 		}
 
 		void CommonSetup ()
 		{
 			// Restore the last active directory
-			string tmp = (string) propertyService.GetProperty (LastPathProperty);
-			if (tmp != null && tmp.Length > 0)
-			{
-				if (tmp.EndsWith ("/"))
-					lastPath = String.Format ("{0}", tmp.Trim ());
-				else
-					lastPath = String.Format ("{0}/", tmp.Trim ());
-			}
+			string last = (string) propertyService.GetProperty (LastPathProperty);
+			if (last != null && last.Length > 0)
+				this.SetCurrentFolder (last);
 			else
-			{
-				// FIXME: use ~/DefaultPath?
-				lastPath = Environment.GetEnvironmentVariable ("HOME");
-			}
+				this.SetCurrentFolder (Environment.GetFolderPath (Environment.SpecialFolder.Personal));
 
-			// Set the dir here, must end in "/" to work right
-			this.SetFilename (lastPath);
+			// add ~/Projects as a MD bookmark
+			this.AddShortcutFolder (System.IO.Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "Projects"));
 
-			// Basically need to track if the directory has
-			// been changed in the simplest way possible
-			// I think that this always changes when the dir does
-			this.CurrentFolderChanged += OnOptionListChanged;
+			// FIXME: only set this once per-dialog
+			// perhaps in Dispose ()? or only when a file or dir is selected
+			this.CurrentFolderChanged += OnCurrentFolderChanged;
 		}
 
-		void OnOptionListChanged (object o, EventArgs args)
+		void OnCurrentFolderChanged (object o, EventArgs args)
 		{
-			UpdateLastDir ();
+			propertyService.SetProperty (LastPathProperty, this.CurrentFolder);
 		}
-
-		void UpdateLastDir ()
-		{
-			if (this.Filename == null || this.Filename == "")
-				return;
-			
-			if (this.Filename.EndsWith ("/") || Directory.Exists (this.Filename))
-				lastPath = this.Filename;
-			else
-				lastPath = System.IO.Path.GetDirectoryName (this.Filename);
-		
-			// Console.WriteLine ("storing: {0}", lastPath);
-			// FIXME: find a way to only set this once per-dialog
-			propertyService.SetProperty (LastPathProperty, lastPath);
-		}
 	}
 }
 




More information about the Monodevelop-patches-list mailing list