[bijiben] bjbSearchToolbar: use GtkSearchBar
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] bjbSearchToolbar: use GtkSearchBar
- Date: Fri, 18 Oct 2013 19:31:11 +0000 (UTC)
commit 45bbc988f35053ec98ee3db609914ba4079ae383
Author: Pierre-Yves Luyten <py luyten fr>
Date: Fri Oct 18 21:30:11 2013 +0200
bjbSearchToolbar: use GtkSearchBar
Little cleanup
src/bjb-search-toolbar.c | 125 +++++++++++++++-------------------------------
src/bjb-search-toolbar.h | 25 ++++++----
src/bjb-window-base.c | 8 ++--
3 files changed, 59 insertions(+), 99 deletions(-)
---
diff --git a/src/bjb-search-toolbar.c b/src/bjb-search-toolbar.c
index 50f701f..9c19381 100644
--- a/src/bjb-search-toolbar.c
+++ b/src/bjb-search-toolbar.c
@@ -55,17 +55,15 @@ struct _BjbSearchToolbarPrivate
/* Signals */
gulong key_pressed;
- gulong key_released;
gulong deleted;
gulong inserted;
- /* Misc UI */
- GtkRevealer *revealer;
- GtkWidget *widget; // GTK_WIDGET (self)
+
GtkWidget *window;
};
-G_DEFINE_TYPE (BjbSearchToolbar, bjb_search_toolbar, GTK_TYPE_TOOLBAR);
+G_DEFINE_TYPE (BjbSearchToolbar, bjb_search_toolbar, GTK_TYPE_SEARCH_BAR);
+
static void
bjb_search_toolbar_toggle_search_button (BjbSearchToolbar *self,
@@ -75,58 +73,36 @@ bjb_search_toolbar_toggle_search_button (BjbSearchToolbar *self,
state);
}
+
+
void
bjb_search_toolbar_fade_in (BjbSearchToolbar *self)
{
- if (!gtk_revealer_get_child_revealed (self->priv->revealer))
- {
- GdkDevice *device;
-
+ if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (self)) == TRUE)
+ return;
- /* show the search */
- gtk_revealer_set_reveal_child (self->priv->revealer, TRUE);
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (self), TRUE);
+ bjb_search_toolbar_toggle_search_button (self, TRUE);
+}
- /* focus */
- device = gtk_get_current_event_device ();
- if (device)
- gd_entry_focus_hack (GTK_WIDGET (self->priv->entry), device);
- /* manually toggle search button */
- bjb_search_toolbar_toggle_search_button (self, TRUE);
- }
-}
void
bjb_search_toolbar_fade_out (BjbSearchToolbar *self)
{
- if (gtk_revealer_get_child_revealed (self->priv->revealer))
- {
- /* clear the search before hiding */
- gtk_entry_set_text (GTK_ENTRY (self->priv->entry), "");
- bjb_controller_set_needle (self->priv->controller, "");
+ if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (self)) == FALSE)
+ return;
- /* hide */
- gtk_revealer_set_reveal_child (self->priv->revealer, FALSE);
-
- /* manually toggle search button */
- bjb_search_toolbar_toggle_search_button (self, FALSE);
- }
-}
+ /* clear the search before hiding */
+ gtk_entry_set_text (GTK_ENTRY (self->priv->entry), "");
+ bjb_controller_set_needle (self->priv->controller, "");
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (self), FALSE);
+ bjb_search_toolbar_toggle_search_button (self, FALSE);
+}
-/* If some text has been input, handle position */
-static gboolean
-on_key_released (GtkWidget *widget,GdkEvent *event,gpointer user_data)
-{
- BjbSearchToolbar *self = BJB_SEARCH_TOOLBAR (user_data);
- BjbSearchToolbarPrivate *priv = self->priv;
- if (gtk_revealer_get_child_revealed (self->priv->revealer) == TRUE)
- gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1);
-
- return FALSE;
-}
static gboolean
on_key_pressed (GtkWidget *widget,GdkEvent *event,gpointer user_data)
@@ -142,7 +118,7 @@ on_key_pressed (GtkWidget *widget,GdkEvent *event,gpointer user_data)
return FALSE;
/* Reveal the entry is text is input. TODO add more keys not input */
- if (gtk_revealer_get_child_revealed (self->priv->revealer) == FALSE)
+ if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (self)) == FALSE)
{
switch (event->key.keyval)
{
@@ -172,6 +148,7 @@ on_key_pressed (GtkWidget *widget,GdkEvent *event,gpointer user_data)
return FALSE;
}
+
static void
bjb_search_toolbar_get_property (GObject *object,
guint property_id,
@@ -194,6 +171,7 @@ bjb_search_toolbar_get_property (GObject *object,
}
}
+
static void
bjb_search_toolbar_set_property (GObject *object,
guint property_id,
@@ -217,12 +195,16 @@ bjb_search_toolbar_set_property (GObject *object,
}
+
+
static void
action_search_entry (GtkEntry *entry, BjbController *controller)
{
bjb_controller_set_needle (controller, gtk_entry_get_text (entry));
}
+
+
static void
action_entry_insert_callback (GtkEntryBuffer *buffer,
guint position,
@@ -234,6 +216,9 @@ action_entry_insert_callback (GtkEntryBuffer *buffer,
self->priv->controller);
}
+
+
+
static void
action_entry_delete_callback (GtkEntryBuffer *buffer,
guint position,
@@ -244,22 +229,25 @@ action_entry_delete_callback (GtkEntryBuffer *buffer,
self->priv->controller);
}
+
void
bjb_search_toolbar_disconnect (BjbSearchToolbar *self)
{
BjbSearchToolbarPrivate *priv = self->priv ;
-
+
+
g_signal_handler_disconnect (priv->window,priv->key_pressed);
- g_signal_handler_disconnect (priv->window,priv->key_released);
g_signal_handler_disconnect (priv->entry_buf, priv->inserted);
g_signal_handler_disconnect (priv->entry_buf, priv->deleted);
- priv->key_released = 0;
+
priv->key_pressed = 0;
priv->inserted = 0;
priv->deleted = 0;
+
}
+
static void
bjb_search_toolbar_finalize (GObject *obj)
{
@@ -276,9 +264,6 @@ bjb_search_toolbar_connect (BjbSearchToolbar *self)
priv->key_pressed = g_signal_connect(priv->window,"key-press-event",
G_CALLBACK(on_key_pressed),self);
- if (priv->key_released == 0)
- priv->key_released = g_signal_connect(priv->window,"key-release-event",
- G_CALLBACK(on_key_released),self);
if (priv->inserted ==0)
priv->inserted = g_signal_connect (priv->entry_buf, "inserted-text",
@@ -309,41 +294,21 @@ bjb_search_toolbar_constructed (GObject *obj)
}
}
+
static void
bjb_search_toolbar_init (BjbSearchToolbar *self)
{
BjbSearchToolbarPrivate *priv;
- GtkStyleContext *context;
- GtkToolbar *tlbar;
- GtkWidget *search_container;
- GtkToolItem *item ;
- tlbar = GTK_TOOLBAR (self);
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BJB_TYPE_SEARCH_TOOLBAR, BjbSearchToolbarPrivate);
priv = self->priv;
- priv->widget = GTK_WIDGET (self);
- priv->revealer = GTK_REVEALER (gtk_revealer_new ());
-
- gtk_container_add (GTK_CONTAINER (priv->revealer), priv->widget);
-
- gtk_toolbar_set_show_arrow (tlbar, FALSE);
- gtk_toolbar_set_icon_size (tlbar, GTK_ICON_SIZE_LARGE_TOOLBAR);
- context = gtk_widget_get_style_context (GTK_WIDGET (self));
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
-
- /* (SELF) TOOL_BAR <- TOOL_ITEM <- BOX <- GD_TAGGED_ENTRY */
- item = gtk_tool_item_new ();
- gtk_tool_item_set_expand (item, TRUE);
- gtk_toolbar_insert (tlbar, item,-1);
-
- search_container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GTK_ALIGN_CENTER);
- gtk_container_add (GTK_CONTAINER (item), search_container);
priv->entry = gd_tagged_entry_new ();
g_object_set (priv->entry, "width_request", 500, NULL);
- gtk_box_pack_start (GTK_BOX (search_container), GTK_WIDGET (priv->entry), TRUE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (priv->entry));
}
+
static void
bjb_search_toolbar_class_init (BjbSearchToolbarClass *class)
{
@@ -374,24 +339,14 @@ bjb_search_toolbar_class_init (BjbSearchToolbarClass *class)
g_type_class_add_private (class, sizeof (BjbSearchToolbarPrivate));
}
+
BjbSearchToolbar *
bjb_search_toolbar_new (GtkWidget *window,
BjbController *controller)
{
return g_object_new (BJB_TYPE_SEARCH_TOOLBAR,
- "window",window,
- "controller",controller,
+ "window", window,
+ "controller", controller,
NULL);
}
-GtkWidget *
-bjb_search_toolbar_get_revealer (BjbSearchToolbar *self)
-{
- return GTK_WIDGET (self->priv->revealer);
-}
-
-gboolean
-bjb_search_toolbar_is_shown (BjbSearchToolbar *self)
-{
- return gtk_revealer_get_child_revealed (self->priv->revealer);
-}
diff --git a/src/bjb-search-toolbar.h b/src/bjb-search-toolbar.h
index 91f703e..5145e2e 100644
--- a/src/bjb-search-toolbar.h
+++ b/src/bjb-search-toolbar.h
@@ -40,30 +40,35 @@ typedef struct _BjbSearchToolbarPrivate BjbSearchToolbarPrivate;
struct _BjbSearchToolbar
{
- GtkToolbar parent_instance;
+ GtkSearchBar parent_instance;
BjbSearchToolbarPrivate *priv;
};
struct _BjbSearchToolbarClass
{
- GtkToolbarClass parent_class;
+ GtkSearchBarClass parent_class;
};
-GType bjb_search_toolbar_get_type (void) G_GNUC_CONST;
-BjbSearchToolbar * bjb_search_toolbar_new (GtkWidget *window, BjbController *controller);
+GType bjb_search_toolbar_get_type (void) G_GNUC_CONST;
-void bjb_search_toolbar_fade_in (BjbSearchToolbar *self);
-void bjb_search_toolbar_fade_out (BjbSearchToolbar *self);
+BjbSearchToolbar *bjb_search_toolbar_new (GtkWidget *window,
+ BjbController *controller);
-GtkWidget * bjb_search_toolbar_get_revealer (BjbSearchToolbar *self);
-void bjb_search_toolbar_disconnect (BjbSearchToolbar *self);
+void bjb_search_toolbar_fade_in (BjbSearchToolbar *self);
+
+
+void bjb_search_toolbar_fade_out (BjbSearchToolbar *self);
+
+
+void bjb_search_toolbar_disconnect (BjbSearchToolbar *self);
+
+
+void bjb_search_toolbar_connect (BjbSearchToolbar *self);
-void bjb_search_toolbar_connect (BjbSearchToolbar *self);
-gboolean bjb_search_toolbar_is_shown (BjbSearchToolbar *self);
G_END_DECLS
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 0d0dbdc..650e058 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -104,7 +104,6 @@ bjb_window_base_constructed (GObject *obj)
GList *icons = NULL;
GdkPixbuf *bjb ;
GError *error = NULL;
- GtkWidget *revealer;
G_OBJECT_CLASS (bjb_window_base_parent_class)->constructed (obj);
@@ -155,8 +154,7 @@ bjb_window_base_constructed (GObject *obj)
/* Search entry toolbar */
priv->search_bar = bjb_search_toolbar_new (GTK_WIDGET (obj), priv->controller);
- revealer = bjb_search_toolbar_get_revealer (priv->search_bar);
- gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (revealer), FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (priv->search_bar), FALSE, FALSE, 0);
/* UI : stack for different views */
priv->stack = GTK_STACK (gtk_stack_new ());
@@ -401,12 +399,14 @@ bjb_window_base_get_main_view (BjbWindowBase *self)
gboolean
bjb_window_base_get_show_search_bar (BjbWindowBase *self)
{
+
/* There is no search bar at startup,
* when main toolbar is first built... */
if (!self->priv->search_bar)
return FALSE;
- return bjb_search_toolbar_is_shown (self->priv->search_bar);
+ return gtk_search_bar_get_search_mode (
+ GTK_SEARCH_BAR (self->priv->search_bar));
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]