[gnome-builder/wip/chergert/perspective] workbench: implement ide_workbench_focus()



commit ddf655cc46318f335ebc608a9ea9a5229a0e5d2c
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 5 23:40:46 2015 -0800

    workbench: implement ide_workbench_focus()
    
    This helper focus a widget and ensures the hierarchy to the widget is
    visible for known internal container types (such as IdeLayout,
    IdePerspective, and views).

 libide/ide-workbench.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-workbench.c b/libide/ide-workbench.c
index 43a389b..8671099 100644
--- a/libide/ide-workbench.c
+++ b/libide/ide-workbench.c
@@ -22,6 +22,10 @@
 #include "ide-genesis-perspective.h"
 #include "ide-greeter-perspective.h"
 #include "ide-gtk.h"
+#include "ide-layout.h"
+#include "ide-layout-pane.h"
+#include "ide-layout-view.h"
+#include "ide-layout-stack.h"
 #include "ide-macros.h"
 #include "ide-preferences-perspective.h"
 #include "ide-window-settings.h"
@@ -663,3 +667,41 @@ ide_workbench_set_visible_perspective_name (IdeWorkbench *self,
   if (perspective != NULL)
     ide_workbench_set_visible_perspective (self, perspective);
 }
+
+static void
+ide_workbench_show_parents (GtkWidget *widget)
+{
+  GtkWidget *parent;
+
+  g_assert (GTK_IS_WIDGET (widget));
+
+  parent = gtk_widget_get_parent (widget);
+
+  if (IDE_IS_LAYOUT_PANE (widget))
+    {
+      gtk_container_child_set (GTK_CONTAINER (parent), widget,
+                               "reveal", TRUE,
+                               NULL);
+    }
+
+  if (IDE_IS_PERSPECTIVE (widget))
+    ide_workbench_set_visible_perspective (ide_widget_get_workbench (widget),
+                                           IDE_PERSPECTIVE (widget));
+
+  if (GTK_IS_STACK (parent))
+    gtk_stack_set_visible_child (GTK_STACK (parent), widget);
+
+  if (parent != NULL)
+    ide_workbench_show_parents (parent);
+}
+
+void
+ide_workbench_focus (IdeWorkbench *self,
+                     GtkWidget    *widget)
+{
+  g_return_if_fail (IDE_IS_WORKBENCH (self));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  ide_workbench_show_parents (widget);
+  gtk_widget_grab_focus (widget);
+}


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