[gnome-builder/wip/gtk4-port: 580/736] libide/gui: allow search with primary workspace




commit c743bf54ee1ee3e6ec4417da9c5073790adb5a54
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 13 11:09:33 2022 -0700

    libide/gui: allow search with primary workspace

 src/libide/gui/ide-primary-workspace.c | 13 +++++++--
 src/libide/gui/ide-workbench.c         | 51 +++++++++++++++++++++++---------
 src/libide/gui/ide-workspace-private.h |  2 ++
 src/libide/gui/ide-workspace.c         | 53 +++++++++++++++++++++++++++++++---
 src/libide/gui/ide-workspace.h         |  1 +
 5 files changed, 101 insertions(+), 19 deletions(-)
---
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 6017e0274..09e9a2fbd 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -149,6 +149,12 @@ ide_primary_workspace_get_frame_at_position (IdeWorkspace     *workspace,
                                     self->grid);
 }
 
+static gboolean
+ide_primary_workspace_can_search (IdeWorkspace *workspace)
+{
+  return TRUE;
+}
+
 static void
 ide_primary_workspace_dispose (GObject *object)
 {
@@ -173,11 +179,12 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
 
   object_class->dispose = ide_primary_workspace_dispose;
 
-  workspace_class->context_set = ide_primary_workspace_context_set;
   workspace_class->add_page = ide_primary_workspace_add_page;
   workspace_class->add_pane = ide_primary_workspace_add_pane;
-  workspace_class->get_most_recent_frame = ide_primary_workspace_get_most_recent_frame;
+  workspace_class->can_search = ide_primary_workspace_can_search;
+  workspace_class->context_set = ide_primary_workspace_context_set;
   workspace_class->get_frame_at_position = ide_primary_workspace_get_frame_at_position;
+  workspace_class->get_most_recent_frame = ide_primary_workspace_get_most_recent_frame;
 
   ide_workspace_class_set_kind (workspace_class, "primary");
 
@@ -192,6 +199,8 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, project_title);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, run_button);
 
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_CONTROL_MASK, 
"workbench.global-search", NULL);
+
   g_type_ensure (IDE_TYPE_GRID);
   g_type_ensure (IDE_TYPE_NOTIFICATIONS_BUTTON);
   g_type_ensure (IDE_TYPE_OMNI_BAR);
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 8605e1daf..9c19e8aa9 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -112,24 +112,26 @@ enum {
   N_PROPS
 };
 
-static void ide_workbench_action_close       (IdeWorkbench *self,
-                                              GVariant     *param);
-static void ide_workbench_action_open        (IdeWorkbench *self,
-                                              GVariant     *param);
-static void ide_workbench_action_dump_tasks  (IdeWorkbench *self,
-                                              GVariant     *param);
-static void ide_workbench_action_object_tree (IdeWorkbench *self,
-                                              GVariant     *param);
-static void ide_workbench_action_inspector   (IdeWorkbench *self,
-                                              GVariant     *param);
-static void ide_workbench_action_reload_all  (IdeWorkbench *self,
-                                              GVariant     *param);
-
+static void ide_workbench_action_close         (IdeWorkbench *self,
+                                                GVariant     *param);
+static void ide_workbench_action_open          (IdeWorkbench *self,
+                                                GVariant     *param);
+static void ide_workbench_action_dump_tasks    (IdeWorkbench *self,
+                                                GVariant     *param);
+static void ide_workbench_action_object_tree   (IdeWorkbench *self,
+                                                GVariant     *param);
+static void ide_workbench_action_inspector     (IdeWorkbench *self,
+                                                GVariant     *param);
+static void ide_workbench_action_reload_all    (IdeWorkbench *self,
+                                                GVariant     *param);
+static void ide_workbench_action_global_search (IdeWorkbench *self,
+                                                GVariant     *param);
 
 IDE_DEFINE_ACTION_GROUP (IdeWorkbench, ide_workbench, {
   { "close", ide_workbench_action_close },
   { "open", ide_workbench_action_open },
   { "reload-files", ide_workbench_action_reload_all },
+  { "global-search", ide_workbench_action_global_search },
   { "-inspector", ide_workbench_action_inspector },
   { "-object-tree", ide_workbench_action_object_tree },
   { "-dump-tasks", ide_workbench_action_dump_tasks },
@@ -1417,6 +1419,29 @@ ide_workbench_action_open (IdeWorkbench *self,
   gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
 }
 
+static void
+ide_workbench_action_global_search (IdeWorkbench *self,
+                                    GVariant     *param)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_WORKBENCH (self));
+  g_assert (param == NULL);
+
+  for (const GList *iter = self->mru_queue.head; iter; iter = iter->next)
+    {
+      IdeWorkspace *workspace = iter->data;
+
+      if (_ide_workspace_can_search (workspace))
+        {
+          _ide_workspace_begin_global_search (workspace);
+          IDE_EXIT;
+        }
+    }
+
+  IDE_EXIT;
+}
+
 /**
  * ide_workbench_get_search_engine:
  * @self: a #IdeWorkbench
diff --git a/src/libide/gui/ide-workspace-private.h b/src/libide/gui/ide-workspace-private.h
index 7dc2d90c2..79b9fc2be 100644
--- a/src/libide/gui/ide-workspace-private.h
+++ b/src/libide/gui/ide-workspace-private.h
@@ -36,6 +36,8 @@ void        _ide_workspace_move_front_page_mru (IdeWorkspace        *workspace,
                                                 GList               *mru_link);
 void        _ide_workspace_set_context         (IdeWorkspace        *workspace,
                                                 IdeContext          *context);
+gboolean    _ide_workspace_can_search          (IdeWorkspace        *self);
+void        _ide_workspace_begin_global_search (IdeWorkspace        *self);
 void        _ide_workspace_add_widget          (IdeWorkspace        *workspace,
                                                 PanelWidget         *widget,
                                                 IdePanelPosition    *position,
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 41e690d0d..ef4aa12fd 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include <libide-search.h>
 #include <libide-plugins.h>
 
 #include "ide-gui-global.h"
@@ -33,7 +34,6 @@
 #define GET_PRIORITY(w)   GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"PRIORITY"))
 #define SET_PRIORITY(w,i) g_object_set_data(G_OBJECT(w),"PRIORITY",GINT_TO_POINTER(i))
 
-
 typedef struct
 {
   /* Used as a link in IdeWorkbench's GQueue to track the most-recently-used
@@ -61,6 +61,9 @@ typedef struct
   /* A statusbar, if any, that was added to the workspace */
   PanelStatusbar *statusbar;
 
