Bug 61019 - add a 'lock' flag per layer to protect it

Took patch from Martin Nordholts and ported it to add a "lock-content"
property, signal and API in the same way as it's done for "visible"
and "linked".
This commit is contained in:
Michael Natterer 2009-08-19 13:37:41 +02:00
parent f7ba1d1f2e
commit fb1a672546
2 changed files with 100 additions and 30 deletions

View File

@ -49,6 +49,7 @@ enum
REMOVED,
VISIBILITY_CHANGED,
LINKED_CHANGED,
LOCK_CONTENT_CHANGED,
LAST_SIGNAL
};
@ -61,7 +62,8 @@ enum
PROP_OFFSET_X,
PROP_OFFSET_Y,
PROP_VISIBLE,
PROP_LINKED
PROP_LINKED,
PROP_LOCK_CONTENT
};
@ -153,6 +155,15 @@ gimp_item_class_init (GimpItemClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
gimp_item_signals[LOCK_CONTENT_CHANGED] =
g_signal_new ("lock-content-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpItemClass, lock_content_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->set_property = gimp_item_set_property;
object_class->get_property = gimp_item_get_property;
object_class->finalize = gimp_item_finalize;
@ -165,6 +176,7 @@ gimp_item_class_init (GimpItemClass *klass)
klass->removed = NULL;
klass->visibility_changed = gimp_item_real_visibility_changed;
klass->linked_changed = NULL;
klass->lock_content_changed = NULL;
klass->is_attached = NULL;
klass->get_container = NULL;
@ -225,6 +237,12 @@ gimp_item_class_init (GimpItemClass *klass)
g_param_spec_boolean ("linked", NULL, NULL,
FALSE,
GIMP_PARAM_READABLE));
g_object_class_install_property (object_class, PROP_LOCK_CONTENT,
g_param_spec_boolean ("lock-content",
NULL, NULL,
FALSE,
GIMP_PARAM_READABLE));
}
static void
@ -232,19 +250,20 @@ gimp_item_init (GimpItem *item)
{
g_object_force_floating (G_OBJECT (item));
item->ID = 0;
item->tattoo = 0;
item->image = NULL;
item->parasites = gimp_parasite_list_new ();
item->width = 0;
item->height = 0;
item->offset_x = 0;
item->offset_y = 0;
item->visible = TRUE;
item->linked = FALSE;
item->removed = FALSE;
item->node = NULL;
item->offset_node = NULL;
item->ID = 0;
item->tattoo = 0;
item->image = NULL;
item->parasites = gimp_parasite_list_new ();
item->width = 0;
item->height = 0;
item->offset_x = 0;
item->offset_y = 0;
item->visible = TRUE;
item->linked = FALSE;
item->lock_content = FALSE;
item->removed = FALSE;
item->node = NULL;
item->offset_node = NULL;
}
static void
@ -292,6 +311,9 @@ gimp_item_get_property (GObject *object,
case PROP_LINKED:
g_value_set_boolean (value, item->linked);
break;
case PROP_LOCK_CONTENT:
g_value_set_boolean (value, item->lock_content);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -1512,14 +1534,6 @@ gimp_item_parasite_list (const GimpItem *item,
return list;
}
gboolean
gimp_item_get_visible (const GimpItem *item)
{
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
return item->visible;
}
void
gimp_item_set_visible (GimpItem *item,
gboolean visible,
@ -1527,6 +1541,8 @@ gimp_item_set_visible (GimpItem *item,
{
g_return_if_fail (GIMP_IS_ITEM (item));
visible = visible ? TRUE : FALSE;
if (gimp_item_get_visible (item) != visible)
{
if (push_undo && gimp_item_is_attached (item))
@ -1537,7 +1553,7 @@ gimp_item_set_visible (GimpItem *item,
gimp_image_undo_push_item_visibility (image, NULL, item);
}
item->visible = visible ? TRUE : FALSE;
item->visible = visible;
g_signal_emit (item, gimp_item_signals[VISIBILITY_CHANGED], 0);
@ -1545,6 +1561,14 @@ gimp_item_set_visible (GimpItem *item,
}
}
gboolean
gimp_item_get_visible (const GimpItem *item)
{
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
return item->visible;
}
void
gimp_item_set_linked (GimpItem *item,
gboolean linked,
@ -1552,6 +1576,8 @@ gimp_item_set_linked (GimpItem *item,
{
g_return_if_fail (GIMP_IS_ITEM (item));
linked = linked ? TRUE : FALSE;
if (gimp_item_get_linked (item) != linked)
{
if (push_undo && gimp_item_is_attached (item))
@ -1562,7 +1588,7 @@ gimp_item_set_linked (GimpItem *item,
gimp_image_undo_push_item_linked (image, NULL, item);
}
item->linked = linked ? TRUE : FALSE;
item->linked = linked;
g_signal_emit (item, gimp_item_signals[LINKED_CHANGED], 0);
@ -1578,6 +1604,43 @@ gimp_item_get_linked (const GimpItem *item)
return item->linked;
}
void
gimp_item_set_lock_content (GimpItem *item,
gboolean lock_content,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_ITEM (item));
lock_content = lock_content ? TRUE : FALSE;
if (gimp_item_get_lock_content (item) != lock_content)
{
if (push_undo && gimp_item_is_attached (item))
{
/* Right now I don't think this should be pushed. */
#if 0
GimpImage *image = gimp_item_get_image (item);
gimp_image_undo_push_item_lock_content (image, NULL, item);
#endif
}
item->lock_content = lock_content;
g_signal_emit (item, gimp_item_signals[LOCK_CONTENT_CHANGED], 0);
g_object_notify (G_OBJECT (item), "lock-content");
}
}
gboolean
gimp_item_get_lock_content (const GimpItem *item)
{
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
return item->lock_content;
}
gboolean
gimp_item_is_in_set (GimpItem *item,
GimpItemSet set)

View File

@ -46,8 +46,9 @@ struct _GimpItem
gint width, height; /* size in pixels */
gint offset_x, offset_y; /* pixel offset in image */
guint visible : 1; /* control visibility */
guint linked : 1; /* control linkage */
guint visible : 1; /* control visibility */
guint linked : 1; /* control linkage */
guint lock_content : 1; /* content editability */
guint removed : 1; /* removed from the image? */
@ -61,9 +62,10 @@ struct _GimpItemClass
GimpViewableClass parent_class;
/* signals */
void (* removed) (GimpItem *item);
void (* visibility_changed) (GimpItem *item);
void (* linked_changed) (GimpItem *item);
void (* removed) (GimpItem *item);
void (* visibility_changed) (GimpItem *item);
void (* linked_changed) (GimpItem *item);
void (* lock_content_changed) (GimpItem *item);
/* virtual functions */
gboolean (* is_attached) (GimpItem *item);
@ -261,16 +263,21 @@ const GimpParasite * gimp_item_parasite_find (const GimpItem *item,
gchar ** gimp_item_parasite_list (const GimpItem *item,
gint *count);
gboolean gimp_item_get_visible (const GimpItem *item);
void gimp_item_set_visible (GimpItem *item,
gboolean visible,
gboolean push_undo);
gboolean gimp_item_get_visible (const GimpItem *item);
void gimp_item_set_linked (GimpItem *item,
gboolean linked,
gboolean push_undo);
gboolean gimp_item_get_linked (const GimpItem *item);
void gimp_item_set_lock_content (GimpItem *item,
gboolean lock_content,
gboolean push_undo);
gboolean gimp_item_get_lock_content (const GimpItem *item);
gboolean gimp_item_is_in_set (GimpItem *item,
GimpItemSet set);