Commit d991e64b authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Fixed GimpData's default "writable" and "deletable" behaviour:

2004-02-13  Michael Natterer  <mitch@gimp.org>

	Fixed GimpData's default "writable" and "deletable" behaviour:

	* app/core/gimpdata.c (gimp_data_init): default to writable and
	deletable == TRUE (something that has no filename was never loaded
	from disk and can't be undeletable or read-only).
	Fixes bug #134274.

	* app/core/gimpdata.[ch]: added new function
	gimp_data_make_internal() which frees the filename and sets the
	data's flags accordingly.

	* app/core/gimp-gradients.c (gimp_gradients_add_gradient)
	* app/core/gimpbrush.c (gimp_brush_get_standard)
	* app/core/gimpgradient.c (gimp_gradient_get_standard)
	* app/core/gimppalette.c (gimp_palette_get_standard)
	* app/core/gimppattern.c (gimp_pattern_get_standard): use the
	new function for internal data objects.

	* app/core/gimpdata.c (gimp_data_save, gimp_data_delete_from_disk)
	* app/core/gimpdatafactory.c (gimp_data_factory_save_single):
	bail out with g_return_if_fail() is the data is not writable
	or deletable.

	* app/widgets/gimpdataeditor.c
	* app/widgets/gimpdatafactoryview.c: changed accordingly.
parent 1797d6c7
2004-02-13 Michael Natterer <mitch@gimp.org>
Fixed GimpData's default "writable" and "deletable" behaviour:
* app/core/gimpdata.c (gimp_data_init): default to writable and
deletable == TRUE (something that has no filename was never loaded
from disk and can't be undeletable or read-only).
Fixes bug #134274.
* app/core/gimpdata.[ch]: added new function
gimp_data_make_internal() which frees the filename and sets the
data's flags accordingly.
* app/core/gimp-gradients.c (gimp_gradients_add_gradient)
* app/core/gimpbrush.c (gimp_brush_get_standard)
* app/core/gimpgradient.c (gimp_gradient_get_standard)
* app/core/gimppalette.c (gimp_palette_get_standard)
* app/core/gimppattern.c (gimp_pattern_get_standard): use the
new function for internal data objects.
* app/core/gimpdata.c (gimp_data_save, gimp_data_delete_from_disk)
* app/core/gimpdatafactory.c (gimp_data_factory_save_single):
bail out with g_return_if_fail() is the data is not writable
or deletable.
* app/widgets/gimpdataeditor.c
* app/widgets/gimpdatafactoryview.c: changed accordingly.
2004-02-12 Sven Neumann <sven@gimp.org>
* app/display/gimpcanvas.c (gimp_canvas_gc_new): use
......@@ -114,7 +114,7 @@ gimp_gradients_add_gradient (Gimp *gimp,
gradient = GIMP_GRADIENT (gimp_gradient_new (name,
base_config->stingy_memory_use));
GIMP_DATA (gradient)->internal = TRUE;
gimp_data_make_internal (GIMP_DATA (gradient));
gimp_context_get_foreground (gimp->user_context,
&gradient->segments->left_color);
......
......@@ -369,8 +369,8 @@ gimp_brush_get_standard (void)
{
standard_brush = gimp_brush_new ("Standard", FALSE);
standard_brush->dirty = FALSE;
standard_brush->internal = TRUE;
standard_brush->dirty = FALSE;
gimp_data_make_internal (standard_brush);
/* set ref_count to 2 --> never swap the standard brush */
g_object_ref (standard_brush);
......
......@@ -369,8 +369,8 @@ gimp_brush_get_standard (void)
{
standard_brush = gimp_brush_new ("Standard", FALSE);
standard_brush->dirty = FALSE;
standard_brush->internal = TRUE;
standard_brush->dirty = FALSE;
gimp_data_make_internal (standard_brush);
/* set ref_count to 2 --> never swap the standard brush */
g_object_ref (standard_brush);
......
......@@ -137,10 +137,14 @@ static void
gimp_data_init (GimpData *data)
{
data->filename = NULL;
data->writable = FALSE;
data->deletable = FALSE;
data->writable = TRUE;
data->deletable = TRUE;
data->dirty = TRUE;
data->internal = FALSE;
/* if we can't save, we are not writable */
if (! GIMP_DATA_GET_CLASS (data)->save)
data->writable = FALSE;
}
static void
......@@ -187,6 +191,7 @@ gimp_data_save (GimpData *data,
gboolean success = FALSE;
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
g_return_val_if_fail (data->writable == TRUE, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (data->internal)
......@@ -228,6 +233,7 @@ gimp_data_delete_from_disk (GimpData *data,
{
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
g_return_val_if_fail (data->filename != NULL, FALSE);
g_return_val_if_fail (data->deletable == TRUE, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (data->internal)
......@@ -268,10 +274,7 @@ gimp_data_set_filename (GimpData *data,
return;
if (data->filename)
{
g_free (data->filename);
data->filename = NULL;
}
g_free (data->filename);
data->filename = g_strdup (filename);
data->writable = FALSE;
......@@ -353,19 +356,28 @@ GimpData *
gimp_data_duplicate (GimpData *data,
gboolean stingy_memory_use)
{
GimpData *new = NULL;
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
if (GIMP_DATA_GET_CLASS (data)->duplicate)
{
new = GIMP_DATA_GET_CLASS (data)->duplicate (data, stingy_memory_use);
return GIMP_DATA_GET_CLASS (data)->duplicate (data, stingy_memory_use);
return NULL;
}
if (new)
new->dirty = TRUE;
void
gimp_data_make_internal (GimpData *data)
{
g_return_if_fail (GIMP_IS_DATA (data));
if (data->filename)
{
g_free (data->filename);
data->filename = NULL;
}
return new;
data->internal = TRUE;
data->writable = FALSE;
data->deletable = FALSE;
}
GQuark
......
......@@ -93,6 +93,8 @@ void gimp_data_create_filename (GimpData *data,
GimpData * gimp_data_duplicate (GimpData *data,
gboolean stingy_memory_use);
void gimp_data_make_internal (GimpData *data);
#define GIMP_DATA_ERROR (gimp_data_error_quark ())
......
......@@ -282,7 +282,7 @@ gimp_data_factory_data_save (GimpDataFactory *factory)
if (! data->filename)
gimp_data_create_filename (data, GIMP_OBJECT (data)->name, writable_dir);
if (data->dirty)
if (data->dirty && data->writable)
{
GError *error = NULL;
......@@ -453,6 +453,7 @@ gimp_data_factory_data_save_single (GimpDataFactory *factory,
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 (data->writable == TRUE, FALSE);
if (! data->dirty)
return TRUE;
......
......@@ -318,8 +318,8 @@ gimp_gradient_get_standard (void)
{
standard_gradient = gimp_gradient_new ("Standard", FALSE);
standard_gradient->dirty = FALSE;
standard_gradient->internal = TRUE;
standard_gradient->dirty = FALSE;
gimp_data_make_internal (standard_gradient);
g_object_ref (standard_gradient);
}
......
......@@ -333,8 +333,8 @@ gimp_palette_get_standard (void)
{
standard_palette = gimp_palette_new ("Standard", FALSE);
standard_palette->dirty = FALSE;
standard_palette->internal = TRUE;
standard_palette->dirty = FALSE;
gimp_data_make_internal (standard_palette);
g_object_ref (standard_palette);
}
......
......@@ -333,8 +333,8 @@ gimp_palette_get_standard (void)
{
standard_palette = gimp_palette_new ("Standard", FALSE);
standard_palette->dirty = FALSE;
standard_palette->internal = TRUE;
standard_palette->dirty = FALSE;
gimp_data_make_internal (standard_palette);
g_object_ref (standard_palette);
}
......
......@@ -333,8 +333,8 @@ gimp_palette_get_standard (void)
{
standard_palette = gimp_palette_new ("Standard", FALSE);
standard_palette->dirty = FALSE;
standard_palette->internal = TRUE;
standard_palette->dirty = FALSE;
gimp_data_make_internal (standard_palette);
g_object_ref (standard_palette);
}
......
......@@ -296,8 +296,8 @@ gimp_pattern_get_standard (void)
{
standard_pattern = gimp_pattern_new ("Standard", FALSE);
standard_pattern->dirty = FALSE;
standard_pattern->internal = TRUE;
standard_pattern->dirty = FALSE;
gimp_data_make_internal (standard_pattern);
/* set ref_count to 2 --> never swap the standard pattern */
g_object_ref (standard_pattern);
......
......@@ -296,8 +296,8 @@ gimp_pattern_get_standard (void)
{
standard_pattern = gimp_pattern_new ("Standard", FALSE);
standard_pattern->dirty = FALSE;
standard_pattern->internal = TRUE;
standard_pattern->dirty = FALSE;
gimp_data_make_internal (standard_pattern);
/* set ref_count to 2 --> never swap the standard pattern */
g_object_ref (standard_pattern);
......
......@@ -374,7 +374,7 @@ gimp_data_editor_save_dirty (GimpDataEditor *editor)
{
GimpData *data = editor->data;
if (data && data->dirty)
if (data && data->dirty && data->writable)
gimp_data_factory_data_save_single (editor->data_factory, data);
}
......@@ -350,16 +350,16 @@ gimp_data_factory_view_delete_callback (GtkWidget *widget,
gboolean delete,
gpointer data)
{
GimpDataDeleteData *delete_data;
delete_data = (GimpDataDeleteData *) data;
if (! delete)
return;
GimpDataDeleteData *delete_data = data;
if (gimp_container_have (delete_data->factory->container,
GIMP_OBJECT (delete_data->data)))
{
g_object_ref (delete_data->data);
gimp_container_remove (delete_data->factory->container,
GIMP_OBJECT (delete_data->data));
if (delete_data->data->filename)
{
GError *error = NULL;
......@@ -371,8 +371,7 @@ gimp_data_factory_view_delete_callback (GtkWidget *widget,
}
}
gimp_container_remove (delete_data->factory->container,
GIMP_OBJECT (delete_data->data));
g_object_unref (delete_data->data);
}
}
......@@ -386,8 +385,8 @@ gimp_data_factory_view_delete_clicked (GtkWidget *widget,
gimp_context_get_by_type (GIMP_CONTAINER_EDITOR (view)->view->context,
view->factory->container->children_type);
if (data && ! data->internal && gimp_container_have (view->factory->container,
GIMP_OBJECT (data)))
if (data && data->deletable && gimp_container_have (view->factory->container,
GIMP_OBJECT (data)))
{
GimpDataDeleteData *delete_data;
GtkWidget *dialog;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment