[glide] Implement some undo machinery for slides



commit c7248afee1c644424ed65c060417a93953d599c3
Author: Robert Carr <racarr Valentine localdomain>
Date:   Thu Apr 29 04:55:18 2010 -0400

    Implement some undo machinery for slides

 src/glide-undo-manager-priv.h |    3 +
 src/glide-undo-manager.c      |   92 +++++++++++++++++++++++++++++++++++++++++
 src/glide-undo-manager.h      |    3 +
 3 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/src/glide-undo-manager-priv.h b/src/glide-undo-manager-priv.h
index f2450a3..af5662b 100644
--- a/src/glide-undo-manager-priv.h
+++ b/src/glide-undo-manager-priv.h
@@ -31,6 +31,9 @@ struct _GlideUndoManagerPrivate
   // GlideActor too..
   JsonObject *recorded_state;
   gchar *recorded_label;
+  
+  gchar *recorded_background;
+  ClutterColor recorded_color;
 
   GList *infos;
   GList *position;
diff --git a/src/glide-undo-manager.c b/src/glide-undo-manager.c
index 7e77b5a..deb100c 100644
--- a/src/glide-undo-manager.c
+++ b/src/glide-undo-manager.c
@@ -21,6 +21,7 @@
 #include "glide-undo-manager.h"
 #include "glide-stage-manager.h"
 #include "glide-actor.h"
+#include "glide-slide.h"
 
 #include "glide-undo-manager-priv.h"
 
@@ -102,6 +103,53 @@ glide_undo_delete_actor_redo_callback (GlideUndoManager *undo_manager,
   return TRUE;
 }
 
+typedef struct _GlideUndoSlideData {
+  GlideSlide *slide;
+  
+  ClutterColor old_color;
+  gchar *old_background;
+  
+  ClutterColor new_color;
+  gchar *new_background;
+} GlideUndoSlideData;
+
+static void
+glide_undo_slide_info_free_callback (GlideUndoInfo *info)
+{
+  GlideUndoSlideData *d = (GlideUndoSlideData *)info->user_data;
+  
+  g_free (d->old_background);
+  g_free (d->new_background);
+
+  g_object_unref (G_OBJECT (d->slide));  
+
+  g_free (d);
+}
+
+static gboolean
+glide_undo_slide_action_undo_callback (GlideUndoManager *undo_manager,
+				       GlideUndoInfo *info)
+{
+  GlideUndoSlideData *data = (GlideUndoSlideData *)info->user_data;
+  
+  glide_slide_set_background (data->slide, data->old_background);
+  glide_slide_set_color (data->slide, &data->old_color);
+							      
+  return TRUE;
+}
+
+static gboolean
+glide_undo_slide_action_redo_callback (GlideUndoManager *undo_manager,
+				       GlideUndoInfo *info)
+{
+  GlideUndoSlideData *data = (GlideUndoSlideData *)info->user_data;
+  
+  glide_slide_set_background (data->slide, data->new_background);
+  glide_slide_set_color (data->slide, &data->new_color);
+							      
+  return TRUE;
+}
+
 typedef struct _GlideUndoActorData {
   ClutterActor *actor;
 
@@ -144,6 +192,50 @@ glide_undo_actor_action_redo_callback (GlideUndoManager *undo_manager,
 }
 
 void
+glide_undo_manager_start_slide_action (GlideUndoManager *manager,
+				       GlideSlide *s,
+				       const gchar *label)
+{
+  manager->priv->recorded_actor = (ClutterActor *)s;
+  manager->priv->recorded_label = g_strdup (label);
+  
+  manager->priv->recorded_background = g_strdup (glide_slide_get_background (s));
+  glide_slide_get_color (s, &manager->priv->recorded_color);
+}
+
+void
+glide_undo_manager_end_slide_action (GlideUndoManager *manager,
+				     GlideSlide *a)
+{
+  GlideUndoInfo *info;
+  GlideUndoSlideData *data;
+  
+  if (manager->priv->recorded_actor != (ClutterActor *)a)
+    {
+      g_warning ("Error, mismatched undo manager start/end slide actions.");
+      return;
+    }
+  
+  info = g_malloc (sizeof (GlideUndoInfo));
+  data = g_malloc (sizeof (GlideUndoActorData));
+  
+  info->undo_callback = glide_undo_slide_action_undo_callback;
+  info->redo_callback = glide_undo_slide_action_redo_callback;
+  info->free_callback = glide_undo_slide_info_free_callback;
+  info->label = manager->priv->recorded_label;
+  info->user_data = data;
+  
+  data->slide = (GlideSlide *)g_object_ref (G_OBJECT (a));
+  data->old_color = manager->priv->recorded_color;
+  data->old_background = manager->priv->recorded_background;
+  
+  glide_slide_get_color (a, &data->new_color);
+  data->new_background = g_strdup (glide_slide_get_background (a));
+  
+  glide_undo_manager_append_info (manager, info);
+}
+
+void
 glide_undo_manager_start_actor_action (GlideUndoManager *manager,
 				       GlideActor *a,
 				       const gchar *label)
diff --git a/src/glide-undo-manager.h b/src/glide-undo-manager.h
index 4e8facc..2935b34 100644
--- a/src/glide-undo-manager.h
+++ b/src/glide-undo-manager.h
@@ -88,6 +88,9 @@ gboolean glide_undo_manager_redo (GlideUndoManager *manager);
 void glide_undo_manager_start_actor_action (GlideUndoManager *manager, GlideActor *a, const gchar *label);
 void glide_undo_manager_end_actor_action (GlideUndoManager *manager, GlideActor *a);
 
+void glide_undo_manager_start_slide_action (GlideUndoManager *manager, GlideSlide *s, const gchar *label);
+void glide_undo_manager_end_slide_action (GlideUndoManager *manager, GlideSlide *s);
+
 void glide_undo_manager_append_delete (GlideUndoManager *manager, GlideActor *a);
 void glide_undo_manager_append_insert (GlideUndoManager *manager, GlideActor *a);
 



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