[ease] [general] Added UndoItem



commit dcb71dad93b1d39e8932731a3e04ffa52471fea1
Author: Nate Stedman <natesm gmail com>
Date:   Sun Jul 25 01:47:07 2010 -0400

    [general] Added UndoItem
    
    UndoItem is an abstract base class for UndoAction,
    and future types of undo action.

 Makefile.am                   |    1 +
 src/ease-editor-window.vala   |    4 ++--
 src/ease-undo-action.vala     |   16 ++++------------
 src/ease-undo-controller.vala |   20 ++++++++++----------
 src/ease-undo-item.vala       |   37 +++++++++++++++++++++++++++++++++++++
 src/ease-undo-source.vala     |    4 ++--
 6 files changed, 56 insertions(+), 26 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index dc09453..53b63c3 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-controller.vala \
+	src/ease-undo-item.vala \
 	src/ease-undo-source.vala \
 	src/ease-utilities.vala \
 	src/ease-welcome-actor.vala \
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 66dedb6..651b04c 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -224,9 +224,9 @@ public class Ease.EditorWindow : Gtk.Window
 	/**
 	 * Add the most recent action to the { link UndoController}.
 	 *
-	 * @param action The new { link UndoAction}.
+	 * @param action The new { link UndoItem}.
 	 */
-	public void add_undo_action(UndoAction action)
+	public void add_undo_action(UndoItem action)
 	{
 		undo.add_action(action);
 		undo.clear_redo();
diff --git a/src/ease-undo-action.vala b/src/ease-undo-action.vala
index 79f7592..747051b 100644
--- a/src/ease-undo-action.vala
+++ b/src/ease-undo-action.vala
@@ -16,21 +16,13 @@
 */
 
 /**
- * Abstract base class for undo actions.
- *
- * Subclasses should override apply() and add a constructor, as well as any
- * needed data fields.
+ * Generic undo item, using object/property pairs.
  */
-public class Ease.UndoAction : Object
+public class Ease.UndoAction : UndoItem
 {
 	private Gee.LinkedList<UndoPair> pairs = new Gee.LinkedList<UndoPair>();
 	
 	/**
-	 * Emitted after the action is applied.
-	 */
-	public signal void applied(UndoAction sender);
-	
-	/**
 	 * Creates an UndoAction.
 	 *
 	 * This should be followed up with calls to add() if the action has
@@ -60,7 +52,7 @@ public class Ease.UndoAction : Object
 	 *
 	 * @param action An UndoAction to add properties from.
 	 */
-	public virtual void combine(UndoAction action)
+	public void combine(UndoAction action)
 	{
 		foreach (var p in action.pairs) pairs.add(p);
 	}
@@ -70,7 +62,7 @@ public class Ease.UndoAction : Object
 	 *
 	 * Returns an UndoAction that will redo the undo action.
 	 */
-	public virtual UndoAction apply()
+	public override UndoItem apply()
 	{
 		foreach (var pair in pairs) pair.apply();
 		applied(this);
diff --git a/src/ease-undo-controller.vala b/src/ease-undo-controller.vala
index 0ed823b..1894007 100644
--- a/src/ease-undo-controller.vala
+++ b/src/ease-undo-controller.vala
@@ -25,12 +25,12 @@ public class Ease.UndoController : Object
 	/**
 	 * The undo queue.
 	 */
-	private Gee.LinkedList<UndoAction> undos = new Gee.LinkedList<UndoAction>();
+	private Gee.LinkedList<UndoItem> undos = new Gee.LinkedList<UndoItem>();
 	
 	/**
 	 * The redo queue.
 	 */
-	private Gee.LinkedList<UndoAction> redos = new Gee.LinkedList<UndoAction>();
+	private Gee.LinkedList<UndoItem> redos = new Gee.LinkedList<UndoItem>();
 	
 	/**
 	 * Creates an UndoController. Used by EditorWindow.
@@ -54,7 +54,7 @@ public class Ease.UndoController : Object
 	}
 	
 	/**
-	 * Undoes the first available { link UndoAction} in the undo queue.
+	 * Undoes the first available { link UndoItem} in the undo queue.
 	 */
 	public void undo()
 	{
@@ -62,7 +62,7 @@ public class Ease.UndoController : Object
 	}
 	
 	/**
-	 * Redoes the first available { link UndoAction} in the redo queue.
+	 * Redoes the first available { link UndoItem} in the redo queue.
 	 */
 	public void redo()
 	{
@@ -78,21 +78,21 @@ public class Ease.UndoController : Object
 	}
 	
 	/**
-	 * Adds a new { link UndoAction} as the first action.
+	 * Adds a new { link UndoItem} as the first action.
 	 *
-	 * @param action The new { link UndoAction}.
+	 * @param action The new { link UndoItem}.
 	 */
-	public void add_action(UndoAction action)
+	public void add_action(UndoItem action)
 	{
 		undos.offer_head(action);
 	}
 	
 	/**
-	 * Adds a new { link UndoAction} as the first action.
+	 * Adds a new { link UndoItem} as the first action.
 	 *
-	 * @param action The new { link UndoAction}.
+	 * @param action The new { link UndoItem}.
 	 */
-	private void add_redo_action(UndoAction action)
+	private void add_redo_action(UndoItem action)
 	{
 		redos.offer_head(action);
 	}
diff --git a/src/ease-undo-item.vala b/src/ease-undo-item.vala
new file mode 100644
index 0000000..0b12c0c
--- /dev/null
+++ b/src/ease-undo-item.vala
@@ -0,0 +1,37 @@
+/*  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/>.
+*/
+
+/**
+ * Abstract base class for undo actions.
+ *
+ * Subclasses should override apply() and add a constructor, as well as any
+ * needed data fields.
+ */
+public abstract class Ease.UndoItem : GLib.Object
+{
+	/**
+	 * Emitted after the item is applied.
+	 */
+	public signal void applied(UndoAction sender);
+	
+	/**
+	 * Applies the { link Item}, restoring previous state.
+	 *
+	 * Returns an UndoItem that will redo the undo action.
+	 */
+	public abstract UndoItem apply();
+}
diff --git a/src/ease-undo-source.vala b/src/ease-undo-source.vala
index 17e0f41..fcace0a 100644
--- a/src/ease-undo-source.vala
+++ b/src/ease-undo-source.vala
@@ -16,7 +16,7 @@
 */
 
 /**
- * Provides a signal to notify a controller of UndoActions.
+ * Provides a signal to notify a controller of { link UndoItem}s.
  */
 public interface Ease.UndoSource : GLib.Object
 {
@@ -25,5 +25,5 @@ public interface Ease.UndoSource : GLib.Object
 	 * to notify a parent controller (typically { link EditorWindow}) of a new
 	 * UndoAction.
 	 */
-	public signal void undo(UndoAction action);
+	public signal void undo(UndoItem action);
 }



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