[gnome-panel/wip/packed-objects: 11/17] panel: "Compress" indexes on end of drag
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/packed-objects: 11/17] panel: "Compress" indexes on end of drag
- Date: Thu, 31 Mar 2011 07:00:19 +0000 (UTC)
commit 718dfa800b8c398cc6d780dce55c8b53e88bcc31
Author: Vincent Untz <vuntz gnome org>
Date: Thu Mar 31 04:08:56 2011 +0530
panel: "Compress" indexes on end of drag
To make sure the pack indexes never grow forever, recompute them on the
end of a drag, starting from 0. This way, we always keep a 0:n range of
indexes, instead of x:x+n with a moving x.
While it could be argued it should not be needed, it's much simpler than
specifically handling some cases where we have to explicitly decrease
all indexes, like when moving an object which is moved to another panel,
or removing an object from the panel.
This is not an action that is urgent to do (since "uncompressed"
indexes don't harm in any way), so the end of a drag is a good enough
place to call that.
gnome-panel/panel-widget.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/gnome-panel/panel-widget.c b/gnome-panel/panel-widget.c
index 7ffa415..d0c15db 100644
--- a/gnome-panel/panel-widget.c
+++ b/gnome-panel/panel-widget.c
@@ -556,6 +556,43 @@ get_size_from_hints (AppletData *ad, int cells)
return MAX (cells, ad->min_cells);
}
+static void
+panel_widget_compress_pack_indexes_list (PanelWidget *panel,
+ GList *list)
+{
+ GList *l;
+ AppletData *ad;
+ int index;
+
+ for (l = list, index = 0; l; l = l->next, index++) {
+ ad = l->data;
+ if (ad->pack_index != index) {
+ ad->pack_index = index;
+ emit_applet_moved (panel, ad);
+ }
+ }
+}
+
+/* make sure our lists always start at 0 */
+static void
+panel_widget_compress_pack_indexes (PanelWidget *panel)
+{
+ GList *list;
+
+ list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_START);
+ panel_widget_compress_pack_indexes_list (panel, list);
+ g_list_free (list);
+
+ list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_CENTER);
+ panel_widget_compress_pack_indexes_list (panel, list);
+ g_list_free (list);
+
+ list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_END);
+ list = g_list_reverse (list);
+ panel_widget_compress_pack_indexes_list (panel, list);
+ g_list_free (list);
+}
+
/* Note: this can only be called at the beginning of size_allocate, which means
* that ad->constrained doesn't matter yet (it will be set to the correct
* value in size_allocate). */
@@ -1719,6 +1756,15 @@ panel_widget_applet_drag_end_no_grab (PanelWidget *panel)
moving_timeout = 0;
been_moved = FALSE;
}
+
+ /* Make sure we keep our indexes in a 0:n range, instead of a x:x+n
+ * range, with a growing x. Note that this is useful not only because
+ * of moves, but also because of removal of objects (object 0 could be
+ * removed, but if there is still object 1, we start growing the
+ * range). But doing this compress only once in a while, after moving
+ * objects is good enough, since this is nothing urgent and the user
+ * will move objects before this becomes a real annoying issue. */
+ panel_widget_compress_pack_indexes (panel);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]