[gnome-builder/wip/chergert/headerbar] omnibar: show popover on click



commit 09cb4dfb96d322ff67725498d0d88be4e4488442
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jun 23 00:25:46 2016 -0700

    omnibar: show popover on click

 libide/workbench/ide-omni-bar.c  |   43 +++++++++++++
 libide/workbench/ide-omni-bar.ui |  125 ++++++++++++++++++++-----------------
 2 files changed, 111 insertions(+), 57 deletions(-)
---
diff --git a/libide/workbench/ide-omni-bar.c b/libide/workbench/ide-omni-bar.c
index 7c63381..617d1ca 100644
--- a/libide/workbench/ide-omni-bar.c
+++ b/libide/workbench/ide-omni-bar.c
@@ -37,10 +37,12 @@ struct _IdeOmniBar
 
   EggSignalGroup *build_result_signals;
   GSource        *looper_source;
+  GtkGesture     *gesture;
 
   guint           seen_count;
 
   GtkLabel       *branch_label;
+  GtkEventBox    *event_box;
   GtkLabel       *project_label;
   GtkLabel       *build_result_mode_label;
   GtkImage       *build_result_diagnostics_image;
@@ -237,6 +239,35 @@ ide_omni_bar_constructed (GObject *object)
 }
 
 static void
+multipress_pressed_cb (GtkGestureMultiPress *gesture,
+                       guint                 n_press,
+                       gdouble               x,
+                       gdouble               y,
+                       IdeOmniBar           *self)
+{
+  g_assert (IDE_IS_OMNI_BAR (self));
+
+  gtk_widget_show (GTK_WIDGET (self->popover));
+  gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+}
+
+static void
+event_box_realize (GtkWidget  *event_box,
+                   IdeOmniBar *self)
+{
+  GdkWindow *window;
+  GdkCursor *cursor;
+
+  g_assert (GTK_IS_EVENT_BOX (event_box));
+  g_assert (IDE_IS_OMNI_BAR (self));
+
+  window = gtk_widget_get_window (event_box);
+  cursor = gdk_cursor_new_from_name (gdk_window_get_display (window), "pointer");
+  gdk_window_set_cursor (window, cursor);
+  g_clear_object (&cursor);
+}
+
+static void
 ide_omni_bar_finalize (GObject *object)
 {
   IdeOmniBar *self = (IdeOmniBar *)object;
@@ -254,6 +285,7 @@ ide_omni_bar_destroy (GtkWidget *widget)
   g_assert (IDE_IS_OMNI_BAR (self));
 
   g_clear_pointer (&self->looper_source, g_source_destroy);
+  g_clear_object (&self->gesture);
 
   GTK_WIDGET_CLASS (ide_omni_bar_parent_class)->destroy (widget);
 }
@@ -277,6 +309,7 @@ ide_omni_bar_class_init (IdeOmniBarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, build_result_diagnostics_image);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, build_result_mode_label);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, config_name_label);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, event_box);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, message_stack);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, popover);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, project_label);
@@ -287,6 +320,16 @@ ide_omni_bar_init (IdeOmniBar *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_BUTTON_PRESS_MASK);
+
+  g_signal_connect_after (self->event_box,
+                          "realize",
+                          G_CALLBACK (event_box_realize),
+                          self);
+
+  self->gesture = gtk_gesture_multi_press_new (GTK_WIDGET (self->event_box));
+  g_signal_connect (self->gesture, "pressed", G_CALLBACK (multipress_pressed_cb), self);
+
   self->build_result_signals = egg_signal_group_new (IDE_TYPE_BUILD_RESULT);
 
   egg_signal_group_connect_object (self->build_result_signals,
diff --git a/libide/workbench/ide-omni-bar.ui b/libide/workbench/ide-omni-bar.ui
index ae28f4a..c19da0c 100644
--- a/libide/workbench/ide-omni-bar.ui
+++ b/libide/workbench/ide-omni-bar.ui
@@ -7,70 +7,81 @@
     <child type="center">
       <object class="EggEntryBox" id="frame">
         <property name="max-width-chars">50</property>
-        <property name="spacing">6</property>
         <property name="visible">true</property>
         <child>
-          <object class="GtkLabel" id="project_label">
-            <property name="ellipsize">end</property>
+          <object class="GtkEventBox" id="event_box">
             <property name="visible">true</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel">
-            <property name="label">/</property>
-            <property name="visible">true</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="branch_label">
-            <property name="ellipsize">end</property>
-            <property name="visible">true</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkImage" id="build_result_diagnostics_image">
-            <property name="icon-name">dialog-warning</property>
-          </object>
-          <packing>
-            <property name="pack-type">end</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkStack" id="message_stack">
-            <property name="homogeneous">false</property>
-            <property name="transition-type">slide-left</property>
-            <property name="transition-duration">500</property>
-            <property name="visible">true</property>
-            <child>
-              <object class="GtkLabel" id="config_name_label">
-                <property name="visible">true</property>
-                <property name="ellipsize">end</property>
-              </object>
-              <packing>
-                <property name="name">config</property>
-              </packing>
-            </child>
             <child>
-              <object class="GtkLabel" id="build_result_mode_label">
+              <object class="GtkBox">
+                <property name="hexpand">true</property>
                 <property name="visible">true</property>
-                <property name="ellipsize">end</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="project_label">
+                    <property name="ellipsize">end</property>
+                    <property name="visible">true</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="label">/</property>
+                    <property name="visible">true</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="branch_label">
+                    <property name="ellipsize">end</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkImage" id="build_result_diagnostics_image">
+                    <property name="icon-name">dialog-warning</property>
+                  </object>
+                  <packing>
+                    <property name="pack-type">end</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkStack" id="message_stack">
+                    <property name="homogeneous">false</property>
+                    <property name="transition-type">slide-left</property>
+                    <property name="transition-duration">500</property>
+                    <property name="visible">true</property>
+                    <child>
+                      <object class="GtkLabel" id="config_name_label">
+                        <property name="visible">true</property>
+                        <property name="ellipsize">end</property>
+                      </object>
+                      <packing>
+                        <property name="name">config</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="build_result_mode_label">
+                        <property name="visible">true</property>
+                        <property name="ellipsize">end</property>
+                      </object>
+                      <packing>
+                        <property name="name">build</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="pack-type">end</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
               </object>
-              <packing>
-                <property name="name">build</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="pack-type">end</property>
-            <property name="position">0</property>
-          </packing>
         </child>
       </object>
     </child>
@@ -104,7 +115,7 @@
   </object>
   <object class="GtkPopover" id="popover">
     <property name="border-width">20</property>
-    <property name="relative-to">frame</property>
+    <property name="relative-to">event_box</property>
     <property name="position">bottom</property>
     <child>
       <object class="GtkBox">


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