Skip to content

Commit 53d3dbe

Browse files
authored
Dragdrop documents (#44)
* Allow Drag&Drop from Documents * Actually ok without * Drop would fail without permission - mention that case * also make it translatable * linter * also undo the translatable part, leave it to the other PR
1 parent 2dde00d commit 53d3dbe

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

io.github.wpkelso.slate.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ finish-args:
1212
- --socket=wayland
1313
# GPU acceleration if needed
1414
- --device=dri
15+
# Access files dropped from documents
16+
- --filesystem=xdg-documents
1517

1618
modules:
1719
- name: slate

src/Application.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class Application : Gtk.Application {
147147
var error_dialog = new
148148
Granite.MessageDialog.with_image_from_icon_name (
149149
"Couldn't open file",
150-
"The specified file is not a valid text file",
150+
"The specified file is not a valid text file, or Slate could not access it",
151151
"dialog-error"
152152
) {
153153
transient_for = window

src/Window.vala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public class AppWindow : Gtk.Window {
9090
this.close_request.connect (on_close);
9191
buf.changed.connect (on_buffer_changed);
9292

93+
var drop_target = new Gtk.DropTarget (typeof (Gdk.FileList), Gdk.DragAction.COPY);
94+
text_view.add_controller (drop_target);
95+
drop_target.drop.connect (on_dropped);
9396
}
9497

9598

@@ -205,4 +208,19 @@ public class AppWindow : Gtk.Window {
205208

206209
return false;
207210
}
211+
212+
public bool on_dropped (Gtk.DropTarget target, GLib.Value value, double x, double y) {
213+
if (value.type () == typeof (Gdk.FileList)) {
214+
var list = (Gdk.FileList)value;
215+
File[] file_array = {};
216+
217+
foreach (unowned var file in list.get_files ()) {
218+
file_array += file;
219+
}
220+
221+
application.open (file_array, "");
222+
return true;
223+
}
224+
return false;
225+
}
208226
}

0 commit comments

Comments
 (0)