Don't PDB-modify locked vectors

This commit is contained in:
Michael Natterer 2009-08-21 18:06:58 +02:00
parent 45aa584b3e
commit cb8a611e93
4 changed files with 102 additions and 79 deletions

View File

@ -461,20 +461,22 @@ gimp_pdb_image_is_not_base_type (GimpImage *image,
GimpStroke * GimpStroke *
gimp_pdb_get_vectors_stroke (GimpVectors *vectors, gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
gint stroke_ID, gint stroke_ID,
gboolean writable,
GError **error) GError **error)
{ {
GimpStroke *stroke; GimpStroke *stroke = NULL;
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL); g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
stroke = gimp_vectors_stroke_get_by_ID (vectors, stroke_ID); if (! writable || gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error))
if (! stroke)
{ {
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, stroke = gimp_vectors_stroke_get_by_ID (vectors, stroke_ID);
_("Vectors object %d does not contain stroke with ID %d"),
gimp_item_get_ID (GIMP_ITEM (vectors)), stroke_ID); if (! stroke)
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
_("Vectors object %d does not contain stroke with ID %d"),
gimp_item_get_ID (GIMP_ITEM (vectors)), stroke_ID);
} }
return stroke; return stroke;

View File

@ -70,6 +70,7 @@ gboolean gimp_pdb_image_is_not_base_type (GimpImage *image,
GimpStroke * gimp_pdb_get_vectors_stroke (GimpVectors *vectors, GimpStroke * gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
gint stroke_ID, gint stroke_ID,
gboolean writable,
GError **error); GError **error);

View File

