[totem] main: Make search entry keyboard navigable



commit 21b0a07ad84d3541a812197c565f376b3a4afacc
Author: Gabor Karsay <gabor karsay gmx at>
Date:   Sat Oct 26 12:53:35 2019 +0200

    main: Make search entry keyboard navigable
    
    Add a dropdown button next to the search entry to select the search source,
    instead of a tag. The button is now reachable through the keyboard via tab
    navigation.
    
    Co-authored: Bastien Nocera <hadess hadess net>
    
    Closes: #71

 docs/reference/meson.build |  1 -
 meson.build                |  1 -
 src/grilo.ui               | 14 +----------
 src/totem-search-entry.c   | 61 ++++++++++++++++++++++------------------------
 4 files changed, 30 insertions(+), 47 deletions(-)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index 2f1f8b410..f04e2e475 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -4,7 +4,6 @@ private_headers = [
   'bacon-time-label.h',
   'bacon-video-widget-gst-missing-plugins.h',
   'bacon-video-widget-properties.h',
-  'gd-tagged-entry.h',
   'icon-helpers.h',
   'screenshot-filename-builder.h',
   'totem-gallery-progress.h',
diff --git a/meson.build b/meson.build
index c77dc828b..b9faf1abf 100644
--- a/meson.build
+++ b/meson.build
@@ -159,7 +159,6 @@ libgd = subproject(
     'with-gtk-hacks=true',
     'with-main-view=true',
     'with-main-icon-view=true',
-    'with-tagged-entry=true',
   ]
 )
 libgd_dep = libgd.get_variable('libgd_dep')
diff --git a/src/grilo.ui b/src/grilo.ui
index 31cbc15b5..b5089a359 100644
--- a/src/grilo.ui
+++ b/src/grilo.ui
@@ -102,23 +102,11 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <child>
-          <object class="GtkHBox" id="gw_box">
+          <object class="TotemSearchEntry" id="search_entry">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="spacing">6</property>
             <property name="width_request">500</property>
             <property name="halign">center</property>
-            <child>
-              <object class="TotemSearchEntry" id="search_entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
           </object>
         </child>
       </object>
diff --git a/src/totem-search-entry.c b/src/totem-search-entry.c
index d5294d545..7174c470b 100644
--- a/src/totem-search-entry.c
+++ b/src/totem-search-entry.c
@@ -20,7 +20,6 @@
  */
 
 #include "totem-search-entry.h"
