Skip to content

Commit 32e39ec

Browse files
committed
filediff: Support drag-and-drop directly on to textviews (#177)
The behaviour here is hopefully fairly intuitive. If the user drops a single URI on a file pane, we will load it into that pane. If they drop several URIs, we'll check to see whether they've dropped the right number to load all panes, and if so then load them all. This doesn't handle correctly prelighting of drop zones to e.g., show the user that they can't drop two files on to a three-way comparison. This omission is partly due to laziness, but mostly because I don't think it's a big deal and the drag-motion signal is a bit wild given that we'd have to coordinate our handling with GtkTextView and also need to handle the request data dance with drag-data-received.
1 parent d84166b commit 32e39ec

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

meld/filediff.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def __init__(self, num_panes):
205205
for t in self.textview:
206206
t.connect("focus-in-event", self.on_current_diff_changed)
207207
t.connect("focus-out-event", self.on_current_diff_changed)
208+
t.connect(
209+
"drag_data_received", self.on_textview_drag_data_received)
208210

209211
# Bind all overwrite properties together, so that toggling
210212
# overwrite mode is per-FileDiff.
@@ -768,6 +770,22 @@ def _set_external_action_sensitivity(self):
768770
except AttributeError:
769771
pass
770772

773+
def on_textview_drag_data_received(
774+
self, widget, context, x, y, selection_data, info, time):
775+
uris = selection_data.get_uris()
776+
if uris:
777+
gfiles = [Gio.File.new_for_uri(uri) for uri in uris]
778+
779+
if len(gfiles) == self.num_panes:
780+
if self.check_save_modified() == Gtk.ResponseType.OK:
781+
self.set_files(gfiles)
782+
elif len(gfiles) == 1:
783+
pane = self.textview.index(widget)
784+
buffer = self.textbuffer[pane]
785+
if self.check_save_modified([buffer]) == Gtk.ResponseType.OK:
786+
self.set_file(pane, gfiles[0])
787+
return True
788+
771789
def on_textview_focus_in_event(self, view, event):
772790
self.focus_pane = view
773791
self.findbar.textview = view

meld/sourceview.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def set_show_line_numbers(self, show):
147147

148148
def __init__(self, *args, **kwargs):
149149
super().__init__(*args, **kwargs)
150+
151+
self.drag_dest_add_uri_targets()
152+
150153
binding_set = Gtk.binding_set_find('GtkSourceView')
151154
for key, modifiers in self.replaced_entries:
152155
Gtk.binding_entry_remove(binding_set, key, modifiers)

0 commit comments

Comments
 (0)