diff --git a/io.github.wpkelso.slate.yaml b/io.github.wpkelso.slate.yaml index f825a29..35018ae 100644 --- a/io.github.wpkelso.slate.yaml +++ b/io.github.wpkelso.slate.yaml @@ -12,6 +12,8 @@ finish-args: - --socket=wayland # GPU acceleration if needed - --device=dri + # Access files dropped from documents + - --filesystem=xdg-documents modules: - name: slate diff --git a/src/Application.vala b/src/Application.vala index 82f4b18..6c10029 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -147,7 +147,7 @@ public class Application : Gtk.Application { var error_dialog = new Granite.MessageDialog.with_image_from_icon_name ( "Couldn't open file", - "The specified file is not a valid text file", + "The specified file is not a valid text file, or Slate could not access it", "dialog-error" ) { transient_for = window diff --git a/src/Window.vala b/src/Window.vala index e5e9da2..1e63147 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -90,6 +90,9 @@ public class AppWindow : Gtk.Window { this.close_request.connect (on_close); buf.changed.connect (on_buffer_changed); + var drop_target = new Gtk.DropTarget (typeof (Gdk.FileList), Gdk.DragAction.COPY); + text_view.add_controller (drop_target); + drop_target.drop.connect (on_dropped); } @@ -205,4 +208,19 @@ public class AppWindow : Gtk.Window { return false; } + + public bool on_dropped (Gtk.DropTarget target, GLib.Value value, double x, double y) { + if (value.type () == typeof (Gdk.FileList)) { + var list = (Gdk.FileList)value; + File[] file_array = {}; + + foreach (unowned var file in list.get_files ()) { + file_array += file; + } + + application.open (file_array, ""); + return true; + } + return false; + } }