diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index 5086deaff8..42c9b6c591 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -2263,7 +2263,35 @@ image_set_file_invoker (GimpProcedure *procedure, if (success) { - gimp_image_set_file (image, file); + gchar *uri; + gchar *folded_uri; + gchar *folded_ext; + + uri = g_file_get_uri (file); + folded_uri = g_utf8_casefold (uri, -1); + folded_ext = g_utf8_casefold (".xcf", -1); + + if (! g_str_has_suffix (folded_uri, folded_ext)) + { + gchar *dot = g_strrstr (uri, "."); + + if (dot != NULL && strstr (dot + 1, G_DIR_SEPARATOR_S) == NULL) + g_printerr ("%s: failure to set file '%s' with extension '%s'. " + "The extension must be '.xcf'.\n", + "gimp_image_set_file", uri, dot + 1); + else + g_printerr ("%s: failure to set file '%s' without extension. " + "The extension must be '.xcf'.\n", + "gimp_image_set_file", uri); + + success = FALSE; + } + if (success) + gimp_image_set_file (image, file); + + g_free (uri); + g_free (folded_uri); + g_free (folded_ext); } return gimp_procedure_get_return_values (procedure, success, @@ -4968,8 +4996,9 @@ register_image_procs (GimpPDB *pdb) gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-image-set-file"); gimp_procedure_set_static_help (procedure, - "Sets the specified image's file.", - "This procedure sets the specified image's file.", + "Sets the specified XCF image's file.", + "This procedure sets the specified image's file.\n" + "This is to set the XCF file associated with your image. In particular, do not use this function to set the imported file in file import plug-ins. This is done by the core process.", NULL); gimp_procedure_set_static_attribution (procedure, "Spencer Kimball & Peter Mattis", diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 4a3d9d19ec..9c59564c52 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -2615,9 +2615,12 @@ gimp_image_get_file (GimpImage *image) * @image: The image. * @file: The new image file. * - * Sets the specified image's file. + * Sets the specified XCF image's file. * * This procedure sets the specified image's file. + * This is to set the XCF file associated with your image. In + * particular, do not use this function to set the imported file in + * file import plug-ins. This is done by the core process. * * Returns: TRUE on success. **/ diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index 26abaa43f6..8d228b4ab3 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -2322,10 +2322,14 @@ CODE } sub image_set_file { - $blurb = "Sets the specified image's file."; + $blurb = "Sets the specified XCF image's file."; $help = <<'HELP'; This procedure sets the specified image's file. + +This is to set the XCF file associated with your image. In particular, do not +use this function to set the imported file in file import plug-ins. This is done +by the core process. HELP &std_pdb_misc; @@ -2340,7 +2344,35 @@ HELP %invoke = ( code => <<'CODE' { - gimp_image_set_file (image, file); + gchar *uri; + gchar *folded_uri; + gchar *folded_ext; + + uri = g_file_get_uri (file); + folded_uri = g_utf8_casefold (uri, -1); + folded_ext = g_utf8_casefold (".xcf", -1); + + if (! g_str_has_suffix (folded_uri, folded_ext)) + { + gchar *dot = g_strrstr (uri, "."); + + if (dot != NULL && strstr (dot + 1, G_DIR_SEPARATOR_S) == NULL) + g_printerr ("%s: failure to set file '%s' with extension '%s'. " + "The extension must be '.xcf'.\n", + "gimp_image_set_file", uri, dot + 1); + else + g_printerr ("%s: failure to set file '%s' without extension. " + "The extension must be '.xcf'.\n", + "gimp_image_set_file", uri); + + success = FALSE; + } + if (success) + gimp_image_set_file (image, file); + + g_free (uri); + g_free (folded_uri); + g_free (folded_ext); } CODE );