libgimp, plug-ins: variosu gimp_*_chooser_new() should use specific type…

… for default value.

Don't use the generic GimpResource which implies that we could set any
GimpResource (which of course makes no sense).
This commit is contained in:
Jehan 2024-09-27 16:30:47 +02:00
parent d49077569d
commit bd287d6f89
14 changed files with 78 additions and 72 deletions

View file

@ -156,9 +156,9 @@ gimp_brush_chooser_finalize (GObject *object)
/** /**
* gimp_brush_chooser_new: * gimp_brush_chooser_new:
* @title: (nullable): Title of the dialog to use or %NULL to use the default title. * @title: (nullable): Title of the dialog to use or %NULL to use the default title.
* @label: (nullable): Button label or %NULL for no label. * @label: (nullable): Button label or %NULL for no label.
* @resource: (nullable): Initial brush. * @brush: (nullable): Initial brush.
* *
* Creates a new #GtkWidget that lets a user choose a brush. * Creates a new #GtkWidget that lets a user choose a brush.
* You can put this widget in a plug-in dialog. * You can put this widget in a plug-in dialog.
@ -170,25 +170,27 @@ gimp_brush_chooser_finalize (GObject *object)
* Since: 2.4 * Since: 2.4
*/ */
GtkWidget * GtkWidget *
gimp_brush_chooser_new (const gchar *title, gimp_brush_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource) GimpBrush *brush)
{ {
GtkWidget *self; GtkWidget *self;
if (resource == NULL) g_return_val_if_fail (brush == NULL || GIMP_IS_BRUSH (brush), NULL);
resource = GIMP_RESOURCE (gimp_context_get_brush ());
if (brush == NULL)
brush = gimp_context_get_brush ();
if (title) if (title)
self = g_object_new (GIMP_TYPE_BRUSH_CHOOSER, self = g_object_new (GIMP_TYPE_BRUSH_CHOOSER,
"title", title, "title", title,
"label", label, "label", label,
"resource", resource, "resource", brush,
NULL); NULL);
else else
self = g_object_new (GIMP_TYPE_BRUSH_CHOOSER, self = g_object_new (GIMP_TYPE_BRUSH_CHOOSER,
"label", label, "label", label,
"resource", resource, "resource", brush,
NULL); NULL);
return self; return self;

View file

@ -33,9 +33,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GimpBrushChooser, gimp_brush_chooser, GIMP, BRUSH_CHOOSER, GimpResourceChooser) G_DECLARE_FINAL_TYPE (GimpBrushChooser, gimp_brush_chooser, GIMP, BRUSH_CHOOSER, GimpResourceChooser)
GtkWidget * gimp_brush_chooser_new (const gchar *title, GtkWidget * gimp_brush_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource); GimpBrush *brush);
G_END_DECLS G_END_DECLS

View file

