[gnome-builder/wip/commands] commands: incremental work on the command bar.



commit d73821d6d7d4888c92aed8af32cd73682ed4d548
Author: Christian Hergert <christian hergert me>
Date:   Tue Oct 7 01:50:44 2014 -0700

    commands: incremental work on the command bar.

 .gitignore                            |    2 +-
 src/commandbar/gb-command-bar.c       |   35 ++++++++++++++-
 src/resources/css/builder.Adwaita.css |    5 +-
 src/resources/keybindings/default.ini |    1 +
 src/resources/ui/gb-command-bar.ui    |   13 +-----
 src/resources/ui/gb-workbench.ui      |   80 +++++++++++++++++++-------------
 src/workbench/gb-workbench.c          |   20 ++++++++
 test-command-bar                      |  Bin 127641 -> 0 bytes
 8 files changed, 107 insertions(+), 49 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c59529f..9b7cb3e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,9 +20,9 @@ Makefile.in
 stamp-h1
 *.swp
 test-c-parse-helper
-test-c-parse-helper
 test-c-parse-helper.log
 test-c-parse-helper.trs
+test-command-bar
 test-navigation-list
 test-navigation-list.log
 test-navigation-list.trs
diff --git a/src/commandbar/gb-command-bar.c b/src/commandbar/gb-command-bar.c
index 45c0d19..598e6d2 100644
--- a/src/commandbar/gb-command-bar.c
+++ b/src/commandbar/gb-command-bar.c
@@ -61,6 +61,7 @@ gb_command_bar_show (GbCommandBar *bar)
   g_return_if_fail (GB_IS_COMMAND_BAR (bar));
 
   gtk_revealer_set_reveal_child (GTK_REVEALER (bar), TRUE);
+  gtk_widget_grab_focus (GTK_WIDGET (bar->priv->entry));
 }
 
 static void
@@ -82,6 +83,30 @@ gb_command_bar_on_entry_activate (GbCommandBar *bar,
 }
 
 static gboolean
+gb_command_bar_on_entry_focus_out_event (GbCommandBar *bar,
+                                         GdkEventKey  *event,
+                                         GtkEntry     *entry)
+{
+  g_return_val_if_fail (GB_IS_COMMAND_BAR (bar), FALSE);
+  g_return_val_if_fail (event, FALSE);
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
+
+  gb_command_bar_hide (bar);
+
+  return GDK_EVENT_PROPAGATE;
+}
+
+static void
+gb_command_bar_grab_focus (GtkWidget *widget)
+{
+  GbCommandBar *bar = (GbCommandBar *)widget;
+
+  g_return_if_fail (GB_IS_COMMAND_BAR (bar));
+
+  gtk_widget_grab_focus (GTK_WIDGET (bar->priv->entry));
+}
+
+static gboolean
 gb_command_bar_on_entry_key_press_event (GbCommandBar *bar,
                                          GdkEventKey  *event,
                                          GtkEntry     *entry)
@@ -96,7 +121,7 @@ gb_command_bar_on_entry_key_press_event (GbCommandBar *bar,
       return TRUE;
     }
 
-  return FALSE;
+  return GDK_EVENT_PROPAGATE;
 }
 
 static void
