Skip to content

Commit a3e651d

Browse files
fix drop action
1 parent 18e7c6d commit a3e651d

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

gradia/ui/image_loaders.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ def open_file_dialog(self) -> None:
248248
self.file_loader.open_file_dialog()
249249

250250
def _on_drop_action(self, action: Optional[object], param: object) -> None:
251-
if param and isinstance(param, Gio.File):
252-
self.drag_drop_loader.handle_file_drop(None, param, 0, 0)
251+
if isinstance(param, GLib.Variant):
252+
uri = param.get_string()
253+
file = Gio.File.new_for_uri(uri)
254+
self.drag_drop_loader.handle_file_drop(None, file, 0, 0)
253255
else:
254256
print("ImportManager._on_drop_action: Invalid drop parameter")
255257

gradia/ui/ui_parts.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@ def create_drop_target(stack: Gtk.Stack) -> None:
212212
drop_target = Gtk.DropTarget.new(Gio.File, Gdk.DragAction.COPY)
213213
drop_target.set_preload(True)
214214

215-
def on_file_dropped(_target: Gtk.DropTarget, *value: Gio.File, _x: int, _y: int) -> None:
216-
app = Gio.Application.get_default()
217-
action = app.lookup_action("load-drop") if app else None
218-
if action:
219-
action.activate(None)
215+
def on_file_dropped(_target: Gtk.DropTarget, value: Gio.File, _x: int, _y: int) -> None:
216+
uri = value.get_uri()
217+
if uri:
218+
app = Gio.Application.get_default()
219+
action = app.lookup_action("load-drop") if app else None
220+
if action:
221+
action.activate(GLib.Variant('s', uri))
220222

221223
drop_target.connect("drop", on_file_dropped)
222224
stack.add_controller(drop_target)

gradia/ui/window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, temp_dir: str, version: str, init_with_screenshot: bool = Fal
7575
self.create_action("shortcuts", self._on_shortcuts_activated, ['<primary>question'])
7676

7777
self.create_action("open", lambda *_: self.import_manager.open_file_dialog(), ["<Primary>o"])
78-
self.create_action("load-drop", self.import_manager._on_drop_action)
78+
self.create_action_with_param("load-drop", self.import_manager._on_drop_action)
7979
self.create_action("paste", lambda *_: self.import_manager.load_from_clipboard(), ["<Primary>v"])
8080
self.create_action("screenshot", lambda *_: self.import_manager.take_screenshot(), ["<Primary>a"])
8181

0 commit comments

Comments
 (0)