[gnome-builder/wip/gtk4-port] libide/gui: improve leaving search bars



commit fd7ee6f940eb28b6676d2e876ffeb466caa2d2a2
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 6 17:51:32 2022 -0700

    libide/gui: improve leaving search bars
    
    We still need some work for leaving the search popover as that needs to
    have a controller added to it.

 src/libide/gui/gtk/keybindings.gsl          | 10 +++++++-
 src/libide/gui/gtk/keybindings.json         |  2 +-
 src/libide/gui/ide-search-popover-private.h | 10 ++------
 src/libide/gui/ide-search-popover.h         | 39 +++++++++++++++++++++++++++++
 src/libide/gui/libide-gui.h                 |  1 +
 src/libide/gui/meson.build                  |  1 +
 src/libide/terminal/ide-terminal-launcher.c |  1 +
 src/libide/terminal/ide-terminal-search.c   | 13 ++++++++++
 8 files changed, 67 insertions(+), 10 deletions(-)
---
diff --git a/src/libide/gui/gtk/keybindings.gsl b/src/libide/gui/gtk/keybindings.gsl
index a8edabc4b..8393e5fc9 100644
--- a/src/libide/gui/gtk/keybindings.gsl
+++ b/src/libide/gui/gtk/keybindings.gsl
@@ -41,10 +41,18 @@ def inPopover()
   (focus != null) && (focus.get_ancestor(typeof(Gtk.Popover)) != null)
 end
 
-def inSearch()
+def inPopoverSearch()
   (focus != null) && (focus.get_ancestor(typeof(Ide.SearchPopover)) != null)
 end
 
+def inPageSearch()
+  ((page != null) && \
+   (focus != null) && \
+   focus.is_ancestor(page) && \
+   (focus.get_ancestor(typeof(Gtk.Revealer)) != null) && \
+   !page.is_ancestor(focus.get_ancestor(typeof(Gtk.Revealer))))
+end
+
 def isBuilding()
   (workbench != null) && workbench.has_project() && 
Ide.BuildManager.from_context(workbench.context).get_busy()
 end
diff --git a/src/libide/gui/gtk/keybindings.json b/src/libide/gui/gtk/keybindings.json
index 6d5bdff48..d484fce52 100644
--- a/src/libide/gui/gtk/keybindings.json
+++ b/src/libide/gui/gtk/keybindings.json
@@ -1,6 +1,6 @@
 /* Global Search */
 { "trigger" : "<Control>Return", "action" : "workbench.global-search", "when" : "canSearch()", "phase" : 
"capture" },
-{ "trigger" : "Escape", "action" : "search.hide", "when" : "inSearch()", "phase" : "capture" },
+{ "trigger" : "Escape", "action" : "search.hide", "when" : "inPopoverSearch() || inPageSearch()", "phase" : 
"capture" },
 
 /* New Files */
 { "trigger" : "<Control>n", "action" : "editorui.new-file", "when" : "canEdit()", "phase" : "bubble" },
diff --git a/src/libide/gui/ide-search-popover-private.h b/src/libide/gui/ide-search-popover-private.h
index 5ee25fbbd..27cdc15fb 100644
--- a/src/libide/gui/ide-search-popover-private.h
+++ b/src/libide/gui/ide-search-popover-private.h
@@ -20,20 +20,14 @@
 
 #pragma once
 
-#include <gtk/gtk.h>
-
-#include <libide-core.h>
-#include <libide-search.h>
+#include "ide-search-popover.h"
 
 G_BEGIN_DECLS
 
-#define IDE_TYPE_SEARCH_POPOVER (ide_search_popover_get_type())
-
-G_DECLARE_FINAL_TYPE (IdeSearchPopover, ide_search_popover, IDE, SEARCH_POPOVER, GtkPopover)
-
 GtkWidget *ide_search_popover_new     (IdeSearchEngine  *search_engine);
 void       ide_search_popover_present (IdeSearchPopover *self,
                                        int               parent_width,
                                        int               parent_height);
 
+
 G_END_DECLS
diff --git a/src/libide/gui/ide-search-popover.h b/src/libide/gui/ide-search-popover.h
new file mode 100644
index 000000000..95692e9c1
--- /dev/null
+++ b/src/libide/gui/ide-search-popover.h
@@ -0,0 +1,39 @@
+/* ide-search-popover.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_GUI_INSIDE) && !defined (IDE_GUI_COMPILATION)
+# error "Only <libide-gui.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+#include <libide-core.h>
+#include <libide-search.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_SEARCH_POPOVER (ide_search_popover_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeSearchPopover, ide_search_popover, IDE, SEARCH_POPOVER, GtkPopover)
+
+G_END_DECLS
diff --git a/src/libide/gui/libide-gui.h b/src/libide/gui/libide-gui.h
index abcea657e..2bcee84ca 100644
--- a/src/libide/gui/libide-gui.h
+++ b/src/libide/gui/libide-gui.h
@@ -51,6 +51,7 @@
 # include "ide-preferences-window.h"
 # include "ide-primary-workspace.h"
 # include "ide-run-button.h"
+# include "ide-search-popover.h"
 # include "ide-session-addin.h"
 # include "ide-workbench.h"
 # include "ide-workbench-addin.h"
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index f96003d95..0c5909b3f 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -29,6 +29,7 @@ libide_gui_public_headers = [
   'ide-preferences-window.h',
   'ide-primary-workspace.h',
   'ide-run-button.h',
+  'ide-search-popover.h',
   'ide-session-addin.h',
   'ide-workbench.h',
   'ide-workbench-addin.h',
diff --git a/src/libide/terminal/ide-terminal-launcher.c b/src/libide/terminal/ide-terminal-launcher.c
index 28ab4d4e6..0dedcb658 100644
--- a/src/libide/terminal/ide-terminal-launcher.c
+++ b/src/libide/terminal/ide-terminal-launcher.c
@@ -30,6 +30,7 @@
 #include "ide-private.h"
 
 #include "ide-terminal-launcher.h"
+#include "ide-terminal-private.h"
 #include "ide-terminal-util.h"
 
 typedef enum
diff --git a/src/libide/terminal/ide-terminal-search.c b/src/libide/terminal/ide-terminal-search.c
index fb0841820..3df04d6a7 100644
--- a/src/libide/terminal/ide-terminal-search.c
+++ b/src/libide/terminal/ide-terminal-search.c
@@ -256,6 +256,17 @@ search_revealer_cb (GtkRevealer       *search_revealer,
     }
 }
 
+static void
+search_hide_action (GtkWidget  *widget,
+                    const char *action_name,
+                    GVariant   *param)
+{
+  IdeTerminalSearch *self = IDE_TERMINAL_SEARCH (widget);
+
+  gtk_revealer_set_reveal_child (self->search_revealer, FALSE);
+  gtk_widget_grab_focus (GTK_WIDGET (self->terminal));
+}
+
 static void
 ide_terminal_search_connect_terminal (IdeTerminalSearch *self)
 {
@@ -322,6 +333,8 @@ ide_terminal_search_class_init (IdeTerminalSearchClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_revealer);
   gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_options);
 
+  gtk_widget_class_install_action (widget_class, "search.hide", NULL, search_hide_action);
+
   signals[SEARCH] =
     g_signal_new ("search",
                   G_OBJECT_CLASS_TYPE (object_class),


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