[gimp] app: make the ChannelOptionsDialog private



commit e703f8482e16a4d9ea1298ce40d9930c9fbc01b2
Author: Michael Natterer <mitch gimp org>
Date:   Sat Sep 24 22:10:32 2016 +0200

    app: make the ChannelOptionsDialog private
    
    and provide a custom callback instead. Also attach the "New Layer",
    "Edit Layer Attributes" and "Configure Quick Mask" dialogs to their
    image/channel.

 app/actions/channels-commands.c      |  266 ++++++++++++++++++----------------
 app/actions/quick-mask-commands.c    |  102 +++++++------
 app/dialogs/channel-options-dialog.c |  192 ++++++++++++++++--------
 app/dialogs/channel-options-dialog.h |   55 ++++----
 4 files changed, 349 insertions(+), 266 deletions(-)
---
diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c
index 068e1e2..8e2d51d 100644
--- a/app/actions/channels-commands.c
+++ b/app/actions/channels-commands.c
@@ -44,6 +44,7 @@
 #include "widgets/gimpdock.h"
 #include "widgets/gimphelp-ids.h"
 
+#include "dialogs/dialogs.h"
 #include "dialogs/channel-options-dialog.h"
 
 #include "actions.h"
@@ -54,12 +55,22 @@
 
 /*  local function prototypes  */
 
-static void   channels_new_channel_response  (GtkWidget            *widget,
-                                              gint                  response_id,
-                                              ChannelOptionsDialog *options);
-static void   channels_edit_channel_response (GtkWidget            *widget,
-                                              gint                  response_id,
-                                              ChannelOptionsDialog *options);
+static void   channels_new_callback             (GtkWidget     *dialog,
+                                                 GimpImage     *image,
+                                                 GimpChannel   *channel,
+                                                 GimpContext   *context,
+                                                 const gchar   *channel_name,
+                                                 const GimpRGB *channel_color,
+                                                 gboolean       save_selection,
+                                                 gpointer       user_data);
+static void   channels_edit_attributes_callback (GtkWidget     *dialog,
+                                                 GimpImage     *image,
+                                                 GimpChannel   *channel,
+                                                 GimpContext   *context,
+                                                 const gchar   *channel_name,
+                                                 const GimpRGB *channel_color,
+                                                 gboolean       save_selection,
+                                                 gpointer       user_data);
 
 
 /*  public functions  */
