Commit 9e7edcd6 authored by Martin Nordholts's avatar Martin Nordholts

app: Introduce file_write_with_uri_and_proc()

Introduce file_write_with_uri_and_proc() so that the
file_save_cmd_callback() switch case becomes more managable and so
that we can reuse that logic later.
parent c3be07e9
......@@ -64,25 +64,31 @@
/* local function prototypes */
static void file_open_dialog_show (Gimp *gimp,
GtkWidget *parent,
const gchar *title,
GimpImage *image,
const gchar *uri,
gboolean open_as_layers);
static void file_save_dialog_show (GimpImage *image,
GtkWidget *parent,
const gchar *title,
gboolean save_a_copy,
gboolean close_after_saving);
static void file_save_dialog_destroyed (GtkWidget *dialog,
GimpImage *image);
static void file_new_template_callback (GtkWidget *widget,
const gchar *name,
gpointer data);
static void file_revert_confirm_response (GtkWidget *dialog,
gint response_id,
GimpDisplay *display);
static void file_open_dialog_show (Gimp *gimp,
GtkWidget *parent,
const gchar *title,
GimpImage *image,
const gchar *uri,
gboolean open_as_layers);
static void file_save_dialog_show (GimpImage *image,
GtkWidget *parent,
const gchar *title,
gboolean save_a_copy,
gboolean close_after_saving);
static gboolean file_write_with_uri_and_proc (GimpImage *image,
GimpContext *context,
GimpDisplay *display,
const gchar *uri,
GimpPlugInProcedure *proc);
static void file_save_dialog_destroyed (GtkWidget *dialog,
GimpImage *image);
static void file_new_template_callback (GtkWidget *widget,
const gchar *name,
gpointer data);
static void file_revert_confirm_response (GtkWidget *dialog,
gint response_id,
GimpDisplay *display);
/* public functions */
......@@ -236,59 +242,11 @@ file_save_cmd_callback (GtkAction *action,
if (uri && save_proc)
{
GimpPDBStatusType status;
GError *error = NULL;
GList *list;
for (list = gimp_action_groups_from_name ("file");
list;
list = g_list_next (list))
{
gimp_action_group_set_action_sensitive (list->data,
"file-quit",
FALSE);
}
status = file_save (image, action_data_get_context (data),
GIMP_PROGRESS (display),
uri, save_proc,
GIMP_RUN_WITH_LAST_VALS, FALSE, &error);
switch (status)
{
case GIMP_PDB_SUCCESS:
saved = TRUE;
break;
case GIMP_PDB_CANCEL:
gimp_message_literal (image->gimp,
G_OBJECT (display), GIMP_MESSAGE_INFO,
_("Saving canceled"));
break;
default:
{
gchar *filename = file_utils_uri_display_name (uri);
gimp_message (image->gimp, G_OBJECT (display),
GIMP_MESSAGE_ERROR,
_("Saving '%s' failed:\n\n%s"),
filename, error->message);
g_free (filename);
g_clear_error (&error);
}
break;
}
for (list = gimp_action_groups_from_name ("file");
list;
list = g_list_next (list))
{
gimp_action_group_set_action_sensitive (list->data,
"file-quit",
TRUE);
}
saved = file_write_with_uri_and_proc (image,
action_data_get_context (data),
display,
uri,
save_proc);
break;
}
......@@ -543,6 +501,70 @@ file_save_dialog_show (GimpImage *image,
}
}
static gboolean
file_write_with_uri_and_proc (GimpImage *image,
GimpContext *context,
GimpDisplay *display,
const gchar *uri,
GimpPlugInProcedure *proc)
{
gboolean saved = FALSE;
GimpPDBStatusType status;
GError *error = NULL;
GList *list;
for (list = gimp_action_groups_from_name ("file");
list;
list = g_list_next (list))
{
gimp_action_group_set_action_sensitive (list->data,
"file-quit",
FALSE);
}
status = file_save (image, context,
GIMP_PROGRESS (display),
uri, proc,
GIMP_RUN_WITH_LAST_VALS, FALSE, &error);
switch (status)
{
case GIMP_PDB_SUCCESS:
saved = TRUE;
break;
case GIMP_PDB_CANCEL:
gimp_message_literal (image->gimp,
G_OBJECT (display), GIMP_MESSAGE_INFO,
_("Saving canceled"));
break;
default:
{
gchar *filename = file_utils_uri_display_name (uri);
gimp_message (image->gimp, G_OBJECT (display),
GIMP_MESSAGE_ERROR,
_("Saving '%s' failed:\n\n%s"),
filename, error->message);
g_free (filename);
g_clear_error (&error);
}
break;
}
for (list = gimp_action_groups_from_name ("file");
list;
list = g_list_next (list))
{
gimp_action_group_set_action_sensitive (list->data,
"file-quit",
TRUE);
}
return saved;
}
static void
file_save_dialog_destroyed (GtkWidget *dialog,
GimpImage *image)
......
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