Ticket #4014: 0001-Favorites-view-do-drag-and-drop-of-icons-only-in-the.patch

File 0001-Favorites-view-do-drag-and-drop-of-icons-only-in-the.patch, 4.2 KB (added by manuq, 11 years ago)
  • src/jarabe/desktop/favoritesview.py

    From 42a48d4e2b86fa9b470515ec33cc11cb52dcfd07 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Tue, 13 Nov 2012 10:27:01 -0300
    Subject: [PATCH shell] Favorites view: do drag and drop of icons only in the
     Random layout - SL #4014
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    Connect the view to the drag and drop callbacks when the layout is
    set, only if it is a Random layout.
    
    The layout is read from the settings and set at the end of the
    constructor, because the object needs to be initializated to connect
    callbacks to signals.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/jarabe/desktop/favoritesview.py | 41 ++++++++++++++++++++++++++++++-------
     1 file changed, 34 insertions(+), 7 deletions(-)
    
    diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
    index 152dd6e..76ab196 100644
    a b class FavoritesView(ViewContainer): 
    112112        self._box = box
    113113        self._layout = None
    114114
    115         favorites_settings = get_settings()
    116         favorites_settings.changed.connect(self.__settings_changed_cb)
    117         self._set_layout(favorites_settings.layout)
    118 
    119115        owner_icon = OwnerIcon(style.XLARGE_ICON_SIZE)
    120116        owner_icon.connect('register-activate', self.__register_activate_cb)
    121117
    class FavoritesView(ViewContainer): 
    128124        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
    129125                        Gdk.EventMask.POINTER_MOTION_HINT_MASK)
    130126        self.drag_dest_set(0, [], 0)
    131         self.connect('drag-motion', self.__drag_motion_cb)
    132         self.connect('drag-drop', self.__drag_drop_cb)
    133         self.connect('drag-data-received', self.__drag_data_received_cb)
     127
     128        # Drag and drop is set only for the Random layout.  This is
     129        # the flag that enables or disables it.
     130        self._dragging_mode = False
     131
     132        self._drag_motion_hid = None
     133        self._drag_drop_hid = None
     134        self._drag_data_received_hid = None
    134135
    135136        self._dragging = False
    136137        self._pressed_button = None
    class FavoritesView(ViewContainer): 
    145146
    146147        GObject.idle_add(self.__connect_to_bundle_registry_cb)
    147148
     149        favorites_settings = get_settings()
     150        favorites_settings.changed.connect(self.__settings_changed_cb)
     151        self._set_layout(favorites_settings.layout)
     152
    148153    def __settings_changed_cb(self, **kwargs):
    149154        favorites_settings = get_settings()
    150155        layout_set = self._set_layout(favorites_settings.layout)
    class FavoritesView(ViewContainer): 
    165170        if type(self._layout) == LAYOUT_MAP[layout]:
    166171            return False
    167172
     173        if self._layout is not None and self._dragging_mode:
     174            self.disconnect(self._drag_motion_hid)
     175            self.disconnect(self._drag_drop_hid)
     176            self.disconnect(self._drag_data_received_hid)
     177
     178        if layout == favoriteslayout.RandomLayout.key:
     179            self._dragging_mode = True
     180            self._drag_motion_hid = self.connect(
     181                'drag-motion', self.__drag_motion_cb)
     182            self._drag_drop_hid = self.connect(
     183                'drag-drop', self.__drag_drop_cb)
     184            self._drag_data_received_hid = self.connect(
     185                'drag-data-received', self.__drag_data_received_cb)
     186        else:
     187            self._dragging_mode = False
     188
    168189        self._layout = LAYOUT_MAP[layout]()
    169190        return True
    170191
    class FavoritesView(ViewContainer): 
    196217        return False
    197218
    198219    def __motion_notify_event_cb(self, widget, event):
     220        if not self._dragging_mode:
     221            return False
     222
    199223        # if the mouse button is not pressed, no drag should occurr
    200224        if not event.get_state() & Gdk.ModifierType.BUTTON1_MASK:
    201225            self._pressed_button = None
    class FavoritesView(ViewContainer): 
    221245        return False
    222246
    223247    def __drag_begin_cb(self, widget, context):
     248        if not self._dragging_mode:
     249            return False
     250
    224251        pixbuf = GdkPixbuf.Pixbuf.new_from_file(widget.props.file_name)
    225252
    226253        self._hot_x = pixbuf.props.width / 2