[nautilus/wip/neilh/toolbar-reorg: 7/16] toolbar-view-menu: replace zoom slider with buttons



commit 06029b1ae9e4b7a220a9c25d772ce0a9729877af
Author: Neil Herald <neil herald gmail com>
Date:   Mon May 2 18:34:57 2016 +0100

    toolbar-view-menu: replace zoom slider with buttons
    
    Convert the zoom slider into a horizontal button list, with a button in
    the middle to show the current zoom level percentage.
    
    This is part of the toolbar menu redesign to improve the usability of
    the menus.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764632

 src/nautilus-canvas-view.c                     |   20 +++++
 src/nautilus-empty-view.c                      |   13 +++
 src/nautilus-files-view.c                      |   64 ++++++++++-----
 src/nautilus-files-view.h                      |    8 ++
 src/nautilus-list-view.c                       |   22 +++++
 src/resources/ui/nautilus-toolbar-view-menu.ui |  101 ++++++++++++++++++------
 6 files changed, 182 insertions(+), 46 deletions(-)
---
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index 9cd3f34..563a48c 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -834,6 +834,12 @@ nautilus_canvas_view_restore_default_zoom_level (NautilusFilesView *view)
                (view, get_default_zoom_level (canvas_view));
 }
 
+static void
+nautilus_canvas_view_restore_standard_zoom_level (NautilusFilesView *view)
+{
+        nautilus_canvas_view_zoom_to_level (view, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
+}
+
 static gboolean 
 nautilus_canvas_view_can_zoom_in (NautilusFilesView *view)
 {
@@ -852,6 +858,18 @@ nautilus_canvas_view_can_zoom_out (NautilusFilesView *view)
                > NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL;
 }
 
+static gfloat
+nautilus_canvas_view_get_zoom_level_percentage (NautilusFilesView *view)
+{
+        guint icon_size;
+        NautilusCanvasZoomLevel zoom_level;
+
+        zoom_level = nautilus_canvas_view_get_zoom_level (view);
+        icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (zoom_level);
+
+        return (gfloat) icon_size / NAUTILUS_CANVAS_ICON_SIZE_LARGE;
+}
+
 static gboolean
 nautilus_canvas_view_is_empty (NautilusFilesView *view)
 {
@@ -1898,6 +1916,7 @@ nautilus_canvas_view_class_init (NautilusCanvasViewClass *klass)
        nautilus_files_view_class->bump_zoom_level = nautilus_canvas_view_bump_zoom_level;
        nautilus_files_view_class->can_zoom_in = nautilus_canvas_view_can_zoom_in;
        nautilus_files_view_class->can_zoom_out = nautilus_canvas_view_can_zoom_out;
+        nautilus_files_view_class->get_zoom_level_percentage = 
nautilus_canvas_view_get_zoom_level_percentage;
        nautilus_files_view_class->clear = nautilus_canvas_view_clear;
        nautilus_files_view_class->end_loading = nautilus_canvas_view_end_loading;
        nautilus_files_view_class->file_changed = nautilus_canvas_view_file_changed;
@@ -1907,6 +1926,7 @@ nautilus_canvas_view_class_init (NautilusCanvasViewClass *klass)
        nautilus_files_view_class->is_empty = nautilus_canvas_view_is_empty;
        nautilus_files_view_class->remove_file = nautilus_canvas_view_remove_file;
        nautilus_files_view_class->restore_default_zoom_level = 
nautilus_canvas_view_restore_default_zoom_level;
+        nautilus_files_view_class->restore_standard_zoom_level = 
nautilus_canvas_view_restore_standard_zoom_level;
        nautilus_files_view_class->reveal_selection = nautilus_canvas_view_reveal_selection;
        nautilus_files_view_class->select_all = nautilus_canvas_view_select_all;
        nautilus_files_view_class->select_first = nautilus_canvas_view_select_first;
diff --git a/src/nautilus-empty-view.c b/src/nautilus-empty-view.c
index b8518ab..97c9ce7 100644
--- a/src/nautilus-empty-view.c
+++ b/src/nautilus-empty-view.c
@@ -155,6 +155,11 @@ nautilus_empty_view_restore_default_zoom_level (NautilusFilesView *view)
 {
 }
 
+static void
+nautilus_empty_view_restore_standard_zoom_level (NautilusFilesView *view)
+{
+}
+
 static gboolean 
 nautilus_empty_view_can_zoom_in (NautilusFilesView *view)
 {
@@ -167,6 +172,12 @@ nautilus_empty_view_can_zoom_out (NautilusFilesView *view)
        return FALSE;
 }
 
+static gfloat
+nautilus_empty_view_get_zoom_level_percentage (NautilusFilesView *view)
+{
+        return 1.0;
+}
+
 static void
 nautilus_empty_view_click_policy_changed (NautilusFilesView *directory_view)
 {
@@ -242,6 +253,7 @@ nautilus_empty_view_class_init (NautilusEmptyViewClass *class)
        nautilus_files_view_class->bump_zoom_level = nautilus_empty_view_bump_zoom_level;
        nautilus_files_view_class->can_zoom_in = nautilus_empty_view_can_zoom_in;
        nautilus_files_view_class->can_zoom_out = nautilus_empty_view_can_zoom_out;
+        nautilus_files_view_class->get_zoom_level_percentage = nautilus_empty_view_get_zoom_level_percentage;
         nautilus_files_view_class->click_policy_changed = nautilus_empty_view_click_policy_changed;
        nautilus_files_view_class->clear = nautilus_empty_view_clear;
        nautilus_files_view_class->file_changed = nautilus_empty_view_file_changed;
@@ -251,6 +263,7 @@ nautilus_empty_view_class_init (NautilusEmptyViewClass *class)
        nautilus_files_view_class->remove_file = nautilus_empty_view_remove_file;
        nautilus_files_view_class->update_menus = nautilus_empty_view_update_menus;
        nautilus_files_view_class->restore_default_zoom_level = 
nautilus_empty_view_restore_default_zoom_level;
+        nautilus_files_view_class->restore_standard_zoom_level = 
nautilus_empty_view_restore_standard_zoom_level;
        nautilus_files_view_class->reveal_selection = nautilus_empty_view_reveal_selection;
        nautilus_files_view_class->select_all = nautilus_empty_view_select_all;
        nautilus_files_view_class->set_selection = nautilus_empty_view_set_selection;
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 078a27c..04fac01 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -268,8 +268,8 @@ struct NautilusFilesViewDetails
         GtkWidget *visible_columns;
         GtkWidget *stop;
         GtkWidget *reload;
-        GtkAdjustment *zoom_adjustment;
-        GtkWidget *zoom_level_scale;
+        GtkWidget *zoom_controls_box;
+        GtkWidget *zoom_level_label;
 
         GtkWidget *undo_button;
         GtkWidget *redo_button;
@@ -780,6 +780,28 @@ nautilus_files_view_restore_default_zoom_level (NautilusFilesView *view)
         NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->restore_default_zoom_level (view);
 }
 
+/**
+ * nautilus_files_view_restore_standard_zoom_level:
+ *
+ * Restore the zoom level to 100%
+ */
+static void
+nautilus_files_view_restore_standard_zoom_level (NautilusFilesView *view)
+{
+        if (!nautilus_files_view_supports_zooming (view))
+                return;
+
+        NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->restore_standard_zoom_level (view);
+}
+
+static gfloat
+nautilus_files_view_get_zoom_level_percentage (NautilusFilesView *view)
+{
+        g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), 1);
+
+        return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_zoom_level_percentage (view);
+}
+
 gboolean
 nautilus_files_view_is_searching (NautilusView *view)
 {
@@ -1548,15 +1570,6 @@ action_select_pattern (GSimpleAction *action,
         select_pattern(user_data);
 }
 
-static void
-zoom_level_changed (GtkRange          *range,
-                    NautilusFilesView *view)
-{
-        g_action_group_change_action_state (view->details->view_action_group,
-                                            "zoom-to-level",
-                                            g_variant_new_int32 (gtk_range_get_value (range)));
-}
-
 typedef struct {
         NautilusFilesView *directory_view;
         GHashTable *added_locations;
@@ -2361,6 +2374,14 @@ action_zoom_default (GSimpleAction *action,
 }
 
 static void
+action_zoom_standard (GSimpleAction *action,
+                      GVariant      *state,
+                      gpointer       user_data)
+{
+        nautilus_files_view_restore_standard_zoom_level (user_data);
+}
+
+static void
 action_open_item_new_window (GSimpleAction *action,
                              GVariant      *state,
                              gpointer       user_data)
@@ -6016,6 +6037,7 @@ const GActionEntry view_entries[] = {
         { "zoom-in",  action_zoom_in },
         { "zoom-out", action_zoom_out },
         { "zoom-default", action_zoom_default },
+        { "zoom-standard", action_zoom_standard },
         { "show-hidden-files", NULL, NULL, "true", action_show_hidden_files },
         /* Background menu */
         { "new-folder", action_new_folder },
@@ -6622,6 +6644,10 @@ real_update_actions_state (NautilusFilesView *view)
         g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
                                      nautilus_files_view_supports_zooming (view));
         action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+                                             "zoom-standard");
+        g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+                                     nautilus_files_view_supports_zooming (view));
+        action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                              "zoom-to-level");
         g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
                                      !nautilus_files_view_is_empty (view));
