From faf956a5d4cfce214c87f101c5ae83182829fc7d Mon Sep 17 00:00:00 2001 From: teamcons Date: Thu, 14 Aug 2025 22:22:59 +0200 Subject: [PATCH 1/6] Allow Drag&Drop from Documents --- io.github.wpkelso.slate.yaml | 2 ++ src/Utils.vala | 1 + src/Window.vala | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) 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/Utils.vala b/src/Utils.vala index 80b5c9f..f2eebc2 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -48,6 +48,7 @@ } catch (Error err) { warning ("Failed to get file information: %s", err.message); + return false; } return false; diff --git a/src/Window.vala b/src/Window.vala index e5e9da2..7e3054e 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; + } } From f43b7eb25af4f294474bec1c8008a6a5eff4b5a5 Mon Sep 17 00:00:00 2001 From: teamcons Date: Thu, 14 Aug 2025 22:25:57 +0200 Subject: [PATCH 2/6] Actually ok without --- src/Utils.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Utils.vala b/src/Utils.vala index f2eebc2..80b5c9f 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -48,7 +48,6 @@ } catch (Error err) { warning ("Failed to get file information: %s", err.message); - return false; } return false; From 91f7055bb3a124f539fbcfab503d502e72173b5d Mon Sep 17 00:00:00 2001 From: teamcons Date: Thu, 14 Aug 2025 22:27:04 +0200 Subject: [PATCH 3/6] Drop would fail without permission - mention that case --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7af361c2f61b1627a509943e2ea92093e1db6492 Mon Sep 17 00:00:00 2001 From: teamcons Date: Thu, 14 Aug 2025 22:27:44 +0200 Subject: [PATCH 4/6] also make it translatable --- src/Application.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 6c10029..5c09b33 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -146,8 +146,8 @@ public class Application : Gtk.Application { var window = get_windows ().first ().data; var error_dialog = new Granite.MessageDialog.with_image_from_icon_name ( - "Couldn't open file", - "The specified file is not a valid text file, or Slate could not access it", + _("Couldn't open file"), + _("The specified file is not a valid text file, or Slate could not access it"), "dialog-error" ) { transient_for = window From 23a82cc3ab431a88432d455bb618bbf7b2bd1f4d Mon Sep 17 00:00:00 2001 From: teamcons Date: Thu, 14 Aug 2025 22:29:24 +0200 Subject: [PATCH 5/6] linter --- src/Window.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Window.vala b/src/Window.vala index 7e3054e..1e63147 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -213,7 +213,7 @@ public class AppWindow : Gtk.Window { 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; } From 6f791e89b3fc0ce44a64a3357ad065483a1273a6 Mon Sep 17 00:00:00 2001 From: teamcons Date: Thu, 14 Aug 2025 22:35:48 +0200 Subject: [PATCH 6/6] also undo the translatable part, leave it to the other PR --- src/Application.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 5c09b33..6c10029 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -146,8 +146,8 @@ public class Application : Gtk.Application { var window = get_windows ().first ().data; var error_dialog = new Granite.MessageDialog.with_image_from_icon_name ( - _("Couldn't open file"), - _("The specified file is not a valid text file, or Slate could not access it"), + "Couldn't open file", + "The specified file is not a valid text file, or Slate could not access it", "dialog-error" ) { transient_for = window