Ticket #3999: journal_drag_and_drop_testing.diff

File journal_drag_and_drop_testing.diff, 11.2 KB (added by godiard, 11 years ago)

On going work patch

  • src/jarabe/frame/clipboardicon.py

    diff --git a/src/jarabe/frame/clipboardicon.py b/src/jarabe/frame/clipboardicon.py
    index 26af595..cca8d95 100644
    a b class ClipboardIcon(RadioToolButton): 
    7676    def _drag_data_get_cb(self, widget, context, selection, target_type,
    7777                          event_time):
    7878        logging.debug('_drag_data_get_cb: requested target %s',
    79                       selection.target)
    80         data = self._cb_object.get_formats()[selection.target].get_data()
     79                      selection.get_target())
     80        data = self._cb_object.get_formats()[selection.get_target()].get_data()
    8181        selection.set(selection.target, 8, data)
    8282
    8383    def _put_in_clipboard(self):
    class ClipboardIcon(RadioToolButton): 
    161161        icon_theme = Gtk.IconTheme.get_default()
    162162        pixbuf = icon_theme.load_icon(self._icon.props.icon_name,
    163163                                      style.STANDARD_ICON_SIZE, 0)
    164         context.set_icon_pixbuf(pixbuf, hot_x=pixbuf.props.width / 2,
    165                                 hot_y=pixbuf.props.height / 2)
     164        logging.error('drag_begin_cb %s', dir(context))
     165        Gtk.drag_set_icon_pixbuf(context, pixbuf,
     166                hot_x=pixbuf.props.width / 2, hot_y=pixbuf.props.height / 2)
    166167
    167168    def _notify_active_cb(self, widget, pspec):
    168169        if self.props.active:
  • src/jarabe/frame/clipboardtray.py

    diff --git a/src/jarabe/frame/clipboardtray.py b/src/jarabe/frame/clipboardtray.py
    index abc885e..09e3eea 100644
    a b class ClipboardTray(tray.VTray): 
    7676        return False
    7777
    7878    def _add_selection(self, object_id, selection):
    79         if not selection.data:
     79        if not selection.get_data():
    8080            return
    8181
    82         logging.debug('ClipboardTray: adding type %r', selection.type)
     82        logging.debug('ClipboardTray: adding type %r', selection.get_type())
    8383
    8484        cb_service = clipboard.get_instance()
    85         if selection.type == 'text/uri-list':
    86             uris = selection.data.split('\n')
     85        if selection.get_type() == 'text/uri-list':
     86            uris = selection.get_data().split('\n')
    8787            if len(uris) > 1:
    8888                raise NotImplementedError('Multiple uris in text/uri-list' \
    8989                                          ' still not supported.')
    9090
    9191            cb_service.add_object_format(object_id,
    92                                          selection.type,
     92                                         selection.get_type(),
    9393                                         uris[0],
    9494                                         on_disk=True)
    9595        else:
    9696            cb_service.add_object_format(object_id,
    97                                          selection.type,
    98                                          selection.data,
     97                                         selection.get_type(),
     98                                         selection.get_data(),
    9999                                         on_disk=False)
    100100
    101101    def _object_added_cb(self, cb_service, cb_object):
    class ClipboardTray(tray.VTray): 
    129129        logging.debug('ClipboardTray: %r was deleted', object_id)
    130130
    131131    def drag_motion_cb(self, widget, context, x, y, time):
    132         logging.debug('ClipboardTray._drag_motion_cb')
    133132
    134133        if self._internal_drag(context):
    135             context.drag_status(Gdk.DragAction.MOVE, time)
     134            Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
    136135        else:
    137             context.drag_status(Gdk.DragAction.COPY, time)
     136            Gdk.drag_status(context, Gdk.DragAction.COPY, time)
    138137            self.props.drag_active = True
    139138
    140139        return True
    class ClipboardTray(tray.VTray): 
    148147        if self._internal_drag(context):
    149148            # TODO: We should move the object within the clipboard here
    150149            if not self._context_map.has_context(context):
    151                 context.drop_finish(False, Gtk.get_current_event_time())
     150                Gdk.drop_finish(context, False, Gtk.get_current_event_time())
    152151            return False
    153152
    154153        cb_service = clipboard.get_instance()
    155154        object_id = cb_service.add_object(name="")
    156155
    157         self._context_map.add_context(context, object_id, len(context.targets))
     156        self._context_map.add_context(context, object_id,
     157                len(context.list_targets()))
    158158
    159         for target in context.targets:
     159        for target in context.list_targets():
    160160            if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
    161161                widget.drag_get_data(context, target, time)
    162162
    class ClipboardTray(tray.VTray): 
    167167    def drag_data_received_cb(self, widget, context, x, y, selection,
    168168                              targetType, time):
    169169        logging.debug('ClipboardTray: got data for target %r',
    170             selection.target)
     170            selection.get_target())
    171171
    172172        object_id = self._context_map.get_object_id(context)
    173173        try:
    174174            if selection is None:
    175175                logging.warn('ClipboardTray: empty selection for target %s',
    176                     selection.target)
     176                    selection.get_target())
    177177            else:
    178178                self._add_selection(object_id, selection)
    179179
    class ClipboardTray(tray.VTray): 
    181181            # If it's the last target to be processed, finish
    182182            # the dnd transaction
    183183            if not self._context_map.has_context(context):
    184                 context.drop_finish(True, Gtk.get_current_event_time())
     184                Gdk.drop_finish(context, True, Gtk.get_current_event_time())
    185185
    186186    def _internal_drag(self, context):
    187         source_widget = context.get_source_widget()
    188         if source_widget is None:
     187        source_window = context.get_source_window()
     188        if source_window is None:
    189189            return False
    190         view_ancestor = source_widget.get_ancestor(Gtk.Viewport)
    191         if view_ancestor is self._viewport:
     190        if source_window is self.get_window():
    192191            return True
    193192        else:
    194193            return False
  • src/jarabe/frame/eventarea.py

    diff --git a/src/jarabe/frame/eventarea.py b/src/jarabe/frame/eventarea.py
    index 433a8dc..5fd7225 100644
    a b class EventArea(GObject.GObject): 
    134134        self._notify_leave()
    135135
    136136    def _drag_motion_cb(self, widget, drag_context, x, y, timestamp):
    137         drag_context.drag_status(0, timestamp)
     137        if hasattr(drag_context, "drag_status"):
     138            drag_context.drag_status(0, timestamp)
    138139        self._notify_enter()
    139140        return True
    140141
  • src/jarabe/journal/listmodel.py

    diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
    index b98d01c..124ef8b 100644
    a b class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): 
    236236        return (False, Gtk.TreeIter())
    237237
    238238    def do_drag_data_get(self, path, selection):
     239        logging.error('DO_DRAG_DATA_GET %s %s target %s', path, selection, selection.get_target())
    239240        uid = self[path][ListModel.COLUMN_UID]
    240         if selection.target == 'text/uri-list':
     241        if selection.get_target() == 'text/uri-list':
    241242            # Get hold of a reference so the temp file doesn't get deleted
    242243            self._temp_drag_file_path = model.get_file(uid)
    243244            logging.debug('putting %r in selection', self._temp_drag_file_path)
    244             selection.set(selection.target, 8, self._temp_drag_file_path)
     245            selection.set(selection.get_target(), 8, self._temp_drag_file_path)
    245246            return True
    246247        elif selection.target == 'journal-object-id':
    247             selection.set(selection.target, 8, uid)
     248            selection.set(selection.get_target(), 8, uid)
    248249            return True
    249250
    250251        return False
  • src/jarabe/journal/listview.py

    diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
    index 3005d2f..751249c 100644
    a b class ListView(BaseListView): 
    515515        BaseListView.__init__(self)
    516516        self._is_dragging = False
    517517
     518        self.tree_view.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
     519                                                [('text/uri-list', 0, 0),
     520                                                 ('journal-object-id', 0, 0)],
     521                                                Gdk.DragAction.COPY)
     522
    518523        self.tree_view.connect('drag-begin', self.__drag_begin_cb)
     524        self.tree_view.connect("drag-data-get", self.__drag_data_get_data_cb)
    519525        self.tree_view.connect('button-release-event',
    520526                self.__button_release_event_cb)
    521527
    class ListView(BaseListView): 
    536542        self.tree_view.append_column(column)
    537543
    538544    def __drag_begin_cb(self, widget, drag_context):
     545        logging.error('LISTIEW drag_begin_cb list_targets %s', drag_context.list_targets())
     546        for target in drag_context.list_targets():
     547            logging.error('LISTIEW drag_begin_cb targets %s data %s', target, drag_context.get_data(target))
    539548        self._is_dragging = True
    540549
     550    def __drag_data_get_data_cb(self, treeview, context, selection, target_id,
     551            etime):
     552
     553        treeselection = treeview.get_selection()
     554        model, treeiter = treeselection.get_selected()
     555        logging.error('LISTIEW drag_data_get model: %s, iter: %s target %s', model, treeiter, selection.get_targets())
     556
     557        logging.error('LISTIEW drag_data_get SELECTION %s %s', selection.__class__, dir(selection))
     558        #tree_selection = treeview.get_selection()
     559        #model, tree_iter = selection.get_selection()
     560        #path = model.get_path(tree_iter)
     561
     562        #logging.error('DO_DRAG_DATA_GET %s %s', path, selection)
     563        #uid = model[path][ListModel.COLUMN_UID]
     564        if selection.get_target() == 'text/uri-list':
     565            logging.error('text/urilist DATA %s', selection.get_data())
     566            # Get hold of a reference so the temp file doesn't get deleted
     567            model._temp_drag_file_path = model.get_file(uid)
     568            logging.debug('putting %r in selection',
     569                    model._temp_drag_file_path)
     570            selection.set(selection.get_target(), 8,
     571                    model._temp_drag_file_path)
     572            return True
     573        elif selection.get_target() == 'journal-object-id':
     574            logging.error('text/urilist DATA %s', selection.get_data())
     575            selection.set(selection.get_target(), 8, uid)
     576            return True
     577
     578        return False
     579
    541580    def __button_release_event_cb(self, tree_view, event):
    542581        try:
    543582            if self._is_dragging:
  • src/jarabe/journal/volumestoolbar.py

    diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
    index e1e6331..cea2bf7 100644
    a b class BaseButton(RadioToolButton): 
    291291
    292292    def _drag_data_received_cb(self, widget, drag_context, x, y,
    293293                               selection_data, info, timestamp):
    294         object_id = selection_data.data
     294        logging.error('EN volumestoolbar.py _drag_data_received_cb')
     295        object_id = selection_data.get_data()
    295296        metadata = model.get(object_id)
    296297        file_path = model.get_file(metadata['uid'])
    297298        if not file_path or not os.path.exists(file_path):