[f-spot: 1/16] Detach version menu item added.



commit 4ff1f89d53983a655eb0f4a275de04648e5c4f6b
Author: Anton Keks <anton azib net>
Date:   Mon Jul 20 22:20:29 2009 +0300

    Detach version menu item added.
    
    Detach creates a separate photo from the selected version, making it an opposite of reparenting.

 src/Core/Photo.cs           |   10 +++++-
 src/MainWindow.cs           |   28 +++++++---------
 src/PhotoVersionCommands.cs |   74 ++++++++++++++++++++++++++++++------------
 src/ui/main_window.ui       |    8 +++++
 4 files changed, 83 insertions(+), 37 deletions(-)
---
diff --git a/src/Core/Photo.cs b/src/Core/Photo.cs
index c29014c..c460893 100644
--- a/src/Core/Photo.cs
+++ b/src/Core/Photo.cs
@@ -437,7 +437,15 @@ namespace FSpot
 	//		File.Move (old_path, new_path);
 	//		PhotoStore.MoveThumbnail (old_path, new_path);
 		}
-	
+		
+		public void CopyAttributesFrom (PhotoVersion that) 
+		{			
+			Time = that.Time;
+			Description = that.Description;
+			Rating = that.Rating;
+			MD5Sum = that.MD5Sum;
+			AddTag (that.Tags);
+		}
 	
 		// Tag management.
 	
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index f1edd8c..4c19adb 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -57,9 +57,10 @@ namespace FSpot
 		[GtkBeans.Builder.Object] Label status_label;
 	
 		[GtkBeans.Builder.Object] Gtk.UIManager uimanager;
-		// File
+		// Photo
 		[GtkBeans.Builder.Object] Gtk.Action create_version_menu_item;
 		[GtkBeans.Builder.Object] Gtk.Action delete_version_menu_item;
+		[GtkBeans.Builder.Object] Gtk.Action detach_version_menu_item;
 		[GtkBeans.Builder.Object] Gtk.Action rename_version_menu_item;
 		
 		[GtkBeans.Builder.Object] Gtk.Action tools;
@@ -1705,31 +1706,25 @@ namespace FSpot
 		void HandleCreateVersionCommand (object obj, EventArgs args)
 		{
 			PhotoVersionCommands.Create cmd = new PhotoVersionCommands.Create ();
-	
 			cmd.Execute (Database.Photos, CurrentPhoto, GetToplevel (null));
-	//		if (cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null))) {
-	//			query.MarkChanged (ActiveIndex (), true, false);
-	//		}
 		}
 	
 		void HandleDeleteVersionCommand (object obj, EventArgs args)
 		{
 			PhotoVersionCommands.Delete cmd = new PhotoVersionCommands.Delete ();
-	
 			cmd.Execute (Database.Photos, CurrentPhoto, GetToplevel (null));
-	//		if (cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null))) {
-	//			query.MarkChanged (ActiveIndex (), true, true);
-	//		}
+		}
+		
+		void HandleDetachVersionCommand (object obj, EventArgs args)
+		{
+			PhotoVersionCommands.Detach cmd = new PhotoVersionCommands.Detach ();
+			cmd.Execute (db.Photos, CurrentPhoto, GetToplevel (null));
 		}
 	
 		void HandleRenameVersionCommand (object obj, EventArgs args)
 		{
 			PhotoVersionCommands.Rename cmd = new PhotoVersionCommands.Rename ();
-	
 			cmd.Execute (Database.Photos, CurrentPhoto, main_window);
-	//		if (cmd.Execute (db.Photos, CurrentPhoto, main_window)) {
-	//			query.MarkChanged (ActiveIndex (), true, false);
-	//		}
 		}
 		
 		public void HandleCreateTagAndAttach (object sender, EventArgs args)
@@ -2699,6 +2694,7 @@ namespace FSpot
 	
 				create_version_menu_item.Sensitive = false;
 				delete_version_menu_item.Sensitive = false;
+				detach_version_menu_item.Sensitive = false;
 				rename_version_menu_item.Sensitive = false;
 	
 				sharpen.Sensitive = false;
@@ -2709,9 +2705,11 @@ namespace FSpot
 				
 				if (CurrentPhoto.DefaultVersionId == Photo.OriginalVersionId) {
 					delete_version_menu_item.Sensitive = false;
+					detach_version_menu_item.Sensitive = false;
 					rename_version_menu_item.Sensitive = false;
 				} else {
 					delete_version_menu_item.Sensitive = true;
+					detach_version_menu_item.Sensitive = true;
 					rename_version_menu_item.Sensitive = true;
 				}
 	
@@ -2921,12 +2919,12 @@ namespace FSpot
 		}
 	
 		public void GetWidgetPosition(Widget widget, out int x, out int y)
