Merge branch 'matthiasc/for-master' into 'master'

Matthiasc/for master

See merge request GNOME/gtk!2233
This commit is contained in:
Matthias Clasen 2020-07-12 21:23:07 +00:00
commit 032302c358
3 changed files with 31 additions and 3 deletions

View File

@ -1070,13 +1070,23 @@ get_child_model (gpointer item,
return NULL;
}
static void
clear_search (GtkSearchBar *bar)
{
if (!gtk_search_bar_get_search_mode (bar))
{
GtkWidget *entry = gtk_search_bar_get_child (GTK_SEARCH_BAR (bar));
gtk_editable_set_text (GTK_EDITABLE (entry), "");
}
}
static void
activate (GApplication *app)
{
GtkBuilder *builder;
GListModel *listmodel;
GtkTreeListModel *treemodel;
GtkWidget *window, *listview, *search_entry;
GtkWidget *window, *listview, *search_entry, *search_bar;
GtkFilterListModel *filter_model;
GtkFilter *filter;
@ -1099,6 +1109,8 @@ activate (GApplication *app)
toplevel = GTK_WIDGET (window);
listview = GTK_WIDGET (gtk_builder_get_object (builder, "listview"));
g_signal_connect (listview, "activate", G_CALLBACK (activate_cb), window);
search_bar = GTK_WIDGET (gtk_builder_get_object (builder, "searchbar"));
g_signal_connect (search_bar, "notify::search-mode-enabled", G_CALLBACK (clear_search), NULL);
listmodel = create_demo_model ();
treemodel = gtk_tree_list_model_new (FALSE,

View File

@ -60,8 +60,8 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkSearchBar">
<property name="search-mode-enabled">1</property>
<object class="GtkSearchBar" id="searchbar">
<property name="key-capture-widget">window</property>
<child>
<object class="GtkSearchEntry" id="search-entry"/>
</child>

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]);
}
/**