Commit 858a7f9a authored by Adrien Plazas's avatar Adrien Plazas
Browse files

shell: Make the search bar adaptive

parent 830619bb
......@@ -323,17 +323,22 @@
</object>
</child>
<child>
<object class="GtkSearchBar" id="search_bar">
<object class="HdySearchBar" id="search_bar">
<property name="visible">True</property>
<child>
<object class="GtkSearchEntry" id="entry_search">
<object class="HdyColumn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
<property name="width_request">500</property>
<property name="max_length">100</property>
<property name="maximum_width">400</property>
<property name="linear_growth_width">300</property>
<property name="hexpand">True</property>
<property name="halign">center</property>
<child>
<object class="GtkSearchEntry" id="entry_search">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
<property name="max_length">100</property>
</object>
</child>
</object>
</child>
</object>
......
......@@ -11,6 +11,8 @@
#include <string.h>
#include <glib/gi18n.h>
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
#include "gs-common.h"
#include "gs-shell.h"
......@@ -248,7 +250,7 @@ gs_shell_change_mode (GsShell *shell,
mode == GS_SHELL_MODE_SEARCH);
/* hide unless we're going to search */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (widget),
hdy_search_bar_set_search_mode (HDY_SEARCH_BAR (widget),
mode == GS_SHELL_MODE_SEARCH);
priv->in_mode_change = FALSE;
......@@ -581,13 +583,13 @@ window_keypress_handler (GtkWidget *window, GdkEvent *event, GsShell *shell)
if ((e->state & GDK_CONTROL_MASK) > 0 &&
e->keyval == GDK_KEY_f) {
w = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
if (!gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (w))) {
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (w), TRUE);
if (!hdy_search_bar_get_search_mode (HDY_SEARCH_BAR (w))) {
hdy_search_bar_set_search_mode (HDY_SEARCH_BAR (w), TRUE);
w = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"entry_search"));
gtk_widget_grab_focus (w);
} else {
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (w), FALSE);
hdy_search_bar_set_search_mode (HDY_SEARCH_BAR (w), FALSE);
}
return GDK_EVENT_PROPAGATE;
}
......@@ -595,7 +597,7 @@ window_keypress_handler (GtkWidget *window, GdkEvent *event, GsShell *shell)
/* pass to search bar */
w = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
return gtk_search_bar_handle_event (GTK_SEARCH_BAR (w), event);
return hdy_search_bar_handle_event (HDY_SEARCH_BAR (w), event);
}
static void
......@@ -625,7 +627,7 @@ search_button_clicked_cb (GtkToggleButton *toggle_button, GsShell *shell)
GtkWidget *search_bar;
search_bar = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (search_bar),
hdy_search_bar_set_search_mode (HDY_SEARCH_BAR (search_bar),
gtk_toggle_button_get_active (toggle_button));
if (priv->in_mode_change)
......@@ -638,14 +640,14 @@ search_button_clicked_cb (GtkToggleButton *toggle_button, GsShell *shell)
}
static void
search_mode_enabled_cb (GtkSearchBar *search_bar, GParamSpec *pspec, GsShell *shell)
search_mode_enabled_cb (HdySearchBar *search_bar, GParamSpec *pspec, GsShell *shell)
{
GsShellPrivate *priv = gs_shell_get_instance_private (shell);
GtkWidget *search_button;
search_button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_button"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (search_button),
gtk_search_bar_get_search_mode (search_bar));
hdy_search_bar_get_search_mode (search_bar));
}
static void
......@@ -2011,6 +2013,9 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
g_signal_connect_after (priv->main_window, "button_press_event",
G_CALLBACK (window_button_press_event), shell);
/* connect the search entry to the serch bar */
hdy_search_bar_connect_entry (HDY_SEARCH_BAR (gtk_builder_get_object (priv->builder, "search_bar")),
GTK_ENTRY (gtk_builder_get_object (priv->builder, "entry_search")));
/* show the search bar when clicking on the search button */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_button"));
g_signal_connect (widget, "clicked",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment