Beispiel #1
0
        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

                if entry.get_text():
                        mimes = [entry.get_text()]
                else:
                        mimes = []

                for uri in uris:
                        try:
                                mime = Gio.content_type_guess(uri)
                        except:
                                mime = None

                        if mime:
                                mimes.append(mime)

                entry.set_text(', '.join(mimes))
                self.on_entry_drop_targets_focus_out(entry, None)
                context.finish(True, False, timestamp)

                entry.stop_emission('drag_data_received')
Beispiel #2
0
        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)
                uris.reverse()
                stop = False

                for uri in uris:
                        try:
                                mime = Gio.content_type_guess(uri)
                        except:
                                mime = None

                        if not mime:
                                continue

                        snippets = Library().from_drop_target(mime, self.language_id)

                        if snippets:
                                stop = True
                                self.apply_uri_snippet(snippets[0], mime, uri)

                if stop:
                        context.finish(True, False, timestamp)
                        view.stop_emission('drag-data-received')
                        view.get_toplevel().present()
                        view.grab_focus()
Beispiel #3
0
        def on_tree_view_drag_motion(self, widget, context, x, y, timestamp):
                # Return False if we are dragging
                if self.dragging:
                        return False
                
                # Check uri target
                if not Gtk.targets_include_uri(context.targets):
                        return False

                # Check action
                action = None
                if context.suggested_action == Gdk.DragAction.COPY:
                        action = Gdk.DragAction.COPY
                else:
                        for act in context.actions:
                                if act == Gdk.DragAction.COPY:
                                      action = Gdk.DragAction.COPY
                                      break  
                
                if action == Gdk.DragAction.COPY:
                        context.drag_status(Gdk.DragAction.COPY, timestamp)
                        return True
                else:
                        return False
Beispiel #4
0
    def on_tree_view_drag_motion(self, widget, context, x, y, timestamp):
        # Return False if we are dragging
        if self.dragging:
            return False

        # Check uri target
        if not Gtk.targets_include_uri(context.targets):
            return False

        # Check action
        action = None
        if context.suggested_action == Gdk.DragAction.COPY:
            action = Gdk.DragAction.COPY
        else:
            for act in context.actions:
                if act == Gdk.DragAction.COPY:
                    action = Gdk.DragAction.COPY
                    break

        if action == Gdk.DragAction.COPY:
            context.drag_status(Gdk.DragAction.COPY, timestamp)
            return True
        else:
            return False