Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Quiñones <manuq@laptop.org>2012-11-13 13:27:01 (GMT)
committer Manuel Quiñones <manuq@laptop.org>2012-11-22 17:09:54 (GMT)
commit3b2557655db815a47f164522980e92819f8ca3ec (patch)
tree85331c54b8f10ce7b2f3368a93a5be135621141c
parent342d56d021606a84052913a00b810b451744535f (diff)
Favorites view: do drag and drop of icons only in the Random layout - SL #4014
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> Acked-by: Simon Schampijer <simon@laptop.org>
-rw-r--r--src/jarabe/desktop/favoritesview.py41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 152dd6e..76ab196 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -112,10 +112,6 @@ class FavoritesView(ViewContainer):
self._box = box
self._layout = None
- favorites_settings = get_settings()
- favorites_settings.changed.connect(self.__settings_changed_cb)
- self._set_layout(favorites_settings.layout)
-
owner_icon = OwnerIcon(style.XLARGE_ICON_SIZE)
owner_icon.connect('register-activate', self.__register_activate_cb)
@@ -128,9 +124,14 @@ class FavoritesView(ViewContainer):
self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.POINTER_MOTION_HINT_MASK)
self.drag_dest_set(0, [], 0)
- self.connect('drag-motion', self.__drag_motion_cb)
- self.connect('drag-drop', self.__drag_drop_cb)
- self.connect('drag-data-received', self.__drag_data_received_cb)
+
+ # Drag and drop is set only for the Random layout. This is
+ # the flag that enables or disables it.
+ self._dragging_mode = False
+
+ self._drag_motion_hid = None
+ self._drag_drop_hid = None
+ self._drag_data_received_hid = None
self._dragging = False
self._pressed_button = None
@@ -145,6 +146,10 @@ class FavoritesView(ViewContainer):
GObject.idle_add(self.__connect_to_bundle_registry_cb)
+ favorites_settings = get_settings()
+ favorites_settings.changed.connect(self.__settings_changed_cb)
+ self._set_layout(favorites_settings.layout)
+
def __settings_changed_cb(self, **kwargs):
favorites_settings = get_settings()
layout_set = self._set_layout(favorites_settings.layout)
@@ -165,6 +170,22 @@ class FavoritesView(ViewContainer):
if type(self._layout) == LAYOUT_MAP[layout]:
return False
+ if self._layout is not None and self._dragging_mode:
+ self.disconnect(self._drag_motion_hid)
+ self.disconnect(self._drag_drop_hid)
+ self.disconnect(self._drag_data_received_hid)
+
+ if layout == favoriteslayout.RandomLayout.key:
+ self._dragging_mode = True
+ self._drag_motion_hid = self.connect(
+ 'drag-motion', self.__drag_motion_cb)
+ self._drag_drop_hid = self.connect(
+ 'drag-drop', self.__drag_drop_cb)
+ self._drag_data_received_hid = self.connect(
+ 'drag-data-received', self.__drag_data_received_cb)
+ else:
+ self._dragging_mode = False
+
self._layout = LAYOUT_MAP[layout]()
return True
@@ -196,6 +217,9 @@ class FavoritesView(ViewContainer):
return False
def __motion_notify_event_cb(self, widget, event):
+ if not self._dragging_mode:
+ return False
+
# if the mouse button is not pressed, no drag should occurr
if not event.get_state() & Gdk.ModifierType.BUTTON1_MASK:
self._pressed_button = None
@@ -221,6 +245,9 @@ class FavoritesView(ViewContainer):
return False
def __drag_begin_cb(self, widget, context):
+ if not self._dragging_mode:
+ return False
+
pixbuf = GdkPixbuf.Pixbuf.new_from_file(widget.props.file_name)
self._hot_x = pixbuf.props.width / 2