searchbar: Add a key-capture-widget property

This is handy to set up this relationship in ui files,
and also makes it accessible in the inspector.
This commit is contained in:
Matthias Clasen 2020-07-12 16:25:24 -04:00
parent 22c1b541df
commit f32239df1f

View File

@ -119,6 +119,7 @@ enum {
PROP_SEARCH_MODE_ENABLED,
PROP_SHOW_CLOSE_BUTTON,
PROP_CHILD,
PROP_KEY_CAPTURE_WIDGET,
LAST_PROPERTY
};
@ -206,6 +207,9 @@ gtk_search_bar_set_property (GObject *object,
case PROP_CHILD:
gtk_search_bar_set_child (bar, g_value_get_object (value));
break;
case PROP_KEY_CAPTURE_WIDGET:
gtk_search_bar_set_key_capture_widget (bar, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -231,6 +235,9 @@ gtk_search_bar_get_property (GObject *object,
case PROP_CHILD:
g_value_set_object (value, gtk_search_bar_get_child (bar));
break;
case PROP_KEY_CAPTURE_WIDGET:
g_value_set_object (value, gtk_search_bar_get_key_capture_widget (bar));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -318,6 +325,13 @@ gtk_search_bar_class_init (GtkSearchBarClass *klass)
GTK_TYPE_WIDGET,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY);
widget_props[PROP_KEY_CAPTURE_WIDGET]
= g_param_spec_object ("key-capture-widget",
P_("Key Capture Widget"),
P_("Key Capture Widget"),
GTK_TYPE_WIDGET,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, LAST_PROPERTY, widget_props);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
@ -610,6 +624,8 @@ gtk_search_bar_set_key_capture_widget (GtkSearchBar *bar,
G_CALLBACK (capture_widget_key_handled), bar);
gtk_widget_add_controller (widget, bar->capture_widget_controller);
}
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_KEY_CAPTURE_WIDGET]);
}
/**