diff options
author | Krifa75 <yahiaoui.fakhri@gmail.com> | 2022-11-24 00:59:12 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-11-24 13:43:59 +0100 |
commit | dc0a72b117ab6bbf13f91f31de378c72da807883 (patch) | |
tree | 4647a243675fd9a1c6fc98e4c7340ce71ac50772 | |
parent | fe52b0ab2f53c228a9038a139b9ad4c530662d9c (diff) | |
download | totem-dc0a72b117ab6bbf13f91f31de378c72da807883.tar.gz |
main: Use template to create TotemSearchEntry
-rw-r--r-- | data/totem-search-entry.ui | 56 | ||||
-rw-r--r-- | data/totem.gresource.xml | 1 | ||||
-rw-r--r-- | src/totem-search-entry.c | 63 |
3 files changed, 72 insertions, 48 deletions
diff --git a/data/totem-search-entry.ui b/data/totem-search-entry.ui new file mode 100644 index 000000000..77e42f962 --- /dev/null +++ b/data/totem-search-entry.ui @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <object class="GtkPopover" id="popover"> + <property name="visible">True</property> + <property name="modal">True</property> + <property name="position">bottom</property> + <signal name="closed" handler="popover_closed_cb"/> + <child> + <object class="GtkListBox" id="listbox"> + <property name="visible">True</property> + <property name="activate-on-single-click">True</property> + <signal name="row-activated" handler="listbox_row_activated"/> + </object> + </child> + </object> + + <template class="TotemSearchEntry" parent="GtkBox"> + <property name="visible">True</property> + <property name="orientation">horizontal</property> + <style> + <class name="linked"/> + </style> + <child> + <object class="GtkSearchEntry" id="entry"> + <property name="visible">True</property> + <property name="hexpand">True</property> + <signal name="activate" handler="entry_activate_cb"/> + </object> + </child> + <child> + <object class="GtkMenuButton" id="dropdown_button"> + <property name="visible">True</property> + <property name="popover">popover</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="orientation">horizontal</property> + <property name="spacing">12</property> + <child> + <object class="GtkLabel" id="label"> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="icon-name">pan-down-symbolic</property> + <property name="icon-size">4</property> + </object> + </child> + </object> + </child> + </object> + </child> + </template> +</interface>
\ No newline at end of file diff --git a/data/totem.gresource.xml b/data/totem.gresource.xml index 6341197ec..b1b392b24 100644 --- a/data/totem.gresource.xml +++ b/data/totem.gresource.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/org/gnome/totem/ui"> + <file compressed="true">totem-search-entry.ui</file> <file compressed="true">totem-preferences-dialog.ui</file> <file compressed="true">totem-preferences-plugin-row.ui</file> <file compressed="true">playlist.ui</file> diff --git a/src/totem-search-entry.c b/src/totem-search-entry.c index c33d02081..29e86a92f 100644 --- a/src/totem-search-entry.c +++ b/src/totem-search-entry.c @@ -117,55 +117,9 @@ popover_closed_cb (GtkPopover *popover, static void totem_search_entry_init (TotemSearchEntry *self) { - GtkStyleContext *context; - GtkWidget *entry, *child, *box; - - /* Entry */ - entry = GTK_WIDGET (gtk_entry_new ()); - gtk_box_pack_start (GTK_BOX (self), - entry, - TRUE, TRUE, 0); - - self->entry = entry; - - /* Dropdown button */ - self->dropdown_button = gtk_menu_button_new (); - self->label = gtk_label_new (NULL); - child = gtk_bin_get_child (GTK_BIN (self->dropdown_button)); - g_object_ref (child); - gtk_container_remove (GTK_CONTAINER (self->dropdown_button), child); - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (box), self->label, FALSE, FALSE, 0); - gtk_box_pack_end (GTK_BOX (box), child, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (self->dropdown_button), box); - gtk_box_pack_end (GTK_BOX (self), - self->dropdown_button, - FALSE, FALSE, 0); - - context = gtk_widget_get_style_context (GTK_WIDGET (self)); - gtk_style_context_add_class (context, "linked"); - gtk_widget_show_all (GTK_WIDGET (self)); - - /* Popover */ - self->popover = gtk_popover_new (GTK_WIDGET (self)); - gtk_popover_set_modal (GTK_POPOVER (self->popover), TRUE); - gtk_popover_set_position (GTK_POPOVER (self->popover), GTK_POS_BOTTOM); - g_signal_connect (G_OBJECT (self->popover), "closed", - G_CALLBACK (popover_closed_cb), self); - gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->dropdown_button), self->popover); - - self->listbox = gtk_list_box_new (); - gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (self->listbox), TRUE); - gtk_list_box_set_sort_func (GTK_LIST_BOX (self->listbox), sort_sources, self, NULL); - gtk_widget_show (self->listbox); - gtk_container_add (GTK_CONTAINER (self->popover), self->listbox); - - g_signal_connect (self->listbox, "row-activated", - G_CALLBACK (listbox_row_activated), self); + gtk_widget_init_template (GTK_WIDGET (self)); - /* Connect signals */ - g_signal_connect (self->entry, "activate", - G_CALLBACK (entry_activate_cb), self); + gtk_list_box_set_sort_func (GTK_LIST_BOX (self->listbox), sort_sources, self, NULL); } static void @@ -204,6 +158,7 @@ static void totem_search_entry_class_init (TotemSearchEntryClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); gobject_class->set_property = totem_search_entry_set_property; gobject_class->get_property = totem_search_entry_get_property; @@ -221,6 +176,18 @@ totem_search_entry_class_init (TotemSearchEntryClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/totem/ui/totem-search-entry.ui"); + + gtk_widget_class_bind_template_child (widget_class, TotemSearchEntry, entry); + gtk_widget_class_bind_template_child (widget_class, TotemSearchEntry, dropdown_button); + gtk_widget_class_bind_template_child (widget_class, TotemSearchEntry, label); + gtk_widget_class_bind_template_child (widget_class, TotemSearchEntry, popover); + gtk_widget_class_bind_template_child (widget_class, TotemSearchEntry, listbox); + + gtk_widget_class_bind_template_callback (widget_class, entry_activate_cb); + gtk_widget_class_bind_template_callback (widget_class, listbox_row_activated); + gtk_widget_class_bind_template_callback (widget_class, popover_closed_cb); } TotemSearchEntry * |