diff options
author | Razvan Chitu <razvan.ch95@gmail.com> | 2016-01-08 23:42:51 +0200 |
---|---|---|
committer | Razvan Chitu <razvan.ch95@gmail.com> | 2016-01-12 20:51:07 +0200 |
commit | d52c523414a9fde659c22c1446494ccee9354ec1 (patch) | |
tree | 55b8b1c2bbf3a3484399fee8decee5d7bed49049 | |
parent | 050d031250970b55bbb0e4a58dfaded84c89b354 (diff) | |
download | nautilus-d52c523414a9fde659c22c1446494ccee9354ec1.tar.gz |
file-undo-manager: handle undo_redo_flag internally
Nautilus undo manager reuses undo information based on a flag that marks whether
an undo / redo operation is currently being performed. Previously, the flag was
managed both internally and externally. This proved to be unnecessary and even
harmful, as it led to an unexpected behavior.
Remove push and pop functions and handle the flag explicitly, at the start and
at the end of an undo / redo operation. Replace external use of pop with the use
of a getter function, also introduced in this patch.
https://bugzilla.gnome.org/show_bug.cgi?id=759850
-rw-r--r-- | libnautilus-private/nautilus-file-operations.c | 18 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-undo-manager.c | 26 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-undo-manager.h | 3 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-undo-operations.c | 7 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 8 |
5 files changed, 20 insertions, 42 deletions
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c index c48bbb3d5..2b5fc58de 100644 --- a/libnautilus-private/nautilus-file-operations.c +++ b/libnautilus-private/nautilus-file-operations.c @@ -2231,7 +2231,7 @@ trash_or_delete_internal (GList *files, inhibit_power_manager ((CommonJob *)job, _("Deleting Files")); } - if (!nautilus_file_undo_manager_pop_flag () && try_trash) { + if (!nautilus_file_undo_manager_get_flag () && try_trash) { job->common.undo_info = nautilus_file_undo_info_trash_new (g_list_length (files)); } @@ -5126,7 +5126,7 @@ nautilus_file_operations_copy (GList *files, inhibit_power_manager ((CommonJob *)job, _("Copying Files")); - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { GFile* src_dir; src_dir = g_file_get_parent (files->data); @@ -5667,7 +5667,7 @@ nautilus_file_operations_move (GList *files, inhibit_power_manager ((CommonJob *)job, _("Moving Files")); - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { GFile* src_dir; src_dir = g_file_get_parent (files->data); @@ -5994,7 +5994,7 @@ nautilus_file_operations_link (GList *files, } job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL); - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { GFile* src_dir; src_dir = g_file_get_parent (files->data); @@ -6042,7 +6042,7 @@ nautilus_file_operations_duplicate (GList *files, } job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL); - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { GFile* src_dir; src_dir = g_file_get_parent (files->data); @@ -6214,7 +6214,7 @@ nautilus_file_set_permissions_recursive (const char *directory, job->done_callback = callback; job->done_callback_data = callback_data; - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { job->common.undo_info = nautilus_file_undo_info_rec_permissions_new (job->file, file_permissions, file_mask, @@ -6739,7 +6739,7 @@ nautilus_file_operations_new_folder (GtkWidget *parent_view, job->has_position = TRUE; } - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER); } @@ -6781,7 +6781,7 @@ nautilus_file_operations_new_file_from_template (GtkWidget *parent_view, job->src = g_file_new_for_uri (template_uri); } - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE); } @@ -6822,7 +6822,7 @@ nautilus_file_operations_new_file (GtkWidget *parent_view, job->length = length; job->filename = g_strdup (target_filename); - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE); } diff --git a/libnautilus-private/nautilus-file-undo-manager.c b/libnautilus-private/nautilus-file-undo-manager.c index 497e3d10f..7de970148 100644 --- a/libnautilus-private/nautilus-file-undo-manager.c +++ b/libnautilus-private/nautilus-file-undo-manager.c @@ -158,6 +158,8 @@ undo_info_apply_ready (GObject *source, success = nautilus_file_undo_info_apply_finish (info, res, &user_cancel, NULL); + self->priv->undo_redo_flag = FALSE; + /* just return in case we got another another operation set */ if ((self->priv->info != NULL) && (self->priv->info != info)) { @@ -189,8 +191,8 @@ do_undo_redo (NautilusFileUndoManager *self, gboolean undo = self->priv->state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO; self->priv->last_state = self->priv->state; - - nautilus_file_undo_manager_push_flag (); + + self->priv->undo_redo_flag = TRUE; nautilus_file_undo_info_apply_async (self->priv->info, undo, parent_window, undo_info_apply_ready, self); @@ -261,28 +263,12 @@ nautilus_file_undo_manager_get_state (void) return self->priv->state; } -void -nautilus_file_undo_manager_push_flag () -{ - NautilusFileUndoManager *self = get_singleton (); - NautilusFileUndoManagerPrivate *priv = self->priv; - - priv->undo_redo_flag = TRUE; -} gboolean -nautilus_file_undo_manager_pop_flag () +nautilus_file_undo_manager_get_flag () { NautilusFileUndoManager *self = get_singleton (); - NautilusFileUndoManagerPrivate *priv = self->priv; - gboolean retval = FALSE; - - if (priv->undo_redo_flag) { - retval = TRUE; - } - - priv->undo_redo_flag = FALSE; - return retval; + return self->priv->undo_redo_flag; } NautilusFileUndoManager * diff --git a/libnautilus-private/nautilus-file-undo-manager.h b/libnautilus-private/nautilus-file-undo-manager.h index f8d8ccdb6..8163a32b2 100644 --- a/libnautilus-private/nautilus-file-undo-manager.h +++ b/libnautilus-private/nautilus-file-undo-manager.h @@ -79,7 +79,6 @@ NautilusFileUndoManagerState nautilus_file_undo_manager_get_state (void); void nautilus_file_undo_manager_undo (GtkWindow *parent_window); void nautilus_file_undo_manager_redo (GtkWindow *parent_window); -void nautilus_file_undo_manager_push_flag (void); -gboolean nautilus_file_undo_manager_pop_flag (void); +gboolean nautilus_file_undo_manager_get_flag (void); #endif /* __NAUTILUS_FILE_UNDO_MANAGER_H__ */ diff --git a/libnautilus-private/nautilus-file-undo-operations.c b/libnautilus-private/nautilus-file-undo-operations.c index 6a47223d5..7201ceda5 100644 --- a/libnautilus-private/nautilus-file-undo-operations.c +++ b/libnautilus-private/nautilus-file-undo-operations.c @@ -1218,9 +1218,6 @@ trash_undo_func (NautilusFileUndoInfo *info, { NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info); - /* Internally managed op, pop flag. */ - nautilus_file_undo_manager_pop_flag (); - trash_retrieve_files_to_restore_async (self, trash_retrieve_files_ready, NULL); } @@ -1349,10 +1346,6 @@ rec_permissions_undo_func (NautilusFileUndoInfo *info, { NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info); - /* Internally managed op, pop flag. */ - /* TODO: why? */ - nautilus_file_undo_manager_pop_flag (); - if (g_hash_table_size (self->priv->original_permissions) > 0) { GList *gfiles_list; guint32 perm; diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index e1219f6be..9f809b27e 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -1970,7 +1970,7 @@ nautilus_file_rename (NautilusFile *file, location = nautilus_file_get_location (file); /* Tell the undo manager a rename is taking place */ - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { op->undo_info = nautilus_file_undo_info_rename_new (); old_name = nautilus_file_get_display_name (file); @@ -5249,7 +5249,7 @@ nautilus_file_set_permissions (NautilusFile *file, return; } - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { NautilusFileUndoInfo *undo_info; undo_info = nautilus_file_undo_info_permissions_new (nautilus_file_get_location (file), @@ -5562,7 +5562,7 @@ nautilus_file_set_owner (NautilusFile *file, return; } - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { NautilusFileUndoInfo *undo_info; char* current_owner; @@ -5840,7 +5840,7 @@ nautilus_file_set_group (NautilusFile *file, return; } - if (!nautilus_file_undo_manager_pop_flag ()) { + if (!nautilus_file_undo_manager_get_flag ()) { NautilusFileUndoInfo *undo_info; char *current_group; |