[egg-list-box/flow-box-enhancements] Improve selection behaviour
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [egg-list-box/flow-box-enhancements] Improve selection behaviour
- Date: Sat, 28 Sep 2013 18:12:11 +0000 (UTC)
commit 60066d2712ba354e2362b86c2589bb5902ed2ff1
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 28 14:02:02 2013 -0400
Improve selection behaviour
Make the multi-selection keybindings a bit more conventional. In
general, Shift extends the selection, and Ctrl modifies it. As
a nod toward touch, we allow selections to be modified by single
unmodified clicks.
egg-flow-box.c | 142 +++++++++++++++++++++++++++-----------------------------
1 files changed, 68 insertions(+), 74 deletions(-)
---
diff --git a/egg-flow-box.c b/egg-flow-box.c
index 7bd0e0e..6bbdd97 100644
--- a/egg-flow-box.c
+++ b/egg-flow-box.c
@@ -216,24 +216,37 @@ egg_flow_box_child_get_box (EggFlowBoxChild *child)
}
static void
-egg_flow_box_child_set_focus (EggFlowBoxChild *child)
+get_current_selection_modifiers (GtkWidget *widget,
+ gboolean *modify,
+ gboolean *extend)
{
- EggFlowBox *box = egg_flow_box_child_get_box (child);
GdkModifierType state = 0;
- gboolean modify_selection_pressed;
+ GdkModifierType mask;
+
+ *modify = FALSE;
+ *extend = FALSE;
- modify_selection_pressed = FALSE;
if (gtk_get_current_event_state (&state))
{
- GdkModifierType modify_mod_mask;
- modify_mod_mask =
- gtk_widget_get_modifier_mask (GTK_WIDGET (box),
- GDK_MODIFIER_INTENT_MODIFY_SELECTION);
- if ((state & modify_mod_mask) == modify_mod_mask)
- modify_selection_pressed = TRUE;
+ mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
+ if ((state & mask) == mask)
+ *modify = TRUE;
+ mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
+ if ((state & mask) == mask)
+ *extend = TRUE;
}
+}
+
+static void
+egg_flow_box_child_set_focus (EggFlowBoxChild *child)
+{
+ EggFlowBox *box = egg_flow_box_child_get_box (child);
+ gboolean modify_selection;
+ gboolean extend_selection;
+
+ get_current_selection_modifiers (GTK_WIDGET (box), &modify_selection, &extend_selection);
- if (modify_selection_pressed)
+ if (modify_selection)
egg_flow_box_update_cursor (box, child);
else
egg_flow_box_update_selection (box, child, FALSE, FALSE);
@@ -2636,7 +2649,7 @@ egg_flow_box_select_all_between (EggFlowBox *box,
iter2 = iter;
}
- for (iter = iter1; ; iter = g_sequence_iter_next (iter))
+ for (iter = iter1; !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter))
{
GtkWidget *child;
@@ -2725,39 +2738,21 @@ egg_flow_box_button_release_event (GtkWidget *widget,
{
EggFlowBox *box = EGG_FLOW_BOX (widget);
EggFlowBoxPrivate *priv = box->priv;
+ gboolean modify_selection;
+ gboolean extend_selection;
if (event->button == GDK_BUTTON_PRIMARY)
{
- if (priv->active_child != NULL &&
- priv->active_child_active)
+ if (priv->active_child != NULL && priv->active_child_active)
{
- GdkModifierType state = 0;
- gboolean modify_selection_pressed;
- gboolean extend_selection_pressed;
-
- modify_selection_pressed = FALSE;
- extend_selection_pressed = FALSE;
- if (gtk_get_current_event_state (&state))
- {
- GdkModifierType extend_mod_mask;
- GdkModifierType modify_mod_mask;
-
- extend_mod_mask = gtk_widget_get_modifier_mask (GTK_WIDGET (box),
- GDK_MODIFIER_INTENT_EXTEND_SELECTION);
- if ((state & extend_mod_mask) == extend_mod_mask)
- extend_selection_pressed = TRUE;
-
- modify_mod_mask = gtk_widget_get_modifier_mask (GTK_WIDGET (box),
- GDK_MODIFIER_INTENT_MODIFY_SELECTION);
- if ((state & modify_mod_mask) == modify_mod_mask)
- modify_selection_pressed = TRUE;
- }
+ get_current_selection_modifiers (GTK_WIDGET (box), &modify_selection, &extend_selection);
if (priv->activate_on_single_click)
egg_flow_box_select_and_activate (box, priv->active_child);
else
- egg_flow_box_update_selection (box, priv->active_child, modify_selection_pressed,
extend_selection_pressed);
+ egg_flow_box_update_selection (box, priv->active_child, TRUE, extend_selection);
}
+
priv->active_child = NULL;
priv->active_child_active = FALSE;
gtk_widget_queue_draw (GTK_WIDGET (box));
@@ -2990,27 +2985,36 @@ egg_flow_box_add_move_binding (GtkBindingSet *binding_set,
GtkMovementStep step,
gint count)
{
+ GdkDisplay *display;
+ GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
+ GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
+
+ display = gdk_display_get_default ();
+ if (display)
+ {
+ extend_mod_mask = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
+ GDK_MODIFIER_INTENT_EXTEND_SELECTION);
+ modify_mod_mask = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
+ GDK_MODIFIER_INTENT_MODIFY_SELECTION);
+ }
+
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
- "move-cursor", (guint) 2,
+ "move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
- gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
- "move-cursor", (guint) 2,
+ gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask,
+ "move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
-
- if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
- return;
-
- gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
- "move-cursor", (guint) 2,
+ gtk_binding_entry_add_signal (binding_set, keyval, modmask | modify_mod_mask,
+ "move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
- gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
- "move-cursor", (guint) 2,
+ gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask | modify_mod_mask,
+ "move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
@@ -3044,17 +3048,14 @@ egg_flow_box_toggle_cursor_child (EggFlowBox *box)
}
static void
-egg_flow_box_move_cursor (EggFlowBox *box,
- GtkMovementStep step,
- gint count)
+egg_flow_box_move_cursor (EggFlowBox *box,
+ GtkMovementStep step,
+ gint count)
{
EggFlowBoxPrivate *priv = box->priv;
- GdkModifierType state;
- gboolean extend_selection_pressed;
- gboolean modify_selection_pressed;
+ gboolean modify_selection;
+ gboolean extend_selection;
EggFlowBoxChild *child;
- GdkModifierType extend_mod_mask;
- GdkModifierType modify_mod_mask;
EggFlowBoxChild *prev;
EggFlowBoxChild *next;
EggFlowBoxChildPrivate *child_priv;
@@ -3063,21 +3064,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
gint start_y;
gint end_y;
- extend_selection_pressed = FALSE;
- modify_selection_pressed = FALSE;
-
- if (gtk_get_current_event_state (&state))
- {
- extend_mod_mask = gtk_widget_get_modifier_mask (GTK_WIDGET (box),
- GDK_MODIFIER_INTENT_EXTEND_SELECTION);
- if ((state & extend_mod_mask) == extend_mod_mask)
- extend_selection_pressed = TRUE;
-
- modify_mod_mask = gtk_widget_get_modifier_mask (GTK_WIDGET (box),
- GDK_MODIFIER_INTENT_MODIFY_SELECTION);
- if ((state & modify_mod_mask) == modify_mod_mask)
- modify_selection_pressed = TRUE;
- }
+ get_current_selection_modifiers (GTK_WIDGET (box), &modify_selection, &extend_selection);
child = NULL;
switch (step)
@@ -3105,6 +3092,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
child = g_sequence_get (iter);
}
break;
+
case GTK_MOVEMENT_BUFFER_ENDS:
if (count < 0)
iter = egg_flow_box_get_first_focusable (box);
@@ -3113,6 +3101,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
if (iter != NULL && !g_sequence_iter_is_end (iter))
child = g_sequence_get (iter);
break;
+
case GTK_MOVEMENT_DISPLAY_LINES:
if (priv->cursor_child != NULL)
{
@@ -3134,6 +3123,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
child = g_sequence_get (iter);
}
break;
+
case GTK_MOVEMENT_PAGES:
page_size = 100;
if (priv->adjustment != NULL)
@@ -3196,8 +3186,9 @@ egg_flow_box_move_cursor (EggFlowBox *box,
end_y = child_priv->area.y;
}
break;
+
default:
- return;
+ g_assert_not_reached ();
}
if (child == NULL || child == priv->cursor_child)
@@ -3220,8 +3211,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
}
egg_flow_box_update_cursor (box, child);
- if (!modify_selection_pressed)
- egg_flow_box_update_selection (box, child, FALSE, extend_selection_pressed);
+ egg_flow_box_update_selection (box, child, modify_selection, extend_selection);
}
void
@@ -3735,6 +3725,7 @@ egg_flow_box_set_selection_mode (EggFlowBox *box,
GtkSelectionMode mode)
{
gboolean dirty = FALSE;
+
g_return_if_fail (EGG_IS_FLOW_BOX (box));
if (mode == box->priv->selection_mode)
@@ -3742,7 +3733,10 @@ egg_flow_box_set_selection_mode (EggFlowBox *box,
if (mode == GTK_SELECTION_NONE ||
box->priv->selection_mode == GTK_SELECTION_MULTIPLE)
- dirty = egg_flow_box_unselect_all_internal (box);
+ {
+ dirty = egg_flow_box_unselect_all_internal (box);
+ box->priv->selected_child = NULL;
+ }
box->priv->selection_mode = mode;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]