@@ -68,66 +79,79 @@ void
 channels_edit_attributes_cmd_callback (GtkAction *action,
                                        gpointer   data)
 {
-  ChannelOptionsDialog *options;
-  GimpImage            *image;
-  GimpChannel          *channel;
-  GtkWidget            *widget;
+  GimpImage   *image;
+  GimpChannel *channel;
+  GtkWidget   *widget;
+  GtkWidget   *dialog;
   return_if_no_channel (image, channel, data);
   return_if_no_widget (widget, data);
 
-  options = channel_options_dialog_new (image, channel,
-                                        action_data_get_context (data),
-                                        widget,
-                                        _("Channel Attributes"),
-                                        "gimp-channel-edit",
-                                        "gtk-edit",
-                                        _("Edit Channel Attributes"),
-                                        GIMP_HELP_CHANNEL_EDIT,
-                                        &channel->color,
-                                        gimp_object_get_name (channel),
-                                        _("Edit Channel Color"),
-                                        _("_Fill opacity:"),
-                                        FALSE);
-
-  g_signal_connect (options->dialog, "response",
-                    G_CALLBACK (channels_edit_channel_response),
-                    options);
-
-  gtk_widget_show (options->dialog);
+#define EDIT_DIALOG_KEY "gimp-channel-edit-attributes-dialog"
+
+  dialog = dialogs_get_dialog (G_OBJECT (channel), EDIT_DIALOG_KEY);
+
+  if (! dialog)
+    {
+      dialog = channel_options_dialog_new (image, channel,
+                                           action_data_get_context (data),
+                                           widget,
+                                           _("Channel Attributes"),
+                                           "gimp-channel-edit",
+                                           "gtk-edit",
+                                           _("Edit Channel Attributes"),
+                                           GIMP_HELP_CHANNEL_EDIT,
+                                           gimp_object_get_name (channel),
+                                           &channel->color,
+                                           _("Edit Channel Color"),
+                                           _("_Fill opacity:"),
+                                           FALSE,
+                                           channels_edit_attributes_callback,
+                                           NULL);
+
+      dialogs_attach_dialog (G_OBJECT (channel), EDIT_DIALOG_KEY, dialog);
+    }
+
+  gtk_window_present (GTK_WINDOW (dialog));
 }
 
 void
 channels_new_cmd_callback (GtkAction *action,
                            gpointer   data)
 {
-  ChannelOptionsDialog *options;
-  GimpImage            *image;
-  GtkWidget            *widget;
-  GimpDialogConfig     *config;
+  GimpImage *image;
+  GtkWidget *widget;
+  GtkWidget *dialog;
   return_if_no_image (image, data);
   return_if_no_widget (widget, data);
 
-  config = GIMP_DIALOG_CONFIG (image->gimp->config);
+#define NEW_DIALOG_KEY "gimp-channel-new-dialog"
+
+  dialog = dialogs_get_dialog (G_OBJECT (image), NEW_DIALOG_KEY);
+
+  if (! dialog)
+    {
+      GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
+      dialog = channel_options_dialog_new (image, NULL,
+                                           action_data_get_context (data),
+                                           widget,
+                                           _("New Channel"),
+                                           "gimp-channel-new",
+                                           GIMP_STOCK_CHANNEL,
+                                           _("New Channel Options"),
+                                           GIMP_HELP_CHANNEL_NEW,
+                                           config->channel_new_name,
+                                           &config->channel_new_color,
+                                           _("New Channel Color"),
+                                           _("_Fill opacity:"),
+                                           TRUE,
+                                           channels_new_callback,
+                                           NULL);
+
+      dialogs_attach_dialog (G_OBJECT (image), NEW_DIALOG_KEY, dialog);
+    }
 
-  options = channel_options_dialog_new (image, NULL,
-                                        action_data_get_context (data),
-                                        widget,
-                                        _("New Channel"),
-                                        "gimp-channel-new",
-                                        GIMP_STOCK_CHANNEL,
-                                        _("New Channel Options"),
-                                        GIMP_HELP_CHANNEL_NEW,
-                                        &config->channel_new_color,
-                                        config->channel_new_name,
-                                        _("New Channel Color"),
-                                        _("_Fill opacity:"),
-                                        TRUE);
-
-  g_signal_connect (options->dialog, "response",
-                    G_CALLBACK (channels_new_channel_response),
-                    options);
-
-  gtk_widget_show (options->dialog);
+  gtk_window_present (GTK_WINDOW (dialog));
 }
 
 void
@@ -325,101 +349,89 @@ channels_to_selection_cmd_callback (GtkAction *action,
 /*  private functions  */
 
 static void
-channels_new_channel_response (GtkWidget            *widget,
-                               gint                  response_id,
-                               ChannelOptionsDialog *dialog)
+channels_new_callback (GtkWidget     *dialog,
+                       GimpImage     *image,
+                       GimpChannel   *channel,
+                       GimpContext   *context,
+                       const gchar   *channel_name,
+                       const GimpRGB *channel_color,
+                       gboolean       save_selection,
+                       gpointer       user_data)
 {
-  if (response_id == GTK_RESPONSE_OK)
+  GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
+  g_object_set (config,
+                "channel-new-name",  channel_name,
+                "channel-new-color", channel_color,
+                NULL);
+
+  if (save_selection)
     {
-      GimpDialogConfig *config;
-      GimpChannel      *channel;
-      GimpRGB           channel_color;
-
-      config = GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
-
-      gimp_color_button_get_color (GIMP_COLOR_BUTTON (dialog->color_panel),
-                                   &channel_color);
-
-      g_object_set (config,
-                    "channel-new-name",
-                    gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)),
-                   "channel-new-color", &channel_color,
-                    NULL);
-
-      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->save_sel_checkbutton)))
-        {
-          GimpChannel *selection = gimp_image_get_mask (dialog->image);
-
-          channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
-                                                      GIMP_TYPE_CHANNEL));
-
-          gimp_object_set_name (GIMP_OBJECT (channel),
-                               config->channel_new_name);
-          gimp_channel_set_color (channel, &config->channel_new_color, FALSE);
-        }
-      else
-        {
-          channel = gimp_channel_new (dialog->image,
-                                     gimp_image_get_width  (dialog->image),
-                                     gimp_image_get_height (dialog->image),
-                                     config->channel_new_name,
-                                     &config->channel_new_color);
-
-          gimp_drawable_fill (GIMP_DRAWABLE (channel),
-                              dialog->context,
-                              GIMP_FILL_TRANSPARENT);
-        }
-
-      gimp_image_add_channel (dialog->image, channel,
-                              GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
-
-      gimp_image_flush (dialog->image);
+      GimpChannel *selection = gimp_image_get_mask (image);
+
+      channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
+                                                   GIMP_TYPE_CHANNEL));
+
+      gimp_object_set_name (GIMP_OBJECT (channel),
+                            config->channel_new_name);
+      gimp_channel_set_color (channel, &config->channel_new_color, FALSE);
+    }
+  else
+    {
+      channel = gimp_channel_new (image,
+                                  gimp_image_get_width  (image),
+                                  gimp_image_get_height (image),
+                                  config->channel_new_name,
+                                  &config->channel_new_color);
+
+      gimp_drawable_fill (GIMP_DRAWABLE (channel), context,
+                          GIMP_FILL_TRANSPARENT);
     }
 
