Commit 18d4df5b2715b0b3cfe249eab6d521624646bbe0

Fix Copy to Clipboard

The SetUris method of SelectionData seems to not work correctly since
it gets a string but its native pendant gets a string array. This commits
works around it.

https://bugzilla.gnome.org/show_bug.cgi?id=628048
  
99using System;
1010using System.Text;
1111using System.Linq;
12using System.IO;
1213using System.Collections;
1314using System.Collections.Generic;
1415
22892289 return;
22902290 }
22912291
2292 clipboard.SetWithData (new TargetEntry[] {
2293 DragDropTargets.PlainTextEntry,
2294 DragDropTargets.UriListEntry,
2295 DragDropTargets.CopyFilesEntry,},
2296 delegate (Clipboard clip, SelectionData data, uint info) {
2297 var paths = new List<string> ();
2298 var uris = new List<string> ();
2299 foreach (Photo p in SelectedPhotos ()) {
2300 paths.Add (System.IO.Path.GetFullPath (p.DefaultVersion.Uri.LocalPath));
2301 uris.Add (p.DefaultVersion.Uri.ToString ());
2302 }
2303 data.Text = String.Join (" ", paths.ToArray ());
2304 data.SetUris (String.Join (" ", uris.ToArray ()));
2305 data.Set (Atom.Intern ("x-special/gnome-copied-files", true), 8, System.Text.Encoding.UTF8.GetBytes ("copy\n" + String.Join ("\n", uris.ToArray ())));
2292 var target_entries = new TargetEntry[] {
2293 DragDropTargets.PlainTextEntry,
2294 DragDropTargets.UriListEntry,
2295 DragDropTargets.CopyFilesEntry};
23062296
2307 },
2308 delegate {});
2297 // use eager evaluation, because we want to copy the photos which are currently selected ...
2298 var uris = new UriList (from p in SelectedPhotos () select p.DefaultVersion.Uri);
2299 var paths = String.Join (" ",
2300 (from p in SelectedPhotos ()
2301 select p.DefaultVersion.Uri.LocalPath).ToArray ()
2302 );
23092303
2310 var pt = new List<string> ();
2311 foreach (Photo p in SelectedPhotos ()) {
2312 pt.Add (System.IO.Path.GetFullPath (p.DefaultVersion.Uri.LocalPath));
2313 }
2304 clipboard.SetWithData (target_entries, delegate (Clipboard clip, SelectionData data, uint info) {
23142305
2315 primary.Text = String.Join (" ", pt.ToArray ());
2306 if (info == DragDropTargets.PlainTextEntry.Info) {
2307 data.Text = paths;
2308 return;
2309 }
2310
2311 if (info == DragDropTargets.UriListEntry.Info) {
2312 data.SetUriListData (uris);
2313 return;
2314 }
2315
2316 if (info == DragDropTargets.CopyFilesEntry.Info) {
2317 data.SetCopyFiles (uris);
2318 return;
2319 }
2320
2321 Log.DebugFormat ("Unknown Selection Data Target (info: {0})", info);
2322 }, delegate {});
2323
2324 primary.Text = paths;
23162325 }
23172326
23182327 void HandleSetAsBackgroundCommand (object sender, EventArgs args)
  
1010
1111using System;
1212using System.Text;
13using System.Linq;
1314
1415using Gtk;
1516using Gdk;
110110 selection_data.Set (target, 8, data, data.Length);
111111 }
112112
113 public static void SetUriListData (this SelectionData selection_data, UriList uri_list)
114 {
115 selection_data.SetUriListData (uri_list, Atom.Intern ("text/uri-list", true));
116 }
117
113118 public static UriList GetUriListData (this SelectionData selection_data)
114119 {
115120 return new UriList (GetStringData (selection_data));
116121 }
122
123 public static void SetCopyFiles (this SelectionData selection_data, UriList uri_list)
124 {
125 var uris = (from p in uri_list select p.ToString ()).ToArray ();
126 var data = Encoding.UTF8.GetBytes ("copy\n" + String.Join ("\n", uris));
127
128 selection_data.Set (Atom.Intern ("x-special/gnome-copied-files", true), 8, data, data.Length);
129 }
117130 }
118131}