[gnome-builder/wip/chergert/perspective] workbench: implement global search for editor perspective



commit 0b1a3ba1864eef2ea12a3b3ad1e763246b412dc3
Author: Christian Hergert <chergert redhat com>
Date:   Fri Dec 4 01:42:33 2015 -0800

    workbench: implement global search for editor perspective

 data/ui/ide-editor-perspective.ui      |    2 +
 libide/editor/ide-editor-perspective.c |   38 ++++++++++++++++++++++++++------
 libide/ide-workbench-header-bar.c      |   12 ++++++++++
 libide/ide-workbench-header-bar.h      |    3 +-
 4 files changed, 47 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/ide-editor-perspective.ui b/data/ui/ide-editor-perspective.ui
index 3e99139..2f1301b 100644
--- a/data/ui/ide-editor-perspective.ui
+++ b/data/ui/ide-editor-perspective.ui
@@ -85,4 +85,6 @@
       </packing>
     </child>
   </object>
+  <object class="GSimpleActionGroup" id="actions">
+  </object>
 </interface>
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index a4bc8dd..331610c 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -38,6 +38,7 @@ struct _IdeEditorPerspective
 
   IdeLayoutGrid         *grid;
   IdeWorkbenchHeaderBar *titlebar;
+  GSimpleActionGroup    *actions;
 
   EggSignalGroup        *buffer_manager_signals;
 };
@@ -47,13 +48,6 @@ static void ide_perspective_iface_init (IdePerspectiveInterface *iface);
 G_DEFINE_TYPE_EXTENDED (IdeEditorPerspective, ide_editor_perspective, IDE_TYPE_LAYOUT, 0,
                         G_IMPLEMENT_INTERFACE (IDE_TYPE_PERSPECTIVE, ide_perspective_iface_init))
 
-enum {
-  PROP_0,
-  LAST_PROP
-};
-
-static GParamSpec *properties [LAST_PROP];
-
 static void
 ide_editor_perspective_restore_panel_state (IdeEditorPerspective *self)
 {
@@ -182,6 +176,18 @@ ide_editor_perspective_focus_buffer (IdeEditorPerspective *self,
 }
 
 static void
+global_search_activate (GSimpleAction *action,
+                        GVariant      *param,
+                        gpointer       user_data)
+{
+  IdeEditorPerspective *self = user_data;
+
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+
+  ide_workbench_header_bar_focus_search (self->titlebar);
+}
+
+static void
 ide_editor_perspective_finalize (GObject *object)
 {
   IdeEditorPerspective *self = (IdeEditorPerspective *)object;
@@ -224,6 +230,7 @@ ide_editor_perspective_class_init (IdeEditorPerspectiveClass *klass)
   container_class->add = ide_editor_perspective_add;
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-editor-perspective.ui");
+  gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, actions);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, grid);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, titlebar);
 }
@@ -232,6 +239,9 @@ static void
 ide_editor_perspective_init (IdeEditorPerspective *self)
 {
   GActionGroup *actions;
+  static const GActionEntry entries[] = {
+    { "global-search", global_search_activate },
+  };
 
   self->buffer_manager_signals = egg_signal_group_new (IDE_TYPE_BUFFER_MANAGER);
 
@@ -249,6 +259,9 @@ ide_editor_perspective_init (IdeEditorPerspective *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  g_action_map_add_action_entries (G_ACTION_MAP (self->actions), entries,
+                                   G_N_ELEMENTS (entries), self);
+
   actions = gtk_widget_get_action_group (GTK_WIDGET (self), "panels");
   gtk_widget_insert_action_group (GTK_WIDGET (self->titlebar), "panels", actions);
 
@@ -294,9 +307,20 @@ ide_editor_perspective_views_foreach (IdePerspective *perspective,
   ide_layout_grid_foreach_view (self->grid, callback, user_data);
 }
 
+static GActionGroup *
+ide_editor_perspective_get_actions (IdePerspective *perspective)
+{
+  IdeEditorPerspective *self = (IdeEditorPerspective *)perspective;
+
+  g_return_val_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self), NULL);
+
+  return g_object_ref (self->actions);
+}
+
 static void
 ide_perspective_iface_init (IdePerspectiveInterface *iface)
 {
+  iface->get_actions = ide_editor_perspective_get_actions;
   iface->get_id = ide_editor_perspective_get_id;
   iface->get_title = ide_editor_perspective_get_title;
   iface->get_titlebar = ide_editor_perspective_get_titlebar;
diff --git a/libide/ide-workbench-header-bar.c b/libide/ide-workbench-header-bar.c
index 75a159e..a26a651 100644
--- a/libide/ide-workbench-header-bar.c
+++ b/libide/ide-workbench-header-bar.c
@@ -56,3 +56,15 @@ ide_workbench_header_bar_init (IdeWorkbenchHeaderBar *self)
   popover = gtk_popover_new_from_model (NULL, G_MENU_MODEL (model));
   gtk_menu_button_set_popover (priv->menu_button, popover);
 }
+
+void
+ide_workbench_header_bar_focus_search (IdeWorkbenchHeaderBar *self)
+{
+  GtkWidget *entry;
+
+  g_return_if_fail (IDE_IS_WORKBENCH_HEADER_BAR (self));
+
+  entry = gtk_header_bar_get_custom_title (GTK_HEADER_BAR (self));
+  if (GTK_IS_ENTRY (entry))
+    gtk_widget_grab_focus (GTK_WIDGET (entry));
+}
diff --git a/libide/ide-workbench-header-bar.h b/libide/ide-workbench-header-bar.h
index cb91fa9..881626b 100644
--- a/libide/ide-workbench-header-bar.h
+++ b/libide/ide-workbench-header-bar.h
@@ -32,7 +32,8 @@ struct _IdeWorkbenchHeaderBarClass
   GtkHeaderBarClass parent;
 };
 
-GtkWidget *ide_workbench_header_bar_new (void);
+GtkWidget *ide_workbench_header_bar_new          (void);
+void       ide_workbench_header_bar_focus_search (IdeWorkbenchHeaderBar *self);
 
 G_END_DECLS
 


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