Patch to remember highlighted tag



The attached patch passes the currently highlighted tag to the create
tag dialogue. It could be improved in the case where multiple items are
highlighted (it should probably pass the last tag the user highlighted,
rather than the first in the list).

This is the first C# code I've written, so comments on
style/idiom/correctness are welcome.

cheers

Loz Hygate
? Makefile.solution.f-spot
? configure.scan
? f-spot.cmbx
? f-spot.mdsx
? make.sh
? po/Makefile
? po/Makefile.in
? po/Makefile.in.in
? po/POTFILES
? po/es.gmo
? src/AssemblyInfo.cs
? src/Main.cs
? src/Makefile.f-spot
? src/MyProgram.cs
? src/f-spot.pidb
? src/f-spot.prjx
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.102
diff -u -r1.102 MainWindow.cs
--- src/MainWindow.cs	13 Oct 2004 06:01:55 -0000	1.102
+++ src/MainWindow.cs	16 Oct 2004 13:41:34 -0000
@@ -877,14 +877,14 @@
 	public void HandleCreateNewTagCommand (object sender, EventArgs args)
 	{
 		TagCommands.Create command = new TagCommands.Create (db.Tags, main_window);
-		if (command.Execute (TagCommands.TagType.Tag))
+		if (command.Execute (TagCommands.TagType.Tag, tag_selection_widget.SingleCategoryHighlight))
 			tag_selection_widget.Update ();
 	}
 
 	public void HandleCreateNewCategoryCommand (object sender, EventArgs args)
 	{
 		TagCommands.Create command = new TagCommands.Create (db.Tags, main_window);
-		if (command.Execute (TagCommands.TagType.Category))
+		if (command.Execute (TagCommands.TagType.Category, tag_selection_widget.SingleCategoryHighlight))
 			tag_selection_widget.Update ();
 	}
 
Index: src/TagCommands.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/TagCommands.cs,v
retrieving revision 1.8
diff -u -r1.8 TagCommands.cs
--- src/TagCommands.cs	12 Sep 2004 19:26:38 -0000	1.8
+++ src/TagCommands.cs	16 Oct 2004 13:41:34 -0000
@@ -111,7 +111,28 @@
 			Update ();
 		}
 
-		public bool Execute (TagType type)
+		private Category Category {
+			get {
+				if (categories.Count == 0)
+					return tag_store.RootCategory;
+				else
+					return categories [category_option_menu.History] as Category;
+			}
+			set {
+				if ((value != null) && (categories.Count > 0)) {
+					//System.Console.WriteLine("TagCreateCommand.set_Category(" + value.Name + ")");
+					for (int i = 0; i < categories.Count; i++) {
+						Category category = (Category)categories[i];
+						// should there be an equals type method?
+						if (value.Id == category.Id) {
+							category_option_menu.SetHistory((uint)i);
+							return;
+						}
+					}	
+				}
+			}
+		}
+		public bool Execute (TagType type, Category default_category)
 		{
 			Glade.XML xml = new Glade.XML (null, "f-spot.glade", "create_tag_dialog", null);
 			xml.Autoconnect (this);
@@ -130,6 +151,7 @@
 			}
 
 			PopulateCategoryOptionMenu ();
+			Category = default_category;
 			Update ();
 
 			ResponseType response = (ResponseType) create_tag_dialog.Run ();
@@ -138,12 +160,7 @@
 
 			if (response == ResponseType.Ok) {
 				try {
-					Category parent_category;
-
-					if (categories.Count == 0)
-						parent_category = tag_store.RootCategory;
-					else
-						parent_category = categories [category_option_menu.History] as Category;
+					Category parent_category = Category;
 
 					if (type == TagType.Category)
 						tag_store.CreateCategory (parent_category, tag_name_entry.Text);
Index: src/TagSelectionWidget.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/TagSelectionWidget.cs,v
retrieving revision 1.11
diff -u -r1.11 TagSelectionWidget.cs
--- src/TagSelectionWidget.cs	17 Jun 2004 04:05:57 -0000	1.11
+++ src/TagSelectionWidget.cs	16 Oct 2004 13:41:35 -0000
@@ -104,8 +104,35 @@
 			SelectionChanged (this);
 		}
 	}
-
-
+	
+	// For actions that want to act on a single tag
+	// it can obviously be sped up by stopping after the first match
+	// May want to consider returning the last tag the user tag highlighted
+	public Tag SingleTagHighlight
+	{
+		get {
+			Tag[] highlight = TagHighlight();
+			if (highlight.Length > 0) 
+				return highlight[0];
+			else
+				return null;
+		}
+	}
+	
+	// For actions that want to act on a single category
+	// Uses SingleTagSelection so fixing that to return the last tag the user highlighted would make this return last category...
+	public Category SingleCategoryHighlight
+	{
+		get {
+			Tag tag = SingleTagHighlight;
+			if (tag == null)
+				return null; 
+			else if (tag is Category)
+				return tag as Category;
+			else
+				return tag.Category;
+		}
+	}
 	// Loading up the store.
 
 	private void LoadCategory (Category category, TreeIter parent_iter)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]