static GimpValueArray * file_load_layer_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; gint32 run_mode; GimpImage *image; const gchar *filename; GimpLayer *layer = NULL; run_mode = g_value_get_enum (gimp_value_array_index (args, 0)); image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp); filename = g_value_get_string (gimp_value_array_index (args, 2)); if (success) { gchar *uri = file_utils_filename_to_uri (gimp, filename, error); if (uri) { GList *layers; GimpPDBStatusType status; layers = file_open_layers (gimp, context, progress, image, FALSE, uri, run_mode, NULL, &status, error); if (layers) { layer = layers->data; g_list_free (layers); } else success = FALSE; } else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_layer (gimp_value_array_index (return_vals, 1), layer); return return_vals; }
static gboolean file_open_dialog_open_layers (GtkWidget *open_dialog, GimpImage *image, const gchar *uri, const gchar *entered_filename, GimpPlugInProcedure *load_proc) { GList *new_layers; GimpPDBStatusType status; GError *error = NULL; new_layers = file_open_layers (image->gimp, gimp_get_user_context (image->gimp), GIMP_PROGRESS (open_dialog), image, FALSE, uri, GIMP_RUN_INTERACTIVE, load_proc, &status, &error); if (new_layers) { gimp_image_add_layers (image, new_layers, GIMP_IMAGE_ACTIVE_PARENT, -1, 0, 0, gimp_image_get_width (image), gimp_image_get_height (image), _("Open layers")); g_list_free (new_layers); return TRUE; } else if (status != GIMP_PDB_CANCEL) { gchar *filename = file_utils_uri_display_name (uri); gimp_message (image->gimp, G_OBJECT (open_dialog), GIMP_MESSAGE_ERROR, _("Opening '%s' failed:\n\n%s"), filename, error->message); g_clear_error (&error); g_free (filename); } return FALSE; }
static void gimp_display_shell_drop_uri_list (GtkWidget *widget, gint x, gint y, GList *uri_list, gpointer data) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data); GimpImage *image; GimpContext *context; GList *list; gboolean open_as_layers; /* If the app is already being torn down, shell->display might be NULL here. * Play it safe. */ if (! shell->display) { return; } image = shell->display->image; context = gimp_get_user_context (shell->display->gimp); GIMP_LOG (DND, NULL); open_as_layers = (shell->display->image != NULL); for (list = uri_list; list; list = g_list_next (list)) { const gchar *uri = list->data; GimpPDBStatusType status; GError *error = NULL; gboolean warn = FALSE; if (! shell->display) { /* It seems as if GIMP is being torn down for quitting. Bail out. */ return; } if (open_as_layers) { GList *new_layers; new_layers = file_open_layers (shell->display->gimp, context, GIMP_PROGRESS (shell->display), image, FALSE, uri, GIMP_RUN_INTERACTIVE, NULL, &status, &error); if (new_layers) { gint x, y; gint width, height; gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); gimp_image_add_layers (image, new_layers, -1, x, y, width, height, _("Drop layers")); g_list_free (new_layers); } else if (status != GIMP_PDB_CANCEL) { warn = TRUE; } } else if (shell->display->image) { /* open any subsequent images in a new display */ GimpImage *new_image; new_image = file_open_with_display (shell->display->gimp, context, NULL, uri, FALSE, &status, &error); if (! new_image && status != GIMP_PDB_CANCEL) warn = TRUE; } else { /* open the first image in the empty display */ image = file_open_with_display (shell->display->gimp, context, GIMP_PROGRESS (shell->display), uri, FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) warn = TRUE; } /* Something above might have run a few rounds of the main loop. Check * that shell->display is still there, otherwise ignore this as the app * is being torn down for quitting. */ if (warn && shell->display) { gchar *filename = file_utils_uri_display_name (uri); gimp_message (shell->display->gimp, G_OBJECT (shell->display), GIMP_MESSAGE_ERROR, _("Opening '%s' failed:\n\n%s"), filename, error->message); g_clear_error (&error); g_free (filename); } } if (image) gimp_display_shell_dnd_flush (shell, image); }
static GimpValueArray * file_load_layers_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; gint32 run_mode; GimpImage *image; const gchar *filename; gint32 num_layers = 0; gint32 *layer_ids = NULL; run_mode = g_value_get_enum (gimp_value_array_index (args, 0)); image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp); filename = g_value_get_string (gimp_value_array_index (args, 2)); if (success) { gchar *uri = file_utils_filename_to_uri (gimp, filename, error); if (uri) { GList *layers; GimpPDBStatusType status; layers = file_open_layers (gimp, context, progress, image, FALSE, uri, run_mode, NULL, &status, error); if (layers) { GList *list; gint i; num_layers = g_list_length (layers); layer_ids = g_new (gint32, num_layers); for (i = 0, list = layers; i < num_layers; i++, list = g_list_next (list)) layer_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data)); g_list_free (layers); } else success = FALSE; } else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) { g_value_set_int (gimp_value_array_index (return_vals, 1), num_layers); gimp_value_take_int32array (gimp_value_array_index (return_vals, 2), layer_ids, num_layers); } return return_vals; }