-  gtk_widget_destroy (dialog->dialog);
+  gimp_image_add_channel (image, channel,
+                          GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
+  gimp_image_flush (image);
+
+  gtk_widget_destroy (dialog);
 }
 
 static void
-channels_edit_channel_response (GtkWidget            *widget,
-                                gint                  response_id,
-                                ChannelOptionsDialog *options)
+channels_edit_attributes_callback (GtkWidget     *dialog,
+                                   GimpImage     *image,
+                                   GimpChannel   *channel,
+                                   GimpContext   *context,
+                                   const gchar   *channel_name,
+                                   const GimpRGB *channel_color,
+                                   gboolean       save_selection,
+                                   gpointer       user_data)
 {
-  if (response_id == GTK_RESPONSE_OK)
-    {
-      GimpChannel *channel = options->channel;
-      const gchar *new_name;
-      GimpRGB      color;
-      gboolean     name_changed  = FALSE;
-      gboolean     color_changed = FALSE;
+  gboolean name_changed  = FALSE;
+  gboolean color_changed = FALSE;
 
-      new_name = gtk_entry_get_text (GTK_ENTRY (options->name_entry));
+  if (strcmp (channel_name, gimp_object_get_name (channel)))
+    name_changed = TRUE;
 
-      gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
-                                   &color);
-
-      if (strcmp (new_name, gimp_object_get_name (channel)))
-        name_changed = TRUE;
-
-      if (gimp_rgba_distance (&color, &channel->color) > 0.0001)
-        color_changed = TRUE;
+  if (gimp_rgba_distance (channel_color, &channel->color) > 0.0001)
+    color_changed = TRUE;
 
+  if (name_changed || color_changed)
+    {
       if (name_changed && color_changed)
-        gimp_image_undo_group_start (options->image,
+        gimp_image_undo_group_start (image,
                                      GIMP_UNDO_GROUP_ITEM_PROPERTIES,
                                      _("Channel Attributes"));
 
       if (name_changed)
-        gimp_item_rename (GIMP_ITEM (channel), new_name, NULL);
+        gimp_item_rename (GIMP_ITEM (channel), channel_name, NULL);
 
       if (color_changed)
-        gimp_channel_set_color (channel, &color, TRUE);
+        gimp_channel_set_color (channel, channel_color, TRUE);
 
       if (name_changed && color_changed)
-        gimp_image_undo_group_end (options->image);
+        gimp_image_undo_group_end (image);
 
-      if (name_changed || color_changed)
-        gimp_image_flush (options->image);
+      gimp_image_flush (image);
     }
 
-  gtk_widget_destroy (options->dialog);
+  gtk_widget_destroy (dialog);
 }
diff --git a/app/actions/quick-mask-commands.c b/app/actions/quick-mask-commands.c
index fd8465a..910372b 100644
--- a/app/actions/quick-mask-commands.c
+++ b/app/actions/quick-mask-commands.c
@@ -32,6 +32,7 @@
 
 #include "widgets/gimphelp-ids.h"
 
+#include "dialogs/dialogs.h"
 #include "dialogs/channel-options-dialog.h"
 
 #include "actions.h"
@@ -42,9 +43,14 @@
 
 /*  local function prototypes  */
 
-static void   quick_mask_configure_response (GtkWidget            *widget,
-                                             gint                  response_id,
-                                             ChannelOptionsDialog *options);
+static void   quick_mask_configure_callback (GtkWidget     *dialog,
+                                             GimpImage     *image,
+                                             GimpChannel   *channel,
+                                             GimpContext   *context,
+                                             const gchar   *channel_name,
+                                             const GimpRGB *channel_color,
+                                             gboolean       save_selection,
+                                             gpointer       user_data);
 
 
 /*  public functionss */
@@ -88,60 +94,66 @@ void
 quick_mask_configure_cmd_callback (GtkAction *action,
                                    gpointer   data)
 {
-  ChannelOptionsDialog *options;
-  GimpImage            *image;
-  GtkWidget            *widget;
-  GimpRGB               color;
+  GimpImage *image;
+  GtkWidget *widget;
+  GtkWidget *dialog;
   return_if_no_image (image, data);
   return_if_no_widget (widget, data);
 
-  gimp_image_get_quick_mask_color (image, &color);
-
-  options = channel_options_dialog_new (image, NULL,
-                                        action_data_get_context (data),
-                                        widget,
-                                       _("Quick Mask Attributes"),
-                                        "gimp-quick-mask-edit",
-                                        GIMP_STOCK_QUICK_MASK_ON,
-                                        _("Edit Quick Mask Attributes"),
-                                        GIMP_HELP_QUICK_MASK_EDIT,
-                                        &color,
-                                        NULL,
-                                         _("Edit Quick Mask Color"),
-                                        _("_Mask opacity:"),
-                                        FALSE);
-
-  g_signal_connect (options->dialog, "response",
-                    G_CALLBACK (quick_mask_configure_response),
-                    options);
-
-  gtk_widget_show (options->dialog);
+#define CONFIGURE_DIALOG_KEY "gimp-image-quick-mask-configure-dialog"
+
+  dialog = dialogs_get_dialog (G_OBJECT (image), CONFIGURE_DIALOG_KEY);
+
+  if (! dialog)
+    {
+      GimpRGB color;
+
+      gimp_image_get_quick_mask_color (image, &color);
+
+      dialog = channel_options_dialog_new (image, NULL,
+                                           action_data_get_context (data),
+                                           widget,
+                                           _("Quick Mask Attributes"),
+                                           "gimp-quick-mask-edit",
+                                           GIMP_STOCK_QUICK_MASK_ON,
+                                           _("Edit Quick Mask Attributes"),
+                                           GIMP_HELP_QUICK_MASK_EDIT,
+                                           NULL,
+                                           &color,
+                                           _("Edit Quick Mask Color"),
+                                           _("_Mask opacity:"),
+                                           FALSE,
+                                           quick_mask_configure_callback,
+                                           NULL);
+
+      dialogs_attach_dialog (G_OBJECT (image), CONFIGURE_DIALOG_KEY, dialog);
+    }
+
+  gtk_window_present (GTK_WINDOW (dialog));
 }
 
 
 /*  private functions  */
 
 static void
-quick_mask_configure_response (GtkWidget            *widget,
-                               gint                  response_id,
-                               ChannelOptionsDialog *options)
+quick_mask_configure_callback (GtkWidget     *dialog,
+                               GimpImage     *image,
+                               GimpChannel   *channel,
+                               GimpContext   *context,
+                               const gchar   *channel_name,
+                               const GimpRGB *channel_color,
+                               gboolean       save_selection,
+                               gpointer       user_data)
 {
-  if (response_id == GTK_RESPONSE_OK)
-    {
-      GimpRGB old_color;
-      GimpRGB new_color;
-
-      gimp_image_get_quick_mask_color (options->image, &old_color);
-      gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
-                                   &new_color);
+  GimpRGB old_color;
 
-      if (gimp_rgba_distance (&old_color, &new_color) > 0.0001)
-        {
-          gimp_image_set_quick_mask_color (options->image, &new_color);
+  gimp_image_get_quick_mask_color (image, &old_color);
 
-          gimp_image_flush (options->image);
-        }
+  if (gimp_rgba_distance (&old_color, channel_color) > 0.0001)
+    {
+      gimp_image_set_quick_mask_color (image, channel_color);
+      gimp_image_flush (image);
     }
 
-  gtk_widget_destroy (options->dialog);
+  gtk_widget_destroy (dialog);
 }
diff --git a/app/dialogs/channel-options-dialog.c b/app/dialogs/channel-options-dialog.c
index 5c7f97a..96c653a 100644
--- a/app/dialogs/channel-options-dialog.c
+++ b/app/dialogs/channel-options-dialog.c
@@ -37,34 +37,56 @@
 #include "gimp-intl.h"
 
 
+typedef struct _ChannelOptionsDialog ChannelOptionsDialog;
+
+struct _ChannelOptionsDialog
+{
+  GimpImage                  *image;
+  GimpContext                *context;
+  GimpChannel                *channel;
+  GimpChannelOptionsCallback  callback;
+  gpointer                    user_data;
+
+  GtkWidget                  *name_entry;
+  GtkWidget                  *color_panel;
+  GtkWidget                  *save_sel_checkbutton;
+};
+
+
 /*  local function prototypes  */
 
-static void channel_options_opacity_update (GtkAdjustment        *adjustment,
-                                            gpointer              data);
-static void channel_options_color_changed  (GimpColorButton      *button,
-                                            gpointer              data);
-static void channel_options_dialog_free    (ChannelOptionsDialog *options);
+static void channel_options_dialog_response (GtkWidget            *dialog,
+                                             gint                  response_id,
+                                             ChannelOptionsDialog *private);
+static void channel_options_opacity_update  (GtkAdjustment        *adjustment,
+                                             GimpColorButton      *color_button);
+static void channel_options_color_changed   (GimpColorButton      *color_button,
+                                             GtkAdjustment        *adjustment);
+static void channel_options_dialog_free     (ChannelOptionsDialog *private);
 
 
 /*  public functions  */
 
-ChannelOptionsDialog *
-channel_options_dialog_new (GimpImage     *image,
-                            GimpChannel   *channel,
-                            GimpContext   *context,
-                            GtkWidget     *parent,
-                            const gchar   *title,
-                            const gchar   *role,
-                            const gchar   *icon_name,
-                            const gchar   *desc,
-                            const gchar   *help_id,
-                            const GimpRGB *channel_color,
-                            const gchar   *channel_name,
-                            const gchar   *color_label,
-                            const gchar   *opacity_label,
-                            gboolean       show_from_sel)
+GtkWidget *
+channel_options_dialog_new (GimpImage                  *image,
+                            GimpChannel                *channel,
+                            GimpContext                *context,
+                            GtkWidget                  *parent,
+                            const gchar                *title,
+                            const gchar                *role,
+                            const gchar                *icon_name,
+                            const gchar                *desc,
+                            const gchar                *help_id,
+                            const gchar                *channel_name,
+                            const GimpRGB              *channel_color,
+                            const gchar                *color_label,
+                            const gchar                *opacity_label,
+                            gboolean                    show_from_sel,
+                            GimpChannelOptionsCallback  callback,
+                            gpointer                    user_data)
 {
-  ChannelOptionsDialog *options;
+  ChannelOptionsDialog *private;
+  GtkWidget            *dialog;
   GimpViewable         *viewable;
   GtkWidget            *hbox;
   GtkWidget            *vbox;
@@ -83,48 +105,46 @@ channel_options_dialog_new (GimpImage     *image,
   g_return_val_if_fail (channel_color != NULL, NULL);
   g_return_val_if_fail (color_label != NULL, NULL);
   g_return_val_if_fail (opacity_label != NULL, NULL);
+  g_return_val_if_fail (callback != NULL, NULL);
 
-  options = g_slice_new0 (ChannelOptionsDialog);
-
-  options->image   = image;
-  options->context = context;
-  options->channel = channel;
+  private = g_slice_new0 (ChannelOptionsDialog);
 
-  options->color_panel = gimp_color_panel_new (color_label,
-                                               channel_color,
-                                               GIMP_COLOR_AREA_LARGE_CHECKS,
-                                               48, 64);
-  gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
-                                context);
+  private->image     = image;
+  private->channel   = channel;
+  private->context   = context;
+  private->callback  = callback;
+  private->user_data = user_data;
 
   if (channel)
     viewable = GIMP_VIEWABLE (channel);
   else
     viewable = GIMP_VIEWABLE (image);
 
-  options->dialog =
-    gimp_viewable_dialog_new (viewable, context,
-                              title, role, icon_name, desc,
-                              parent,
-                              gimp_standard_help_func, help_id,
-
-                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                              GTK_STOCK_OK,     GTK_RESPONSE_OK,
+  dialog = gimp_viewable_dialog_new (viewable, context,
+                                     title, role, icon_name, desc,
+                                     parent,
+                                     gimp_standard_help_func, help_id,
 
-                              NULL);
+                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                     GTK_STOCK_OK,     GTK_RESPONSE_OK,
 
-  g_object_weak_ref (G_OBJECT (options->dialog),
-                     (GWeakNotify) channel_options_dialog_free,
-                     options);
+                                     NULL);
 
-  gtk_dialog_set_alternative_button_order (GTK_DIALOG (options->dialog),
+  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                            GTK_RESPONSE_OK,
                                            GTK_RESPONSE_CANCEL,
                                            -1);
 
+  g_object_weak_ref (G_OBJECT (dialog),
+                     (GWeakNotify) channel_options_dialog_free, private);
+
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (channel_options_dialog_response),
+                    private);
+
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
-  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (options->dialog))),
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                       hbox, TRUE, TRUE, 0);
   gtk_widget_show (hbox);
 
