void floating_sel_to_layer (GimpLayer *layer) { GimpItem *item; GimpImage *image; g_return_if_fail (GIMP_IS_LAYER (layer)); g_return_if_fail (gimp_layer_is_floating_sel (layer)); item = GIMP_ITEM (layer); if (! (image = gimp_item_get_image (item))) return; /* Check if the floating layer belongs to a channel... */ if (GIMP_IS_CHANNEL (layer->fs.drawable)) { gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING, _("Cannot create a new layer from the floating selection " "because it belongs to a layer mask or channel.")); return; } gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_TO_LAYER, _("Floating Selection to Layer")); /* restore the contents of the drawable */ floating_sel_restore (layer, item->offset_x, item->offset_y, item->width, item->height); gimp_image_undo_push_fs_to_layer (image, NULL, layer); /* clear the selection */ gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (layer)); /* Set pointers */ layer->fs.drawable = NULL; image->floating_sel = NULL; gimp_item_set_visible (GIMP_ITEM (layer), TRUE, TRUE); gimp_layer_set_lock_alpha (layer, FALSE, TRUE); gimp_image_undo_group_end (image); gimp_object_name_changed (GIMP_OBJECT (layer)); gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, GIMP_ITEM (layer)->width, GIMP_ITEM (layer)->height); gimp_image_floating_selection_changed (image); }
gboolean floating_sel_to_layer (GimpLayer *layer, GError **error) { GimpItem *item; GimpImage *image; g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE); g_return_val_if_fail (gimp_layer_is_floating_sel (layer), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); item = GIMP_ITEM (layer); image = gimp_item_get_image (item); /* Check if the floating layer belongs to a channel */ if (GIMP_IS_CHANNEL (gimp_layer_get_floating_sel_drawable (layer))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Cannot create a new layer from the floating " "selection because it belongs to a layer mask " "or channel.")); return FALSE; } gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_TO_LAYER, C_("undo-type", "Floating Selection to Layer")); gimp_image_undo_push_fs_to_layer (image, NULL, layer); gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (layer)); gimp_layer_set_floating_sel_drawable (layer, NULL); gimp_item_set_visible (item, TRUE, TRUE); gimp_layer_set_lock_alpha (layer, FALSE, TRUE); gimp_image_undo_group_end (image); /* When the floating selection is converted to/from a normal layer * it does something resembling a name change, so emit the * "name-changed" signal */ gimp_object_name_changed (GIMP_OBJECT (layer)); gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, gimp_item_get_width (item), gimp_item_get_height (item)); return TRUE; }
static void gimp_floating_sel_undo_pop (GimpUndo *undo, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { GimpFloatingSelUndo *floating_sel_undo = GIMP_FLOATING_SEL_UNDO (undo); GimpLayer *floating_layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item); GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum); switch (undo->undo_type) { case GIMP_UNDO_FS_TO_LAYER: if (undo_mode == GIMP_UNDO_MODE_UNDO) { /* Update the preview for the floating sel */ gimp_viewable_invalidate_preview (GIMP_VIEWABLE (floating_layer)); gimp_layer_set_floating_sel_drawable (floating_layer, floating_sel_undo->drawable); gimp_image_set_active_layer (undo->image, floating_layer); gimp_drawable_attach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer), floating_layer); } else { gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer)); gimp_layer_set_floating_sel_drawable (floating_layer, NULL); } /* When the floating selection is converted to/from a normal * layer it does something resembling a name change, so emit the * "name-changed" signal */ gimp_object_name_changed (GIMP_OBJECT (floating_layer)); gimp_drawable_update (GIMP_DRAWABLE (floating_layer), 0, 0, gimp_item_get_width (GIMP_ITEM (floating_layer)), gimp_item_get_height (GIMP_ITEM (floating_layer))); break; default: g_assert_not_reached (); } }
void gimp_object_set_static_name (GimpObject *object, const gchar *name) { g_return_if_fail (GIMP_IS_OBJECT (object)); if (! g_strcmp0 (object->p->name, name)) return; gimp_object_name_free (object); object->p->name = (gchar *) name; object->p->static_name = TRUE; gimp_object_name_changed (object); g_object_notify (G_OBJECT (object), "name"); }
/** * gimp_object_set_name_safe: * @object: a #GimpObject * @name: the @object's new name * * A safe version of gimp_object_set_name() that takes care of * handling newlines and overly long names. The actual name set * may be different to the @name you pass. **/ void gimp_object_set_name_safe (GimpObject *object, const gchar *name) { g_return_if_fail (GIMP_IS_OBJECT (object)); if (! g_strcmp0 (object->p->name, name)) return; gimp_object_name_free (object); object->p->name = gimp_utf8_strtrim (name, 30); object->p->static_name = FALSE; gimp_object_name_changed (object); g_object_notify (G_OBJECT (object), "name"); }
void gimp_object_take_name (GimpObject *object, gchar *name) { g_return_if_fail (GIMP_IS_OBJECT (object)); if (! g_strcmp0 (object->p->name, name)) { g_free (name); return; } gimp_object_name_free (object); object->p->name = name; object->p->static_name = FALSE; gimp_object_name_changed (object); g_object_notify (G_OBJECT (object), "name"); }
GimpPDBStatusType file_save (Gimp *gimp, GimpImage *image, GimpProgress *progress, const gchar *uri, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, gboolean change_saved_state, gboolean export_backward, gboolean export_forward, GError **error) { GimpDrawable *drawable; GimpValueArray *return_vals; GimpPDBStatusType status; gchar *filename; gint32 image_ID; gint32 drawable_ID; g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail ((export_backward && export_forward) == FALSE, GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (error == NULL || *error == NULL, GIMP_PDB_CALLING_ERROR); drawable = gimp_image_get_active_drawable (image); if (! drawable) return GIMP_PDB_EXECUTION_ERROR; filename = file_utils_filename_from_uri (uri); if (filename) { /* check if we are saving to a file */ if (g_file_test (filename, G_FILE_TEST_EXISTS)) { if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Not a regular file")); status = GIMP_PDB_EXECUTION_ERROR; goto out; } if (g_access (filename, W_OK) != 0) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_ACCES, g_strerror (errno)); status = GIMP_PDB_EXECUTION_ERROR; goto out; } } if (file_proc->handles_uri) { g_free (filename); filename = g_strdup (uri); } } else { filename = g_strdup (uri); } /* ref the image, so it can't get deleted during save */ g_object_ref (image); image_ID = gimp_image_get_ID (image); drawable_ID = gimp_item_get_ID (GIMP_ITEM (drawable)); return_vals = gimp_pdb_execute_procedure_by_name (image->gimp->pdb, gimp_get_user_context (gimp), progress, error, gimp_object_get_name (file_proc), GIMP_TYPE_INT32, run_mode, GIMP_TYPE_IMAGE_ID, image_ID, GIMP_TYPE_DRAWABLE_ID, drawable_ID, G_TYPE_STRING, filename, G_TYPE_STRING, uri, G_TYPE_NONE); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); gimp_value_array_unref (return_vals); if (status == GIMP_PDB_SUCCESS) { GimpDocumentList *documents; GimpImagefile *imagefile; if (change_saved_state) { gimp_image_set_uri (image, uri); gimp_image_set_save_proc (image, file_proc); /* Forget the import source when we save. We interpret a * save as that the user is not interested in being able * to quickly export back to the original any longer */ gimp_image_set_imported_uri (image, NULL); gimp_image_clean_all (image); } else if (export_backward) { /* We exported the image back to its imported source, * change nothing about export/import flags, only set * the export state to clean */ gimp_image_export_clean_all (image); gimp_object_name_changed (GIMP_OBJECT (image)); } else if (export_forward) { /* Remember the last entered Export URI for the image. We * only need to do this explicitly when exporting. It * happens implicitly when saving since the GimpObject name * of a GimpImage is the last-save URI */ gimp_image_set_exported_uri (image, uri); /* An image can not be considered both exported and imported * at the same time, so stop consider it as imported now * that we consider it exported. */ gimp_image_set_imported_uri (image, NULL); gimp_image_export_clean_all (image); } if (export_backward || export_forward) gimp_image_exported (image, uri); else gimp_image_saved (image, uri); documents = GIMP_DOCUMENT_LIST (image->gimp->documents); imagefile = gimp_document_list_add_uri (documents, uri, file_proc->mime_type); /* only save a thumbnail if we are saving as XCF, see bug #25272 */ if (GIMP_PROCEDURE (file_proc)->proc_type == GIMP_INTERNAL) gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, image); } else if (status != GIMP_PDB_CANCEL) { if (error && *error == NULL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("%s plug-in could not save image"), gimp_plug_in_procedure_get_label (file_proc)); } } gimp_image_flush (image); g_object_unref (image); out: g_free (filename); return status; }
GimpPDBStatusType file_save (Gimp *gimp, GimpImage *image, GimpProgress *progress, GFile *file, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, gboolean change_saved_state, gboolean export_backward, gboolean export_forward, GError **error) { GimpDrawable *drawable; GimpValueArray *return_vals; GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; GFile *local_file = NULL; gchar *path = NULL; gchar *uri = NULL; gint32 image_ID; gint32 drawable_ID; GError *my_error = NULL; g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (G_IS_FILE (file), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail ((export_backward && export_forward) == FALSE, GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (error == NULL || *error == NULL, GIMP_PDB_CALLING_ERROR); /* ref image and file, so they can't get deleted during save */ g_object_ref (image); g_object_ref (file); drawable = gimp_image_get_active_drawable (image); if (! drawable) goto out; /* FIXME enable these tests for remote files again, needs testing */ if (g_file_is_native (file) && g_file_query_exists (file, NULL)) { GFileInfo *info; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, error); if (! info) goto out; if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Not a regular file")); g_object_unref (info); goto out; } if (! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Permission denied")); g_object_unref (info); goto out; } g_object_unref (info); } if (! g_file_is_native (file) && ! file_remote_mount_file (gimp, file, progress, &my_error)) { if (my_error) g_propagate_error (error, my_error); else status = GIMP_PDB_CANCEL; goto out; } if (! file_proc->handles_uri) { path = g_file_get_path (file); if (! path) { local_file = file_remote_upload_image_prepare (gimp, file, progress, &my_error); if (! local_file) { if (my_error) g_propagate_error (error, my_error); else status = GIMP_PDB_CANCEL; goto out; } path = g_file_get_path (local_file); } } if (! path) path = g_file_get_uri (file); uri = g_file_get_uri (file); image_ID = gimp_image_get_ID (image); drawable_ID = gimp_item_get_ID (GIMP_ITEM (drawable)); return_vals = gimp_pdb_execute_procedure_by_name (image->gimp->pdb, gimp_get_user_context (gimp), progress, error, gimp_object_get_name (file_proc), GIMP_TYPE_INT32, run_mode, GIMP_TYPE_IMAGE_ID, image_ID, GIMP_TYPE_DRAWABLE_ID, drawable_ID, G_TYPE_STRING, path, G_TYPE_STRING, uri, G_TYPE_NONE); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); gimp_value_array_unref (return_vals); if (local_file) { if (status == GIMP_PDB_SUCCESS) { GError *my_error = NULL; if (! file_remote_upload_image_finish (gimp, file, local_file, progress, &my_error)) { status = GIMP_PDB_EXECUTION_ERROR; if (my_error) g_propagate_error (error, my_error); else status = GIMP_PDB_CANCEL; } } g_file_delete (local_file, NULL, NULL); g_object_unref (local_file); } if (status == GIMP_PDB_SUCCESS) { GimpDocumentList *documents; GimpImagefile *imagefile; if (change_saved_state) { gimp_image_set_file (image, file); gimp_image_set_save_proc (image, file_proc); /* Forget the import source when we save. We interpret a * save as that the user is not interested in being able * to quickly export back to the original any longer */ gimp_image_set_imported_file (image, NULL); gimp_image_clean_all (image); } else if (export_backward) { /* We exported the image back to its imported source, * change nothing about export/import flags, only set * the export state to clean */ gimp_image_export_clean_all (image); gimp_object_name_changed (GIMP_OBJECT (image)); } else if (export_forward) { /* Remember the last entered Export URI for the image. We * only need to do this explicitly when exporting. It * happens implicitly when saving since the GimpObject name * of a GimpImage is the last-save URI */ gimp_image_set_exported_file (image, file); gimp_image_set_export_proc (image, file_proc); /* An image can not be considered both exported and imported * at the same time, so stop consider it as imported now * that we consider it exported. */ gimp_image_set_imported_file (image, NULL); gimp_image_export_clean_all (image); } if (export_backward || export_forward) gimp_image_exported (image, file); else gimp_image_saved (image, file); documents = GIMP_DOCUMENT_LIST (image->gimp->documents); imagefile = gimp_document_list_add_file (documents, file, file_proc->mime_type); /* only save a thumbnail if we are saving as XCF, see bug #25272 */ if (GIMP_PROCEDURE (file_proc)->proc_type == GIMP_INTERNAL) gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, image, NULL); } else if (status != GIMP_PDB_CANCEL) { if (error && *error == NULL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("%s plug-in could not save image"), gimp_plug_in_procedure_get_label (file_proc)); } } gimp_image_flush (image); out: g_object_unref (file); g_object_unref (image); g_free (path); g_free (uri); return status; }
void gimp_device_info_set_device (GimpDeviceInfo *info, GdkDevice *device, GdkDisplay *display) { gint i; g_return_if_fail (GIMP_IS_DEVICE_INFO (info)); g_return_if_fail ((device == NULL && display == NULL) || (GDK_IS_DEVICE (device) && GDK_IS_DISPLAY (display))); g_return_if_fail ((info->device == NULL && GDK_IS_DEVICE (device)) || (GDK_IS_DEVICE (info->device) && device == NULL)); g_return_if_fail (device == NULL || strcmp (device->name, gimp_object_get_name (info)) == 0); if (device) { info->device = device; info->display = display; g_object_set_data (G_OBJECT (device), GIMP_DEVICE_INFO_DATA_KEY, info); gimp_device_info_set_mode (info, info->mode); if (info->n_axes != device->num_axes) g_printerr ("%s: stored 'num-axes' for device '%s' doesn't match " "number of axes present in device\n", G_STRFUNC, device->name); for (i = 0; i < MIN (info->n_axes, device->num_axes); i++) gimp_device_info_set_axis_use (info, i, info->axes[i]); if (info->n_keys != device->num_keys) g_printerr ("%s: stored 'num-keys' for device '%s' doesn't match " "number of keys present in device\n", G_STRFUNC, device->name); for (i = 0; i < MIN (info->n_keys, device->num_keys); i++) gimp_device_info_set_key (info, i, info->keys[i].keyval, info->keys[i].modifiers); } else { device = info->device; display = info->display; info->device = NULL; info->display = NULL; g_object_set_data (G_OBJECT (device), GIMP_DEVICE_INFO_DATA_KEY, NULL); gimp_device_info_set_mode (info, device->mode); info->n_axes = device->num_axes; info->axes = g_renew (GdkAxisUse, info->axes, info->n_axes); memset (info->axes, 0, info->n_axes * sizeof (GdkAxisUse)); for (i = 0; i < device->num_axes; i++) gimp_device_info_set_axis_use (info, i, device->axes[i].use); info->n_keys = device->num_keys; info->keys = g_renew (GdkDeviceKey, info->keys, info->n_keys); memset (info->keys, 0, info->n_keys * sizeof (GdkDeviceKey)); for (i = 0; i < MIN (info->n_keys, device->num_keys); i++) gimp_device_info_set_key (info, i, device->keys[i].keyval, device->keys[i].modifiers); } /* sort order depends on device presence */ gimp_object_name_changed (GIMP_OBJECT (info)); g_object_notify (G_OBJECT (info), "device"); gimp_device_info_changed (info); }