[gimp] Bug 599573 - Remember dialog defaults between Gimp sessions



commit 8132d51b29d66f062715672f027b24740f380756
Author: Michael Natterer <mitch gimp org>
Date:   Wed Aug 24 18:27:49 2016 +0200

    Bug 599573 - Remember dialog defaults between Gimp sessions
    
    Remember the "New Channel" dialog settings in GimpDialogConfig.

 app/actions/channels-commands.c  |   88 ++++++++++++++++++++------------------
 app/config/gimpdialogconfig.c    |   50 ++++++++++++++++++++-
 app/config/gimpdialogconfig.h    |    3 +
 app/config/gimprc-blurbs.h       |    6 +++
 app/dialogs/preferences-dialog.c |   44 +++++++++++++++---
 5 files changed, 139 insertions(+), 52 deletions(-)
---
diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c
index 9b977d2..2c7745d 100644
--- a/app/actions/channels-commands.c
+++ b/app/actions/channels-commands.c
@@ -28,6 +28,9 @@
 
 #include "actions-types.h"
 
+#include "config/gimpdialogconfig.h"
+
+#include "core/gimp.h"
 #include "core/gimpchannel.h"
 #include "core/gimpchannel-select.h"
 #include "core/gimpcontext.h"
@@ -59,12 +62,6 @@ static void   channels_edit_channel_response (GtkWidget            *widget,
                                               ChannelOptionsDialog *options);
 
 
-/*  private variables  */
-
-static gchar   *channel_name  = NULL;
-static GimpRGB  channel_color = { 0.0, 0.0, 0.0, 0.5 };
-
-
 /*  public functions  */
 
 void
@@ -106,15 +103,17 @@ channels_new_cmd_callback (GtkAction *action,
   ChannelOptionsDialog *options;
   GimpImage            *image;
   GtkWidget            *widget;
+  GimpDialogConfig     *config;
   return_if_no_image (image, data);
   return_if_no_widget (widget, data);
 
+  config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
   options = channel_options_dialog_new (image, NULL,
                                         action_data_get_context (data),
                                         widget,
-                                        &channel_color,
-                                        channel_name ? channel_name :
-                                        _("Channel"),
+                                        &config->channel_new_color,
+                                        config->channel_new_name,
                                         _("New Channel"),
                                         "gimp-channel-new",
                                         GIMP_STOCK_CHANNEL,
@@ -135,12 +134,15 @@ void
 channels_new_last_vals_cmd_callback (GtkAction *action,
                                      gpointer   data)
 {
-  GimpImage   *image;
-  GimpChannel *new_channel;
-  gint         width, height;
-  GimpRGB      color;
+  GimpImage        *image;
+  GimpChannel      *new_channel;
+  gint              width, height;
+  GimpRGB           color;
+  GimpDialogConfig *config;
   return_if_no_image (image, data);
 
+  config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
   if (GIMP_IS_CHANNEL (GIMP_ACTION (action)->viewable))
     {
       GimpChannel *template = GIMP_CHANNEL (GIMP_ACTION (action)->viewable);
@@ -153,14 +155,14 @@ channels_new_last_vals_cmd_callback (GtkAction *action,
     {
       width  = gimp_image_get_width (image);
       height = gimp_image_get_height (image);
-      color  = channel_color;
+      color  = config->channel_new_color;
     }
 
   gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
                                _("New Channel"));
 
   new_channel = gimp_channel_new (image, width, height,
-                                  channel_name, &color);
+                                  config->channel_new_name, &color);
 
   gimp_drawable_fill (GIMP_DRAWABLE (new_channel),
                       action_data_get_context (data),
@@ -325,52 +327,56 @@ channels_to_selection_cmd_callback (GtkAction *action,
 static void
 channels_new_channel_response (GtkWidget            *widget,
                                gint                  response_id,
-                               ChannelOptionsDialog *options)
+                               ChannelOptionsDialog *dialog)
 {
   if (response_id == GTK_RESPONSE_OK)
     {
-      GimpChannel *new_channel;
-
-      if (channel_name)
-        g_free (channel_name);
+      GimpDialogConfig *config;
+      GimpChannel      *channel;
+      GimpRGB           channel_color;
 
-      channel_name =
-        g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
+      config = GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
 
-      gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
+      gimp_color_button_get_color (GIMP_COLOR_BUTTON (dialog->color_panel),
                                    &channel_color);
 
-      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (options->save_sel_checkbutton)))
+      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 (options->image);
+          GimpChannel *selection = gimp_image_get_mask (dialog->image);
 
-          new_channel =
-            GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
-                                               GIMP_TYPE_CHANNEL));
+          channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
+                                                      GIMP_TYPE_CHANNEL));
 