@@ -140,13 +160,13 @@ channel_options_dialog_new (GimpImage     *image,
 
   if (channel_name)
     {
-      options->name_entry = gtk_entry_new ();
-      gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
+      private->name_entry = gtk_entry_new ();
+      gtk_entry_set_activates_default (GTK_ENTRY (private->name_entry), TRUE);
       gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
                                  _("Channel _name:"), 0.0, 0.5,
-                                 options->name_entry, 2, FALSE);
+                                 private->name_entry, 2, FALSE);
 
-      gtk_entry_set_text (GTK_ENTRY (options->name_entry), channel_name);
+      gtk_entry_set_text (GTK_ENTRY (private->name_entry), channel_name);
     }
 
   opacity_adj = gimp_scale_entry_new (GTK_TABLE (table),
@@ -157,54 +177,96 @@ channel_options_dialog_new (GimpImage     *image,
                                       TRUE, 0.0, 0.0,
                                       NULL, NULL);
 
+  private->color_panel = gimp_color_panel_new (color_label,
+                                               channel_color,
+                                               GIMP_COLOR_AREA_LARGE_CHECKS,
+                                               48, 64);
+  gimp_color_panel_set_context (GIMP_COLOR_PANEL (private->color_panel),
+                                context);
+
   g_signal_connect (opacity_adj, "value-changed",
                     G_CALLBACK (channel_options_opacity_update),
-                    options->color_panel);
+                    private->color_panel);
 
-  gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
+  gtk_box_pack_start (GTK_BOX (hbox), private->color_panel,
                       TRUE, TRUE, 0);
-  gtk_widget_show (options->color_panel);
+  gtk_widget_show (private->color_panel);
 
-  g_signal_connect (options->color_panel, "color-changed",
+  g_signal_connect (private->color_panel, "color-changed",
                     G_CALLBACK (channel_options_color_changed),
                     opacity_adj);
 
   if (show_from_sel)
     {
-      options->save_sel_checkbutton =
+      private->save_sel_checkbutton =
         gtk_check_button_new_with_mnemonic (_("Initialize from _selection"));
 
-      gtk_box_pack_start (GTK_BOX (vbox), options->save_sel_checkbutton,
+      gtk_box_pack_start (GTK_BOX (vbox), private->save_sel_checkbutton,
                           FALSE, FALSE, 0);
-      gtk_widget_show (options->save_sel_checkbutton);
+      gtk_widget_show (private->save_sel_checkbutton);
     }
 
-  return options;
+  return dialog;
 }
 
 
 /*  private functions  */
 
 static void
-channel_options_opacity_update (GtkAdjustment *adjustment,
-                                gpointer       data)
+channel_options_dialog_response (GtkWidget            *dialog,
+                                 gint                  response_id,
+                                 ChannelOptionsDialog *private)
+{
+  if (response_id == GTK_RESPONSE_OK)
+    {
+      const gchar *name           = NULL;
+      GimpRGB      color;
+      gboolean     save_selection = FALSE;
+
+      if (private->name_entry)
+        name = gtk_entry_get_text (GTK_ENTRY (private->name_entry));
+
+      gimp_color_button_get_color (GIMP_COLOR_BUTTON (private->color_panel),
+                                   &color);
+
+      if (private->save_sel_checkbutton)
+        save_selection =
+          gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (private->save_sel_checkbutton));
+
+      private->callback (dialog,
+                         private->image,
+                         private->channel,
+                         private->context,
+                         name,
+                         &color,
+                         save_selection,
+                         private->user_data);
+    }
+  else
+    {
+      gtk_widget_destroy (dialog);
+    }
+}
+
+static void
+channel_options_opacity_update (GtkAdjustment   *adjustment,
+                                GimpColorButton *color_button)
 {
   GimpRGB  color;
 
-  gimp_color_button_get_color (GIMP_COLOR_BUTTON (data), &color);
+  gimp_color_button_get_color (color_button, &color);
   gimp_rgb_set_alpha (&color, gtk_adjustment_get_value (adjustment) / 100.0);
-  gimp_color_button_set_color (GIMP_COLOR_BUTTON (data), &color);
+  gimp_color_button_set_color (color_button, &color);
 }
 
 static void
 channel_options_color_changed (GimpColorButton *button,
-                               gpointer         data)
+                               GtkAdjustment   *adjustment)
 {
-  GtkAdjustment *adj = GTK_ADJUSTMENT (data);
   GimpRGB        color;
 
   gimp_color_button_get_color (button, &color);
-  gtk_adjustment_set_value (adj, color.a * 100.0);
+  gtk_adjustment_set_value (adjustment, color.a * 100.0);
 }
 
 static void
