[f-spot] Allow to copy files to clipboard



commit d86e6b1687437fccd4a7af520a6f38735c77a03e
Author: Stephane Delcroix <stephane delcroix org>
Date:   Sat Dec 19 21:37:56 2009 +0100

    Allow to copy files to clipboard
    
    extend the CopyLocation to allow to ctrl-C and paste to nautilus
    
    fixes bgo#597647

 src/DragDropTargets.cs          |   24 ++++++++++++++--------
 src/Extensions/PopupCommands.cs |    4 +-
 src/FSpot.addin.xml             |    2 +-
 src/MainWindow.cs               |   40 +++++++++++++++++++++++---------------
 src/ui/main_window.ui           |   11 +++++----
 5 files changed, 48 insertions(+), 33 deletions(-)
---
diff --git a/src/DragDropTargets.cs b/src/DragDropTargets.cs
index f893e0a..433f099 100644
--- a/src/DragDropTargets.cs
+++ b/src/DragDropTargets.cs
@@ -14,36 +14,42 @@ namespace FSpot
 {	
 	public static class DragDropTargets
 	{
-		enum TargetType {
+		enum TargetType : uint {
 			PlainText = 0,
 			UriList,
 			TagList,
 			TagQueryItem,
 			UriQueryItem,
 			PhotoList,
-			RootWindow
+			RootWindow,
+			CopyFiles,
 		};
 
+		[Obsolete ("better use gtk_target_list_add_text_targets")]
 		public static readonly TargetEntry PlainTextEntry =
-			new TargetEntry ("text/plain", 0, (uint) TargetType.PhotoList);
+			new TargetEntry ("text/plain", 0, (uint)TargetType.PhotoList);
 		
 		public static readonly TargetEntry PhotoListEntry =
-			new TargetEntry ("application/x-fspot-photos", 0, (uint) TargetType.PhotoList);
+			new TargetEntry ("application/x-fspot-photos", 0, (uint)TargetType.PhotoList);
 		
+		[Obsolete ("Use gtk_target_list_add_uri_target")]
 		public static readonly TargetEntry UriListEntry =
-			new TargetEntry ("text/uri-list", 0, (uint) TargetType.UriList);
+			new TargetEntry ("text/uri-list", 0, (uint)TargetType.UriList);
 		
 		public static readonly TargetEntry TagListEntry =
-			new TargetEntry ("application/x-fspot-tags", 0, (uint) TargetType.TagList);
+			new TargetEntry ("application/x-fspot-tags", 0, (uint)TargetType.TagList);
 		
 		/* FIXME: maybe we need just one fspot-query-item */
 		public static readonly TargetEntry UriQueryEntry =
-			new TargetEntry ("application/x-fspot-uri-query-item", 0, (uint) TargetType.UriQueryItem);
+			new TargetEntry ("application/x-fspot-uri-query-item", 0, (uint)TargetType.UriQueryItem);
 		
 		public static readonly TargetEntry TagQueryEntry =
-			new TargetEntry ("application/x-fspot-tag-query-item", 0, (uint) TargetType.TagQueryItem);
+			new TargetEntry ("application/x-fspot-tag-query-item", 0, (uint)TargetType.TagQueryItem);
 		
 		public static readonly TargetEntry RootWindowEntry =
-			new TargetEntry ("application/x-root-window-drop", 0, (uint) TargetType.RootWindow);
+			new TargetEntry ("application/x-root-window-drop", 0, (uint)TargetType.RootWindow);
+
+		public static readonly TargetEntry CopyFilesEntry =
+			new TargetEntry ("x-special/gnome-copied-files", 0, (uint)TargetType.CopyFiles);
 	}
 }
diff --git a/src/Extensions/PopupCommands.cs b/src/Extensions/PopupCommands.cs
index a0ae7b5..787533b 100644
--- a/src/Extensions/PopupCommands.cs
+++ b/src/Extensions/PopupCommands.cs
@@ -14,11 +14,11 @@ using FSpot.Widgets;
 
 namespace FSpot.Extensions 
 {
-	public class CopyLocation : ICommand
+	public class Copy : ICommand
 	{
 		public void Run (object o, EventArgs e)
 		{
-			MainWindow.Toplevel.HandleCopyLocation (o, e);
+			MainWindow.Toplevel.HandleCopy (o, e);
 		}		
 	}
 
diff --git a/src/FSpot.addin.xml b/src/FSpot.addin.xml
index 053c7bf..e54e6b3 100644
--- a/src/FSpot.addin.xml
+++ b/src/FSpot.addin.xml
@@ -45,7 +45,7 @@
 	<ConditionType id="ViewMode" type="FSpot.Extensions.ViewModeCondition" />
 
 	<Extension path = "/FSpot/Menus/PhotoPopup">
-		<Command id = "CopyLocation" _label = "Copy Photo Locat_ion" command_type = "FSpot.Extensions.CopyLocation" />
+		<Command id = "Copy" _label = "Copy Photo" command_type = "FSpot.Extensions.Copy" />
 		<MenuSeparator id = "Separator1" />
 		<Command id = "RLeft" _label = "Rotate _Left" icon = "object-rotate-left" command_type = "FSpot.Extensions.Rotate270" />
 		<Command id = "RRight" _label = "Rotate _Right" icon = "object-rotate-right" command_type = "FSpot.Extensions.Rotate90" />
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index 5e7c1fb..d2a4bc8 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -70,7 +70,7 @@ namespace FSpot
 		[GtkBeans.Builder.Object] Gtk.Action send_mail;
 	
 		// Edit
-		[GtkBeans.Builder.Object] Gtk.Action copy_location;
+		[GtkBeans.Builder.Object] Gtk.Action copy;
 		[GtkBeans.Builder.Object] Gtk.Action select_none;
 		[GtkBeans.Builder.Object] Gtk.Action rotate_left;
 		[GtkBeans.Builder.Object] Gtk.Action rotate_right;
@@ -2391,27 +2391,35 @@ namespace FSpot
 			RotateSelectedPictures (GetToplevel (sender), RotateDirection.Counterclockwise);
 		}
 	
-		public void HandleCopyLocation (object sender, EventArgs args)
+		public void HandleCopy (object sender, EventArgs args)
 		{
-			/*
-			 * FIXME this should really set uri atoms as well as string atoms
-			 */
 			Clipboard primary = Clipboard.Get (Atom.Intern ("PRIMARY", false));
 			Clipboard clipboard = Clipboard.Get (Atom.Intern ("CLIPBOARD", false));
+
+			clipboard.SetWithData (new TargetEntry[] {
+						DragDropTargets.PlainTextEntry,
+						DragDropTargets.UriListEntry,
+						DragDropTargets.CopyFilesEntry,},
+					delegate (Clipboard clip, SelectionData data, uint info) {
+						var paths = new List<string> ();
+						var uris = new List<string> ();
+						foreach (Photo p in SelectedPhotos ()) {
+							paths.Add (System.IO.Path.GetFullPath (p.DefaultVersionUri.LocalPath));
+							uris.Add (p.DefaultVersionUri.ToString ());
+						}
+						data.Text = String.Join (" ", paths.ToArray ());
+						data.SetUris (String.Join (" ", uris.ToArray ()));
+						data.Set (Atom.Intern ("x-special/gnome-copied-files", true), 8, System.Text.Encoding.UTF8.GetBytes ("copy\n" + String.Join ("\n", uris.ToArray ())));
+						
+					},
+					delegate {});
 	
-			StringBuilder paths = new StringBuilder ();
-			
-			int i = 0;
+			var pt = new List<string> ();
 			foreach (Photo p in SelectedPhotos ()) {
-				if (i++ > 0)
-					paths.Append (" ");
-	
-				paths.Append (System.IO.Path.GetFullPath (p.DefaultVersionUri.LocalPath));
+				pt.Add (System.IO.Path.GetFullPath (p.DefaultVersionUri.LocalPath));
 			}
 			
-			String data = paths.ToString ();
-			primary.Text = data;
-			clipboard.Text = data;
+			primary.Text = String.Join (" ", pt.ToArray ());
 		}
 	
 		void HandleSetAsBackgroundCommand (object sender, EventArgs args)
@@ -2748,7 +2756,7 @@ namespace FSpot
 			send_mail.Sensitive = active_selection;
 			print.Sensitive = active_selection;
 			select_none.Sensitive = active_selection;
-			copy_location.Sensitive = active_selection;
+			copy.Sensitive = active_selection;
 			remove_from_catalog.Sensitive = active_selection;
 			
 			clear_rating_filter.Sensitive = (query.RatingRange != null);
diff --git a/src/ui/main_window.ui b/src/ui/main_window.ui
index b165189..6ef2e30 100644
--- a/src/ui/main_window.ui
+++ b/src/ui/main_window.ui
@@ -106,11 +106,12 @@
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="copy_location">
-            <property name="name">copy_location</property>
-            <property name="label" translatable="yes">Copy Locat_ion</property>
-            <signal handler="HandleCopyLocation" name="activate"/>
+          <object class="GtkAction" id="copy">
+            <property name="name">copy</property>
+            <property name="label" translatable="yes">Copy</property>
+            <signal handler="HandleCopy" name="activate"/>
           </object>
+	  <accelerator key="C" modifiers="GDK_CONTROL_MASK"/>
         </child>
         <child>
           <object class="GtkAction" id="select_all">
@@ -583,7 +584,7 @@
           <menuitem action="quit"/>
         </menu>
         <menu action="edit2">
-          <menuitem action="copy_location"/>
+          <menuitem action="copy"/>
           <menuitem action="select_all"/>
           <menuitem action="select_none"/>
           <separator/>



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