Skip to content
Snippets Groups Projects
Commit f416a9f5 authored by Alexander Schwinn's avatar Alexander Schwinn
Browse files

Undo/Redo: Improve error handling

Handle operation errors and cancelation via dialog separately

MR !338

(cherry picked (not cleanly) from commit f3d22f98)
parent ab12177c
No related branches found
No related tags found
No related merge requests found
......@@ -307,6 +307,7 @@ thunar_job_operation_history_undo (void)
gchar *file_uri;
GError *err = NULL;
const GList *overwritten_files;
gboolean operation_canceled;
g_mutex_lock (&job_operation_history->job_operation_list_mutex);
......@@ -366,12 +367,21 @@ thunar_job_operation_history_undo (void)
}
inverted_operation = thunar_job_operation_new_invert (operation_marker);
thunar_job_operation_execute (inverted_operation, &err);
operation_canceled = thunar_job_operation_execute (inverted_operation, &err);
g_object_unref (inverted_operation);
if (err == NULL)
if (err == NULL && !operation_canceled)
thunar_notify_undo (operation_marker);
if (err != NULL)
{
xfce_dialog_show_warning (NULL,
err->message,
_("Failed to undo operation '%s'"),
thunar_job_operation_get_kind_nick (operation_marker));
g_clear_error (&err);
}
g_mutex_unlock (&job_operation_history->job_operation_list_mutex);
/* Notify all subscribers of our properties */
......@@ -394,6 +404,7 @@ thunar_job_operation_history_redo (void)
gchar *file_uri;
GError *err = NULL;
const GList *overwritten_files;
gboolean operation_canceled;
g_mutex_lock (&job_operation_history->job_operation_list_mutex);
......@@ -451,10 +462,19 @@ thunar_job_operation_history_redo (void)
g_string_free (warning_body, TRUE);
}
thunar_job_operation_execute (operation_marker, &err);
operation_canceled = thunar_job_operation_execute (operation_marker, &err);
if (err == NULL)
thunar_notify_redo (operation_marker);
if (err == NULL && !operation_canceled)
thunar_notify_undo (operation_marker);
if (err != NULL)
{
xfce_dialog_show_warning (NULL,
err->message,
_("Failed to redo operation '%s'"),
thunar_job_operation_get_kind_nick (operation_marker));
g_clear_error (&err);
}
g_mutex_unlock (&job_operation_history->job_operation_list_mutex);
......
......@@ -378,8 +378,10 @@ thunar_job_operation_new_invert (ThunarJobOperation *job_operation)
* @error: A #GError to propagate any errors encountered.
*
* Executes the given @job_operation, depending on what kind of an operation it is.
*
* Return value: TRUE if the operation was canceled, FALSE otherwise
**/
void
gboolean
thunar_job_operation_execute (ThunarJobOperation *job_operation,
GError **error)
{
......@@ -391,9 +393,9 @@ thunar_job_operation_execute (ThunarJobOperation *job_operation,
GFile *parent_dir;
gchar *display_name;
GFile *template_file;
gboolean execute_failed = FALSE;
gboolean operation_canceled = FALSE;
_thunar_return_if_fail (THUNAR_IS_JOB_OPERATION (job_operation));
_thunar_return_val_if_fail (THUNAR_IS_JOB_OPERATION (job_operation), FALSE);
application = thunar_application_get ();
......@@ -428,20 +430,16 @@ thunar_job_operation_execute (ThunarJobOperation *job_operation,
if (thunar_file_list == NULL)
{
execute_failed = TRUE;
*error = g_error_new (G_FILE_ERROR,
G_FILE_ERROR_NOENT,
"No files for deletion found.");
}
else
{
execute_failed = thunar_application_unlink_files (application, NULL, thunar_file_list, TRUE, TRUE);
operation_canceled = thunar_application_unlink_files (application, NULL, thunar_file_list, TRUE, TRUE);
g_list_free_full (thunar_file_list, g_object_unref);
}
if (execute_failed)
{
*error = g_error_new (G_FILE_ERROR,
G_FILE_ERROR_AGAIN,
"Failed to execute operation");
}
break;
case THUNAR_JOB_OPERATION_KIND_MOVE:
......@@ -468,7 +466,7 @@ thunar_job_operation_execute (ThunarJobOperation *job_operation,
g_propagate_error (error, err);
g_clear_error (&err);
g_object_unref (application);
return;
return operation_canceled;
}
}
......@@ -564,6 +562,7 @@ thunar_job_operation_execute (ThunarJobOperation *job_operation,
}
g_object_unref (application);
return operation_canceled;
}
......
......@@ -34,7 +34,7 @@ void thunar_job_operation_add (ThunarJobOpe
void thunar_job_operation_overwrite (ThunarJobOperation *job_operation,
GFile *overwritten_file);
ThunarJobOperation *thunar_job_operation_new_invert (ThunarJobOperation *job_operation);
void thunar_job_operation_execute (ThunarJobOperation *job_operation,
gboolean thunar_job_operation_execute (ThunarJobOperation *job_operation,
GError **error);
gint thunar_job_operation_compare (ThunarJobOperation *operation1,
ThunarJobOperation *operation2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment