static void parasite_copy (const gchar *key, GimpParasite *parasite, GimpParasiteList *list) { gimp_parasite_list_add (list, parasite); }
void gimp_item_parasite_attach (GimpItem *item, const GimpParasite *parasite) { GimpParasite copy; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (parasite != NULL); /* make a temporary copy of the GimpParasite struct because * gimp_parasite_shift_parent() changes it */ copy = *parasite; if (gimp_item_is_attached (item)) { /* only set the dirty bit manually if we can be saved and the new * parasite differs from the current one and we aren't undoable */ if (gimp_parasite_is_undoable (©)) { /* do a group in case we have attach_parent set */ gimp_image_undo_group_start (item->image, GIMP_UNDO_GROUP_PARASITE_ATTACH, _("Attach Parasite")); gimp_image_undo_push_item_parasite (item->image, NULL, item, ©); } else if (gimp_parasite_is_persistent (©) && ! gimp_parasite_compare (©, gimp_item_parasite_find (item, gimp_parasite_name (©)))) { gimp_image_undo_push_cantundo (item->image, _("Attach Parasite to Item")); } } gimp_parasite_list_add (item->parasites, ©); if (gimp_parasite_has_flag (©, GIMP_PARASITE_ATTACH_PARENT)) { gimp_parasite_shift_parent (©); gimp_image_parasite_attach (item->image, ©); } else if (gimp_parasite_has_flag (©, GIMP_PARASITE_ATTACH_GRANDPARENT)) { gimp_parasite_shift_parent (©); gimp_parasite_shift_parent (©); gimp_parasite_attach (item->image->gimp, ©); } if (gimp_item_is_attached (item) && gimp_parasite_is_undoable (©)) { gimp_image_undo_group_end (item->image); } }
void gimp_parasite_attach (Gimp *gimp, const GimpParasite *parasite) { g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (parasite != NULL); gimp_parasite_list_add (gimp->parasites, parasite); }
static gboolean gimp_parasite_list_deserialize (GimpConfig *list, GScanner *scanner, gint nest_level, gpointer data) { GTokenType token; g_scanner_scope_add_symbol (scanner, 0, parasite_symbol, (gpointer) parasite_symbol); token = G_TOKEN_LEFT_PAREN; while (g_scanner_peek_next_token (scanner) == token) { token = g_scanner_get_next_token (scanner); switch (token) { case G_TOKEN_LEFT_PAREN: token = G_TOKEN_SYMBOL; break; case G_TOKEN_SYMBOL: if (scanner->value.v_symbol == parasite_symbol) { gchar *parasite_name = NULL; gint parasite_flags = 0; guint8 *parasite_data = NULL; gint parasite_data_size = 0; GimpParasite *parasite; token = G_TOKEN_STRING; if (g_scanner_peek_next_token (scanner) != token) break; if (! gimp_scanner_parse_string (scanner, ¶site_name)) break; token = G_TOKEN_INT; if (g_scanner_peek_next_token (scanner) != token) goto cleanup; if (! gimp_scanner_parse_int (scanner, ¶site_flags)) goto cleanup; token = G_TOKEN_INT; if (g_scanner_peek_next_token (scanner) != token) { /* old format -- plain string */ gchar *str; if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING) goto cleanup; if (! gimp_scanner_parse_string (scanner, &str)) goto cleanup; parasite_data_size = strlen (str); parasite_data = (guint8 *) str; } else { /* new format -- properly encoded binary data */ if (! gimp_scanner_parse_int (scanner, ¶site_data_size)) goto cleanup; token = G_TOKEN_STRING; if (g_scanner_peek_next_token (scanner) != token) goto cleanup; if (! gimp_scanner_parse_data (scanner, parasite_data_size, ¶site_data)) goto cleanup; } parasite = gimp_parasite_new (parasite_name, parasite_flags, parasite_data_size, parasite_data); gimp_parasite_list_add (GIMP_PARASITE_LIST (list), parasite); /* adds a copy */ gimp_parasite_free (parasite); token = G_TOKEN_RIGHT_PAREN; g_free (parasite_data); cleanup: g_free (parasite_name); } break; case G_TOKEN_RIGHT_PAREN: token = G_TOKEN_LEFT_PAREN; break; default: /* do nothing */ break; } } return gimp_config_deserialize_return (scanner, token, nest_level); }
static void gimp_item_prop_undo_pop (GimpUndo *undo, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { GimpItemPropUndo *item_prop_undo = GIMP_ITEM_PROP_UNDO (undo); GimpItem *item = GIMP_ITEM_UNDO (undo)->item; GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum); switch (undo->undo_type) { case GIMP_UNDO_ITEM_RENAME: { gchar *name; name = g_strdup (gimp_object_get_name (GIMP_OBJECT (item))); gimp_object_take_name (GIMP_OBJECT (item), item_prop_undo->name); item_prop_undo->name = name; } break; case GIMP_UNDO_ITEM_DISPLACE: { gint offset_x; gint offset_y; gimp_item_offsets (item, &offset_x, &offset_y); gimp_item_translate (item, item_prop_undo->offset_x - offset_x, item_prop_undo->offset_y - offset_y, FALSE); item_prop_undo->offset_x = offset_x; item_prop_undo->offset_y = offset_y; } break; case GIMP_UNDO_ITEM_VISIBILITY: { gboolean visible; visible = gimp_item_get_visible (item); gimp_item_set_visible (item, item_prop_undo->visible, FALSE); item_prop_undo->visible = visible; } break; case GIMP_UNDO_ITEM_LINKED: { gboolean linked; linked = gimp_item_get_linked (item); gimp_item_set_linked (item, item_prop_undo->linked, FALSE); item_prop_undo->linked = linked; } break; case GIMP_UNDO_PARASITE_ATTACH: case GIMP_UNDO_PARASITE_REMOVE: { GimpParasite *parasite; parasite = item_prop_undo->parasite; item_prop_undo->parasite = gimp_parasite_copy (gimp_item_parasite_find (item, item_prop_undo->parasite_name)); if (parasite) gimp_parasite_list_add (item->parasites, parasite); else gimp_parasite_list_remove (item->parasites, item_prop_undo->parasite_name); if (parasite) gimp_parasite_free (parasite); } break; default: g_assert_not_reached (); } }