[gnome-builder] workbench: focus helpers



commit 09f9d06049744d6b50c31c1e7d02268da56fc24f
Author: Christian Hergert <christian hergert me>
Date:   Thu Jun 11 02:05:45 2015 -0700

    workbench: focus helpers

 plugins/devhelp/gb-devhelp-panel.c   |   11 ++++++
 src/app/gb-application.c             |    3 +-
 src/workbench/gb-workbench-actions.c |   60 ++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletions(-)
---
diff --git a/plugins/devhelp/gb-devhelp-panel.c b/plugins/devhelp/gb-devhelp-panel.c
index 816e0ca..4883fe3 100644
--- a/plugins/devhelp/gb-devhelp-panel.c
+++ b/plugins/devhelp/gb-devhelp-panel.c
@@ -149,6 +149,14 @@ fixup_box_border_width (GtkWidget *widget,
 }
 
 static void
+gb_devhelp_panel_grab_focus (GtkWidget *widget)
+{
+  GbDevhelpPanel *self = (GbDevhelpPanel *)widget;
+
+  dh_sidebar_set_search_focus (DH_SIDEBAR (self->sidebar));
+}
+
+static void
 gb_devhelp_panel_finalize (GObject *object)
 {
   GbDevhelpPanel *self = (GbDevhelpPanel *)object;
@@ -197,11 +205,14 @@ static void
 gb_devhelp_panel_class_init (GbDevhelpPanelClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->finalize = gb_devhelp_panel_finalize;
   object_class->get_property = gb_devhelp_panel_get_property;
   object_class->set_property = gb_devhelp_panel_set_property;
 
+  widget_class->grab_focus = gb_devhelp_panel_grab_focus;
+
   gParamSpecs [PROP_WORKBENCH] =
     g_param_spec_object ("workbench",
                          _("Workbench"),
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index 1c4774c..9441267 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -139,7 +139,8 @@ gb_application_load_keybindings (GbApplication *self)
     { "workbench.show-right-pane", "<shift>F9" },
     { "workbench.show-bottom-pane", "<ctrl>F9" },
     { "workbench.toggle-panels", "<ctrl><shift>F9" },
-    { "workspace.focus-sidebar", "<ctrl>0" },
+    { "workbench.focus-left", "<ctrl>grave" },
+    { "workbench.focus-right", "<ctrl>9" },
     { "workbench.focus-stack(1)", "<ctrl>1" },
     { "workbench.focus-stack(2)", "<ctrl>2" },
     { "workbench.focus-stack(3)", "<ctrl>3" },
diff --git a/src/workbench/gb-workbench-actions.c b/src/workbench/gb-workbench-actions.c
index 1ede837..76c0508 100644
--- a/src/workbench/gb-workbench-actions.c
+++ b/src/workbench/gb-workbench-actions.c
@@ -457,11 +457,71 @@ gb_workbench_actions_focus_stack (GSimpleAction *action,
   g_list_free (stacks);
 }
 
+static gboolean
+delayed_focus_timeout (gpointer data)
+{
+  GtkWidget *widget = data;
+
+  if (gtk_widget_get_realized (widget))
+    gtk_widget_grab_focus (widget);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+gb_workbench_actions_focus_left (GSimpleAction *action,
+                                 GVariant      *param,
+                                 gpointer       user_data)
+{
+  GbWorkbench *self = user_data;
+  GtkWidget *pane;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (GB_IS_WORKBENCH (self));
+
+  pane = gb_workspace_get_left_pane (self->workspace);
+  gtk_container_child_set (GTK_CONTAINER (self->workspace), pane,
+                           "reveal", TRUE,
+                           NULL);
+
+  /* delay a bit in case widgets are in reveal */
+  g_timeout_add_full (G_PRIORITY_LOW,
+                      10,
+                      delayed_focus_timeout,
+                      g_object_ref (pane),
+                      g_object_unref);
+}
+
+static void
+gb_workbench_actions_focus_right (GSimpleAction *action,
+                                  GVariant      *param,
+                                  gpointer       user_data)
+{
+  GbWorkbench *self = user_data;
+  GtkWidget *pane;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (GB_IS_WORKBENCH (self));
+
+  pane = gb_workspace_get_right_pane (self->workspace);
+  gtk_container_child_set (GTK_CONTAINER (self->workspace), pane,
+                           "reveal", TRUE,
+                           NULL);
+
+  /* delay a bit in case widgets are in reveal */
+  g_timeout_add_full (G_PRIORITY_LOW,
+                      10,
+                      delayed_focus_timeout,
+                      g_object_ref (pane),
+                      g_object_unref);
+}
 
 static const GActionEntry GbWorkbenchActions[] = {
   { "build",            gb_workbench_actions_build },
   { "dayhack",          gb_workbench_actions_dayhack },
   { "focus-stack",      gb_workbench_actions_focus_stack, "i" },
+  { "focus-left",       gb_workbench_actions_focus_left },
+  { "focus-right",      gb_workbench_actions_focus_right },
   { "global-search",    gb_workbench_actions_global_search },
   { "new-document",     gb_workbench_actions_new_document },
   { "nighthack",        gb_workbench_actions_nighthack },


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