usability: Change tooltip for view_toggle_button

Currently, the tooltip says 'Toggle view', which isn't clear.

Usability testers had difficulty finding out how to change between
list and grid view.

Change tooltip to say 'Show list' or 'Show grid', depending on which
view it can change to.

Fixes: https://gitlab.gnome.org/GNOME/nautilus/issues/893
This commit is contained in:
Ujjwal Kumar 2020-03-09 02:37:02 +05:30 committed by António Fernandes
parent f5ad501568
commit a700db42bb
5 changed files with 120 additions and 0 deletions

View file

@ -114,6 +114,7 @@ struct _NautilusToolbar
NautilusWindowSlot *window_slot;
GBinding *icon_binding;
GBinding *search_binding;
GBinding *tooltip_binding;
};
enum
@ -1379,6 +1380,26 @@ nautilus_toolbar_view_toggle_icon_transform_to (GBinding *binding,
return TRUE;
}
static gboolean
nautilus_toolbar_view_toggle_tooltip_transform_to (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer user_data)
{
const gchar *tooltip;
tooltip = g_value_get_string (from_value);
/* As per design decision, we let the previous used tooltip if no
* view menu is available */
if (tooltip)
{
g_value_set_string (to_value, tooltip);
}
return TRUE;
}
/* Called from on_window_slot_destroyed(), since bindings and signal handlers
* are automatically removed once the slot goes away.
*/
@ -1404,6 +1425,14 @@ nautilus_toolbar_set_window_slot_real (NautilusToolbar *self,
self,
NULL);
self->tooltip_binding = g_object_bind_property_full (self->window_slot, "tooltip",
self->view_toggle_button, "tooltip-text",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE,
(GBindingTransformFunc) nautilus_toolbar_view_toggle_tooltip_transform_to,
NULL,
self,
NULL);
self->search_binding = g_object_bind_property (self->window_slot, "searching",
self, "searching",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);

View file

@ -19,6 +19,7 @@
#include "config.h"
#include "nautilus-view.h"
#include <glib/gi18n.h>
G_DEFINE_INTERFACE (NautilusView, nautilus_view, GTK_TYPE_WIDGET)
@ -137,6 +138,35 @@ nautilus_view_get_icon (guint view_id)
}
}
/**
* nautilus_view_get_tooltip:
* @view: a #NautilusView
*
* Retrieves the static string that represents @view.
*
* Returns: (transfer none): a static string
*/
const gchar *
nautilus_view_get_tooltip (guint view_id)
{
if (view_id == NAUTILUS_VIEW_GRID_ID)
{
return _("Show grid");
}
else if (view_id == NAUTILUS_VIEW_LIST_ID)
{
return _("Show list");
}
else if (view_id == NAUTILUS_VIEW_OTHER_LOCATIONS_ID)
{
return _("Show List");
}
else
{
return NULL;
}
}
/**
* nautilus_view_get_view_id:
* @view: a #NautilusView

View file

@ -88,6 +88,8 @@ struct _NautilusViewInterface
GIcon * nautilus_view_get_icon (guint view_id);
const gchar * nautilus_view_get_tooltip (guint view_id);
guint nautilus_view_get_view_id (NautilusView *view);
NautilusToolbarMenuSections * nautilus_view_get_toolbar_menu_sections (NautilusView *view);

View file

@ -60,6 +60,7 @@ enum
PROP_SEARCHING,
PROP_SELECTION,
PROP_LOCATION,
PROP_TOOLTIP,
NUM_PROPERTIES
};
@ -947,6 +948,12 @@ nautilus_window_slot_get_property (GObject *object,
}
break;
case PROP_TOOLTIP:
{
g_value_set_static_string (value, nautilus_window_slot_get_tooltip (self));
}
break;
default:
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -3049,6 +3056,7 @@ nautilus_window_slot_switch_new_content_view (NautilusWindowSlot *self)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TOOLBAR_MENU_SECTIONS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXTENSIONS_BACKGROUND_MENU]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TEMPLATES_MENU]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TOOLTIP]);
}
done:
@ -3267,6 +3275,13 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
G_TYPE_FILE,
G_PARAM_READWRITE);
properties[PROP_TOOLTIP] =
g_param_spec_string ("tooltip",
"Tooltip that represents the slot",
"The tooltip that represents the slot",
NULL,
G_PARAM_READWRITE);
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
@ -3565,6 +3580,48 @@ nautilus_window_slot_get_icon (NautilusWindowSlot *self)
}
}
const gchar *
nautilus_window_slot_get_tooltip (NautilusWindowSlot *self)
{
guint current_view_id;
NautilusWindowSlotPrivate *priv;
g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NULL);
priv = nautilus_window_slot_get_instance_private (self);
if (priv->content_view == NULL)
{
return NULL;
}
current_view_id = nautilus_view_get_view_id (NAUTILUS_VIEW (priv->content_view));
switch (current_view_id)
{
case NAUTILUS_VIEW_LIST_ID:
{
return nautilus_view_get_tooltip (NAUTILUS_VIEW_GRID_ID);
}
break;
case NAUTILUS_VIEW_GRID_ID:
{
return nautilus_view_get_tooltip (NAUTILUS_VIEW_LIST_ID);
}
break;
case NAUTILUS_VIEW_OTHER_LOCATIONS_ID:
{
return nautilus_view_get_tooltip (NAUTILUS_VIEW_OTHER_LOCATIONS_ID);
}
break;
default:
{
return NULL;
}
}
}
NautilusToolbarMenuSections *
nautilus_window_slot_get_toolbar_menu_sections (NautilusWindowSlot *self)
{

View file

@ -99,6 +99,8 @@ void nautilus_window_slot_queue_reload (NautilusWindowSlot *slot);
GIcon* nautilus_window_slot_get_icon (NautilusWindowSlot *slot);
const gchar* nautilus_window_slot_get_tooltip (NautilusWindowSlot *slot);
NautilusToolbarMenuSections * nautilus_window_slot_get_toolbar_menu_sections (NautilusWindowSlot *slot);
GMenuModel* nautilus_window_slot_get_templates_menu (NautilusWindowSlot *self);