Bug 599573 - Remember dialog defaults between Gimp sessions

Remember the "Feather Selection", "Grow Selection", "Shrink Selection"
and "Border Selection" dialog settings in GimpDialogConfig.
This commit is contained in:
Michael Natterer 2016-08-26 15:43:25 +02:00
parent bbe6b3828d
commit dfa390fd95
5 changed files with 296 additions and 77 deletions

View file

@ -25,6 +25,8 @@
#include "actions-types.h"
#include "config/gimpdialogconfig.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
@ -68,17 +70,6 @@ static void select_shrink_callback (GtkWidget *widget,
gpointer data);
/* private variables */
static gdouble select_feather_radius = 5.0;
static gint select_grow_pixels = 1;
static gint select_shrink_pixels = 1;
static gboolean select_shrink_edge_lock = FALSE;
static gint select_border_radius = 5;
static GimpChannelBorderStyle select_border_style = GIMP_CHANNEL_BORDER_STYLE_SMOOTH;
static gboolean select_border_edge_lock = FALSE;
/* public functions */
void
@ -144,14 +135,16 @@ void
select_feather_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
GimpImage *image;
GtkWidget *dialog;
gdouble xres;
gdouble yres;
GimpDisplay *display;
GimpImage *image;
GimpDialogConfig *config;
GtkWidget *dialog;
gdouble xres;
gdouble yres;
return_if_no_display (display, data);
image = gimp_display_get_image (display);
image = gimp_display_get_image (display);
config = GIMP_DIALOG_CONFIG (image->gimp->config);
gimp_image_get_resolution (image, &xres, &yres);
@ -160,7 +153,7 @@ select_feather_cmd_callback (GtkAction *action,
gimp_standard_help_func,
GIMP_HELP_SELECTION_FEATHER,
_("Feather selection by"),
select_feather_radius, 0, 32767, 3,
config->selection_feather_radius, 0, 32767, 3,
gimp_display_get_shell (display)->unit,
MIN (xres, yres),
FALSE,
@ -184,15 +177,17 @@ void
select_shrink_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
GimpImage *image;
GtkWidget *dialog;
GtkWidget *button;
gdouble xres;
gdouble yres;
GimpDisplay *display;
GimpImage *image;
GimpDialogConfig *config;
GtkWidget *dialog;
GtkWidget *button;
gdouble xres;
gdouble yres;
return_if_no_display (display, data);
image = gimp_display_get_image (display);
image = gimp_display_get_image (display);
config = GIMP_DIALOG_CONFIG (image->gimp->config);
gimp_image_get_resolution (image, &xres, &yres);
@ -201,7 +196,7 @@ select_shrink_cmd_callback (GtkAction *action,
gimp_standard_help_func,
GIMP_HELP_SELECTION_SHRINK,
_("Shrink selection by"),
select_shrink_pixels, 1, 32767, 0,
config->selection_shrink_radius, 1, 32767, 0,
gimp_display_get_shell (display)->unit,
MIN (xres, yres),
FALSE,
@ -216,7 +211,7 @@ select_shrink_cmd_callback (GtkAction *action,
"continued outside the image."),
NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
select_shrink_edge_lock);
config->selection_shrink_edge_lock);
gtk_box_pack_start (GTK_BOX (GIMP_QUERY_BOX_VBOX (dialog)), button,
FALSE, FALSE, 0);
gtk_widget_show (button);
@ -228,14 +223,16 @@ void
select_grow_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
GimpImage *image;
GtkWidget *dialog;
gdouble xres;
gdouble yres;
GimpDisplay *display;
GimpImage *image;
GimpDialogConfig *config;
GtkWidget *dialog;
gdouble xres;
gdouble yres;
return_if_no_display (display, data);
image = gimp_display_get_image (display);
image = gimp_display_get_image (display);
config = GIMP_DIALOG_CONFIG (image->gimp->config);
gimp_image_get_resolution (image, &xres, &yres);
@ -244,7 +241,7 @@ select_grow_cmd_callback (GtkAction *action,
gimp_standard_help_func,
GIMP_HELP_SELECTION_GROW,
_("Grow selection by"),
select_grow_pixels, 1, 32767, 0,
config->selection_grow_radius, 1, 32767, 0,
gimp_display_get_shell (display)->unit,
MIN (xres, yres),
FALSE,
@ -257,16 +254,18 @@ void
select_border_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
GimpImage *image;
GtkWidget *dialog;
GtkWidget *combo;
GtkWidget *button;
gdouble xres;
gdouble yres;
GimpDisplay *display;
GimpImage *image;
GimpDialogConfig *config;
GtkWidget *dialog;
GtkWidget *combo;
GtkWidget *button;
gdouble xres;
gdouble yres;
return_if_no_display (display, data);
image = gimp_display_get_image (display);
image = gimp_display_get_image (display);
config = GIMP_DIALOG_CONFIG (image->gimp->config);
gimp_image_get_resolution (image, &xres, &yres);
@ -275,7 +274,7 @@ select_border_cmd_callback (GtkAction *action,
gimp_standard_help_func,
GIMP_HELP_SELECTION_BORDER,
_("Border selection by"),
select_border_radius, 1, 32767, 0,
config->selection_border_radius, 1, 32767, 0,
gimp_display_get_shell (display)->unit,
MIN (xres, yres),
FALSE,
@ -291,7 +290,7 @@ select_border_cmd_callback (GtkAction *action,
g_object_set_data (G_OBJECT (dialog), "border-style-combo", combo);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo),
select_border_style);
config->selection_border_style);
gtk_widget_show (combo);
/* Edge lock button */
@ -302,7 +301,7 @@ select_border_cmd_callback (GtkAction *action,
"continued outside the image."),
NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
select_border_edge_lock);
config->selection_border_edge_lock);
gtk_box_pack_start (GTK_BOX (GIMP_QUERY_BOX_VBOX (dialog)), button,
FALSE, FALSE, 0);
gtk_widget_show (button);
@ -504,11 +503,17 @@ select_feather_callback (GtkWidget *widget,
GimpUnit unit,
gpointer data)
{
GimpImage *image = GIMP_IMAGE (data);
gdouble radius_x;
gdouble radius_y;
GimpImage *image = GIMP_IMAGE (data);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
gdouble radius_x;
gdouble radius_y;
radius_x = radius_y = select_feather_radius = size;
g_object_set (config,
"selection-feather-radius", size,
NULL);
radius_x = config->selection_feather_radius;
radius_y = config->selection_feather_radius;
if (unit != GIMP_UNIT_PIXEL)
{
@ -537,23 +542,28 @@ select_border_callback (GtkWidget *widget,
GimpUnit unit,
gpointer data)
{
GimpImage *image = GIMP_IMAGE (data);
GtkWidget *style_combo = g_object_get_data (G_OBJECT (widget),
"border-style-combo");
GtkWidget *edge_lock_button = g_object_get_data (G_OBJECT (widget),
"edge-lock-toggle");
gdouble radius_x;
gdouble radius_y;
gint border_style;
GimpImage *image = GIMP_IMAGE (data);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
GtkWidget *combo;
GtkWidget *button;
gdouble radius_x;
gdouble radius_y;
gint border_style;
radius_x = radius_y = select_border_radius = ROUND (size);
combo = g_object_get_data (G_OBJECT (widget), "border-style-combo");
button = g_object_get_data (G_OBJECT (widget), "edge-lock-toggle");
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (style_combo),
&border_style))
select_border_style = (GimpChannelBorderStyle) border_style;
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo), &border_style);
select_border_edge_lock =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (edge_lock_button));
g_object_set (config,
"selection-border-radius", size,
"selection-border-style", border_style,
"selection-border-edge-lock",
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)),
NULL);
radius_x = ROUND (config->selection_border_radius);
radius_y = ROUND (config->selection_border_radius);
if (unit != GIMP_UNIT_PIXEL)
{
@ -573,7 +583,9 @@ select_border_callback (GtkWidget *widget,
}
gimp_channel_border (gimp_image_get_mask (image), radius_x, radius_y,
select_border_style, select_border_edge_lock, TRUE);
config->selection_border_style,
config->selection_border_edge_lock,
TRUE);
gimp_image_flush (image);
}
@ -583,11 +595,17 @@ select_grow_callback (GtkWidget *widget,
GimpUnit unit,
gpointer data)
{
GimpImage *image = GIMP_IMAGE (data);
gdouble radius_x;
gdouble radius_y;
GimpImage *image = GIMP_IMAGE (data);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
gdouble radius_x;
gdouble radius_y;
radius_x = radius_y = select_grow_pixels = ROUND (size);
g_object_set (config,
"selection-grow-radius", size,
NULL);
radius_x = ROUND (config->selection_grow_radius);
radius_y = ROUND (config->selection_grow_radius);
if (unit != GIMP_UNIT_PIXEL)
{
@ -616,15 +634,22 @@ select_shrink_callback (GtkWidget *widget,
GimpUnit unit,
gpointer data)
{
GimpImage *image = GIMP_IMAGE (data);
GtkWidget *button = g_object_get_data (G_OBJECT (widget), "edge-lock-toggle");
gint radius_x;
gint radius_y;
GimpImage *image = GIMP_IMAGE (data);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
GtkWidget *button;
gint radius_x;
gint radius_y;
radius_x = radius_y = select_shrink_pixels = ROUND (size);
button = g_object_get_data (G_OBJECT (widget), "edge-lock-toggle");
select_shrink_edge_lock =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
g_object_set (config,
"selection-shrink-radius", size,
"selection-shrink-edge-lock",
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)),
NULL);
radius_x = ROUND (config->selection_shrink_radius);
radius_y = ROUND (config->selection_shrink_radius);
if (unit != GIMP_UNIT_PIXEL)
{
@ -644,6 +669,7 @@ select_shrink_callback (GtkWidget *widget,
}
gimp_channel_shrink (gimp_image_get_mask (image), radius_x, radius_y,
select_shrink_edge_lock, TRUE);
config->selection_shrink_edge_lock,
TRUE);
gimp_image_flush (image);
}

View file

@ -50,7 +50,18 @@ enum
PROP_CHANNEL_NEW_NAME,
PROP_CHANNEL_NEW_COLOR,
PROP_VECTORS_NEW_NAME
PROP_VECTORS_NEW_NAME,
PROP_SELECTION_FEATHER_RADIUS,
PROP_SELECTION_GROW_RADIUS,
PROP_SELECTION_SHRINK_RADIUS,
PROP_SELECTION_SHRINK_EDGE_LOCK,
PROP_SELECTION_BORDER_RADIUS,
PROP_SELECTION_BORDER_STYLE,
PROP_SELECTION_BORDER_EDGE_LOCK
};
@ -139,6 +150,56 @@ gimp_dialog_config_class_init (GimpDialogConfigClass *klass)
VECTORS_NEW_NAME_BLURB,
_("Path"),
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_SELECTION_FEATHER_RADIUS,
"selection-feather-radius",
"Selection feather radius",
SELECTION_FEATHER_RADIUS_BLURB,
0.0, 32767.0, 5.0,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_SELECTION_GROW_RADIUS,
"selection-grow-radius",
"Selection grow radius",
SELECTION_GROW_RADIUS_BLURB,
1.0, 32767.0, 1.0,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_SELECTION_SHRINK_RADIUS,
"selection-shrink-radius",
"Selection shrink radius",
SELECTION_SHRINK_RADIUS_BLURB,
1.0, 32767.0, 1.0,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SELECTION_SHRINK_EDGE_LOCK,
"selection-shrink-edge-lock",
"Selection shrink edge lock",
SELECTION_SHRINK_EDGE_LOCK_BLURB,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_SELECTION_BORDER_RADIUS,
"selection-border-radius",
"Selection border radius",
SELECTION_BORDER_RADIUS_BLURB,
1.0, 32767.0, 5.0,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SELECTION_BORDER_EDGE_LOCK,
"selection-border-edge-lock",
"Selection border edge lock",
SELECTION_BORDER_EDGE_LOCK_BLURB,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_SELECTION_BORDER_STYLE,
"selection-border-style",
"Selection border style",
SELECTION_BORDER_STYLE_BLURB,
GIMP_TYPE_CHANNEL_BORDER_STYLE,
GIMP_CHANNEL_BORDER_STYLE_SMOOTH,
GIMP_PARAM_STATIC_STRINGS);
}
static void
@ -217,6 +278,31 @@ gimp_dialog_config_set_property (GObject *object,
config->vectors_new_name = g_value_dup_string (value);
break;
case PROP_SELECTION_FEATHER_RADIUS:
config->selection_feather_radius = g_value_get_double (value);
break;
case PROP_SELECTION_GROW_RADIUS:
config->selection_grow_radius = g_value_get_double (value);
break;
case PROP_SELECTION_SHRINK_RADIUS:
config->selection_shrink_radius = g_value_get_double (value);
break;
case PROP_SELECTION_SHRINK_EDGE_LOCK:
config->selection_shrink_edge_lock = g_value_get_boolean (value);
break;
case PROP_SELECTION_BORDER_RADIUS:
config->selection_border_radius = g_value_get_double (value);
break;
case PROP_SELECTION_BORDER_EDGE_LOCK:
config->selection_border_edge_lock = g_value_get_boolean (value);
break;
case PROP_SELECTION_BORDER_STYLE:
config->selection_border_style = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -262,6 +348,31 @@ gimp_dialog_config_get_property (GObject *object,
g_value_set_string (value, config->vectors_new_name);
break;
case PROP_SELECTION_FEATHER_RADIUS:
g_value_set_double (value, config->selection_feather_radius);
break;
case PROP_SELECTION_GROW_RADIUS:
g_value_set_double (value, config->selection_grow_radius);
break;
case PROP_SELECTION_SHRINK_RADIUS:
g_value_set_double (value, config->selection_shrink_radius);
break;
case PROP_SELECTION_SHRINK_EDGE_LOCK:
g_value_set_boolean (value, config->selection_shrink_edge_lock);
break;
case PROP_SELECTION_BORDER_RADIUS:
g_value_set_double (value, config->selection_border_radius);
break;
case PROP_SELECTION_BORDER_EDGE_LOCK:
g_value_set_boolean (value, config->selection_border_edge_lock);
break;
case PROP_SELECTION_BORDER_STYLE:
g_value_set_enum (value, config->selection_border_style);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;

View file

@ -49,6 +49,17 @@ struct _GimpDialogConfig
GimpRGB channel_new_color;
gchar *vectors_new_name;
gdouble selection_feather_radius;
gdouble selection_grow_radius;
gdouble selection_shrink_radius;
gboolean selection_shrink_edge_lock;
gdouble selection_border_radius;
gboolean selection_border_edge_lock;
GimpChannelBorderStyle selection_border_style;
};
struct _GimpDialogConfigClass

View file

@ -441,6 +441,29 @@ _("Sets the default color and opacity for the 'New Channel' dialog.")
#define VECTORS_NEW_NAME_BLURB \
_("Sets the default path name for the 'New Path' dialog.")
#define SELECTION_FEATHER_RADIUS_BLURB \
_("Sets the default feather radius for the 'Feather Selection' dialog.")
#define SELECTION_GROW_RADIUS_BLURB \
_("Sets the default grow radius for the 'Grow Selection' dialog.")
#define SELECTION_SHRINK_RADIUS_BLURB \
_("Sets the default shrink radius for the 'Shrink Selection' dialog.")
#define SELECTION_SHRINK_EDGE_LOCK_BLURB \
_("Sets the default 'Selected areas continue outside the image' setting " \
"for the 'Shrink Selection' dialog.")
#define SELECTION_BORDER_RADIUS_BLURB \
_("Sets the default border radius for the 'Border Selection' dialog.")
#define SELECTION_BORDER_EDGE_LOCK_BLURB \
_("Sets the default 'Selected areas continue outside the image' setting " \
"for the 'Border Selection' dialog.")
#define SELECTION_BORDER_STYLE_BLURB \
_("Sets the default border style for the 'Border Selection' dialog.")
#define THUMBNAIL_SIZE_BLURB \
_("Sets the size of the thumbnail shown in the Open dialog.")

View file

@ -2100,6 +2100,54 @@ prefs_dialog_new (Gimp *gimp,
GTK_TABLE (table), 0, FALSE,
size_group);
/* Feather Selection Dialog */
vbox2 = prefs_frame_new (_("Feather Selection Dialog"),
GTK_CONTAINER (vbox), FALSE);
table = prefs_table_new (1, GTK_CONTAINER (vbox2));
prefs_spin_button_add (object, "selection-feather-radius", 1.0, 10.0, 2,
_("Feather radius:"),
GTK_TABLE (table), 0, size_group);
/* Grow Selection Dialog */
vbox2 = prefs_frame_new (_("Grow Selection Dialog"),
GTK_CONTAINER (vbox), FALSE);
table = prefs_table_new (1, GTK_CONTAINER (vbox2));
prefs_spin_button_add (object, "selection-grow-radius", 1.0, 10.0, 0,
_("Grow radius:"),
GTK_TABLE (table), 0, size_group);
/* Shrink Selection Dialog */
vbox2 = prefs_frame_new (_("Shrink Selection Dialog"),
GTK_CONTAINER (vbox), FALSE);
table = prefs_table_new (1, GTK_CONTAINER (vbox2));
prefs_spin_button_add (object, "selection-shrink-radius", 1.0, 10.0, 0,
_("Shrink radius:"),
GTK_TABLE (table), 0, size_group);
prefs_check_button_add (object, "selection-shrink-edge-lock",
_("Selected areas continue outside the image"),
GTK_BOX (vbox2));
/* Border Selection Dialog */
vbox2 = prefs_frame_new (_("Border Selection Dialog"),
GTK_CONTAINER (vbox), FALSE);
table = prefs_table_new (2, GTK_CONTAINER (vbox2));
prefs_spin_button_add (object, "selection-border-radius", 1.0, 10.0, 0,
_("Border radius:"),
GTK_TABLE (table), 0, size_group);
prefs_enum_combo_box_add (object, "selection-border-style", 0, 0,
_("Border style:"),
GTK_TABLE (table), 1, size_group);
prefs_check_button_add (object, "selection-border-edge-lock",
_("Selected areas continue outside the image"),
GTK_BOX (vbox2));
g_object_unref (size_group);