[gnome-builder] plugins: port more plugins to new IdeLayoutView



commit 51d45039343788a76d7e714fa7f44e71fff72809
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 28 02:14:57 2017 -0700

    plugins: port more plugins to new IdeLayoutView

 libide/editor/ide-editor-perspective.c      |   18 +++
 plugins/devhelp/gbp-devhelp-view.c          |    2 +
 plugins/terminal/gb-terminal-view-actions.c |   31 +----
 plugins/terminal/gb-terminal-view-private.h |   10 --
 plugins/terminal/gb-terminal-view.c         |  198 ++++-----------------------
 plugins/terminal/gb-terminal-view.ui        |   23 ---
 6 files changed, 53 insertions(+), 229 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index db90446..487b705 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -39,9 +39,27 @@ G_DEFINE_TYPE_WITH_CODE (IdeEditorPerspective, ide_editor_perspective, IDE_TYPE_
                          G_IMPLEMENT_INTERFACE (IDE_TYPE_PERSPECTIVE, perspective_iface_init))
 
 static void
+ide_editor_perspective_add (GtkContainer *container,
+                            GtkWidget    *widget)
+{
+  IdeEditorPerspective *self = (IdeEditorPerspective *)container;
+
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+  g_assert (GTK_IS_WIDGET (widget));
+
+  if (IDE_IS_LAYOUT_VIEW (widget))
+    gtk_container_add (GTK_CONTAINER (self->grid), widget);
+  else
+    GTK_CONTAINER_CLASS (ide_editor_perspective_parent_class)->add (container, widget);
+}
+
+static void
 ide_editor_perspective_class_init (IdeEditorPerspectiveClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+
+  container_class->add = ide_editor_perspective_add;
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-editor-perspective.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, grid);
diff --git a/plugins/devhelp/gbp-devhelp-view.c b/plugins/devhelp/gbp-devhelp-view.c
index 2445048..6301fbf 100644
--- a/plugins/devhelp/gbp-devhelp-view.c
+++ b/plugins/devhelp/gbp-devhelp-view.c
@@ -180,6 +180,8 @@ gbp_devhelp_view_init (GbpDevhelpView *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  ide_layout_view_set_can_split (IDE_LAYOUT_VIEW (self), TRUE);
+
   self->search = g_object_new (GBP_TYPE_DEVHELP_SEARCH, NULL);
   self->search_revealer = gbp_devhelp_search_get_revealer (self->search);
   self->clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
diff --git a/plugins/terminal/gb-terminal-view-actions.c b/plugins/terminal/gb-terminal-view-actions.c
index 9ce16ef..e5cff43 100644
--- a/plugins/terminal/gb-terminal-view-actions.c
+++ b/plugins/terminal/gb-terminal-view-actions.c
@@ -160,16 +160,8 @@ save_as_cb (GObject      *object,
     }
   else
     {
-      if (view->bottom_has_focus && view->terminal_bottom != NULL)
-        {
-          g_clear_object (&view->save_as_file_bottom);
-          view->save_as_file_bottom = file;
-        }
-      else
-        {
-          g_clear_object (&view->save_as_file_top);
-          view->save_as_file_top = file;
-        }
+      g_clear_object (&view->save_as_file_top);
+      view->save_as_file_top = file;
     }
 }
 
