[gnome-photos] application, pipeline: Add API to revert a series of edits and use it



commit 96b21d9c373280ce8cc7ca512095dd0c619539f2
Author: Rafael Fonseca <r4f4rfs gmail com>
Date:   Wed Feb 17 17:20:56 2016 +0100

    application, pipeline: Add API to revert a series of edits and use it
    
    The undo operation doesn't fit with the realities of our current UX
    because we don't allow undoing a single edit. We always revert a series
    of edits. In the following patches we will implement snapshots which
    will let us revert a specific set of edits.
    
    Therefore, a revert operation to remove all the operation nodes in the
    GEGL graph is clearer and more useful.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761683

 src/photos-application.c |    3 +--
 src/photos-base-item.c   |    7 +++++++
 src/photos-base-item.h   |    2 ++
 src/photos-pipeline.c    |   23 +++++++++++++++++++++++
 src/photos-pipeline.h    |    2 ++
 5 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 32a4596..45e7bbf 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -722,8 +722,7 @@ photos_application_edit_cancel (PhotosApplication *self)
   item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->state->item_mngr));
   g_return_if_fail (item != NULL);
 
-  while (photos_base_item_operation_undo (item))
-    ;
+  photos_base_item_operations_revert (item);
 
   g_application_hold (G_APPLICATION (self));
   photos_base_item_process_async (item, NULL, photos_application_edit_cancel_process, self);
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 51f42df..18b9745 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -2177,6 +2177,13 @@ photos_base_item_operation_undo (PhotosBaseItem *self)
 
 
 void
+photos_base_item_operations_revert (PhotosBaseItem *self)
+{
+  return photos_pipeline_revert (self->priv->pipeline);
+}
+
+
+void
 photos_base_item_pipeline_save_async (PhotosBaseItem *self,
                                       GCancellable *cancellable,
                                       GAsyncReadyCallback callback,
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index e6c0657..68d3bff 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -197,6 +197,8 @@ gboolean            photos_base_item_operation_get           (PhotosBaseItem *se
 
 gboolean            photos_base_item_operation_undo          (PhotosBaseItem *self);
 
+void                photos_base_item_operations_revert       (PhotosBaseItem *self);
+
 void                photos_base_item_pipeline_save_async     (PhotosBaseItem *self,
                                                               GCancellable *cancellable,
                                                               GAsyncReadyCallback callback,
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
index 5d86bda..e8c00e0 100644
--- a/src/photos-pipeline.c
+++ b/src/photos-pipeline.c
@@ -576,3 +576,26 @@ photos_pipeline_undo (PhotosPipeline *self)
   g_free (operation);
   return ret_val;
 }
+
+
+void
+photos_pipeline_revert (PhotosPipeline *self)
+{
+  GeglNode *input;
+  GeglNode *last;
+  GeglNode *output;
+
+  input = gegl_node_get_input_proxy (self->graph, "input");
+  output = gegl_node_get_output_proxy (self->graph, "output");
+  last = gegl_node_get_producer (output, "input", NULL);
+
+  g_hash_table_remove_all (self->hash);
+
+  while (last != NULL && last != input)
+    {
+      gegl_node_remove_child (self->graph, last);
+      last = gegl_node_get_producer (output, "input", NULL);
+    }
+
+  gegl_node_link (input, output);
+}
diff --git a/src/photos-pipeline.h b/src/photos-pipeline.h
index 7430f06..bb302e7 100644
--- a/src/photos-pipeline.h
+++ b/src/photos-pipeline.h
@@ -89,6 +89,8 @@ gboolean               photos_pipeline_save_finish       (PhotosPipeline *self,
 
 gboolean               photos_pipeline_undo              (PhotosPipeline *self);
 
+void                   photos_pipeline_revert            (PhotosPipeline *self);
+
 G_END_DECLS
 
 #endif /* PHOTOS_PIPELINE_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]