~elementary-apps/pantheon-files/trunk

« back to all changes in this revision

Viewing changes to libcore/DndHandler.vala

  • Committer: Jeremy Wootten
  • Date: 2017-01-13 13:36:33 UTC
  • mfrom: (2444 pantheon-files)
  • mto: This revision was merged to the branch mainline in revision 2471.
  • Revision ID: jeremy@elementaryos.org-20170113133633-ajg6izr1e6irmj0g
Merge r2444

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***
2
 
    Copyright (c) 2015-2016 elementary LLC (http://launchpad.net/elementary)
 
2
    Copyright (c) 2015-2017 elementary LLC (http://launchpad.net/elementary)
3
3
 
4
4
    This program is free software; you can redistribute it and/or modify
5
5
    it under the terms of the GNU General Public License as published by
154
154
                                           );
155
155
 
156
156
            if (exists && data != null) {
157
 
                string name = data_to_string (data);
 
157
                string name = DndHandler.data_to_string (data);
158
158
                if (GLib.Path.DIR_SEPARATOR.to_string () in name) {
159
159
                    warning ("invalid source filename");
160
160
                    return null; /* not a valid filename */
246
246
        }
247
247
 
248
248
 
249
 
        public bool selection_data_is_uri_list (Gtk.SelectionData selection_data, uint info, out string? text) {
 
249
        public static bool selection_data_is_uri_list (Gtk.SelectionData selection_data, uint info, out string? text) {
250
250
            text = null;
251
251
 
252
252
            if (info == Marlin.TargetType.TEXT_URI_LIST &&
253
253
                selection_data.get_format () == 8 &&
254
254
                selection_data.get_length () > 0) {
255
255
 
256
 
                text = data_to_string (selection_data.get_data_with_length ());
 
256
                text = DndHandler.data_to_string (selection_data.get_data_with_length ());
257
257
            }
258
258
            debug ("DNDHANDLER selection data is uri list returning %s", (text != null).to_string ());
259
259
            return (text != null);
260
260
        }
261
261
 
262
 
        private string data_to_string (uchar [] cdata) {
 
262
        public static string data_to_string (uchar [] cdata) {
263
263
            var sb = new StringBuilder ("");
264
264
 
265
265
            foreach (uchar u in cdata)
267
267
 
268
268
            return sb.str;
269
269
        }
 
270
 
 
271
        public static void set_selection_data_from_file_list (Gtk.SelectionData selection_data,
 
272
                                                              GLib.List<GOF.File> file_list,
 
273
                                                              string? prefix = "") {
 
274
 
 
275
            GLib.StringBuilder sb = new GLib.StringBuilder (prefix);
 
276
            bool in_recent = file_list.data.is_recent_uri_scheme ();
 
277
 
 
278
            file_list.@foreach ((file) => {
 
279
                var target = in_recent ? file.get_display_target_uri () : file.get_target_location ().get_uri ();
 
280
                sb.append (target);
 
281
                sb.append ("\r\n");  /* Drop onto Filezilla does not work without the "\r" */
 
282
            });
 
283
 
 
284
            selection_data.@set (selection_data.get_target (),
 
285
                                 8,
 
286
                                 sb.data);
 
287
 
 
288
        }
270
289
    }
271
290
}