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 *find_prev_button;
GtkWidget *replace_button; GtkWidget *replace_button;
GtkWidget *replace_all_button; GtkWidget *replace_all_button;
GtkWidget *close_button;
}; };
G_DEFINE_TYPE(XedSearchbar, xed_searchbar, GTK_TYPE_BOX) G_DEFINE_TYPE(XedSearchbar, xed_searchbar, GTK_TYPE_BOX)
@ -422,8 +423,8 @@ search_text_entry_changed (GtkEditable *editable,
{ {
const gchar *search_string; const gchar *search_string;
search_string = gtk_entry_get_text (GTK_ENTRY(editable)); search_string = gtk_entry_get_text (GTK_ENTRY (editable));
g_return_if_fail(search_string != NULL); g_return_if_fail (search_string != NULL);
if (*search_string != '\0') if (*search_string != '\0')
{ {
@ -433,6 +434,7 @@ search_text_entry_changed (GtkEditable *editable,
else else
{ {
search_buttons_set_sensitive (searchbar, FALSE); search_buttons_set_sensitive (searchbar, FALSE);
do_find (searchbar, FALSE);
} }
} }
@ -506,16 +508,26 @@ on_search_text_entry_activated (GtkEntry *widget,
do_find (searchbar, FALSE); do_find (searchbar, FALSE);
} }
static void
close_button_clicked_callback (GtkWidget *button,
XedSearchbar *searchbar)
{
xed_searchbar_hide (searchbar);
}
static void static void
xed_searchbar_init (XedSearchbar *searchbar) xed_searchbar_init (XedSearchbar *searchbar)
{ {
GtkWidget *content; GtkWidget *content;
GtkSizeGroup *size_group; GtkSizeGroup *size_group;
GtkWidget *error_widget; GtkWidget *error_widget;
GtkStyleContext *context;
GtkCssProvider *provider;
gchar *file; gchar *file;
gchar *root_objects[] = { "searchbar_content", NULL }; gchar *root_objects[] = { "searchbar_content", NULL };
const gchar *data = ".button {padding: 0;}";
searchbar->priv = XED_SEARCHBAR_GET_PRIVATE(searchbar); searchbar->priv = XED_SEARCHBAR_GET_PRIVATE (searchbar);
file = xed_dirs_get_ui_file ("xed-searchbar.ui"); file = xed_dirs_get_ui_file ("xed-searchbar.ui");
xed_utils_get_ui_objects (file, xed_utils_get_ui_objects (file,
@ -533,73 +545,82 @@ xed_searchbar_init (XedSearchbar *searchbar)
"find_prev_button", &searchbar->priv->find_prev_button, "find_prev_button", &searchbar->priv->find_prev_button,
"replace_button", &searchbar->priv->replace_button, "replace_button", &searchbar->priv->replace_button,
"replace_all_button", &searchbar->priv->replace_all_button, "replace_all_button", &searchbar->priv->replace_all_button,
"close_button", &searchbar->priv->close_button,
NULL); NULL);
g_free (file); g_free (file);
searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE); searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE);
gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE); gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE);
xed_history_entry_set_escape_func (XED_HISTORY_ENTRY(searchbar->priv->search_entry), xed_history_entry_set_escape_func (XED_HISTORY_ENTRY (searchbar->priv->search_entry),
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text); (XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
searchbar->priv->search_text_entry = xed_history_entry_get_entry (XED_HISTORY_ENTRY(searchbar->priv->search_entry)); searchbar->priv->search_text_entry = xed_history_entry_get_entry (XED_HISTORY_ENTRY (searchbar->priv->search_entry));
gtk_entry_set_activates_default (GTK_ENTRY(searchbar->priv->search_text_entry), TRUE); gtk_entry_set_activates_default (GTK_ENTRY (searchbar->priv->search_text_entry), TRUE);
gtk_widget_show (searchbar->priv->search_entry); gtk_widget_show (searchbar->priv->search_entry);
gtk_grid_attach (GTK_GRID(searchbar->priv->grid), searchbar->priv->search_entry, 2, 0, 1, 1); gtk_grid_attach (GTK_GRID (searchbar->priv->grid), searchbar->priv->search_entry, 2, 0, 1, 1);
searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", TRUE); searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", TRUE);
xed_history_entry_set_escape_func (XED_HISTORY_ENTRY(searchbar->priv->replace_entry), xed_history_entry_set_escape_func (XED_HISTORY_ENTRY(searchbar->priv->replace_entry),
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text); (XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
searchbar->priv->replace_text_entry = xed_history_entry_get_entry ( searchbar->priv->replace_text_entry = xed_history_entry_get_entry (
XED_HISTORY_ENTRY(searchbar->priv->replace_entry)); XED_HISTORY_ENTRY (searchbar->priv->replace_entry));
gtk_entry_set_activates_default (GTK_ENTRY(searchbar->priv->replace_text_entry), TRUE); gtk_entry_set_activates_default (GTK_ENTRY (searchbar->priv->replace_text_entry), TRUE);
gtk_widget_show (searchbar->priv->replace_entry); gtk_widget_show (searchbar->priv->replace_entry);
gtk_grid_attach (GTK_GRID(searchbar->priv->grid), searchbar->priv->replace_entry, 2, 1, 1, 1); gtk_grid_attach (GTK_GRID (searchbar->priv->grid), searchbar->priv->replace_entry, 2, 1, 1, 1);
gtk_label_set_mnemonic_widget (GTK_LABEL(searchbar->priv->search_label), searchbar->priv->search_entry); 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); 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); 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_button));
gtk_size_group_add_widget (size_group, GTK_WIDGET(searchbar->priv->find_prev_button)); gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->find_prev_button));
gtk_size_group_add_widget (size_group, GTK_WIDGET(searchbar->priv->replace_button)); gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->replace_button));
gtk_size_group_add_widget (size_group, GTK_WIDGET(searchbar->priv->replace_all_button)); gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->replace_all_button));
/* insensitive by default */ /* insensitive by default */
search_buttons_set_sensitive (searchbar, FALSE); search_buttons_set_sensitive (searchbar, FALSE);
xed_searchbar_hide (searchbar); xed_searchbar_hide (searchbar);
gtk_box_pack_start (GTK_BOX(searchbar), content, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (searchbar), content, TRUE, TRUE, 0);
gtk_widget_show (GTK_WIDGET(searchbar)); gtk_widget_show (GTK_WIDGET (searchbar));
g_object_unref (content); g_object_unref (content);
g_signal_connect(searchbar->priv->search_text_entry, "insert_text", g_signal_connect (searchbar->priv->search_text_entry, "insert_text",
G_CALLBACK (insert_text_handler), NULL); G_CALLBACK (insert_text_handler), NULL);
g_signal_connect(searchbar->priv->replace_text_entry, "insert_text", g_signal_connect (searchbar->priv->replace_text_entry, "insert_text",
G_CALLBACK (insert_text_handler), NULL); G_CALLBACK (insert_text_handler), NULL);
g_signal_connect(searchbar->priv->search_text_entry, "changed", g_signal_connect (searchbar->priv->search_text_entry, "changed",
G_CALLBACK (search_text_entry_changed), searchbar); G_CALLBACK (search_text_entry_changed), searchbar);
g_signal_connect(searchbar->priv->search_text_entry, "activate", g_signal_connect (searchbar->priv->search_text_entry, "activate",
G_CALLBACK (on_search_text_entry_activated), searchbar); G_CALLBACK (on_search_text_entry_activated), searchbar);
g_signal_connect(searchbar->priv->find_button, "clicked", g_signal_connect (searchbar->priv->find_button, "clicked",
G_CALLBACK (find_button_clicked_callback), searchbar); G_CALLBACK (find_button_clicked_callback), searchbar);
g_signal_connect(searchbar->priv->find_prev_button, "clicked", g_signal_connect (searchbar->priv->find_prev_button, "clicked",
G_CALLBACK (find_prev_button_clicked_callback), searchbar); G_CALLBACK (find_prev_button_clicked_callback), searchbar);
g_signal_connect(searchbar->priv->replace_button, "clicked", g_signal_connect (searchbar->priv->replace_button, "clicked",
G_CALLBACK (replace_button_clicked_callback), searchbar); G_CALLBACK (replace_button_clicked_callback), searchbar);
g_signal_connect(searchbar->priv->replace_all_button, "clicked", g_signal_connect (searchbar->priv->replace_all_button, "clicked",
G_CALLBACK (replace_all_button_clicked_callback), searchbar); G_CALLBACK (replace_all_button_clicked_callback), searchbar);
g_signal_connect (searchbar->priv->close_button, "clicked",
G_CALLBACK (close_button_clicked_callback), searchbar);
} }
GtkWidget * GtkWidget *

View File

@ -184,6 +184,34 @@
<property name="top_attach">0</property> <property name="top_attach">0</property>
</packing> </packing>
</child> </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> <child>
<placeholder/> <placeholder/>
</child> </child>