-	    {
+		{
 			main_window.GdkWindow.GetOrigin(out x, out y);
 			
 			x += widget.Allocation.X;
 			y += widget.Allocation.Y;
-	 	}
+		}
 	
 		// Tag typing ...
 	
diff --git a/src/PhotoVersionCommands.cs b/src/PhotoVersionCommands.cs
index ef1d27f..1a753d7 100644
--- a/src/PhotoVersionCommands.cs
+++ b/src/PhotoVersionCommands.cs
@@ -143,38 +143,34 @@ public class PhotoVersionCommands
 			string version_name = photo.GetVersion (photo.DefaultVersionId).Name;
 			Label label = new Label (String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), version_name));
 			label.Show ();
-			dialog.VBox.PackStart (label, false, true, 6);;
+			dialog.VBox.PackStart (label, false, true, 6);
 
-			if (dialog.Run () == (int) ResponseType.Ok) {
-				try {
+			try {
+				if (dialog.Run () == (int) ResponseType.Ok) {
 					photo.DeleteVersion (photo.DefaultVersionId);
 					store.Commit (photo);
-				} catch (Exception e) {
-					Log.DebugException (e);
-					string msg = Catalog.GetString ("Could not delete a version");
-					string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to delete version \"{1}\""),
-								     e.Message, photo.Name);
-					
-					HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
-										    Gtk.MessageType.Error, ButtonsType.Ok, 
-										    msg,
-										    desc);
-					md.Run ();
-					md.Destroy ();
-					dialog.Destroy (); // Delete confirmation window.
-					return false;
+					return true;
 				}
-
+			} catch (Exception e) {
+				Log.DebugException (e);
+				string msg = Catalog.GetString ("Could not delete a version");
+				string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to delete version \"{1}\""),
+							     e.Message, photo.Name);
+				
+				HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
+									    Gtk.MessageType.Error, ButtonsType.Ok, msg, desc);
+				md.Run ();
+				md.Destroy ();
+				dialog.Destroy (); // Delete confirmation window.
+			}
+			finally {
 				dialog.Destroy ();
-				return true;
 			}
 
-			dialog.Destroy ();
 			return false;
 		}
 	}
 
-
 	// Renaming a version.
 
 	public class Rename {
@@ -210,7 +206,43 @@ public class PhotoVersionCommands
 		}
 	}
 
+	// Detaching a version (making it a separate photo).
+	
+	public class Detach {
+		public bool Execute (PhotoStore store, Photo photo, Gtk.Window parent_window)
+		{
+			string ok_caption = Catalog.GetString ("De_tach");
+			string msg = String.Format (Catalog.GetString ("Really detach version \"{0}\" from \"{1}\"?"), photo.DefaultVersion.Name, photo.Name.Replace("_", "__"));
+			string desc = Catalog.GetString ("This makes the verion appear as a separate photo in the library.");
+			try {
+				if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, 
+									   MessageType.Warning, msg, desc, ok_caption)) {
+					Gdk.Pixbuf thumbnail = null;
+					Photo new_photo = store.Create (photo.DefaultVersionUri, photo.RollId, out thumbnail);
+					new_photo.CopyAttributesFrom (photo.DefaultVersion);
+					store.Commit (new_photo);
+
+					photo.DeleteVersion (photo.DefaultVersionId, false, true);
+					store.Commit (photo);
+					return true;
+				}
+			} catch (Exception e) {
+				Log.DebugException (e);
+				msg = Catalog.GetString ("Could not detach a version");
+				desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to detach version \"{1}\""),
+							     e.Message, photo.Name);
+				HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, 
+									    Gtk.MessageType.Error, ButtonsType.Ok, msg, desc);
+				md.Run ();
+				md.Destroy ();					
+			}
+
+			return false;
+		}
+	}
+
 	// Reparenting a photo as version of another one
+	
 	public class Reparent {
 		public bool Execute (PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
 		{
diff --git a/src/ui/main_window.ui b/src/ui/main_window.ui
index 7082d1d..2e12700 100644
--- a/src/ui/main_window.ui
+++ b/src/ui/main_window.ui
@@ -55,6 +55,13 @@
           </object>
         </child>
         <child>
+          <object class="GtkAction" id="detach_version_menu_item">
+            <property name="name">detach_version_menu_item</property>
+            <property name="label" translatable="yes">De_tach Version</property>
+            <signal handler="HandleDetachVersionCommand" name="activate"/>
+          </object>
+        </child>
+        <child>
           <object class="GtkAction" id="export">
             <property name="name">export</property>
             <property name="label" translatable="yes">_Export to</property>
@@ -582,6 +589,7 @@
           <menuitem action="create_version_menu_item"/>
           <menuitem action="delete_version_menu_item"/>
           <menuitem action="rename_version_menu_item"/>
+          <menuitem action="detach_version_menu_item"/>
           <separator/>
           <menuitem action="export"/>
           <menuitem action="print"/>



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