-          gimp_object_set_name (GIMP_OBJECT (new_channel), channel_name);
-          gimp_channel_set_color (new_channel, &channel_color, FALSE);
+          gimp_object_set_name (GIMP_OBJECT (channel),
+                               config->channel_new_name);
+          gimp_channel_set_color (channel, &config->channel_new_color, FALSE);
         }
       else
         {
-          new_channel = gimp_channel_new (options->image,
-                                          gimp_image_get_width  (options->image),
-                                          gimp_image_get_height (options->image),
-                                          channel_name,
-                                          &channel_color);
-
-          gimp_drawable_fill (GIMP_DRAWABLE (new_channel),
-                              options->context,
+          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 (options->image, new_channel,
+      gimp_image_add_channel (dialog->image, channel,
                               GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
 
-      gimp_image_flush (options->image);
+      gimp_image_flush (dialog->image);
     }
 
-  gtk_widget_destroy (options->dialog);
+  gtk_widget_destroy (dialog->dialog);
 }
 
 static void
diff --git a/app/config/gimpdialogconfig.c b/app/config/gimpdialogconfig.c
index 5520433..c89d81c 100644
--- a/app/config/gimpdialogconfig.c
+++ b/app/config/gimpdialogconfig.c
@@ -20,9 +20,12 @@
 
 #include "config.h"
 
-#include <gio/gio.h>
+#include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpcolor/gimpcolor.h"
 #include "libgimpconfig/gimpconfig.h"
 
 #include "config-types.h"
@@ -42,7 +45,10 @@ enum
   PROP_LAYER_NEW_FILL_TYPE,
 
   PROP_LAYER_ADD_MASK_TYPE,
-  PROP_LAYER_ADD_MASK_INVERT
+  PROP_LAYER_ADD_MASK_INVERT,
+
+  PROP_CHANNEL_NEW_NAME,
+  PROP_CHANNEL_NEW_COLOR
 };
 
 
@@ -65,7 +71,8 @@ G_DEFINE_TYPE (GimpDialogConfig, gimp_dialog_config, GIMP_TYPE_GUI_CONFIG)
 static void
 gimp_dialog_config_class_init (GimpDialogConfigClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class     = G_OBJECT_CLASS (klass);
+  GimpRGB       half_transparent = { 0.0, 0.0, 0.0, 0.5 };
 
   object_class->finalize     = gimp_dialog_config_finalize;
   object_class->set_property = gimp_dialog_config_set_property;
@@ -108,6 +115,21 @@ gimp_dialog_config_class_init (GimpDialogConfigClass *klass)
                             LAYER_ADD_MASK_INVERT_BLURB,
                             FALSE,
                             GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_STRING (object_class, PROP_CHANNEL_NEW_NAME,
+                           "channel-new-name",
+                           "Default new channel name",
+                           CHANNEL_NEW_NAME_BLURB,
+                           _("Channel"),
+                           GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_RGB (object_class, PROP_CHANNEL_NEW_COLOR,
+                        "channel-new-color",
+                        "Default new channel color and opacity",
+                        CHANNEL_NEW_COLOR_BLURB,
+                        TRUE,
+                        &half_transparent,
+                        GIMP_PARAM_STATIC_STRINGS);
 }
 
 static void
@@ -126,6 +148,12 @@ gimp_dialog_config_finalize (GObject *object)
       config->layer_new_name = NULL;
     }
 
+  if (config->channel_new_name)
+    {
+      g_free (config->channel_new_name);
+      config->channel_new_name = NULL;
+    }
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -159,6 +187,15 @@ gimp_dialog_config_set_property (GObject      *object,
       config->layer_add_mask_invert = g_value_get_boolean (value);
       break;
 
+    case PROP_CHANNEL_NEW_NAME:
+      if (config->channel_new_name)
+        g_free (config->channel_new_name);
+      config->channel_new_name = g_value_dup_string (value);
+      break;
+    case PROP_CHANNEL_NEW_COLOR:
+      gimp_value_get_rgb (value, &config->channel_new_color);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -193,6 +230,13 @@ gimp_dialog_config_get_property (GObject    *object,
       g_value_set_boolean (value, config->layer_add_mask_invert);
       break;
 
+    case PROP_CHANNEL_NEW_NAME:
+      g_value_set_string (value, config->channel_new_name);
+      break;
+    case PROP_CHANNEL_NEW_COLOR:
+      gimp_value_set_rgb (value, &config->channel_new_color);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
diff --git a/app/config/gimpdialogconfig.h b/app/config/gimpdialogconfig.h
index eb4d6cc..b9360c2 100644
--- a/app/config/gimpdialogconfig.h
+++ b/app/config/gimpdialogconfig.h
@@ -44,6 +44,9 @@ struct _GimpDialogConfig
 
   GimpAddMaskType         layer_add_mask_type;
   gboolean                layer_add_mask_invert;
+
+  gchar                  *channel_new_name;
+  GimpRGB                 channel_new_color;
 };
 
 struct _GimpDialogConfigClass
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 98dfdcc..1017e69 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -432,6 +432,12 @@ _("Sets the default mask for the 'Add Layer Mask' dialog.")
 #define LAYER_ADD_MASK_INVERT_BLURB \
 _("Sets the default 'invert mask' state for the 'Add Layer Mask' dialog.")
 
+#define CHANNEL_NEW_NAME_BLURB \
+_("Sets the default channel name for the 'New Channel' dialog.")
+
+#define CHANNEL_NEW_COLOR_BLURB \
+_("Sets the default color and opacity for the 'New Channel' dialog.")
+
 #define THUMBNAIL_SIZE_BLURB \
 _("Sets the size of the thumbnail shown in the Open dialog.")
 
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index deded09..2804557 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -891,11 +891,22 @@ prefs_color_button_add (GObject      *config,
                         gint          table_row,
                         GtkSizeGroup *group)
 {
-  GtkWidget *button = gimp_prop_color_button_new (config, property_name,
-                                                  title,
-                                                  COLOR_BUTTON_WIDTH,
-                                                  COLOR_BUTTON_HEIGHT,
-                                                  GIMP_COLOR_AREA_FLAT);
+  GtkWidget  *button;
+  GParamSpec *pspec;
+  gboolean    has_alpha;
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
+                                        property_name);
+
+  has_alpha = gimp_param_spec_rgb_has_alpha (pspec);
+
+  button = gimp_prop_color_button_new (config, property_name,
+                                       title,
+                                       COLOR_BUTTON_WIDTH,
+                                       COLOR_BUTTON_HEIGHT,
+                                       has_alpha ?
+                                       GIMP_COLOR_AREA_SMALL_CHECKS :
+                                       GIMP_COLOR_AREA_FLAT);
 
   if (button)
     prefs_widget_add_aligned (button, label, table, table_row, TRUE, group);
@@ -1102,9 +1113,9 @@ prefs_display_options_frame_add (Gimp         *gimp,
 
 static void
 prefs_behavior_options_frame_add (Gimp         *gimp,
-                                 GObject      *object,
-                                 const gchar  *label,
-                                 GtkContainer *parent)
+                                  GObject      *object,
+                                  const gchar  *label,
+                                  GtkContainer *parent)
 {
   GtkWidget *vbox;
   GtkWidget *hbox;
@@ -2062,6 +2073,23 @@ prefs_dialog_new (Gimp       *gimp,
                           _("Invert mask"),
                           GTK_BOX (vbox2));
 
+  /*  New Channel Dialog  */
+  vbox2 = prefs_frame_new (_("New Channel Dialog"),
+                           GTK_CONTAINER (vbox), FALSE);
+  table = prefs_table_new (2, GTK_CONTAINER (vbox2));
+
+  entry = gimp_prop_entry_new (object, "channel-new-name", -1);
+  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
+                             _("Channel name:"), 0.0, 0.5,
+                             entry, 1, FALSE);
+
+  button = prefs_color_button_add (object, "channel-new-color",
+                                   _("Color and opacity:"),
+                                   _("Default New Channel Color and Opacity"),
+                                   GTK_TABLE (table), 1, size_group);
+  gimp_color_panel_set_context (GIMP_COLOR_PANEL (button),
+                                gimp_get_user_context (gimp));
+
   g_object_unref (size_group);
 
 


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