[gnome-builder/wip/chergert/shortcuts] shortcuts: implement view selection



commit 798ab1ac66a3a697a16ccb8f4b3d7ebe8a781116
Author: Christian Hergert <christian hergert me>
Date:   Sat Aug 29 01:16:09 2015 -0700

    shortcuts: implement view selection

 data/theme/Adwaita-shared.css         |   12 ++++++
 data/ui/gb-shortcuts-window.ui        |   48 ++++++++++++++++++++++++
 src/keybindings/gb-shortcuts-window.c |   64 +++++++++++++++++++++++++++++++-
 3 files changed, 122 insertions(+), 2 deletions(-)
---
diff --git a/data/theme/Adwaita-shared.css b/data/theme/Adwaita-shared.css
index 4f03d50..7256208 100644
--- a/data/theme/Adwaita-shared.css
+++ b/data/theme/Adwaita-shared.css
@@ -83,3 +83,15 @@ SymbolTree GtkSearchEntry {
   border-top: none;
   border-radius: 0px;
 }
+
+
+.shortcuts-list-box GtkListBoxRow {
+  border-bottom: 1px solid @borders;
+}
+.shortcuts-list-box GtkListBoxRow:last-child {
+  border-bottom: none;
+}
+
+.shortcuts-list-box GtkLabel {
+  padding: 6px;
+}
diff --git a/data/ui/gb-shortcuts-window.ui b/data/ui/gb-shortcuts-window.ui
index 6585bfc..062c3f7 100644
--- a/data/ui/gb-shortcuts-window.ui
+++ b/data/ui/gb-shortcuts-window.ui
@@ -9,10 +9,37 @@
         <property name="visible">true</property>
         <child type="title">
           <object class="GtkMenuButton" id="menu_button">
+            <property name="focus-on-click">false</property>
+            <property name="popover">popover</property>
             <property name="visible">true</property>
             <style>
               <class name="flat"/>
             </style>
+            <child>
+              <object class="GtkBox">
+                <property name="orientation">horizontal</property>
+                <property name="spacing">6</property>
+                <property name="visible">true</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+                <child>
+                  <object class="GtkArrow">
+                    <property name="arrow-type">down</property>
+                    <property name="visible">true</property>
+                  </object>
+                  <packing>
+                    <property name="pack-type">end</property>
+                  </packing>
+                </child>
+                <child type="center">
+                  <!-- FIXME: hrmm, child="center" doesn't seem to be working -->
+                  <object class="GtkLabel" id="menu_label">
+                    <property name="visible">true</property>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
         <child>
@@ -64,4 +91,25 @@
       </object>
     </child>
   </template>
+  <object class="GtkPopover" id="popover">
+    <child>
+      <object class="GbScrolledWindow">
+        <property name="max-content-height">300</property>
+        <property name="max-content-width">300</property>
+        <property name="min-content-width">150</property>
+        <property name="border-width">6</property>
+        <property name="shadow-type">in</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkListBox" id="list_box">
+            <property name="visible">true</property>
+            <property name="selection-mode">none</property>
+            <style>
+              <class name="shortcuts-list-box"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/src/keybindings/gb-shortcuts-window.c b/src/keybindings/gb-shortcuts-window.c
index 2e3b2fe..627156d 100644
--- a/src/keybindings/gb-shortcuts-window.c
+++ b/src/keybindings/gb-shortcuts-window.c
@@ -46,7 +46,10 @@
 #include <glib/gi18n.h>
 #include <ide.h>
 
+#include "egg-search-bar.h"
+
 #include "gb-accel-label.h"
+#include "gb-scrolled-window.h"
 #include "gb-shortcuts-window.h"
 #include "gb-widget.h"
 
@@ -56,8 +59,12 @@ struct _GbShortcutsWindow
 
   GHashTable     *widget_keywords;
 
+  GtkListBox     *list_box;
   GtkStack       *stack;
   GtkMenuButton  *menu_button;