-#include "libgd/gd-tagged-entry.h"
 
 enum {
        SIGNAL_ACTIVATE,
@@ -37,9 +36,10 @@ static guint signals[LAST_SIGNAL] = { 0, };
 struct _TotemSearchEntry {
        GtkBox parent;
        GtkWidget *entry;
+       GtkWidget *dropdown_button;
+       GtkWidget *label;
        GtkWidget *popover;
        GtkWidget *listbox;
-       GdTaggedEntryTag *tag;
 };
 
 G_DEFINE_TYPE (TotemSearchEntry, totem_search_entry, GTK_TYPE_BOX)
@@ -49,8 +49,7 @@ totem_search_entry_finalize (GObject *obj)
 {
        TotemSearchEntry *self = TOTEM_SEARCH_ENTRY (obj);
 
-       g_clear_object (&self->tag);
-       /* The popover will be destroyed with it parent (us) */
+       /* The popover will be destroyed with its parent (us) */
 
        G_OBJECT_CLASS (totem_search_entry_parent_class)->finalize (obj);
 }
@@ -67,19 +66,6 @@ entry_activate_cb (GtkEntry *entry,
        g_signal_emit (self, signals[SIGNAL_ACTIVATE], 0);
 }
 
-static void
-tag_clicked_cb (GdTaggedEntry    *entry,
-               GdTaggedEntryTag *tag,
-               TotemSearchEntry *self)
-{
-       cairo_rectangle_int_t rect;
-
-       if (gd_tagged_entry_tag_get_area (tag, &rect)) {
-               gtk_popover_set_pointing_to (GTK_POPOVER (self->popover), &rect);
-               gtk_widget_show (self->popover);
-       }
-}
-
 static void
 listbox_row_activated (GtkListBox    *list_box,
                       GtkListBoxRow *row,
@@ -98,7 +84,7 @@ listbox_row_activated (GtkListBox    *list_box,
 
                        gtk_widget_set_opacity (check, 1.0);
                        label = g_object_get_data (G_OBJECT (l->data), "label");
-                       gd_tagged_entry_tag_set_label (self->tag, label);
+                       gtk_label_set_text (GTK_LABEL (self->label), label);
                        g_object_notify (G_OBJECT (self), "selected-id");
                } else {
                        gtk_widget_set_opacity (check, 0.0);
@@ -141,24 +127,42 @@ popover_closed_cb (GtkPopover       *popover,
 static void
 totem_search_entry_init (TotemSearchEntry *self)
 {
-       GtkWidget *entry;
+       GtkStyleContext *context;
+       GtkWidget *entry, *child, *box;
 
        /* Entry */
-       entry = GTK_WIDGET (gd_tagged_entry_new ());
-       gd_tagged_entry_set_tag_button_visible (GD_TAGGED_ENTRY (entry), FALSE);
+       entry = GTK_WIDGET (gtk_entry_new ());
        gtk_box_pack_start (GTK_BOX (self),
                            entry,
                            TRUE, TRUE, 0);
-       gtk_widget_show (entry);
 
        self->entry = entry;
 
+       /* Dropdown button */
+       self->dropdown_button = gtk_menu_button_new ();
+       self->label = gtk_label_new (NULL);
+       child = gtk_bin_get_child (GTK_BIN (self->dropdown_button));
+       g_object_ref (child);
+       gtk_container_remove (GTK_CONTAINER (self->dropdown_button), child);
+       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+       gtk_box_pack_start (GTK_BOX (box), self->label, FALSE, FALSE, 0);
+       gtk_box_pack_end (GTK_BOX (box), child, FALSE, FALSE, 0);
+       gtk_container_add (GTK_CONTAINER (self->dropdown_button), box);
+       gtk_box_pack_end (GTK_BOX (self),
+                         self->dropdown_button,
+                         FALSE, FALSE, 0);
+
+       context = gtk_widget_get_style_context (GTK_WIDGET (self));
+       gtk_style_context_add_class (context, "linked");
+       gtk_widget_show_all (GTK_WIDGET (self));
+
        /* Popover */
        self->popover = gtk_popover_new (GTK_WIDGET (self));
        gtk_popover_set_modal (GTK_POPOVER (self->popover), TRUE);
        gtk_popover_set_position (GTK_POPOVER (self->popover), GTK_POS_BOTTOM);
        g_signal_connect (G_OBJECT (self->popover), "closed",
                          G_CALLBACK (popover_closed_cb), self);
+       gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->dropdown_button), self->popover);
 
        self->listbox = gtk_list_box_new ();
        gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (self->listbox), TRUE);
@@ -170,8 +174,6 @@ totem_search_entry_init (TotemSearchEntry *self)
                          G_CALLBACK (listbox_row_activated), self);
 
        /* Connect signals */
-       g_signal_connect (self->entry, "tag-clicked",
-                         G_CALLBACK (tag_clicked_cb), self);
        g_signal_connect (self->entry, "activate",
                          G_CALLBACK (entry_activate_cb), self);
 }
@@ -265,12 +267,8 @@ totem_search_entry_add_source (TotemSearchEntry *self,
 
        g_return_if_fail (TOTEM_IS_SEARCH_ENTRY (self));
 
-       if (self->tag == NULL) {
-               self->tag = gd_tagged_entry_tag_new (label);
-               gd_tagged_entry_tag_set_has_close_button (self->tag, FALSE);
-               gd_tagged_entry_insert_tag (GD_TAGGED_ENTRY (self->entry), self->tag, -1);
-               gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
-       }
+       gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
+       gtk_widget_show (self->label);
 
        item = gtk_list_box_row_new ();
        box = padded_label_new (label);
@@ -335,8 +333,7 @@ totem_search_entry_remove_source (TotemSearchEntry *self,
        }
 
        if (num_items == 0) {
-               gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (self->entry), self->tag);
-               g_clear_object (&self->tag);
+               gtk_widget_hide (self->label);
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]