@ -543,7 +543,7 @@ vectors_stroke_get_length_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (stroke) if (stroke)
length = gimp_stroke_get_length (stroke, precision); length = gimp_stroke_get_length (stroke, precision);
@ -586,7 +586,7 @@ vectors_stroke_get_point_at_dist_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (stroke) if (stroke)
{ {
@ -632,7 +632,7 @@ vectors_remove_stroke_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -668,7 +668,7 @@ vectors_stroke_close_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -708,7 +708,7 @@ vectors_stroke_translate_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -748,7 +748,7 @@ vectors_stroke_scale_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -790,7 +790,7 @@ vectors_stroke_rotate_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -830,7 +830,7 @@ vectors_stroke_flip_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -874,7 +874,7 @@ vectors_stroke_flip_free_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -915,7 +915,7 @@ vectors_stroke_get_points_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (GIMP_IS_BEZIER_STROKE (stroke)) if (GIMP_IS_BEZIER_STROKE (stroke))
{ {
@ -1055,7 +1055,7 @@ vectors_stroke_interpolate_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (stroke) if (stroke)
{ {
@ -1118,22 +1118,27 @@ vectors_bezier_stroke_new_moveto_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke; if (gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error))
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES; {
GimpStroke *stroke;
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
coord0.x = x0; coord0.x = x0;
coord0.y = y0; coord0.y = y0;
stroke = gimp_bezier_stroke_new_moveto (&coord0); stroke = gimp_bezier_stroke_new_moveto (&coord0);
if (gimp_item_is_attached (GIMP_ITEM (vectors))) if (gimp_item_is_attached (GIMP_ITEM (vectors)))
gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)), gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
_("Add path stroke"), _("Add path stroke"),
vectors); vectors);
gimp_vectors_stroke_add (vectors, stroke); gimp_vectors_stroke_add (vectors, stroke);
stroke_id = gimp_stroke_get_ID (stroke); stroke_id = gimp_stroke_get_ID (stroke);
}
else
success = FALSE;
} }
return_vals = gimp_procedure_get_return_values (procedure, success, return_vals = gimp_procedure_get_return_values (procedure, success,
@ -1166,7 +1171,7 @@ vectors_bezier_stroke_lineto_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -1215,7 +1220,7 @@ vectors_bezier_stroke_conicto_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -1272,7 +1277,7 @@ vectors_bezier_stroke_cubicto_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -1331,22 +1336,27 @@ vectors_bezier_stroke_new_ellipse_invoker (GimpProcedure *procedure,
if (success) if (success)
{ {
GimpStroke *stroke; if (gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error))
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES; {
GimpStroke *stroke;
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
coord0.x = x0; coord0.x = x0;
coord0.y = y0; coord0.y = y0;
stroke = gimp_bezier_stroke_new_ellipse (&coord0, radius_x, radius_y, angle); stroke = gimp_bezier_stroke_new_ellipse (&coord0, radius_x, radius_y, angle);
if (gimp_item_is_attached (GIMP_ITEM (vectors))) if (gimp_item_is_attached (GIMP_ITEM (vectors)))
gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)), gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
_("Add path stroke"), _("Add path stroke"),
vectors); vectors);
gimp_vectors_stroke_add (vectors, stroke); gimp_vectors_stroke_add (vectors, stroke);
stroke_id = gimp_stroke_get_ID (stroke); stroke_id = gimp_stroke_get_ID (stroke);
}
else
success = FALSE;
} }
return_vals = gimp_procedure_get_return_values (procedure, success, return_vals = gimp_procedure_get_return_values (procedure, success,

View File

@ -485,7 +485,7 @@ sub vectors_stroke_get_length {
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (stroke) if (stroke)
length = gimp_stroke_get_length (stroke, precision); length = gimp_stroke_get_length (stroke, precision);
@ -534,7 +534,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (stroke) if (stroke)
{ {
@ -571,7 +571,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -608,7 +608,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -650,7 +650,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -691,7 +691,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -733,7 +733,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -774,7 +774,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -820,7 +820,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -870,7 +870,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (GIMP_IS_BEZIER_STROKE (stroke)) if (GIMP_IS_BEZIER_STROKE (stroke))
{ {
@ -936,7 +936,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, FALSE, error);
if (stroke) if (stroke)
{ {
@ -1074,22 +1074,27 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke; if (gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error))
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES; {
GimpStroke *stroke;
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
coord0.x = x0; coord0.x = x0;
coord0.y = y0; coord0.y = y0;
stroke = gimp_bezier_stroke_new_moveto (&coord0); stroke = gimp_bezier_stroke_new_moveto (&coord0);
if (gimp_item_is_attached (GIMP_ITEM (vectors))) if (gimp_item_is_attached (GIMP_ITEM (vectors)))
gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)), gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
_("Add path stroke"), _("Add path stroke"),
vectors); vectors);
gimp_vectors_stroke_add (vectors, stroke); gimp_vectors_stroke_add (vectors, stroke);
stroke_id = gimp_stroke_get_ID (stroke); stroke_id = gimp_stroke_get_ID (stroke);
}
else
success = FALSE;
} }
CODE CODE
); );
@ -1118,7 +1123,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -1170,7 +1175,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -1228,7 +1233,7 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, error); GimpStroke *stroke = gimp_pdb_get_vectors_stroke (vectors, stroke_id, TRUE, error);
if (stroke) if (stroke)
{ {
@ -1292,22 +1297,27 @@ HELP
%invoke = ( %invoke = (
code => <<"CODE" code => <<"CODE"
{ {
GimpStroke *stroke; if (gimp_pdb_item_is_writable (GIMP_ITEM (vectors), error))
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES; {
GimpStroke *stroke;
GimpCoords coord0 = GIMP_COORDS_DEFAULT_VALUES;
coord0.x = x0; coord0.x = x0;
coord0.y = y0; coord0.y = y0;
stroke = gimp_bezier_stroke_new_ellipse (&coord0, radius_x, radius_y, angle); stroke = gimp_bezier_stroke_new_ellipse (&coord0, radius_x, radius_y, angle);
if (gimp_item_is_attached (GIMP_ITEM (vectors))) if (gimp_item_is_attached (GIMP_ITEM (vectors)))
gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)), gimp_image_undo_push_vectors_mod (gimp_item_get_image (GIMP_ITEM (vectors)),
_("Add path stroke"), _("Add path stroke"),
vectors); vectors);
gimp_vectors_stroke_add (vectors, stroke); gimp_vectors_stroke_add (vectors, stroke);
stroke_id = gimp_stroke_get_ID (stroke); stroke_id = gimp_stroke_get_ID (stroke);
}
else
success = FALSE;
} }
CODE CODE
); );