+  /* The global search for the workspace, if any */
+  IdeSearchPopover *search_popover;
+
   /* A MRU that is updated as pages are focused. It allows us to move through
    * the pages in the order they've been most-recently focused.
    */
@@ -372,6 +375,14 @@ ide_workspace_size_allocate (GtkWidget *widget,
 
   GTK_WIDGET_CLASS (ide_workspace_parent_class)->size_allocate (widget, width, height, baseline);
 
+  if (priv->search_popover != NULL)
+    {
+      GdkRectangle point = { width / 2, 100, 1, 1 };
+
+      gtk_popover_set_pointing_to (GTK_POPOVER (priv->search_popover), &point);
+      gtk_popover_present (GTK_POPOVER (priv->search_popover));
+    }
+
   if (priv->queued_window_save == 0 &&
       IDE_WORKSPACE_GET_CLASS (self)->save_size != NULL)
     priv->queued_window_save = g_timeout_add_seconds (1, ide_workspace_save_settings, self);
@@ -434,7 +445,12 @@ ide_workspace_real_get_most_recent_frame (IdeWorkspace *self)
     return NULL;
 
   return IDE_FRAME (gtk_widget_get_ancestor (GTK_WIDGET (page), IDE_TYPE_FRAME));
+}
 
+static gboolean
+ide_workspace_real_can_search (IdeWorkspace *self)
+{
+  return FALSE;
 }
 
 static void
@@ -516,13 +532,14 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
 
   window_class->close_request = ide_workspace_close_request;
 
-  klass->foreach_page = ide_workspace_real_foreach_page;
-  klass->context_set = ide_workspace_real_context_set;
   klass->agree_to_close_async = ide_workspace_agree_to_close_async;
   klass->agree_to_close_finish = ide_workspace_agree_to_close_finish;
+  klass->can_search = ide_workspace_real_can_search;
+  klass->context_set = ide_workspace_real_context_set;
+  klass->foreach_page = ide_workspace_real_foreach_page;
+  klass->get_most_recent_frame = ide_workspace_real_get_most_recent_frame;
   klass->restore_size = ide_workspace_restore_size;
   klass->save_size = ide_workspace_save_size;
-  klass->get_most_recent_frame = ide_workspace_real_get_most_recent_frame;
 
   /**
    * IdeWorkspace:context:
@@ -1239,3 +1256,31 @@ ide_workspace_get_frame_at_position (IdeWorkspace     *self,
 
   return NULL;
 }
+
+gboolean
+_ide_workspace_can_search (IdeWorkspace *self)
+{
+  g_return_val_if_fail (IDE_IS_WORKSPACE (self), FALSE);
+
+  return IDE_WORKSPACE_GET_CLASS (self)->can_search (self);
+}
+
+void
+_ide_workspace_begin_global_search (IdeWorkspace *self)
+{
+  IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_WORKSPACE (self));
+
+  if (priv->search_popover == NULL)
+    {
+      IdeWorkbench *workbench = ide_workspace_get_workbench (self);
+      IdeSearchEngine *search_engine = ide_workbench_get_search_engine (workbench);
+
+      priv->search_popover = IDE_SEARCH_POPOVER (ide_search_popover_new (search_engine));
+      gtk_widget_set_parent (GTK_WIDGET (priv->search_popover), GTK_WIDGET (self));
+    }
+
+  if (!gtk_widget_get_visible (GTK_WIDGET (priv->search_popover)))
+    gtk_popover_popup (GTK_POPOVER (priv->search_popover));
+}
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index b87d77220..fc2f43305 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -82,6 +82,7 @@ struct _IdeWorkspaceClass
   gboolean    (*save_size)             (IdeWorkspace         *self,
                                         int                  *width,
                                         int                  *height);
+  gboolean    (*can_search)            (IdeWorkspace         *self);
 };
 
 IDE_AVAILABLE_IN_ALL


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