[nautilus] canvas-view: change action states only when the value differs



commit 0ff112a5a1d658a791deb14004e2763428b03543
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Apr 28 17:32:02 2015 -0300

    canvas-view: change action states only when the value differs
    
    Commit bb884cb6 introduced the faulty behavior where
    NautilusCanvasView keeps scrolling back to the first
    selected item when selecting multiple items.
    
    Backtracing it, it was found out that the icon view
    was changing the "sort" state when selecting items,
    even if nothing actually changed, which triggers the
    sort action changed handler. The handler by itself
    was doing the right job by revealing the selection,
    and the issue was caused by calling it unnecessarily.
    
    Since we may have to update the action states for other
    reasons besidse real sort change, we must change the
    action state only when it makes sense, i.e. only when
    the states really change.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=748265

 src/nautilus-canvas-view.c |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index b7f4edb..b6fe026 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -1061,13 +1061,35 @@ nautilus_canvas_view_update_actions_state (NautilusView *view)
 
        view_action_group = nautilus_view_get_action_group (view);
        if (nautilus_canvas_view_supports_auto_layout (canvas_view)) {
-               g_action_group_change_action_state (view_action_group,
-                                                   "reversed-order",
-                                                   g_variant_new_boolean (NAUTILUS_CANVAS_VIEW 
(view)->details->sort_reversed));
+               GVariant *sort_state;
+               GVariant *reversed_state;
+
+               /* When we change the sort action state, even using the same value, it triggers
+                * the sort action changed handler, which reveals the selection, since we expect
+                * the selection to be visible when the user changes the sort order. But we may
+                * need to update the actions state for others reason than an actual sort change,
+                * so we need to prevent to trigger the sort action changed handler for those cases.
+                * To achieve this, check if the action state value actually changed before setting
+                * it. The same happens to the reversed-order state.
+                */
+               sort_state = g_action_group_get_action_state (view_action_group, "sort");
+               reversed_state = g_action_group_get_action_state (view_action_group, "reversed-order");
+
+               if (NAUTILUS_CANVAS_VIEW (view)->details->sort_reversed != g_variant_get_boolean 
(reversed_state)) {
+                       g_action_group_change_action_state (view_action_group,
+                                                           "reversed-order",
+                                                           g_variant_new_boolean (NAUTILUS_CANVAS_VIEW 
(view)->details->sort_reversed));
+               }
+
+               if (g_strcmp0 (g_variant_get_string (sort_state, NULL),
+                               NAUTILUS_CANVAS_VIEW (view)->details->sort->action_target_name) != 0) {
+                       g_action_group_change_action_state (view_action_group,
+                                                            "sort",
+                                                             g_variant_new_string (NAUTILUS_CANVAS_VIEW 
(view)->details->sort->action_target_name));
+               }
 
-               g_action_group_change_action_state (view_action_group,
-                                                   "sort",
-                                                   g_variant_new_string (NAUTILUS_CANVAS_VIEW 
(view)->details->sort->action_target_name));
+               g_variant_unref (reversed_state);
+               g_variant_unref (sort_state);
        }
 
        action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "keep-aligned");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]