@ -115,9 +115,9 @@ gimp_font_chooser_draw_interior (GimpResourceChooser *self)
/** /**
* gimp_font_chooser_new: * gimp_font_chooser_new:
* @title: (nullable): Title of the dialog to use or %NULL to use the default title. * @title: (nullable): Title of the dialog to use or %NULL to use the default title.
* @label: (nullable): Button label or %NULL for no label. * @label: (nullable): Button label or %NULL for no label.
* @resource: (nullable): Initial font. * @font: (nullable): Initial font.
* *
* Creates a new #GtkWidget that lets a user choose a font. * Creates a new #GtkWidget that lets a user choose a font.
* You can put this widget in a plug-in dialog. * You can put this widget in a plug-in dialog.
@ -131,25 +131,25 @@ gimp_font_chooser_draw_interior (GimpResourceChooser *self)
GtkWidget * GtkWidget *
gimp_font_chooser_new (const gchar *title, gimp_font_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource) GimpFont *font)
{ {
GtkWidget *chooser; GtkWidget *chooser;
g_return_val_if_fail (resource == NULL || GIMP_IS_FONT (resource), NULL); g_return_val_if_fail (font == NULL || GIMP_IS_FONT (font), NULL);
if (resource == NULL) if (font == NULL)
resource = GIMP_RESOURCE (gimp_context_get_font ()); font = gimp_context_get_font ();
if (title) if (title)
chooser = g_object_new (GIMP_TYPE_FONT_CHOOSER, chooser = g_object_new (GIMP_TYPE_FONT_CHOOSER,
"title", title, "title", title,
"label", label, "label", label,
"resource", resource, "resource", font,
NULL); NULL);
else else
chooser = g_object_new (GIMP_TYPE_FONT_CHOOSER, chooser = g_object_new (GIMP_TYPE_FONT_CHOOSER,
"label", label, "label", label,
"resource", resource, "resource", font,
NULL); NULL);
gimp_font_chooser_draw_interior (GIMP_RESOURCE_CHOOSER (chooser)); gimp_font_chooser_draw_interior (GIMP_RESOURCE_CHOOSER (chooser));

View file

@ -33,9 +33,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GimpFontChooser, gimp_font_chooser, GIMP, FONT_CHOOSER, GimpResourceChooser) G_DECLARE_FINAL_TYPE (GimpFontChooser, gimp_font_chooser, GIMP, FONT_CHOOSER, GimpResourceChooser)
GtkWidget * gimp_font_chooser_new (const gchar *title, GtkWidget * gimp_font_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource); GimpFont *font);
G_END_DECLS G_END_DECLS

View file

@ -172,22 +172,24 @@ gimp_gradient_chooser_draw_interior (GimpResourceChooser *self)
GtkWidget * GtkWidget *
gimp_gradient_chooser_new (const gchar *title, gimp_gradient_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *gradient) GimpGradient *gradient)
{ {
GtkWidget *self; GtkWidget *self;
g_return_val_if_fail (gradient == NULL || GIMP_IS_GRADIENT (gradient), NULL);
if (gradient == NULL) if (gradient == NULL)
gradient = GIMP_RESOURCE (gimp_context_get_gradient ()); gradient = gimp_context_get_gradient ();
if (title) if (title)
self = g_object_new (GIMP_TYPE_GRADIENT_CHOOSER, self = g_object_new (GIMP_TYPE_GRADIENT_CHOOSER,
"title", title, "title", title,
"label", label, "label", label,
"resource", gradient, "resource", gradient,
NULL); NULL);
else else
self = g_object_new (GIMP_TYPE_GRADIENT_CHOOSER, self = g_object_new (GIMP_TYPE_GRADIENT_CHOOSER,
"label", label, "label", label,
"resource", gradient, "resource", gradient,
NULL); NULL);

View file

@ -35,7 +35,7 @@ G_DECLARE_FINAL_TYPE (GimpGradientChooser, gimp_gradient_chooser, GIMP, GRADIENT
GtkWidget * gimp_gradient_chooser_new (const gchar *title, GtkWidget * gimp_gradient_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *gradient); GimpGradient *gradient);
G_END_DECLS G_END_DECLS

View file

@ -113,9 +113,9 @@ gimp_palette_chooser_draw_interior (GimpResourceChooser *self)
/** /**
* gimp_palette_chooser_new: * gimp_palette_chooser_new:
* @title: (nullable): Title of the dialog to use or %NULL to use the default title. * @title: (nullable): Title of the dialog to use or %NULL to use the default title.
* @label: (nullable): Button label or %NULL for no label. * @label: (nullable): Button label or %NULL for no label.
* @resource: (nullable): Initial palette. * @palette: (nullable): Initial palette.
* *
* Creates a new #GtkWidget that lets a user choose a palette. * Creates a new #GtkWidget that lets a user choose a palette.
* You can put this widget in a table in a plug-in dialog. * You can put this widget in a table in a plug-in dialog.
@ -127,25 +127,27 @@ gimp_palette_chooser_draw_interior (GimpResourceChooser *self)
* Since: 2.4 * Since: 2.4
*/ */
GtkWidget * GtkWidget *
gimp_palette_chooser_new (const gchar *title, gimp_palette_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource) GimpPalette *palette)
{ {
GtkWidget *self; GtkWidget *self;
if (resource == NULL) g_return_val_if_fail (palette == NULL || GIMP_IS_PALETTE (palette), NULL);
resource = GIMP_RESOURCE (gimp_context_get_palette ());
if (palette == NULL)
palette = gimp_context_get_palette ();
if (title) if (title)
self = g_object_new (GIMP_TYPE_PALETTE_CHOOSER, self = g_object_new (GIMP_TYPE_PALETTE_CHOOSER,
"title", title, "title", title,
"label", label, "label", label,
"resource", resource, "resource", palette,
NULL); NULL);
else else
self = g_object_new (GIMP_TYPE_PALETTE_CHOOSER, self = g_object_new (GIMP_TYPE_PALETTE_CHOOSER,
"label", label, "label", label,
"resource", resource, "resource", palette,
NULL); NULL);
gimp_palette_chooser_draw_interior (GIMP_RESOURCE_CHOOSER (self)); gimp_palette_chooser_draw_interior (GIMP_RESOURCE_CHOOSER (self));

View file

@ -33,9 +33,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GimpPaletteChooser, gimp_palette_chooser, GIMP, PALETTE_CHOOSER, GimpResourceChooser) G_DECLARE_FINAL_TYPE (GimpPaletteChooser, gimp_palette_chooser, GIMP, PALETTE_CHOOSER, GimpResourceChooser)
GtkWidget * gimp_palette_chooser_new (const gchar *title, GtkWidget * gimp_palette_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource); GimpPalette *palette);
G_END_DECLS G_END_DECLS

View file

@ -138,9 +138,9 @@ gimp_pattern_chooser_init (GimpPatternChooser *self)
/** /**
* gimp_pattern_chooser_new: * gimp_pattern_chooser_new:
* @title: (nullable): Title of the dialog to use or %NULL to use the default title. * @title: (nullable): Title of the dialog to use or %NULL to use the default title.
* @label: (nullable): Button label or %NULL for no label. * @label: (nullable): Button label or %NULL for no label.
* @resource: (nullable): Initial pattern. * @pattern: (nullable): Initial pattern.
* *
* Creates a new #GtkWidget that lets a user choose a pattern. * Creates a new #GtkWidget that lets a user choose a pattern.
* You can put this widget in a table in a plug-in dialog. * You can put this widget in a table in a plug-in dialog.
@ -152,26 +152,27 @@ gimp_pattern_chooser_init (GimpPatternChooser *self)
* Since: 2.4 * Since: 2.4
*/ */
GtkWidget * GtkWidget *
gimp_pattern_chooser_new (const gchar *title, gimp_pattern_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource) GimpPattern *pattern)
{ {
GtkWidget *self; GtkWidget *self;
if (resource == NULL) g_return_val_if_fail (pattern == NULL || GIMP_IS_PATTERN (pattern), NULL);
resource = GIMP_RESOURCE (gimp_context_get_pattern ());
g_return_val_if_fail (GIMP_IS_PATTERN (resource), NULL); if (pattern == NULL)
pattern = gimp_context_get_pattern ();
if (title) if (title)
self = g_object_new (GIMP_TYPE_PATTERN_CHOOSER, self = g_object_new (GIMP_TYPE_PATTERN_CHOOSER,
"title", title, "title", title,
"label", label, "label", label,
"resource", resource, "resource", pattern,
NULL); NULL);
else else
self = g_object_new (GIMP_TYPE_PATTERN_CHOOSER, self = g_object_new (GIMP_TYPE_PATTERN_CHOOSER,
"label", label, "label", label,
"resource", resource, "resource", pattern,
NULL); NULL);
gimp_pattern_chooser_draw (GIMP_RESOURCE_CHOOSER (self)); gimp_pattern_chooser_draw (GIMP_RESOURCE_CHOOSER (self));

View file

@ -33,9 +33,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GimpPatternChooser, gimp_pattern_chooser, GIMP, PATTERN_CHOOSER, GimpResourceChooser) G_DECLARE_FINAL_TYPE (GimpPatternChooser, gimp_pattern_chooser, GIMP, PATTERN_CHOOSER, GimpResourceChooser)
GtkWidget * gimp_pattern_chooser_new (const gchar *title, GtkWidget * gimp_pattern_chooser_new (const gchar *title,
const gchar *label, const gchar *label,
GimpResource *resource); GimpPattern *pattern);
G_END_DECLS G_END_DECLS

View file

@ -58,7 +58,7 @@ gimp_prop_brush_chooser_new (GObject *config,
const gchar *property_name, const gchar *property_name,
const gchar *chooser_title) const gchar *chooser_title)
{ {
return gimp_prop_resource_chooser_factory (gimp_brush_chooser_new, return gimp_prop_resource_chooser_factory ((GimpResourceWidgetCreator) gimp_brush_chooser_new,
config, property_name, chooser_title); config, property_name, chooser_title);
} }
@ -79,7 +79,7 @@ gimp_prop_font_chooser_new (GObject *config,
const gchar *property_name, const gchar *property_name,
const gchar *chooser_title) const gchar *chooser_title)
{ {
return gimp_prop_resource_chooser_factory (gimp_font_chooser_new, return gimp_prop_resource_chooser_factory ((GimpResourceWidgetCreator) gimp_font_chooser_new,
config, property_name, chooser_title); config, property_name, chooser_title);
} }
@ -100,7 +100,7 @@ gimp_prop_gradient_chooser_new (GObject *config,
const gchar *property_name, const gchar *property_name,
const gchar *chooser_title) const gchar *chooser_title)
{ {
return gimp_prop_resource_chooser_factory (gimp_gradient_chooser_new, return gimp_prop_resource_chooser_factory ((GimpResourceWidgetCreator) gimp_gradient_chooser_new,
config, property_name, chooser_title); config, property_name, chooser_title);
} }
@ -121,7 +121,7 @@ gimp_prop_palette_chooser_new (GObject *config,
const gchar *property_name, const gchar *property_name,
const gchar *chooser_title) const gchar *chooser_title)
{ {
return gimp_prop_resource_chooser_factory (gimp_palette_chooser_new, return gimp_prop_resource_chooser_factory ((GimpResourceWidgetCreator) gimp_palette_chooser_new,
config, property_name, chooser_title); config, property_name, chooser_title);
} }
@ -142,7 +142,7 @@ gimp_prop_pattern_chooser_new (GObject *config,
const gchar *property_name, const gchar *property_name,
const gchar *chooser_title) const gchar *chooser_title)
{ {
return gimp_prop_resource_chooser_factory (gimp_pattern_chooser_new, return gimp_prop_resource_chooser_factory ((GimpResourceWidgetCreator) gimp_pattern_chooser_new,
config, property_name, chooser_title); config, property_name, chooser_title);
} }

