Merge pull request #57 from JosephMcc/searchbar-close

searchbar: Make some improvements
This commit is contained in:
Clement Lefebvre 2016-12-02 19:43:12 +00:00 committed by GitHub
commit 4028e617fb
2 changed files with 84 additions and 35 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)
@ -433,6 +434,7 @@ search_text_entry_changed (GtkEditable *editable,
else
{
search_buttons_set_sensitive (searchbar, FALSE);
do_find (searchbar, FALSE);
}
}
@ -506,14 +508,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 +545,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 +574,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 +618,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>