[gnome-builder] color-picker: only create the panel at first use



commit fc6ae4f38645af1ae359a776c699a90461f2119e
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Fri Sep 8 22:10:52 2017 +0200

    color-picker: only create the panel at first use

 .../color-picker/gb-color-picker-editor-addin.c    |  170 +++++++++++---------
 1 files changed, 93 insertions(+), 77 deletions(-)
---
diff --git a/plugins/color-picker/gb-color-picker-editor-addin.c 
b/plugins/color-picker/gb-color-picker-editor-addin.c
index 180e15c..a2653cb 100644
--- a/plugins/color-picker/gb-color-picker-editor-addin.c
+++ b/plugins/color-picker/gb-color-picker-editor-addin.c
@@ -69,50 +69,6 @@ struct _GbColorPickerEditorAddin
   DzlSignalGroup *view_addin_signals;
 };
 
-static void
-gb_color_picker_editor_addin_show_panel (GbColorPickerEditorAddin *self)
-{
-  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
-
-  if (self->view != NULL)
-    {
-      IdeLayoutTransientSidebar *sidebar;
-      IdeLayoutView *view = IDE_LAYOUT_VIEW (self->view);
-
-      sidebar = ide_editor_perspective_get_transient_sidebar (self->editor);
-
-      ide_layout_transient_sidebar_set_view (sidebar, view);
-      ide_layout_transient_sidebar_set_panel (sidebar, GTK_WIDGET (self->dock));
-
-      g_object_set (self->editor, "right-visible", TRUE, NULL);
-    }
-}
-
-static void
-gb_color_picker_editor_addin_hide_panel (GbColorPickerEditorAddin *self)
-{
-  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
-}
-
-static void
-gb_color_picker_editor_addin_notify_enabled (GbColorPickerEditorAddin     *self,
-                                             GParamSpec                   *pspec,
-                                             GbColorPickerEditorViewAddin *view_addin)
-{
-  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
-  g_assert (GB_IS_COLOR_PICKER_EDITOR_VIEW_ADDIN (view_addin));
-
-  /* This function is called when the enabled state is toggled
-   * for the specific view in question. We hide the panel if it
-   * is current visible, otherwise we show it.
-   */
-
-  if (gb_color_picker_editor_view_addin_get_enabled (view_addin))
-    gb_color_picker_editor_addin_show_panel (self);
-  else
-    gb_color_picker_editor_addin_hide_panel (self);
-}
-
 /*
  * gb_color_picker_editor_addin_add_palette:
  * @self: a #GbColorPickerEditorAddin
@@ -207,6 +163,83 @@ gb_color_picker_editor_addin_notify_rgba (GbColorPickerEditorAddin *self,
 }
 
 static void
+gb_color_picker_editor_addin_set_panel (GbColorPickerEditorAddin *self)
+{
+  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
+
+  self->panel = g_object_new (GSTYLE_TYPE_COLOR_PANEL,
+                              "visible", TRUE,
+                              NULL);
+  g_signal_connect (self->panel,
+                    "destroy",
+                    G_CALLBACK (gtk_widget_destroyed),
+                    &self->panel);
+  g_signal_connect_object (self->panel,
+                           "notify::rgba",
+                           G_CALLBACK (gb_color_picker_editor_addin_notify_rgba),
+                           self,
+                           G_CONNECT_SWAPPED);
+  gtk_container_add (GTK_CONTAINER (self->dock), GTK_WIDGET (self->panel));
+
+  self->prefs = g_object_new (GB_TYPE_COLOR_PICKER_PREFS,
+                              "panel", self->panel,
+                              NULL);
+
+  gb_color_picker_editor_addin_init_palettes (self);
+}
+
+static void
+gb_color_picker_editor_addin_show_panel (GbColorPickerEditorAddin *self)
+{
+  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
+
+  if (self->view != NULL)
+    {
+      IdeLayoutTransientSidebar *sidebar;
+      IdeLayoutView *view = IDE_LAYOUT_VIEW (self->view);
+
+      if (self->panel == NULL)
+        gb_color_picker_editor_addin_set_panel (self);
+
+      sidebar = ide_editor_perspective_get_transient_sidebar (self->editor);
+
+      ide_layout_transient_sidebar_set_view (sidebar, view);
+      ide_layout_transient_sidebar_set_panel (sidebar, GTK_WIDGET (self->dock));
+
+      g_object_set (self->editor, "right-visible", TRUE, NULL);
+    }
+}
+
+static void
+gb_color_picker_editor_addin_hide_panel (GbColorPickerEditorAddin *self)
+{
+  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
+
+  /* For the case we'll add more code here */
+  if (self->panel == NULL)
+    return;
+}
+
+static void
+gb_color_picker_editor_addin_notify_enabled (GbColorPickerEditorAddin     *self,
+                                             GParamSpec                   *pspec,
+                                             GbColorPickerEditorViewAddin *view_addin)
+{
+  g_assert (GB_IS_COLOR_PICKER_EDITOR_ADDIN (self));
+  g_assert (GB_IS_COLOR_PICKER_EDITOR_VIEW_ADDIN (view_addin));
+
+  /* This function is called when the enabled state is toggled
+   * for the specific view in question. We hide the panel if it
+   * is current visible, otherwise we show it.
+   */
+
+  if (gb_color_picker_editor_view_addin_get_enabled (view_addin))
+    gb_color_picker_editor_addin_show_panel (self);
+  else
+    gb_color_picker_editor_addin_hide_panel (self);
+}
+
+static void
 gb_color_picker_editor_addin_color_found (GbColorPickerEditorAddin     *self,
                                           GstyleColor                  *color,
                                           GbColorPickerEditorViewAddin *view_addin)