@@ -6883,6 +6909,7 @@ nautilus_files_view_reset_view_menu (NautilusFilesView *view)
         GVariantIter iter;
         gboolean show_sort_trash, show_sort_search, show_sort_access, show_sort_modification, sort_available;
         const gchar *hint;
+        g_autofree gchar *zoom_level_percent = NULL;
 
         view_action_group = nautilus_files_view_get_action_group (view);
 
@@ -6898,7 +6925,7 @@ nautilus_files_view_reset_view_menu (NautilusFilesView *view)
          */
         gtk_widget_set_sensitive (view->details->sort_menu,
                                   !nautilus_files_view_is_empty (view));
-        gtk_widget_set_sensitive (view->details->zoom_level_scale,
+        gtk_widget_set_sensitive (view->details->zoom_controls_box,
                                   !nautilus_files_view_is_empty (view));
 
         if (sort_available) {
@@ -6918,10 +6945,8 @@ nautilus_files_view_reset_view_menu (NautilusFilesView *view)
         gtk_widget_set_visible (view->details->sort_trash_time, show_sort_trash);
         gtk_widget_set_visible (view->details->sort_search_relevance, show_sort_search);
 
-        variant = g_action_group_get_action_state (view_action_group, "zoom-to-level");
-        gtk_adjustment_set_value (view->details->zoom_adjustment,
-                                  g_variant_get_int32 (variant));
-        g_variant_unref (variant);
+        zoom_level_percent = g_strdup_printf ("%.0f%%", nautilus_files_view_get_zoom_level_percentage (view) 
* 100.0);
+        gtk_label_set_label (GTK_LABEL (view->details->zoom_level_label), zoom_level_percent);
 }
 
 /* Convenience function to reset the menus owned by the view but managed on
@@ -8234,8 +8259,8 @@ nautilus_files_view_init (NautilusFilesView *view)
         /* View menu */
         builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-view-menu.ui");
         view->details->view_menu_widget =  g_object_ref_sink (gtk_builder_get_object (builder, 
"view_menu_widget"));
-        view->details->zoom_level_scale = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_level_scale"));
-        view->details->zoom_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, 
"zoom_adjustment"));
+        view->details->zoom_controls_box = GTK_WIDGET (gtk_builder_get_object (builder, 
"zoom_controls_box"));
+        view->details->zoom_level_label = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_level_label"));
 
         view->details->sort_menu =  GTK_WIDGET (gtk_builder_get_object (builder, "sort_menu"));
         view->details->sort_trash_time =  GTK_WIDGET (gtk_builder_get_object (builder, "sort_trash_time"));
