[gedit] Fix crash when dropping file in gedit with snippets plugin active



commit 48d33cf9dd29d8a6d42e60e3254c883f1f9ffb56
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Nov 12 11:47:13 2011 +0100

    Fix crash when dropping file in gedit with snippets plugin active

 plugins/snippets/snippets/document.py |    9 ++++++---
 plugins/snippets/snippets/helper.py   |   14 ++++++++------
 plugins/snippets/snippets/manager.py  |    4 ----
 3 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/plugins/snippets/snippets/document.py b/plugins/snippets/snippets/document.py
index 6afe35d..dbc3d16 100644
--- a/plugins/snippets/snippets/document.py
+++ b/plugins/snippets/snippets/document.py
@@ -858,13 +858,16 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
                 return not (x < rect.x or x > rect.x + rect.width or y < rect.y or y > rect.y + rect.height)
 
         def on_drag_data_received(self, view, context, x, y, data, info, timestamp):
-                if not (Gtk.targets_include_uri(context.list_targets()) and data.data and self.in_bounds(x, y)):
-                        return
-
                 if not self.view.get_editable():
                         return
 
                 uris = drop_get_uris(data)
+                if not uris:
+                        return
+
+                if not self.in_bounds(x, y):
+                        return
+
                 uris.reverse()
                 stop = False
 
diff --git a/plugins/snippets/snippets/helper.py b/plugins/snippets/snippets/helper.py
index 0598dc0..ca8c40d 100644
--- a/plugins/snippets/snippets/helper.py
+++ b/plugins/snippets/snippets/helper.py
@@ -169,13 +169,15 @@ def buffer_line_boundary(buf):
         return (start, iter)
 
 def drop_get_uris(selection):
-        lines = re.split('\\s*[\\n\\r]+\\s*', selection.data.strip())
-        result = []
+        uris = []
+        if selection.targets_include_uri():
+                data = selection.get_data()
+                lines = re.split('\\s*[\\n\\r]+\\s*', data.strip())
 
-        for line in lines:
-                if not line.startswith('#'):
-                        result.append(line)
+                for line in lines:
+                        if not line.startswith('#'):
+                                uris.append(line)
 
-        return result
+        return uris
 
 # ex:ts=8:et:
diff --git a/plugins/snippets/snippets/manager.py b/plugins/snippets/snippets/manager.py
index 0736691..73fffbd 100644
--- a/plugins/snippets/snippets/manager.py
+++ b/plugins/snippets/snippets/manager.py
@@ -1105,11 +1105,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
                 self.select_iter(piter)
 
         def on_entry_drop_targets_drag_data_received(self, entry, context, x, y, selection_data, info, timestamp):
-                if not Gtk.targets_include_uri(context.targets):
-                        return
-
                 uris = drop_get_uris(selection_data)
-
                 if not uris:
                         return
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]