[gnome-todo/wip/gbsneto/plugins: 38/62] window: setup header widgets on panel change



commit 5069cc0fce64a5c9ab95f59d1e4dc8e4fd262cd5
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Dec 29 18:33:51 2015 -0200

    window: setup header widgets on panel change
    
    When we change the panels, we expect the header
    widgets to be updated. Implement that.

 src/gtd-window.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/src/gtd-window.c b/src/gtd-window.c
index 35b04d7..ce0d267 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -43,6 +43,8 @@ typedef struct
   GtkStackSwitcher              *stack_switcher;
   GtdProviderDialog             *provider_dialog;
 
+  GtdPanel                      *active_panel;
+
   /* mode */
   GtdWindowMode                  mode;
 
@@ -286,6 +288,65 @@ gtd_window__cancel_selection_button_clicked (GtkWidget *button,
   gtd_window_set_mode (window, GTD_WINDOW_MODE_NORMAL);
 }
 
+static void
+gtd_window__stack_visible_child_cb (GtdWindow  *window,
+                                    GParamSpec *pspec,
+                                    GtkStack   *stack)
+{
+  GtdWindowPrivate *priv;
+  GtkWidget *visible_child;
+  GtdPanel *panel;
+  GList *header_widgets;
+  GList *l;
+
+  priv = gtd_window_get_instance_private (window);
+  visible_child = gtk_stack_get_visible_child (stack);
+  panel = GTD_PANEL (visible_child);
+
+  /* Remove previous panel's widgets */
+  if (priv->active_panel)
+    {
+      header_widgets = gtd_panel_get_header_widgets (priv->active_panel);
+
+      for (l = header_widgets; l != NULL; l = l->next)
+        gtk_container_remove (GTK_CONTAINER (priv->headerbar), l->data);
+
+      g_list_free (header_widgets);
+    }
+
+  /* Add current panel's header widgets */
+  header_widgets = gtd_panel_get_header_widgets (panel);
+
+  for (l = header_widgets; l != NULL; l = l->next)
+    {
+      switch (gtk_widget_get_halign (l->data))
+        {
+        case GTK_ALIGN_START:
+          gtk_header_bar_pack_start (priv->headerbar, l->data);
+          break;
+
+        case GTK_ALIGN_CENTER:
+          gtk_header_bar_set_custom_title (priv->headerbar, l->data);
+          break;
+
+        case GTK_ALIGN_END:
+          gtk_header_bar_pack_end (priv->headerbar, l->data);
+          break;
+
+        case GTK_ALIGN_BASELINE:
+        case GTK_ALIGN_FILL:
+        default:
+          gtk_header_bar_pack_start (priv->headerbar, l->data);
+          break;
+        }
+    }
+
+  g_list_free (header_widgets);
+
+  /* Set panel as the new active panel */
+  g_set_object (&priv->active_panel, panel);
+}
+
 /*
 static void
 gtd_window__create_new_list (GSimpleAction *simple,
@@ -580,6 +641,7 @@ gtd_window_class_init (GtdWindowClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, stack_switcher);
 
   gtk_widget_class_bind_template_callback (widget_class, gtd_window__cancel_selection_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, gtd_window__stack_visible_child_cb);
 }
 
 static void


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