@@ -8247,9 +8272,6 @@ nautilus_files_view_init (NautilusFilesView *view)
         view->details->undo_button = GTK_WIDGET (gtk_builder_get_object (builder, "undo"));
         view->details->redo_button = GTK_WIDGET (gtk_builder_get_object (builder, "redo"));
 
-        g_signal_connect (view->details->zoom_level_scale, "value-changed",
-                          G_CALLBACK (zoom_level_changed), view);
-
         g_signal_connect (view,
                           "end-file-changes",
                           G_CALLBACK (on_end_file_changes),
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 9b5a28b..b76ae6a 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -183,6 +183,11 @@ struct NautilusFilesViewClass {
          * to restore the zoom level of an object to a default setting. */
         void    (* restore_default_zoom_level) (NautilusFilesView *view);
 
+        /*
+         * restore_default_zoom_level: restores the zoom level to 100% (or to
+         * whatever is considered the 'standard' zoom level for the view). */
+        void    (* restore_standard_zoom_level) (NautilusFilesView *view);
+
         /* can_zoom_in is a function pointer that subclasses must override to
          * return whether the view is at maximum size (furthest-in zoom level) */
         gboolean (* can_zoom_in)             (NautilusFilesView *view);
@@ -191,6 +196,9 @@ struct NautilusFilesViewClass {
          * return whether the view is at minimum size (furthest-out zoom level) */
         gboolean (* can_zoom_out)            (NautilusFilesView *view);
 
+        /* The current zoom level as a percentage of the default (0, 1] */
+        gfloat   (* get_zoom_level_percentage) (NautilusFilesView *view);
+
         /* reveal_selection is a function pointer that subclasses may
          * override to make sure the selected items are sufficiently
          * apparent to the user (e.g., scrolled into view). By default,
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index ea5645b..53d8b7e 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -2764,6 +2764,12 @@ nautilus_list_view_restore_default_zoom_level (NautilusFilesView *view)
        nautilus_list_view_zoom_to_level (view, get_default_zoom_level ());
 }
 
+static void
+nautilus_list_view_restore_standard_zoom_level (NautilusFilesView *view)
+{
+        nautilus_list_view_zoom_to_level (view, NAUTILUS_LIST_ZOOM_LEVEL_STANDARD);
+}
+
 static gboolean 
 nautilus_list_view_can_zoom_in (NautilusFilesView *view) 
 {
@@ -2780,6 +2786,20 @@ nautilus_list_view_can_zoom_out (NautilusFilesView *view)
        return NAUTILUS_LIST_VIEW (view)->details->zoom_level > NAUTILUS_LIST_ZOOM_LEVEL_SMALL;
 }
 
+static gfloat
+nautilus_list_view_get_zoom_level_percentage (NautilusFilesView *view)
+{
+        NautilusListView *list_view;
+        guint icon_size;
+
+        g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), 1.0);
+
+        list_view = NAUTILUS_LIST_VIEW (view);
+        icon_size = nautilus_list_model_get_icon_size_for_zoom_level (list_view->details->zoom_level);
+
+        return (gfloat) icon_size / NAUTILUS_LIST_ICON_SIZE_STANDARD;
+}
+
 static void
 nautilus_list_view_click_policy_changed (NautilusFilesView *directory_view)
 {
@@ -3129,6 +3149,7 @@ nautilus_list_view_class_init (NautilusListViewClass *class)
        nautilus_files_view_class->bump_zoom_level = nautilus_list_view_bump_zoom_level;
        nautilus_files_view_class->can_zoom_in = nautilus_list_view_can_zoom_in;
        nautilus_files_view_class->can_zoom_out = nautilus_list_view_can_zoom_out;
+        nautilus_files_view_class->get_zoom_level_percentage = nautilus_list_view_get_zoom_level_percentage;
         nautilus_files_view_class->click_policy_changed = nautilus_list_view_click_policy_changed;
        nautilus_files_view_class->clear = nautilus_list_view_clear;
        nautilus_files_view_class->file_changed = nautilus_list_view_file_changed;
@@ -3138,6 +3159,7 @@ nautilus_list_view_class_init (NautilusListViewClass *class)
        nautilus_files_view_class->is_empty = nautilus_list_view_is_empty;
        nautilus_files_view_class->remove_file = nautilus_list_view_remove_file;
        nautilus_files_view_class->restore_default_zoom_level = nautilus_list_view_restore_default_zoom_level;
+        nautilus_files_view_class->restore_standard_zoom_level = 
nautilus_list_view_restore_standard_zoom_level;
        nautilus_files_view_class->reveal_selection = nautilus_list_view_reveal_selection;
        nautilus_files_view_class->select_all = nautilus_list_view_select_all;
        nautilus_files_view_class->select_first = nautilus_list_view_select_first;
diff --git a/src/resources/ui/nautilus-toolbar-view-menu.ui b/src/resources/ui/nautilus-toolbar-view-menu.ui
index f8e3d24..0442f81 100644
--- a/src/resources/ui/nautilus-toolbar-view-menu.ui
+++ b/src/resources/ui/nautilus-toolbar-view-menu.ui
@@ -12,7 +12,8 @@
           <object class="GtkBox" id="new_buttons_box">
             <property name="visible">True</property>
             <property name="orientation">horizontal</property>
-            <property name="margin-bottom">6</property>
+            <property name="homogeneous">True</property>
+            <property name="margin-bottom">9</property>
             <style>
               <class name="linked"/>
             </style>
@@ -88,25 +89,82 @@
           </object>
         </child>
         <child>
-          <object class="GtkScale" id="zoom_level_scale">
+          <object class="GtkBox" id="zoom_controls_box">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="draw_value">False</property>
-            <property name="has_origin">False</property>
-            <property name="adjustment">zoom_adjustment</property>
-            <property name="round_digits">0</property>
-            <property name="restrict_to_fill_level">False</property>
-            <marks>
-              <mark value="0" position="bottom"/>
-              <mark value="1" position="bottom"/>
-              <mark value="2" position="bottom"/>
-              <mark value="3" position="bottom"/>
-            </marks>
+            <property name="orientation">horizontal</property>
+            <property name="homogeneous">True</property>
+            <style>
+              <class name="linked"/>
+            </style>
+            <child>
+              <object class="GtkButton" id="zoom-out">
+                <property name="visible">True</property>
+                <property name="action-name">view.zoom-out</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon-name">zoom-out-symbolic</property>
+                    <property name="icon-size">1</property>
+                  </object>
+                </child>
+                <child internal-child="accessible">
+                  <object class="AtkObject">
+                    <property name="accessible-name" translatable="yes">Zoom Out</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="zoom-default">
+                <property name="visible">True</property>
+                <property name="action_name">view.zoom-standard</property>
+                <child>
+                  <object class="GtkLabel" id="zoom_level_label">
+                    <property name="visible">True</property>
+                    <property name="width-chars">5</property>
+                  </object>
+                </child>
+                <child internal-child="accessible">
+                  <object class="AtkObject">
+                    <property name="accessible-name" translatable="yes">Reset Zoom</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="zoom-in">
+                <property name="visible">True</property>
+                <property name="action_name">view.zoom-in</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon-name">zoom-in-symbolic</property>
+                    <property name="icon-size">1</property>
+                  </object>
+                </child>
+                <child internal-child="accessible">
+                  <object class="AtkObject">
+                    <property name="accessible-name" translatable="yes">Zoom In</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-          </packing>
         </child>
         <child>
           <object class="GtkSeparator">
@@ -272,11 +330,4 @@
       </object>
     </child>
   </object>
-  <object class="GtkAdjustment" id="zoom_adjustment">
-    <property name="lower">0</property>
-    <property name="upper">3</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">1</property>
-    <property name="value">1</property>
-  </object>
 </interface>


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