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): |
112 | 112 | self._box = box |
113 | 113 | self._layout = None |
114 | 114 | |
115 | | favorites_settings = get_settings() |
116 | | favorites_settings.changed.connect(self.__settings_changed_cb) |
117 | | self._set_layout(favorites_settings.layout) |
118 | | |
119 | 115 | owner_icon = OwnerIcon(style.XLARGE_ICON_SIZE) |
120 | 116 | owner_icon.connect('register-activate', self.__register_activate_cb) |
121 | 117 | |
… |
… |
class FavoritesView(ViewContainer): |
128 | 124 | self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | |
129 | 125 | Gdk.EventMask.POINTER_MOTION_HINT_MASK) |
130 | 126 | 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 |
134 | 135 | |
135 | 136 | self._dragging = False |
136 | 137 | self._pressed_button = None |
… |
… |
class FavoritesView(ViewContainer): |
145 | 146 | |
146 | 147 | GObject.idle_add(self.__connect_to_bundle_registry_cb) |
147 | 148 | |
| 149 | favorites_settings = get_settings() |
| 150 | favorites_settings.changed.connect(self.__settings_changed_cb) |
| 151 | self._set_layout(favorites_settings.layout) |
| 152 | |
148 | 153 | def __settings_changed_cb(self, **kwargs): |
149 | 154 | favorites_settings = get_settings() |
150 | 155 | layout_set = self._set_layout(favorites_settings.layout) |
… |
… |
class FavoritesView(ViewContainer): |
165 | 170 | if type(self._layout) == LAYOUT_MAP[layout]: |
166 | 171 | return False |
167 | 172 | |
| 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 | |
168 | 189 | self._layout = LAYOUT_MAP[layout]() |
169 | 190 | return True |
170 | 191 | |
… |
… |
class FavoritesView(ViewContainer): |
196 | 217 | return False |
197 | 218 | |
198 | 219 | def __motion_notify_event_cb(self, widget, event): |
| 220 | if not self._dragging_mode: |
| 221 | return False |
| 222 | |
199 | 223 | # if the mouse button is not pressed, no drag should occurr |
200 | 224 | if not event.get_state() & Gdk.ModifierType.BUTTON1_MASK: |
201 | 225 | self._pressed_button = None |
… |
… |
class FavoritesView(ViewContainer): |
221 | 245 | return False |
222 | 246 | |
223 | 247 | def __drag_begin_cb(self, widget, context): |
| 248 | if not self._dragging_mode: |
| 249 | return False |
| 250 | |
224 | 251 | pixbuf = GdkPixbuf.Pixbuf.new_from_file(widget.props.file_name) |
225 | 252 | |
226 | 253 | self._hot_x = pixbuf.props.width / 2 |