mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
Merge branch 'wip/corey/tree-expander-bug' into 'main'
Improve treeexpanders See merge request GNOME/gtk!5282
This commit is contained in:
commit
c977f5cbb0
@ -302,6 +302,20 @@ gtk_list_item_widget_select_action (GtkWidget *widget,
|
||||
priv->position, modify, extend);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_widget_scroll_to_action (GtkWidget *widget,
|
||||
const char *action_name,
|
||||
GVariant *parameter)
|
||||
{
|
||||
GtkListItemWidget *self = GTK_LIST_ITEM_WIDGET (widget);
|
||||
GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
|
||||
|
||||
gtk_widget_activate_action (GTK_WIDGET (self),
|
||||
"list.scroll-to-item",
|
||||
"u",
|
||||
priv->position);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_widget_class_init (GtkListItemWidgetClass *klass)
|
||||
{
|
||||
@ -359,6 +373,17 @@ gtk_list_item_widget_class_init (GtkListItemWidgetClass *klass)
|
||||
"(bb)",
|
||||
gtk_list_item_widget_select_action);
|
||||
|
||||
/**
|
||||
* GtkListItem|listitem.scroll-to:
|
||||
*
|
||||
* Moves the visible area of the list to this item with the minimum amount
|
||||
* of scrolling required. If the item is already visible, nothing happens.
|
||||
*/
|
||||
gtk_widget_class_install_action (widget_class,
|
||||
"listitem.scroll-to",
|
||||
NULL,
|
||||
gtk_list_item_widget_scroll_to_action);
|
||||
|
||||
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
|
||||
"activate-keybinding", 0);
|
||||
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
|
||||
@ -418,8 +443,6 @@ gtk_list_item_widget_click_gesture_pressed (GtkGestureClick *gesture,
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_ACTIVE, FALSE);
|
||||
|
||||
if (gtk_widget_get_focus_on_click (widget))
|
||||
gtk_widget_grab_focus (widget);
|
||||
}
|
||||
@ -463,8 +486,6 @@ gtk_list_item_widget_click_gesture_released (GtkGestureClick *gesture,
|
||||
"(ubb)",
|
||||
priv->position, modify, extend);
|
||||
}
|
||||
|
||||
gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_ACTIVE);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -500,14 +521,6 @@ gtk_list_item_widget_hover_cb (GtkEventControllerMotion *controller,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_widget_click_gesture_canceled (GtkGestureClick *gesture,
|
||||
GdkEventSequence *sequence,
|
||||
GtkListItemWidget *self)
|
||||
{
|
||||
gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_ACTIVE);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_item_widget_init (GtkListItemWidget *self)
|
||||
{
|
||||
@ -527,8 +540,6 @@ gtk_list_item_widget_init (GtkListItemWidget *self)
|
||||
G_CALLBACK (gtk_list_item_widget_click_gesture_pressed), self);
|
||||
g_signal_connect (gesture, "released",
|
||||
G_CALLBACK (gtk_list_item_widget_click_gesture_released), self);
|
||||
g_signal_connect (gesture, "cancel",
|
||||
G_CALLBACK (gtk_list_item_widget_click_gesture_canceled), self);
|
||||
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
|
||||
|
||||
controller = gtk_event_controller_focus_new ();
|
||||
|
@ -118,23 +118,6 @@ G_DEFINE_TYPE (GtkTreeExpander, gtk_tree_expander, GTK_TYPE_WIDGET)
|
||||
|
||||
static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||
|
||||
static void
|
||||
gtk_tree_expander_click_gesture_pressed (GtkGestureClick *gesture,
|
||||
int n_press,
|
||||
double x,
|
||||
double y,
|
||||
gpointer unused)
|
||||
{
|
||||
GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
||||
|
||||
gtk_widget_activate_action (widget, "listitem.toggle-expand", NULL);
|
||||
|
||||
gtk_widget_set_state_flags (widget,
|
||||
GTK_STATE_FLAG_ACTIVE,
|
||||
FALSE);
|
||||
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_tree_expander_click_gesture_released (GtkGestureClick *gesture,
|
||||
@ -143,21 +126,13 @@ gtk_tree_expander_click_gesture_released (GtkGestureClick *gesture,
|
||||
double y,
|
||||
gpointer unused)
|
||||
{
|
||||
gtk_widget_unset_state_flags (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
|
||||
GTK_STATE_FLAG_ACTIVE);
|
||||
GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
||||
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_tree_expander_click_gesture_canceled (GtkGestureClick *gesture,
|
||||
GdkEventSequence *sequence,
|
||||
gpointer unused)
|
||||
{
|
||||
gtk_widget_unset_state_flags (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
|
||||
GTK_STATE_FLAG_ACTIVE);
|
||||
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
if (gtk_widget_contains (widget, x, y))
|
||||
{
|
||||
gtk_widget_activate_action (widget, "listitem.toggle-expand", NULL);
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -202,12 +177,8 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
|
||||
FALSE);
|
||||
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture),
|
||||
GDK_BUTTON_PRIMARY);
|
||||
g_signal_connect (gesture, "pressed",
|
||||
G_CALLBACK (gtk_tree_expander_click_gesture_pressed), NULL);
|
||||
g_signal_connect (gesture, "released",
|
||||
G_CALLBACK (gtk_tree_expander_click_gesture_released), NULL);
|
||||
g_signal_connect (gesture, "cancel",
|
||||
G_CALLBACK (gtk_tree_expander_click_gesture_canceled), NULL);
|
||||
gtk_widget_add_controller (self->expander_icon, GTK_EVENT_CONTROLLER (gesture));
|
||||
|
||||
gtk_widget_insert_before (self->expander_icon,
|
||||
@ -501,11 +472,17 @@ gtk_tree_expander_toggle_expand (GtkWidget *widget,
|
||||
GVariant *parameter)
|
||||
{
|
||||
GtkTreeExpander *self = GTK_TREE_EXPANDER (widget);
|
||||
gboolean expand;
|
||||
|
||||
if (self->list_row == NULL)
|
||||
return;
|
||||
|
||||
gtk_tree_list_row_set_expanded (self->list_row, !gtk_tree_list_row_get_expanded (self->list_row));
|
||||
expand = !gtk_tree_list_row_get_expanded (self->list_row);
|
||||
|
||||
if (expand)
|
||||
gtk_widget_activate_action (widget, "listitem.scroll-to", NULL);
|
||||
|
||||
gtk_tree_list_row_set_expanded (self->list_row, expand);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
Loading…
Reference in New Issue
Block a user