Commit 149888b5 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added new function gimp_data_factory_data_delete().

2004-06-01  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpdatafactory.[ch]: added new function
	gimp_data_factory_data_delete().

	* app/actions/data-commands.c (data_delete_callback): use it.

	* tools/pdbgen/pdb/gradients.pdb: applied (slightly modified)
	patch from Shlomi Fish which adds PDB wrappers to create, delete,
	duplicate and rename gradients.

	* app/pdb/gradients_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimpgradients_pdb.[ch]: regenerated.
parent c399ae1f
2004-06-01 Michael Natterer <mitch@gimp.org>
* app/core/gimpdatafactory.[ch]: added new function
gimp_data_factory_data_delete().
* app/actions/data-commands.c (data_delete_callback): use it.
* tools/pdbgen/pdb/gradients.pdb: applied (slightly modified)
patch from Shlomi Fish which adds PDB wrappers to create, delete,
duplicate and rename gradients.
* app/pdb/gradients_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimpgradients_pdb.[ch]: regenerated.
2004-06-01 Michael Natterer <mitch@gimp.org>
* app/core/core-enums.h: renamed the values of the
......
......@@ -134,26 +134,17 @@ data_delete_callback (GtkWidget *widget,
{
GimpDataDeleteData *delete_data = data;
if (delete && gimp_container_have (delete_data->factory->container,
GIMP_OBJECT (delete_data->data)))
if (delete)
{
g_object_ref (delete_data->data);
GError *error = NULL;
gimp_container_remove (delete_data->factory->container,
GIMP_OBJECT (delete_data->data));
if (delete_data->data->filename)
if (! gimp_data_factory_data_delete (delete_data->factory,
delete_data->data,
TRUE, &error))
{
GError *error = NULL;
if (! gimp_data_delete_from_disk (delete_data->data, &error))
{
g_message (error->message);
g_clear_error (&error);
}
g_message (error->message);
g_clear_error (&error);
}
g_object_unref (delete_data->data);
}
}
......
......@@ -428,6 +428,33 @@ gimp_data_factory_data_duplicate (GimpDataFactory *factory,
return new_data;
}
gboolean
gimp_data_factory_data_delete (GimpDataFactory *factory,
GimpData *data,
gboolean delete_from_disk,
GError **error)
{
gboolean retval = TRUE;
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), FALSE);
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (gimp_container_have (factory->container, GIMP_OBJECT (data)))
{
g_object_ref (data);
gimp_container_remove (factory->container, GIMP_OBJECT (data));
if (delete_from_disk && data->filename)
retval = gimp_data_delete_from_disk (data, error);
g_object_unref (data);
}
return retval;
}
GimpData *
gimp_data_factory_data_get_standard (GimpDataFactory *factory)
{
......
......@@ -87,18 +87,22 @@ GimpDataFactory * gimp_data_factory_new (Gimp *
GimpDataNewFunc new_func,
GimpDataGetStandardFunc standard_func);
void gimp_data_factory_data_init (GimpDataFactory *factory,
gboolean no_data);
void gimp_data_factory_data_save (GimpDataFactory *factory);
void gimp_data_factory_data_free (GimpDataFactory *factory);
GimpData * gimp_data_factory_data_new (GimpDataFactory *factory,
const gchar *name);
GimpData * gimp_data_factory_data_duplicate (GimpDataFactory *factory,
GimpData *data);
GimpData * gimp_data_factory_data_get_standard (GimpDataFactory *factory);
gboolean gimp_data_factory_data_save_single (GimpDataFactory *factory,
GimpData *data);
void gimp_data_factory_data_init (GimpDataFactory *factory,
gboolean no_data);
void gimp_data_factory_data_save (GimpDataFactory *factory);
void gimp_data_factory_data_free (GimpDataFactory *factory);
GimpData * gimp_data_factory_data_new (GimpDataFactory *factory,
const gchar *name);
GimpData * gimp_data_factory_data_duplicate (GimpDataFactory *factory,
GimpData *data);
gboolean gimp_data_factory_data_delete (GimpDataFactory *factory,
GimpData *data,
gboolean delete_from_disk,
GError **error);
GimpData * gimp_data_factory_data_get_standard (GimpDataFactory *factory);
gboolean gimp_data_factory_data_save_single (GimpDataFactory *factory,
GimpData *data);
#endif /* __GIMP_DATA_FACTORY_H__ */
......@@ -44,6 +44,10 @@ static ProcRecord gradients_set_gradient_proc;
static ProcRecord gradients_sample_uniform_proc;
static ProcRecord gradients_sample_custom_proc;
static ProcRecord gradients_get_gradient_data_proc;
static ProcRecord gradients_new_proc;
static ProcRecord gradients_duplicate_proc;
static ProcRecord gradients_delete_proc;
static ProcRecord gradients_rename_proc;
void
register_gradients_procs (Gimp *gimp)
......@@ -55,6 +59,10 @@ register_gradients_procs (Gimp *gimp)
procedural_db_register (gimp, &gradients_sample_uniform_proc);
procedural_db_register (gimp, &gradients_sample_custom_proc);
procedural_db_register (gimp, &gradients_get_gradient_data_proc);
procedural_db_register (gimp, &gradients_new_proc);
procedural_db_register (gimp, &gradients_duplicate_proc);
procedural_db_register (gimp, &gradients_delete_proc);
procedural_db_register (gimp, &gradients_rename_proc);
}
static Argument *
......@@ -582,3 +590,306 @@ static ProcRecord gradients_get_gradient_data_proc =
gradients_get_gradient_data_outargs,
{ { gradients_get_gradient_data_invoker } }
};
static Argument *
gradients_new_invoker (Gimp *gimp,
GimpContext *context,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *name;
GimpGradient * gradient = NULL;;
name = (gchar *) args[0].value.pdb_pointer;
if (name == NULL || !g_utf8_validate (name, -1, NULL))
success = FALSE;
if (success)
{
gradient = (GimpGradient *)
gimp_data_factory_data_new (gimp->gradient_factory, name);
}
return_args = procedural_db_return_args (&gradients_new_proc, success);
if (success)
return_args[1].value.pdb_pointer = g_strdup (GIMP_OBJECT (gradient)->name);
return return_args;
}
static ProcArg gradients_new_inargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The requested name of the new gradient"
}
};
static ProcArg gradients_new_outargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The actual new gradient name"
}
};
static ProcRecord gradients_new_proc =
{
"gimp_gradients_new",
"Creates a new gradient",
"This procedure creates a new, uninitialized gradient",
"Shlomi Fish",
"Shlomi Fish",
"2004",
GIMP_INTERNAL,
1,
gradients_new_inargs,
1,
gradients_new_outargs,
{ { gradients_new_invoker } }
};
static Argument *
gradients_duplicate_invoker (Gimp *gimp,
GimpContext *context,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *name;
GimpGradient *gradient = NULL;
GimpGradient *gradient_copy = NULL;
name = (gchar *) args[0].value.pdb_pointer;
if (name == NULL || !g_utf8_validate (name, -1, NULL))
success = FALSE;
if (success)
{
if (strlen (name))
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container,
name);
}
else
{
gradient = gimp_context_get_gradient (context);
}
if (gradient)
{
gradient_copy = (GimpGradient *)
gimp_data_factory_data_duplicate (gimp->gradient_factory,
GIMP_DATA (gradient));
success = (gradient_copy != NULL);
}
else
{
success = FALSE;
}
}
return_args = procedural_db_return_args (&gradients_duplicate_proc, success);
if (success)
return_args[1].value.pdb_pointer = g_strdup (GIMP_OBJECT (gradient_copy)->name);
return return_args;
}
static ProcArg gradients_duplicate_inargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The name of the gradient to duplicate"
}
};
static ProcArg gradients_duplicate_outargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The name of the gradient's copy"
}
};
static ProcRecord gradients_duplicate_proc =
{
"gimp_gradients_duplicate",
"Duplicates a gradient",
"This procedure creates an identical gradient by a different name",
"Shlomi Fish",
"Shlomi Fish",
"2004",
GIMP_INTERNAL,
1,
gradients_duplicate_inargs,
1,
gradients_duplicate_outargs,
{ { gradients_duplicate_invoker } }
};
static Argument *
gradients_delete_invoker (Gimp *gimp,
GimpContext *context,
Argument *args)
{
gboolean success = TRUE;
gchar *name;
GimpGradient *gradient = NULL;
name = (gchar *) args[0].value.pdb_pointer;
if (name == NULL || !g_utf8_validate (name, -1, NULL))
success = FALSE;
if (success)
{
if (strlen (name))
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container,
name);
}
else
{
gradient = gimp_context_get_gradient (context);
}
success = (gradient && GIMP_DATA (gradient)->deletable);
if (success)
{
GError *error = NULL;
success = gimp_data_factory_data_delete (gimp->gradient_factory,
GIMP_DATA (gradient),
TRUE, &error);
if (! success)
{
g_message (error->message);
g_clear_error (&error);
}
}
}
return procedural_db_return_args (&gradients_delete_proc, success);
}
static ProcArg gradients_delete_inargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The name of the gradient to delete"
}
};
static ProcRecord gradients_delete_proc =
{
"gimp_gradients_delete",
"Deletes a gradient",
"This procedure deletes a gradient",
"Shlomi Fish",
"Shlomi Fish",
"2004",
GIMP_INTERNAL,
1,
gradients_delete_inargs,
0,
NULL,
{ { gradients_delete_invoker } }
};
static Argument *
gradients_rename_invoker (Gimp *gimp,
GimpContext *context,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *name;
gchar *new_name;
GimpGradient *gradient = NULL;
name = (gchar *) args[0].value.pdb_pointer;
if (name == NULL || !g_utf8_validate (name, -1, NULL))
success = FALSE;
new_name = (gchar *) args[1].value.pdb_pointer;
if (new_name == NULL || !g_utf8_validate (new_name, -1, NULL))
success = FALSE;
if (success)
{
if (strlen (name))
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container,
name);
}
else
{
gradient = gimp_context_get_gradient (context);
}
success = (gradient && GIMP_DATA (gradient)->writable);
if (success)
gimp_object_set_name (GIMP_OBJECT (gradient), new_name);
}
return_args = procedural_db_return_args (&gradients_rename_proc, success);
if (success)
return_args[1].value.pdb_pointer = g_strdup (GIMP_OBJECT (gradient)->name);
return return_args;
}
static ProcArg gradients_rename_inargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The name of the gradient to rename"
},
{
GIMP_PDB_STRING,
"new_name",
"The new name of the gradient"
}
};
static ProcArg gradients_rename_outargs[] =
{
{
GIMP_PDB_STRING,
"name",
"The actual new name of the gradient"
}
};
static ProcRecord gradients_rename_proc =
{
"gimp_gradients_rename",
"Rename a gradient",
"This procedure renames a gradient",
"Shlomi Fish",
"Shlomi Fish",
"2004",
GIMP_INTERNAL,
2,
gradients_rename_inargs,
1,
gradients_rename_outargs,
{ { gradients_rename_invoker } }
};
......@@ -69,7 +69,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 373 procedures registered total */
/* 377 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -84,109 +84,109 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Brushes"), 0.008);
register_brushes_procs (gimp);
(* status_callback) (NULL, _("Channel"), 0.038);
(* status_callback) (NULL, _("Channel"), 0.037);
register_channel_procs (gimp);
(* status_callback) (NULL, _("Color"), 0.062);
(* status_callback) (NULL, _("Color"), 0.061);
register_color_procs (gimp);
(* status_callback) (NULL, _("Convert"), 0.097);
(* status_callback) (NULL, _("Convert"), 0.095);
register_convert_procs (gimp);
(* status_callback) (NULL, _("Display procedures"), 0.105);
(* status_callback) (NULL, _("Display procedures"), 0.103);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.115);
(* status_callback) (NULL, _("Drawable procedures"), 0.114);
register_drawable_procs (gimp);
(* status_callback) (NULL, _("Edit procedures"), 0.201);
(* status_callback) (NULL, _("Edit procedures"), 0.199);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.223);
(* status_callback) (NULL, _("File Operations"), 0.22);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.247);
(* status_callback) (NULL, _("Floating selections"), 0.244);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.263);
(* status_callback) (NULL, _("Font UI"), 0.26);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.271);
(* status_callback) (NULL, _("Fonts"), 0.268);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.276);
(* status_callback) (NULL, _("Gimprc procedures"), 0.273);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient"), 0.292);
(* status_callback) (NULL, _("Gradient"), 0.289);
register_gradient_edit_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.354);
(* status_callback) (NULL, _("Gradient UI"), 0.35);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.362);
(* status_callback) (NULL, _("Gradients"), 0.358);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.381);
(* status_callback) (NULL, _("Guide procedures"), 0.387);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.397);
(* status_callback) (NULL, _("Help procedures"), 0.403);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.399);
(* status_callback) (NULL, _("Image"), 0.406);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.563);
(* status_callback) (NULL, _("Layer"), 0.568);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.633);
(* status_callback) (NULL, _("Message procedures"), 0.637);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.641);
(* status_callback) (NULL, _("Miscellaneous"), 0.645);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.646);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.65);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.686);
(* status_callback) (NULL, _("Palette"), 0.69);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.702);
(* status_callback) (NULL, _("Palette UI"), 0.706);
register_palette_select_procs (gimp);
(* status_callback) (NULL, _("Palettes"), 0.71);
(* status_callback) (NULL, _("Palettes"), 0.714);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.724);
(* status_callback) (NULL, _("Parasite procedures"), 0.727);
register_parasite_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.756);
(* status_callback) (NULL, _("Paths"), 0.759);
register_paths_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.796);
(* status_callback) (NULL, _("Pattern UI"), 0.798);
register_pattern_select_procs (gimp);
(* status_callback) (NULL, _("Patterns"), 0.804);
(* status_callback) (NULL, _("Patterns"), 0.806);
register_patterns_procs (gimp);
(* status_callback) (NULL, _("Plug-in"), 0.818);
(* status_callback) (NULL, _("Plug-in"), 0.82);
register_plug_in_procs (gimp);
(* status_callback) (NULL, _("Procedural database"), 0.836);
(* status_callback) (NULL, _("Procedural database"), 0.838);
register_procedural_db_procs (gimp);
(* status_callback) (NULL, _("Image mask"), 0.861);
(* status_callback) (NULL, _("Image mask"), 0.862);
register_selection_procs (gimp);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.909);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.91);
register_selection_tools_procs (gimp);
(* status_callback) (NULL, _("Text procedures"), 0.922);
(* status_callback) (NULL, _("Text procedures"), 0.923);
register_text_tool_procs (gimp);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.933);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.934);
register_transform_tools_procs (gimp);
(* status_callback) (NULL, _("Undo"), 0.949);
(* status_callback) (NULL, _("Undo"), 0.95);
register_undo_procs (gimp);
(* status_callback) (NULL, _("Units"), 0.968);
......
......@@ -300,3 +300,125 @@ gimp_gradients_get_gradient_data (const gchar *name,
return ret_name;
}
/**
* gimp_gradients_new:
* @name: The requested name of the new gradient.
*
* Creates a new gradient
*
* This procedure creates a new, uninitialized gradient
*
* Returns: The actual new gradient name.
*/
gchar *
gimp_gradients_new (const gchar *name)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *ret_name = NULL;
return_vals = gimp_run_procedure ("gimp_gradients_new",
&nreturn_vals,
GIMP_PDB_STRING, name,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
ret_name = g_strdup (return_vals[1].data.d_string);
gimp_destroy_params (return_vals, nreturn_vals);
return ret_name;
}
/**
* gimp_gradients_duplicate:
* @name: The name of the gradient to duplicate.
*
* Duplicates a gradient
*
* This procedure creates an identical gradient by a different name
*
* Returns: The name of the gradient's copy.
*/
gchar *
gimp_gradients_duplicate (const gchar *name)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *ret_name = NULL;
return_vals = gimp_run_procedure ("gimp_gradients_duplicate",
&nreturn_vals,
GIMP_PDB_STRING, name,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
ret_name = g_strdup (return_vals[1].data.d_string);
gimp_destroy_params (return_vals, nreturn_vals);
return ret_name;
}
/**
* gimp_gradients_delete:
* @name: The name of the gradient to delete.
*
* Deletes a gradient
*
* This procedure deletes a gradient
*
* Returns: TRUE on success.
*/