@@ -193,12 +185,7 @@ get_last_focused_terminal_file (GbTerminalView *view)
 {
   GFile *file = NULL;
 
-  if (view->bottom_has_focus)
-    {
-      if (G_IS_FILE (view->save_as_file_bottom))
-        file = view->save_as_file_bottom;
-    }
-  else if G_IS_FILE (view->save_as_file_top)
+  if (G_IS_FILE (view->save_as_file_top))
     file = view->save_as_file_top;
 
   return file;
@@ -207,18 +194,12 @@ get_last_focused_terminal_file (GbTerminalView *view)
 static VteTerminal *
 get_last_focused_terminal (GbTerminalView *view)
 {
-  VteTerminal *terminal;
-
-  if (view->bottom_has_focus && view->terminal_bottom != NULL)
-    terminal = view->terminal_bottom;
-  else
-    terminal = view->terminal_top;
-
-  return terminal;
+  return view->terminal_top;
 }
 
 static gchar *
-gb_terminal_get_selected_text (GbTerminalView *view, VteTerminal **terminal_p)
+gb_terminal_get_selected_text (GbTerminalView  *view,
+                               VteTerminal    **terminal_p)
 {
   VteTerminal *terminal;
   gchar *buf = NULL;
diff --git a/plugins/terminal/gb-terminal-view-private.h b/plugins/terminal/gb-terminal-view-private.h
index 6e30244..6467efd 100644
--- a/plugins/terminal/gb-terminal-view-private.h
+++ b/plugins/terminal/gb-terminal-view-private.h
@@ -39,37 +39,27 @@ struct _GbTerminalView
   IdeRuntime          *runtime;
 
   GtkOverlay          *terminal_overlay_top;
-  GtkOverlay          *terminal_overlay_bottom;
 
   GtkRevealer         *search_revealer_top;
-  GtkRevealer         *search_revealer_bottom;
 
   VteTerminal         *terminal_top;
-  VteTerminal         *terminal_bottom;
 
   GtkScrollbar        *top_scrollbar;
-  GtkScrollbar        *bottom_scrollbar;
 
   GbTerminalSearch    *tsearch;
   GbTerminalSearch    *bsearch;
 
   GFile               *save_as_file_top;
-  GFile               *save_as_file_bottom;
 
   gchar               *selection_buffer;
 
-  GtkWidget           *bottom_container;
-
   VtePty              *pty;
 
   gint64               last_respawn;
 
   guint                manage_spawn : 1;
   guint                top_has_spawned : 1;
-  guint                bottom_has_spawned : 1;
-  guint                bottom_has_focus : 1;
   guint                top_has_needs_attention : 1;
-  guint                bottom_has_needs_attention : 1;
 };
 
 G_END_DECLS
diff --git a/plugins/terminal/gb-terminal-view.c b/plugins/terminal/gb-terminal-view.c
index d52950a..dee7cde 100644
--- a/plugins/terminal/gb-terminal-view.c
+++ b/plugins/terminal/gb-terminal-view.c
@@ -396,9 +396,8 @@ gb_terminal_get_preferred_height (GtkWidget *widget,
 }
 
 static void
-gb_terminal_set_needs_attention (GbTerminalView  *self,
-                                 gboolean         needs_attention,
-                                 GtkPositionType  position)
+gb_terminal_set_needs_attention (GbTerminalView *self,
+                                 gboolean        needs_attention)
 {
   GtkWidget *parent;
 
@@ -410,22 +409,11 @@ gb_terminal_set_needs_attention (GbTerminalView  *self,
       !gtk_widget_in_destruction (GTK_WIDGET (self)) &&
       !gtk_widget_in_destruction (parent))
     {
-      if (position == GTK_POS_TOP &&
-          !gtk_widget_in_destruction (GTK_WIDGET (self->terminal_top)))
-        {
-          self->top_has_needs_attention = TRUE;
-        }
-      else if (position == GTK_POS_BOTTOM &&
-               self->terminal_bottom != NULL &&
-               !gtk_widget_in_destruction (GTK_WIDGET (self->terminal_bottom)))
-        {
-          self->bottom_has_needs_attention = TRUE;
-        }
+      if (!gtk_widget_in_destruction (GTK_WIDGET (self->terminal_top)))
+        self->top_has_needs_attention = !!needs_attention;
 
       gtk_container_child_set (GTK_CONTAINER (parent), GTK_WIDGET (self),
-                               "needs-attention",
-                               !!(self->top_has_needs_attention || self->bottom_has_needs_attention) &&
-                               needs_attention,
+                               "needs-attention", needs_attention,
                                NULL);
     }
 }
@@ -440,31 +428,7 @@ notification_received_cb (VteTerminal    *terminal,
   g_assert (GB_IS_TERMINAL_VIEW (self));
 
   if (!gtk_widget_has_focus (GTK_WIDGET (terminal)))
-    {
-      if (terminal == self->terminal_top)
-        gb_terminal_set_needs_attention (self, TRUE, GTK_POS_TOP);
-      else if (terminal == self->terminal_bottom)
-        gb_terminal_set_needs_attention (self, TRUE, GTK_POS_BOTTOM);
-    }
-}
-
-static gchar *
-gb_terminal_get_title (IdeLayoutView *view)
-{
-  const gchar *title = NULL;
-  GbTerminalView *self = (GbTerminalView *)view;
-
-  g_assert (GB_IS_TERMINAL_VIEW (self));
-
-  if (self->bottom_has_focus)
-    title = vte_terminal_get_window_title (self->terminal_bottom);
-  else
-    title = vte_terminal_get_window_title (self->terminal_top);
-
-  if (title == NULL)
-    title = _("Untitled terminal");
-
-  return g_strdup (title);
+    gb_terminal_set_needs_attention (self, TRUE);
 }
 
 static gboolean
@@ -475,20 +439,9 @@ focus_in_event_cb (VteTerminal    *terminal,
   g_assert (VTE_IS_TERMINAL (terminal));
   g_assert (GB_IS_TERMINAL_VIEW (self));
 
-  self->bottom_has_focus = (terminal != self->terminal_top);
-
-  if (terminal == self->terminal_top)
-    {
-      self->top_has_needs_attention = FALSE;
-      gb_terminal_set_needs_attention (self, FALSE, GTK_POS_TOP);
-      gtk_revealer_set_reveal_child (self->search_revealer_top, FALSE);
-    }
-  else if (terminal == self->terminal_bottom)
-    {
-      self->bottom_has_needs_attention = FALSE;
-      gb_terminal_set_needs_attention (self, FALSE, GTK_POS_BOTTOM);
-      gtk_revealer_set_reveal_child (self->search_revealer_bottom, FALSE);
-    }
+  self->top_has_needs_attention = FALSE;
+  gb_terminal_set_needs_attention (self, FALSE);
+  gtk_revealer_set_reveal_child (self->search_revealer_top, FALSE);
 
   return GDK_EVENT_PROPAGATE;
 }
@@ -497,10 +450,17 @@ static void
 window_title_changed_cb (VteTerminal    *terminal,
                          GbTerminalView *self)
 {
+  const gchar *title;
+
   g_assert (VTE_IS_TERMINAL (terminal));
   g_assert (GB_IS_TERMINAL_VIEW (self));
 
-  g_object_notify (G_OBJECT (self), "title");
+  title = vte_terminal_get_window_title (self->terminal_top);
+
+  if (title == NULL)
+    title = _("Untitled terminal");
+
+  ide_layout_view_set_title (IDE_LAYOUT_VIEW (self), title);
 }
 
 static void
@@ -522,23 +482,15 @@ style_context_changed (GtkStyleContext *style_context,
   G_GNUC_END_IGNORE_DEPRECATIONS;
 
   if (bg.alpha == 0.0)
-    {
-      gdk_rgba_parse (&bg, "#f6f7f8");
-    }
+    gdk_rgba_parse (&bg, "#f6f7f8");
 
   vte_terminal_set_colors (self->terminal_top, &fg, &bg,
                            solarized_palette,
                            G_N_ELEMENTS (solarized_palette));
-
-  if (self->terminal_bottom)
-    vte_terminal_set_colors (self->terminal_bottom, &fg, &bg,
-                             solarized_palette,
-                             G_N_ELEMENTS (solarized_palette));
 }
 
 static IdeLayoutView *
-gb_terminal_create_split (IdeLayoutView *view,
-                          GFile         *file)
+gb_terminal_create_split_view (IdeLayoutView *view)
 {
   IdeLayoutView *new_view;
 
@@ -555,103 +507,20 @@ static void
 gb_terminal_view_set_font_name (GbTerminalView *self,
                                 const gchar    *font_name)
 {
-  PangoFontDescription *font_desc = NULL;
-
   g_assert (GB_IS_TERMINAL_VIEW (self));
 
   if (font_name != NULL)
-    font_desc = pango_font_description_from_string (font_name);
-
-  if (font_desc != NULL)
     {
-      vte_terminal_set_font (self->terminal_top, font_desc);
+      PangoFontDescription *font_desc = NULL;
 
-      if (self->terminal_bottom)
-        vte_terminal_set_font (self->terminal_bottom, font_desc);
+      font_desc = pango_font_description_from_string (font_name);
 
-      pango_font_description_free (font_desc);
-    }
-}
-
-static gboolean
-gb_terminal_get_split_view (IdeLayoutView *view)
-{
-  GbTerminalView *self = (GbTerminalView *)view;
-
-  g_assert (GB_IS_TERMINAL_VIEW (self));
-
-  return (self->terminal_bottom != NULL);
-}
-
-static void
-gb_terminal_set_split_view (IdeLayoutView   *view,
-                            gboolean         split_view)
-{
-  GbTerminalView *self = (GbTerminalView *)view;
-  GtkStyleContext *style_context;
-
-  g_assert (GB_IS_TERMINAL_VIEW (self));
-  g_return_if_fail (GB_IS_TERMINAL_VIEW (self));
-
-  if (split_view && (self->terminal_bottom != NULL))
-    return;
-
-  if (!split_view && (self->terminal_bottom == NULL))
-    return;
-
-  if (split_view)
-    {
-      style_context = gtk_widget_get_style_context (GTK_WIDGET (view));
-
-      self->terminal_bottom = g_object_new (GB_TYPE_TERMINAL,
-                                            "audible-bell", FALSE,
-                                            "scrollback-lines", G_MAXUINT,
-                                            "expand", TRUE,
-                                            "visible", TRUE,
-                                            NULL);
-      gtk_container_add_with_properties (GTK_CONTAINER (self->bottom_container),
-                                         GTK_WIDGET (self->terminal_bottom),
-                                         "position", 0,
-                                         NULL);
-      gtk_widget_show ( GTK_WIDGET (self->terminal_overlay_bottom));
-
-      self->bsearch = g_object_new (GB_TYPE_TERMINAL_SEARCH, NULL);
-      self->search_revealer_bottom = gb_terminal_search_get_revealer (self->bsearch);
-
-      gtk_overlay_add_overlay (self->terminal_overlay_bottom,
-                               GTK_WIDGET (self->search_revealer_bottom));
-
-      gb_terminal_view_connect_terminal (self, self->terminal_bottom);
-
-      gb_terminal_search_set_terminal (self->bsearch, self->terminal_bottom);
-
-      style_context_changed (style_context, GB_TERMINAL_VIEW (view));
-
-      gtk_widget_grab_focus (GTK_WIDGET (self->terminal_bottom));
-
-      if (!self->bottom_has_spawned)
+      if (font_desc != NULL)
         {
-          self->bottom_has_spawned = TRUE;
-          gb_terminal_respawn (self, self->terminal_bottom);
+          vte_terminal_set_font (self->terminal_top, font_desc);
+          pango_font_description_free (font_desc);
         }
     }
-  else
-    {
-      gtk_container_remove (GTK_CONTAINER (self->terminal_overlay_bottom),
-                            GTK_WIDGET (self->search_revealer_bottom));
-      gtk_container_remove (GTK_CONTAINER (self->bottom_container),
-                            GTK_WIDGET (self->terminal_bottom));
-      gtk_widget_hide ( GTK_WIDGET (self->terminal_overlay_bottom));
-
-      self->terminal_bottom = NULL;
-      self->search_revealer_bottom = NULL;
-      self->bottom_has_focus = FALSE;
-      self->bottom_has_spawned = FALSE;
-      self->bottom_has_needs_attention = FALSE;
-      g_clear_object (&self->save_as_file_bottom);
-      g_clear_object (&self->bsearch);
-      gtk_widget_grab_focus (GTK_WIDGET (self->terminal_top));
-    }
 }
 
 static void
@@ -661,10 +530,7 @@ gb_terminal_grab_focus (GtkWidget *widget)
 
   g_assert (GB_IS_TERMINAL_VIEW (self));
 
-  if (self->bottom_has_focus && self->terminal_bottom)
-    gtk_widget_grab_focus (GTK_WIDGET (self->terminal_bottom));
-  else
-    gtk_widget_grab_focus (GTK_WIDGET (self->terminal_top));
+  gtk_widget_grab_focus (GTK_WIDGET (self->terminal_top));
 }
 
 static void
@@ -675,10 +541,7 @@ gb_terminal_view_connect_terminal (GbTerminalView *self,
 
   vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (terminal));
 
-  if (terminal == self->terminal_top)
-    gtk_range_set_adjustment (GTK_RANGE (self->top_scrollbar), vadj);
-  else
-    gtk_range_set_adjustment (GTK_RANGE (self->bottom_scrollbar), vadj);
+  gtk_range_set_adjustment (GTK_RANGE (self->top_scrollbar), vadj);
 
   g_signal_connect_object (terminal,
                            "size-allocate",
@@ -714,7 +577,6 @@ gb_terminal_view_finalize (GObject *object)
   GbTerminalView *self = GB_TERMINAL_VIEW (object);
 
   g_clear_object (&self->save_as_file_top);
-  g_clear_object (&self->save_as_file_bottom);
   g_clear_pointer (&self->selection_buffer, g_free);
   g_clear_object (&self->pty);
   g_clear_object (&self->runtime);
@@ -796,18 +658,12 @@ gb_terminal_view_class_init (GbTerminalViewClass *klass)
   widget_class->get_preferred_height = gb_terminal_get_preferred_height;
   widget_class->grab_focus = gb_terminal_grab_focus;
 
-  view_class->get_title = gb_terminal_get_title;
-  view_class->create_split = gb_terminal_create_split;
-  view_class->get_split_view =  gb_terminal_get_split_view;
-  view_class->set_split_view =  gb_terminal_set_split_view;
+  view_class->create_split_view = gb_terminal_create_split_view;
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/terminal/gb-terminal-view.ui");
   gtk_widget_class_bind_template_child (widget_class, GbTerminalView, terminal_top);
-  gtk_widget_class_bind_template_child (widget_class, GbTerminalView, bottom_container);
   gtk_widget_class_bind_template_child (widget_class, GbTerminalView, top_scrollbar);
-  gtk_widget_class_bind_template_child (widget_class, GbTerminalView, bottom_scrollbar);
   gtk_widget_class_bind_template_child (widget_class, GbTerminalView, terminal_overlay_top);
-  gtk_widget_class_bind_template_child (widget_class, GbTerminalView, terminal_overlay_bottom);
 
   g_type_ensure (VTE_TYPE_TERMINAL);
 
diff --git a/plugins/terminal/gb-terminal-view.ui b/plugins/terminal/gb-terminal-view.ui
index 871333a..c1a86d2 100644
--- a/plugins/terminal/gb-terminal-view.ui
+++ b/plugins/terminal/gb-terminal-view.ui
@@ -35,29 +35,6 @@
             </child>
           </object>
         </child>
-        <child>
-          <object class="GtkOverlay" id="terminal_overlay_bottom">
-            <property name="expand">true</property>
-            <property name="visible">false</property>
-            <child>
-              <object class="GtkBox" id="bottom_container">
-                <property name="orientation">horizontal</property>
-                <property name="expand">true</property>
-                <property name="visible">true</property>
-                <child>
-                  <object class="GtkScrollbar" id="bottom_scrollbar">
-                    <property name="orientation">vertical</property>
-                    <property name="visible">true</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="resize">true</property>
-            <property name="shrink">true</property>
-          </packing>
-        </child>
       </object>
     </child>
   </template>


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