diff --git a/app/dialogs/channel-options-dialog.h b/app/dialogs/channel-options-dialog.h
index be58065..a4952a8 100644
--- a/app/dialogs/channel-options-dialog.h
+++ b/app/dialogs/channel-options-dialog.h
@@ -19,35 +19,32 @@
 #define __CHANNEL_OPTIONS_DIALOG_H__
 
 
-typedef struct _ChannelOptionsDialog ChannelOptionsDialog;
-
-struct _ChannelOptionsDialog
-{
-  GtkWidget   *dialog;
-  GtkWidget   *name_entry;
-  GtkWidget   *color_panel;
-  GtkWidget   *save_sel_checkbutton;
-
-  GimpImage   *image;
-  GimpContext *context;
-  GimpChannel *channel;
-};
-
-
-ChannelOptionsDialog * channel_options_dialog_new (GimpImage     *image,
-                                                   GimpChannel   *channel,
-                                                   GimpContext   *context,
-                                                   GtkWidget     *parent,
-                                                   const gchar   *title,
-                                                   const gchar   *role,
-                                                   const gchar   *icon_name,
-                                                   const gchar   *desc,
-                                                   const gchar   *help_id,
-                                                   const GimpRGB *channel_color,
-                                                   const gchar   *channel_name,
-                                                   const gchar   *color_label,
-                                                   const gchar   *opacity_label,
-                                                   gboolean       show_from_sel);
+typedef void (* GimpChannelOptionsCallback) (GtkWidget     *dialog,
+                                             GimpImage     *image,
+                                             GimpChannel   *channel,
+                                             GimpContext   *context,
+                                             const gchar   *channel_name,
+                                             const GimpRGB *channel_color,
+                                             gboolean       save_selection,
+                                             gpointer       user_data);
+
+
+GtkWidget * channel_options_dialog_new (GimpImage                  *image,
+                                        GimpChannel                *channel,
+                                        GimpContext                *context,
+                                        GtkWidget                  *parent,
+                                        const gchar                *title,
+                                        const gchar                *role,
+                                        const gchar                *icon_name,
+                                        const gchar                *desc,
+                                        const gchar                *help_id,
+                                        const gchar                *channel_name,
+                                        const GimpRGB              *channel_color,
+                                        const gchar                *color_label,
+                                        const gchar                *opacity_label,
+                                        gboolean                    show_from_sel,
+                                        GimpChannelOptionsCallback  callback,
+                                        gpointer                    user_data);
 
 
 #endif /* __CHANNEL_OPTIONS_DIALOG_H__ */


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