Add optional single click activation mode for icon view

https://bugzilla.gnome.org/show_bug.cgi?id=345023
This commit is contained in:
William Jon McCann 2013-01-18 00:59:55 -05:00
parent a84f244dc0
commit c7169e119e
5 changed files with 117 additions and 8 deletions

View File

@ -1756,6 +1756,8 @@ gtk_icon_view_set_margin
gtk_icon_view_get_margin
gtk_icon_view_set_item_padding
gtk_icon_view_get_item_padding
gtk_icon_view_set_activate_on_single_click
gtk_icon_view_get_activate_on_single_click
gtk_icon_view_get_cell_rect
gtk_icon_view_select_path
gtk_icon_view_unselect_path

View File

@ -1329,6 +1329,7 @@ gtk_icon_view_create_drag_icon
gtk_icon_view_drop_position_get_type
gtk_icon_view_enable_model_drag_dest
gtk_icon_view_enable_model_drag_source
gtk_icon_view_get_activate_on_single_click
gtk_icon_view_get_cell_rect
gtk_icon_view_get_columns
gtk_icon_view_get_column_spacing
@ -1365,6 +1366,7 @@ gtk_icon_view_scroll_to_path
gtk_icon_view_select_all
gtk_icon_view_selected_foreach
gtk_icon_view_select_path
gtk_icon_view_set_activate_on_single_click
gtk_icon_view_set_columns
gtk_icon_view_set_column_spacing
gtk_icon_view_set_cursor

View File

