[ease] [editor] Allow users to undo/redo slide add/remove



commit 63fa13324c6de00283925311cbbc8f34f8bb5c13
Author: Nate Stedman <natesm gmail com>
Date:   Sun Jul 25 05:49:48 2010 -0400

    [editor] Allow users to undo/redo slide add/remove

 Makefile.am                      |    1 +
 src/ease-document.vala           |    2 +-
 src/ease-editor-window.vala      |   11 ++++-
 src/ease-undo-actions-slide.vala |   93 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 874da54..811df46 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ ease_SOURCES = \
 	src/ease-transitions.vala \
 	src/ease-undo-action.vala \
 	src/ease-undo-actions-element.vala \
+	src/ease-undo-actions-slide.vala \
 	src/ease-undo-controller.vala \
 	src/ease-undo-item.vala \
 	src/ease-undo-source.vala \
diff --git a/src/ease-document.vala b/src/ease-document.vala
index f346d0f..209fa30 100644
--- a/src/ease-document.vala
+++ b/src/ease-document.vala
@@ -232,7 +232,7 @@ public class Ease.Document : GLib.Object
 	 *
 	 * @param s The slide to remove.
 	 */
-	public Slide rm_slide(Slide s)
+	public Slide remove_slide(Slide s)
 	{
 		int ind = index_of(s);
 		
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 2b694dd..9256a87 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -275,6 +275,9 @@ public class Ease.EditorWindow : Gtk.Window
 		
 		var index = document.index_of(slide) + 1;
 		
+		// add an undo action
+		add_undo_action(new SlideAddUndoAction(s));
+		
 		document.add_slide(index, s);
 	}
 	
@@ -287,6 +290,9 @@ public class Ease.EditorWindow : Gtk.Window
 		
 		var index = document.index_of(slide) + 1;
 		
+		// add an undo action
+		add_undo_action(new SlideAddUndoAction(s));
+		
 		document.add_slide(index, s);
 	}
 	
@@ -296,8 +302,11 @@ public class Ease.EditorWindow : Gtk.Window
 		// don't remove the last slide in a document
 		if (document.length < 2) return;
 		
+		// add an undo action
+		add_undo_action(new SlideRemoveUndoAction(slide));
+		
 		// set the slide to something safe
-		slide_button_panel.select_slide(document.rm_slide(slide));
+		slide_button_panel.select_slide(document.remove_slide(slide));
 	}
 	
 	[CCode (instance_pos = -1)]
diff --git a/src/ease-undo-actions-slide.vala b/src/ease-undo-actions-slide.vala
new file mode 100644
index 0000000..bb14620
--- /dev/null
+++ b/src/ease-undo-actions-slide.vala
@@ -0,0 +1,93 @@
+/*  Ease, a GTK presentation application
+    Copyright (C) 2010 Nate Stedman
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * Undos the addition of an { link Slide} to a { link Document}.
+ */
+public class Ease.SlideAddUndoAction : UndoItem
+{
+	/**
+	 * The { link Slide} that was added.
+	 */
+	private Slide slide;
+	
+	/**
+	 * Creates an SlideAddUndoAction.
+	 *
+	 * @param s The slide that was added.
+	 */
+	public SlideAddUndoAction(Slide s)
+	{
+		slide = s;
+	}
+	
+	/**
+	 * Applies the action, removing the { link Slide}.
+	 */
+	public override UndoItem apply()
+	{
+		var action = new SlideRemoveUndoAction(slide);
+		slide.parent.remove_slide(slide);
+		return action;
+	}
+}
+
+/**
+ * Undos the removal of an { link Slide} from a { link Document}.
+ */
+public class Ease.SlideRemoveUndoAction : UndoItem
+{
+	/**
+	 * The { link Slide} that was removed.
+	 */
+	private Slide slide;
+	
+	/**
+	 * The { link Document} that the Slide was removed from.
+	 */
+	private Document document;
+	
+	/**
+	 * The index of the Slide in the Document.
+	 */
+	int index;
+	
+	/**
+	 * Creates an SlideRemoveUndoAction. Note that this method references
+	 * { link Slide.parent}. Therefore, the action must be constructed
+	 * before the Slide is actually removed.
+	 *
+	 * @param s The slide that was added.
+	 */
+	public SlideRemoveUndoAction(Slide s)
+	{
+		slide = s;
+		document = s.parent;
+		index = s.parent.index_of(s);
+	}
+	
+	/**
+	 * Applies the action, restoring the { link Slide}.
+	 */
+	public override UndoItem apply()
+	{
+		document.add_slide(index, slide);
+		return new SlideAddUndoAction(slide);
+	}
+}
+
+



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