@@ -219,6 +252,10 @@ gb_color_picker_editor_addin_color_found (GbColorPickerEditorAddin     *self,
 
   dzl_signal_group_block (self->view_addin_signals);
   gstyle_color_fill_rgba (color, &rgba);
+
+  if (self->panel == NULL)
+    gb_color_picker_editor_addin_set_panel (self);
+
   gstyle_color_panel_set_rgba (self->panel, &rgba);
   dzl_signal_group_unblock (self->view_addin_signals);
 }
@@ -234,8 +271,16 @@ gb_color_picker_editor_addin_load (IdeEditorAddin       *addin,
   g_assert (IDE_IS_EDITOR_PERSPECTIVE (perspective));
 
   self->editor = perspective;
+  self->view_addin_signals = dzl_signal_group_new (GB_TYPE_COLOR_PICKER_EDITOR_VIEW_ADDIN);
+  dzl_signal_group_connect_swapped (self->view_addin_signals,
+                                    "color-found",
+                                    G_CALLBACK (gb_color_picker_editor_addin_color_found),
+                                    self);
 
-  sidebar = ide_editor_perspective_get_transient_sidebar (perspective);
+  dzl_signal_group_connect_swapped (self->view_addin_signals,
+                                    "notify::enabled",
+                                    G_CALLBACK (gb_color_picker_editor_addin_notify_enabled),
+                                    self);
 
   self->dock = g_object_new (DZL_TYPE_DOCK_WIDGET,
                              "title", _("Colors"),
@@ -247,41 +292,12 @@ gb_color_picker_editor_addin_load (IdeEditorAddin       *addin,
                     "destroy",
                     G_CALLBACK (gtk_widget_destroyed),
                     &self->dock);
-  gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (self->dock));
-
-  self->panel = g_object_new (GSTYLE_TYPE_COLOR_PANEL,
-                              "visible", TRUE,
-                              NULL);
-  g_signal_connect (self->panel,
-                    "destroy",
-                    G_CALLBACK (gtk_widget_destroyed),
-                    &self->panel);
-  g_signal_connect_object (self->panel,
-                           "notify::rgba",
-                           G_CALLBACK (gb_color_picker_editor_addin_notify_rgba),
-                           self,
-                           G_CONNECT_SWAPPED);
-  gtk_container_add (GTK_CONTAINER (self->dock), GTK_WIDGET (self->panel));
-
-  self->prefs = g_object_new (GB_TYPE_COLOR_PICKER_PREFS,
-                              "panel", self->panel,
-                              NULL);
-
-  self->view_addin_signals = dzl_signal_group_new (GB_TYPE_COLOR_PICKER_EDITOR_VIEW_ADDIN);
-
-  dzl_signal_group_connect_swapped (self->view_addin_signals,
-                                    "color-found",
-                                    G_CALLBACK (gb_color_picker_editor_addin_color_found),
-                                    self);
-
-  dzl_signal_group_connect_swapped (self->view_addin_signals,
-                                    "notify::enabled",
-                                    G_CALLBACK (gb_color_picker_editor_addin_notify_enabled),
-                                    self);
 
-  gb_color_picker_editor_addin_init_palettes (self);
+  sidebar = ide_editor_perspective_get_transient_sidebar (self->editor);
+  gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (self->dock));
 }
 
+
 static void
 gb_color_picker_editor_addin_unload (IdeEditorAddin       *addin,
                                      IdeEditorPerspective *perspective)


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