+  GtkLabel       *menu_label;
+  GtkPopover     *popover;
+  EggSearchBar   *search_bar;
   GtkSearchEntry *search_entry;
 
   GtkWidget      *previous_view;
@@ -88,7 +95,7 @@ gb_shortcuts_window_set_view (GbShortcutsWindow *self,
       gtk_container_child_get (GTK_CONTAINER (self->stack), child,
                                "title", &title,
                                NULL);
-      gtk_button_set_label (GTK_BUTTON (self->menu_button), title);
+      gtk_label_set_label (self->menu_label, title);
       gtk_stack_set_visible_child (self->stack, child);
     }
 }
@@ -160,6 +167,19 @@ gb_shortcuts_window_build (GbShortcutsWindow *self)
       gtk_widget_show (GTK_WIDGET (switcher)); \
     gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (switcher)), "linked"); \
     gtk_container_foreach (GTK_CONTAINER (switcher), adjust_page_buttons, NULL); \
+    { \
+      GtkListBoxRow *row; \
+      row = g_object_new (GTK_TYPE_LIST_BOX_ROW, \
+                          "visible", TRUE, \
+                          "child", g_object_new (GTK_TYPE_LABEL, \
+                                                 "label", _name, \
+                                                 "visible", TRUE, \
+                                                 "xalign", 0.5f, \
+                                                 NULL), \
+                          NULL); \
+      g_object_set_data (G_OBJECT (row), "view", _ident); \
+      gtk_container_add (GTK_CONTAINER (self->list_box), GTK_WIDGET (row)); \
+    } \
   }
 #define PAGE(_columns) \
   { \
@@ -431,7 +451,34 @@ gb_shortcuts_window__stack__notify_visible_child (GbShortcutsWindow *self,
   gtk_container_child_get (GTK_CONTAINER (stack), visible_child,
                            "title", &title,
                            NULL);
-  gtk_button_set_label (GTK_BUTTON (self->menu_button), title);
+  gtk_label_set_label (self->menu_label, title);
+}
+
+static void
+gb_shortcuts_window__list_box__row_activated (GbShortcutsWindow *self,
+                                              GtkListBoxRow     *row,
+                                              GtkListBox        *list_box)
+{
+  const gchar *view;
+
+  g_assert (GB_IS_SHORTCUTS_WINDOW (self));
+  g_assert (GTK_IS_LIST_BOX_ROW (row));
+  g_assert (GTK_IS_LIST_BOX (list_box));
+
+  view = g_object_get_data (G_OBJECT (row), "view");
+  if (view != NULL)
+    gtk_stack_set_visible_child_name (self->stack, view);
+
+  /*
+   * Ensure search is now hidden.
+   */
+  gtk_entry_set_text (GTK_ENTRY (self->search_entry), "");
+  egg_search_bar_set_search_mode_enabled (self->search_bar, FALSE);
+
+  /*
+   * Apparently we need to hide the popover manually.
+   */
+  gtk_widget_hide (GTK_WIDGET (self->popover));
 }
 
 static void
@@ -467,9 +514,16 @@ gb_shortcuts_window_class_init (GbShortcutsWindowClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/gb-shortcuts-window.ui");
 
+  gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, list_box);
   gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, menu_button);
+  gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, menu_label);
+  gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, popover);
+  gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, search_bar);
   gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, search_entry);
   gtk_widget_class_bind_template_child (widget_class, GbShortcutsWindow, stack);
+
+  g_type_ensure (EGG_TYPE_SEARCH_BAR);
+  g_type_ensure (GB_TYPE_SCROLLED_WINDOW);
 }
 
 static void
@@ -492,4 +546,10 @@ gb_shortcuts_window_init (GbShortcutsWindow *self)
                            G_CALLBACK (gb_shortcuts_window__stack__notify_visible_child),
                            self,
                            G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (self->list_box,
+                           "row-activated",
+                           G_CALLBACK (gb_shortcuts_window__list_box__row_activated),
+                           self,
+                           G_CONNECT_SWAPPED);
 }


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