searchbar: Add a close button

Currently there is no clear way to close the searchbar. Add a simple small close
button to make this easier.
This commit is contained in:
JosephMcc 2016-11-28 14:23:27 -08:00
parent 2133a2f5b5
commit aa31c09fc7
2 changed files with 80 additions and 32 deletions

View File

@ -42,6 +42,7 @@ struct _XedSearchbarPrivate
GtkWidget *find_prev_button;
GtkWidget *replace_button;
GtkWidget *replace_all_button;
GtkWidget *close_button;
};
G_DEFINE_TYPE(XedSearchbar, xed_searchbar, GTK_TYPE_BOX)
@ -506,14 +507,24 @@ on_search_text_entry_activated (GtkEntry *widget,
do_find (searchbar, FALSE);
}
static void
close_button_clicked_callback (GtkWidget *button,
XedSearchbar *searchbar)
{
xed_searchbar_hide (searchbar);
}
static void
xed_searchbar_init (XedSearchbar *searchbar)
{
GtkWidget *content;
GtkSizeGroup *size_group;
GtkWidget *error_widget;
GtkStyleContext *context;
GtkCssProvider *provider;
gchar *file;
gchar *root_objects[] = { "searchbar_content", NULL };
const gchar *data = ".button {padding: 0;}";
searchbar->priv = XED_SEARCHBAR_GET_PRIVATE (searchbar);
@ -533,6 +544,7 @@ xed_searchbar_init (XedSearchbar *searchbar)
"find_prev_button", &searchbar->priv->find_prev_button,
"replace_button", &searchbar->priv->replace_button,
"replace_all_button", &searchbar->priv->replace_all_button,
"close_button", &searchbar->priv->close_button,
NULL);
g_free (file);
@ -561,6 +573,11 @@ xed_searchbar_init (XedSearchbar *searchbar)
gtk_label_set_mnemonic_widget (GTK_LABEL (searchbar->priv->search_label), searchbar->priv->search_entry);
gtk_label_set_mnemonic_widget (GTK_LABEL (searchbar->priv->replace_label), searchbar->priv->replace_entry);
provider = gtk_css_provider_new ();
context = gtk_widget_get_style_context (searchbar->priv->close_button);
gtk_css_provider_load_from_data (provider, data, -1, NULL);
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->find_button));
gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->find_prev_button));
@ -600,6 +617,9 @@ xed_searchbar_init (XedSearchbar *searchbar)
g_signal_connect (searchbar->priv->replace_all_button, "clicked",
G_CALLBACK (replace_all_button_clicked_callback), searchbar);
g_signal_connect (searchbar->priv->close_button, "clicked",
G_CALLBACK (close_button_clicked_callback), searchbar);
}
GtkWidget *

View File

@ -184,6 +184,34 @@
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="close_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Close</property>
<property name="valign">start</property>
<property name="relief">none</property>
<property name="xalign">1</property>
<property name="yalign">0</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">12</property>
<property name="icon_name">window-close-symbolic</property>
<property name="icon_size">0</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">5</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>