View file

@ -944,8 +944,7 @@ explorer_dialog (GimpProcedure *procedure,
/* Pass NULL to set local gradient data from context. */ /* Pass NULL to set local gradient data from context. */
set_grad_data_cache (NULL, n_colors); set_grad_data_cache (NULL, n_colors);
gradient_button = gimp_gradient_chooser_new (_("FractalExplorer Gradient"), gradient_button = gimp_gradient_chooser_new (_("FractalExplorer Gradient"), NULL, gradient);
NULL, GIMP_RESOURCE (gradient));
g_signal_connect_swapped (gradient_button, "resource-set", g_signal_connect_swapped (gradient_button, "resource-set",
G_CALLBACK (explorer_gradient_select_callback), config); G_CALLBACK (explorer_gradient_select_callback), config);
gtk_box_pack_start (GTK_BOX (hbox), gradient_button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), gradient_button, TRUE, TRUE, 0);

View file

@ -506,7 +506,7 @@ gfig_dialog (GimpGfig *gfig)
/* brush selector in Stroke frame */ /* brush selector in Stroke frame */
gfig_context->brush_select gfig_context->brush_select
= gimp_brush_chooser_new (_("Brush"), _("Brush"), = gimp_brush_chooser_new (_("Brush"), _("Brush"),
GIMP_RESOURCE (gfig_context->default_style.brush)); gfig_context->default_style.brush);
g_signal_connect (gfig_context->brush_select, "resource-set", g_signal_connect (gfig_context->brush_select, "resource-set",
G_CALLBACK (gfig_brush_changed_callback), NULL); G_CALLBACK (gfig_brush_changed_callback), NULL);
gtk_box_pack_start (GTK_BOX (vbox), gfig_context->brush_select, gtk_box_pack_start (GTK_BOX (vbox), gfig_context->brush_select,
@ -570,7 +570,7 @@ gfig_dialog (GimpGfig *gfig)
/* A page for the pattern selector */ /* A page for the pattern selector */
gfig_context->pattern_select gfig_context->pattern_select
= gimp_pattern_chooser_new (_("Pattern"), _("Pattern"), = gimp_pattern_chooser_new (_("Pattern"), _("Pattern"),
GIMP_RESOURCE (gfig_context->default_style.pattern)); gfig_context->default_style.pattern);
g_signal_connect (gfig_context->pattern_select, "resource-set", g_signal_connect (gfig_context->pattern_select, "resource-set",
G_CALLBACK (gfig_pattern_changed_callback), NULL); G_CALLBACK (gfig_pattern_changed_callback), NULL);
gtk_widget_show (gfig_context->pattern_select); gtk_widget_show (gfig_context->pattern_select);
@ -580,7 +580,7 @@ gfig_dialog (GimpGfig *gfig)
/* A page for the gradient selector */ /* A page for the gradient selector */
gfig_context->gradient_select gfig_context->gradient_select
= gimp_gradient_chooser_new (_("Gradient"), _("Gradient"), = gimp_gradient_chooser_new (_("Gradient"), _("Gradient"),
GIMP_RESOURCE (gfig_context->default_style.gradient)); gfig_context->default_style.gradient);
g_signal_connect (gfig_context->gradient_select, "resource-set", g_signal_connect (gfig_context->gradient_select, "resource-set",
G_CALLBACK (gfig_gradient_changed_callback), NULL); G_CALLBACK (gfig_gradient_changed_callback), NULL);
gtk_widget_show (gfig_context->gradient_select); gtk_widget_show (gfig_context->gradient_select);

View file

@ -551,23 +551,23 @@ script_fu_resource_widget (const gchar *title,
initial_value = sf_resource_arg_get_value (arg); initial_value = sf_resource_arg_get_value (arg);
if (g_type_is_a (resource_type, GIMP_TYPE_FONT)) if (g_type_is_a (resource_type, GIMP_TYPE_FONT))
{ {
result_widget = gimp_font_chooser_new (title, "", initial_value); result_widget = gimp_font_chooser_new (title, "", GIMP_FONT (initial_value));
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH)) else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{ {
result_widget = gimp_brush_chooser_new (title, "", initial_value); result_widget = gimp_brush_chooser_new (title, "", GIMP_BRUSH (initial_value));
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_GRADIENT)) else if (g_type_is_a (resource_type, GIMP_TYPE_GRADIENT))
{ {
result_widget = gimp_gradient_chooser_new (title, "", initial_value); result_widget = gimp_gradient_chooser_new (title, "", GIMP_GRADIENT (initial_value));
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE)) else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE))
{ {
result_widget = gimp_palette_chooser_new (title, "", initial_value); result_widget = gimp_palette_chooser_new (title, "", GIMP_PALETTE (initial_value));
} }
else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN)) else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN))
{ {
result_widget = gimp_pattern_chooser_new (title, "", initial_value); result_widget = gimp_pattern_chooser_new (title, "", GIMP_PATTERN (initial_value));
} }
else else
{ {