@ -107,12 +107,11 @@ enum
PROP_TOOLTIP_COLUMN,
PROP_ITEM_PADDING,
PROP_CELL_AREA,
/* For scrollable interface */
PROP_HADJUSTMENT,
PROP_VADJUSTMENT,
PROP_HSCROLL_POLICY,
PROP_VSCROLL_POLICY
PROP_VSCROLL_POLICY,
PROP_ACTIVATE_ON_SINGLE_CLICK
};
/* GObject vfuncs */
@ -639,6 +638,22 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
GTK_TYPE_CELL_AREA,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* GtkIconView:activate-on-single-click:
*
* The activate-on-single-click property specifies whether the "item-activated" signal
* will be emitted after a single click.
*
* Since: 3.8
*/
g_object_class_install_property (gobject_class,
PROP_ACTIVATE_ON_SINGLE_CLICK,
g_param_spec_boolean ("activate-on-single-click",
P_("Activate on Single Click"),
P_("Activate row on a single click"),
FALSE,
GTK_PARAM_READWRITE));
/* Scrollable interface properties */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
@ -668,10 +683,12 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
* @path: the #GtkTreePath for the activated item
*
* The ::item-activated signal is emitted when the method
* gtk_icon_view_item_activated() is called or the user double
* clicks an item. It is also emitted when a non-editable item
* is selected and one of the keys: Space, Return or Enter is
* pressed.
* gtk_icon_view_item_activated() is called, when the user double
* clicks an item with the "activate-on-single-click" property set
* to %FALSE, or when the user single clicks an item when the
* "activate-on-single-click" property set to %TRUE. It is also
* emitted when a non-editable item is selected and one of the keys:
* Space, Return or Enter is pressed.
*/
icon_view_signals[ITEM_ACTIVATED] =
g_signal_new (I_("item-activated"),
@ -964,6 +981,7 @@ gtk_icon_view_init (GtkIconView *icon_view)
icon_view->priv->column_spacing = 6;
icon_view->priv->margin = 6;
icon_view->priv->item_padding = 6;
icon_view->priv->activate_on_single_click = FALSE;
icon_view->priv->draw_focus = TRUE;
@ -1091,6 +1109,10 @@ gtk_icon_view_set_property (GObject *object,
gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
break;
case PROP_ACTIVATE_ON_SINGLE_CLICK:
gtk_icon_view_set_activate_on_single_click (icon_view, g_value_get_boolean (value));
break;
case PROP_CELL_AREA:
/* Construct-only, can only be assigned once */
area = g_value_get_object (value);
@ -1187,6 +1209,10 @@ gtk_icon_view_get_property (GObject *object,
g_value_set_int (value, icon_view->priv->item_padding);
break;
case PROP_ACTIVATE_ON_SINGLE_CLICK:
g_value_set_boolean (value, icon_view->priv->activate_on_single_click);
break;
case PROP_CELL_AREA:
g_value_set_object (value, icon_view->priv->cell_area);
break;
@ -2312,7 +2338,9 @@ gtk_icon_view_button_press (GtkWidget *widget,
icon_view->priv->draw_focus = FALSE;
}
if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
if (!icon_view->priv->activate_on_single_click
&& event->button == GDK_BUTTON_PRIMARY
&& event->type == GDK_2BUTTON_PRESS)
{
item = _gtk_icon_view_get_item_at_coords (icon_view,
event->x, event->y,
@ -2338,6 +2366,12 @@ gtk_icon_view_button_press (GtkWidget *widget,
return event->button == GDK_BUTTON_PRIMARY;
}
static gboolean
button_event_modifies_selection (GdkEventButton *event)
{
return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
}
static gboolean
gtk_icon_view_button_release (GtkWidget *widget,
GdkEventButton *event)
@ -2353,6 +2387,28 @@ gtk_icon_view_button_release (GtkWidget *widget,
remove_scroll_timeout (icon_view);
if (event->button == GDK_BUTTON_PRIMARY
&& icon_view->priv->activate_on_single_click
&& !button_event_modifies_selection (event)
&& icon_view->priv->last_single_clicked != NULL)
{
GtkIconViewItem *item;
item = _gtk_icon_view_get_item_at_coords (icon_view,
event->x, event->y,
FALSE,
NULL);
if (item == icon_view->priv->last_single_clicked)
{
GtkTreePath *path;
path = gtk_tree_path_new_from_indices (item->index, -1);
gtk_icon_view_item_activated (icon_view, path);
gtk_tree_path_free (path);
}
icon_view->priv->last_single_clicked = NULL;
}
return TRUE;
}
@ -7134,6 +7190,49 @@ gtk_icon_view_set_reorderable (GtkIconView *icon_view,
g_object_notify (G_OBJECT (icon_view), "reorderable");
}
/**
* gtk_icon_view_set_activate_on_single_click:
* @icon_view: a #GtkIconView
* @setting: %TRUE to emit item-activated on a single click
*
* Causes the "item-activated" signal to be emitted on a single click
* instead of a double click.
*
* Since: 3.8
**/
void
gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
gboolean setting)
{
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
setting = setting != FALSE;
if (icon_view->priv->activate_on_single_click == setting)
return;
icon_view->priv->activate_on_single_click = setting;
g_object_notify (G_OBJECT (icon_view), "activate-on-single-click");
}
/**
* gtk_icon_view_get_activate_on_single_click:
* @icon_view: a #GtkIconView
*
* Gets the setting set by gtk_icon_view_set_activate_on_single_click().
*
* Return value: %TRUE if item-activated will be emitted on a single click
*
* Since: 3.8
**/
gboolean
gtk_icon_view_get_activate_on_single_click (GtkIconView *icon_view)
{
g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
return icon_view->priv->activate_on_single_click;
}
static gboolean
gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
GtkBuilder *builder,

View File

@ -163,6 +163,11 @@ gboolean gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
gboolean gtk_icon_view_get_visible_range (GtkIconView *icon_view,
GtkTreePath **start_path,
GtkTreePath **end_path);
GDK_AVAILABLE_IN_3_8
void gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
gboolean single);
GDK_AVAILABLE_IN_3_8
gboolean gtk_icon_view_get_activate_on_single_click (GtkIconView *icon_view);
void gtk_icon_view_selected_foreach (GtkIconView *icon_view,
GtkIconViewForeachFunc func,

View File

@ -115,6 +115,7 @@ struct _GtkIconViewPrivate
guint dest_set : 1;
guint reorderable : 1;
guint empty_view_drop :1;
guint activate_on_single_click : 1;
guint modify_selection_pressed : 1;
guint extend_selection_pressed : 1;