@@ -113,6 +138,12 @@ gb_command_bar_constructed (GObject *object)
                            G_CONNECT_SWAPPED);
 
   g_signal_connect_object (bar->priv->entry,
+                           "focus-out-event",
+                           G_CALLBACK (gb_command_bar_on_entry_focus_out_event),
+                           bar,
+                           G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (bar->priv->entry,
                            "key-press-event",
                            G_CALLBACK (gb_command_bar_on_entry_key_press_event),
                            bar,
@@ -134,6 +165,8 @@ gb_command_bar_class_init (GbCommandBarClass *klass)
   object_class->constructed = gb_command_bar_constructed;
   object_class->finalize = gb_command_bar_finalize;
 
+  widget_class->grab_focus = gb_command_bar_grab_focus;
+
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/builder/ui/gb-command-bar.ui");
 
diff --git a/src/resources/css/builder.Adwaita.css b/src/resources/css/builder.Adwaita.css
index 754e5cd..5e64594 100644
--- a/src/resources/css/builder.Adwaita.css
+++ b/src/resources/css/builder.Adwaita.css
@@ -145,14 +145,13 @@ GtkStackSwitcher.gb-workspace-switcher > GtkRadioButton:active {
  */
 .gb-command-bar-frame {
     background-color: shade (@theme_base_color, 0.8);
-    padding: 6px;
+    padding: 6px 6px 8px 6px;
     border-color: shade (@theme_base_color, 0.6);
     border-radius: 3px 3px 0 0;
     border-width: 1px 1px 0 1px;
     border-style: solid;
 }
 GtkEntry.gb-command-bar {
-    padding: 10px;
+    padding: 6px;
     font-family: Monospace;
-    font-size: 1.1em;
 }
diff --git a/src/resources/keybindings/default.ini b/src/resources/keybindings/default.ini
index 8387112..3fbd798 100644
--- a/src/resources/keybindings/default.ini
+++ b/src/resources/keybindings/default.ini
@@ -7,6 +7,7 @@ workspace1 = <Control>1
 workspace2 = <Control>2
 go-forward = <Control>I
 go-backward = <Control>O
+show-command-bar = <Control>space
 
 [workbench]
 close-tab = <Control>W
diff --git a/src/resources/ui/gb-command-bar.ui b/src/resources/ui/gb-command-bar.ui
index 3b42f6d..6949dc1 100644
--- a/src/resources/ui/gb-command-bar.ui
+++ b/src/resources/ui/gb-command-bar.ui
@@ -3,7 +3,8 @@
   <!-- interface-requires gtk+ 3.8 -->
   <template class="GbCommandBar" parent="GtkRevealer">
     <property name="visible">True</property>
-    <property name="transition-type">GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP</property>
+    <property name="reveal-child">False</property>
+    <property name="can-focus">True</property>
     <child>
       <object class="GtkFrame" id="frame">
         <property name="visible">True</property>
@@ -17,9 +18,6 @@
             <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="orientation">vertical</property>
-            <style>
-              <class name="linked"/>
-            </style>
             <child>
               <object class="GtkScrolledWindow" id="scroller">
                 <property name="visible">False</property>
@@ -36,15 +34,8 @@
               </object>
             </child>
             <child>
-              <object class="GtkSeparator" id="hsep1">
-                <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
-              </object>
-            </child>
-            <child>
               <object class="GtkEntry" id="entry">
                 <property name="visible">True</property>
-                <property name="has-frame">False</property>
                 <property name="expand">False</property>
                 <property name="valign">end</property>
                 <style>
diff --git a/src/resources/ui/gb-workbench.ui b/src/resources/ui/gb-workbench.ui
index 242cbad..f2d008c 100644
--- a/src/resources/ui/gb-workbench.ui
+++ b/src/resources/ui/gb-workbench.ui
@@ -119,52 +119,66 @@
       </object>
     </child>
     <child>
-      <object class="GtkBox" id="main_hbox">
-        <property name="orientation">horizontal</property>
+      <object class="GtkOverlay" id="main_overlay">
         <property name="visible">True</property>
-        <child>
-          <object class="GtkStackSwitcher" id="switcher">
+        <child type="overlay">
+          <object class="GbCommandBar" id="command_bar">
+            <property name="width-request">500</property>
+            <property name="transition-type">GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP</property>
+            <property name="halign">center</property>
+            <property name="valign">end</property>
             <property name="visible">True</property>
-            <property name="stack">stack</property>
-            <property name="orientation">vertical</property>
-            <property name="border_width">4</property>
-            <property name="spacing">4</property>
-            <style>
-              <class name="gb-workspace-switcher"/>
-            </style>
           </object>
         </child>
         <child>
-          <object class="GtkSeparator" id="sidebar_separator">
-            <property name="visible">True</property>
-            <property name="orientation">vertical</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkStack" id="stack">
+          <object class="GtkBox" id="main_hbox">
+            <property name="orientation">horizontal</property>
             <property name="visible">True</property>
-            <property name="transition_type">GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN</property>
             <child>
-              <object class="GbEditorWorkspace" id="editor">
-                <property name="name">editor</property>
+              <object class="GtkStackSwitcher" id="switcher">
+                <property name="visible">True</property>
+                <property name="stack">stack</property>
+                <property name="orientation">vertical</property>
+                <property name="border_width">4</property>
+                <property name="spacing">4</property>
+                <style>
+                  <class name="gb-workspace-switcher"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator" id="sidebar_separator">
                 <property name="visible">True</property>
+                <property name="orientation">vertical</property>
               </object>
-              <packing>
-                <property name="icon_name">text-editor-symbolic</property>
-                <property name="name">editor</property>
-                <property name="title" translatable="yes">Editor</property>
-              </packing>
             </child>
             <child>
-              <object class="GbDevhelpWorkspace" id="devhelp">
-                <property name="name">devhelp</property>
+              <object class="GtkStack" id="stack">
                 <property name="visible">True</property>
+                <property name="transition_type">GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN</property>
+                <child>
+                  <object class="GbEditorWorkspace" id="editor">
+                    <property name="name">editor</property>
+                    <property name="visible">True</property>
+                  </object>
+                  <packing>
+                    <property name="icon_name">text-editor-symbolic</property>
+                    <property name="name">editor</property>
+                    <property name="title" translatable="yes">Editor</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GbDevhelpWorkspace" id="devhelp">
+                    <property name="name">devhelp</property>
+                    <property name="visible">True</property>
+                  </object>
+                  <packing>
+                    <property name="name">devhelp</property>
+                    <property name="icon_name">help-browser-symbolic</property>
+                    <property name="title" translatable="yes">Documentation</property>
+                  </packing>
+                </child>
               </object>
-              <packing>
-                <property name="name">devhelp</property>
-                <property name="icon_name">help-browser-symbolic</property>
-                <property name="title" translatable="yes">Documentation</property>
-              </packing>
             </child>
           </object>
         </child>
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 7fc06ec..918c2af 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -20,6 +20,7 @@
 
 #include <glib/gi18n.h>
 
+#include "gb-command-bar.h"
 #include "gb-devhelp-workspace.h"
 #include "gb-editor-workspace.h"
 #include "gb-log.h"
@@ -36,6 +37,7 @@ struct _GbWorkbenchPrivate
   GbNavigationList       *navigation_list;
 
   GbWorkspace            *active_workspace;
+  GbCommandBar           *command_bar;
   GbWorkspace            *devhelp;
   GbWorkspace            *editor;
   GtkMenuButton          *add_button;
@@ -227,6 +229,19 @@ on_go_forward_activate (GSimpleAction *action,
 }
 
 static void
+on_show_command_bar_activate (GSimpleAction *action,
+                              GVariant      *variant,
+                              gpointer       user_data)
+{
+  GbWorkbench *workbench = user_data;
+
+  g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+  gb_command_bar_show (workbench->priv->command_bar);
+  gtk_widget_show (GTK_WIDGET (workbench->priv->command_bar));
+}
+
+static void
 on_go_backward_activate (GSimpleAction *action,
                          GVariant      *variant,
                          gpointer       user_data)
@@ -276,6 +291,7 @@ gb_workbench_constructed (GObject *object)
     { "workspace2", on_workspace2_activate },
     { "go-backward", on_go_backward_activate },
     { "go-forward", on_go_forward_activate },
+    { "show-command-bar", on_show_command_bar_activate },
   };
   GbWorkbenchPrivate *priv;
   GbWorkbench *workbench = (GbWorkbench *)object;
@@ -408,6 +424,9 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
                   GB_TYPE_WORKSPACE);
 
   gtk_widget_class_set_template_from_resource (widget_class, UI_RESOURCE_PATH);
+
+  gtk_widget_class_bind_template_child_private (widget_class, GbWorkbench,
+                                                command_bar);
   gtk_widget_class_bind_template_child_private (widget_class, GbWorkbench,
                                                 devhelp);
   gtk_widget_class_bind_template_child_private (widget_class, GbWorkbench,
@@ -431,6 +450,7 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GbWorkbench,
                                                 stack);
 
+  g_type_ensure (GB_TYPE_COMMAND_BAR);
   g_type_ensure (GB_TYPE_EDITOR_WORKSPACE);
   g_type_ensure (GB_TYPE_DEVHELP_WORKSPACE);
   g_type_ensure (GEDIT_TYPE_MENU_STACK_SWITCHER);


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