[gnome-builder/wip/chergert/layout] editor: use actions to focus/hide search revealer



commit 34f2bee14c19e148015740b210c14482b17eb29e
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 11 16:48:05 2017 -0700

    editor: use actions to focus/hide search revealer

 libide/editor/ide-editor-search-bar.ui    |    2 +-
 libide/editor/ide-editor-view-actions.c   |   30 +++++++++++++++++++++++++++++
 libide/editor/ide-editor-view-shortcuts.c |   19 +++--------------
 3 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/libide/editor/ide-editor-search-bar.ui b/libide/editor/ide-editor-search-bar.ui
index 91ed36b..464fc73 100644
--- a/libide/editor/ide-editor-search-bar.ui
+++ b/libide/editor/ide-editor-search-bar.ui
@@ -190,7 +190,7 @@
             <child>
               <object class="GtkButton" id="close_button">
                 <property name="visible">true</property>
-                <property name="action-name">search-entry.exit-search</property>
+                <property name="action-name">editor-view.hide-search</property>
                 <property name="halign">center</property>
                 <property name="valign">center</property>
                 <property name="focus_on_click">false</property>
diff --git a/libide/editor/ide-editor-view-actions.c b/libide/editor/ide-editor-view-actions.c
index a9a19ee..880cf7c 100644
--- a/libide/editor/ide-editor-view-actions.c
+++ b/libide/editor/ide-editor-view-actions.c
@@ -388,6 +388,34 @@ ide_editor_view_actions_save_as (GSimpleAction *action,
 }
 
 static void
+ide_editor_view_actions_focus_search (GSimpleAction *action,
+                                      GVariant      *variant,
+                                      gpointer       user_data)
+{
+  IdeEditorView *self = user_data;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_EDITOR_VIEW (self));
+
+  gtk_revealer_set_reveal_child (self->search_revealer, TRUE);
+  gtk_widget_grab_focus (GTK_WIDGET (self->search_bar));
+}
+
+static void
+ide_editor_view_actions_hide_search (GSimpleAction *action,
+                                     GVariant      *variant,
+                                     gpointer       user_data)
+{
+  IdeEditorView *self = user_data;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_EDITOR_VIEW (self));
+
+  gtk_revealer_set_reveal_child (self->search_revealer, FALSE);
+  gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
+}
+
+static void
 ide_editor_view_actions_notify_file_settings (IdeEditorView *self,
                                               GParamSpec    *pspec,
                                               IdeSourceView *source_view)
@@ -408,6 +436,8 @@ ide_editor_view_actions_notify_file_settings (IdeEditorView *self,
 }
 
 static const GActionEntry editor_view_entries[] = {
+  { "focus-search", ide_editor_view_actions_focus_search },
+  { "hide-search", ide_editor_view_actions_hide_search },
   { "print", ide_editor_view_actions_print },
   { "reload", ide_editor_view_actions_reload },
   { "save", ide_editor_view_actions_save },
diff --git a/libide/editor/ide-editor-view-shortcuts.c b/libide/editor/ide-editor-view-shortcuts.c
index 42a013e..9e91df1 100644
--- a/libide/editor/ide-editor-view-shortcuts.c
+++ b/libide/editor/ide-editor-view-shortcuts.c
@@ -69,17 +69,6 @@ static DzlShortcutEntry editor_view_shortcuts[] = {
     N_("Find the next match") },
 };
 
-static void
-ide_editor_view_shortcuts_find (GtkWidget *widget,
-                                gpointer   user_data)
-{
-  IdeEditorView *self = user_data;
-
-  g_assert (IDE_IS_EDITOR_VIEW (self));
-
-  gtk_revealer_set_reveal_child (self->search_revealer, TRUE);
-}
-
 void
 _ide_editor_view_init_shortcuts (IdeEditorView *self)
 {
@@ -89,10 +78,10 @@ _ide_editor_view_init_shortcuts (IdeEditorView *self)
 
   controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
 
-  dzl_shortcut_controller_add_command_callback (controller,
-                                                I_("org.gnome.builder.editor-view.find"),
-                                                NULL,
-                                                ide_editor_view_shortcuts_find, self, NULL);
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.editor-view.find"),
+                                              NULL,
+                                              I_("editor-view.focus-search"));
 
   dzl_shortcut_controller_add_command_action (controller,
                                               I_("org.gnome.builder.editor-view.find-and-replace"),


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