[ease] [editor] Slide title is automatically based on text



commit a451cc9222cf82fc29aa1950e10e695a9d725cad
Author: Nate Stedman <natesm gmail com>
Date:   Thu Jul 29 04:28:44 2010 -0400

    [editor] Slide title is automatically based on text
    
    The slide's title in the slide sorter is automatically
    set to the text value of the header or title text element
    on the slide, if one exists. When this element is
    deleted, the title is reset to a default.

 ease-core/ease-document.vala |   45 +++++++++++++++++++++++++++++++++++++++-
 ease-core/ease-slide.vala    |   47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletions(-)
---
diff --git a/ease-core/ease-document.vala b/ease-core/ease-document.vala
index d7e2aa1..b30fd19 100644
--- a/ease-core/ease-document.vala
+++ b/ease-core/ease-document.vala
@@ -246,10 +246,13 @@ public class Ease.Document : GLib.Object, UndoSource
 		Gtk.TreeIter itr;
 		slides.insert(out itr, index);
 		slides.set(itr, COL_SLIDE, slide);
-		slides.set(itr, COL_TITLE, DEFAULT_TITLE.printf(index));
+		slides.set(itr, COL_TITLE, DEFAULT_TITLE.printf(index_of(slide) + 1));
 		slide_added(slide, index);
 		listen(slide);
 		
+		slide.title_changed.connect(on_title_changed);
+		slide.title_reset.connect(on_title_reset);
+		
 		if (emit_undo) undo(new SlideAddUndoAction(slide));
 	}
 	
@@ -280,6 +283,10 @@ public class Ease.Document : GLib.Object, UndoSource
 		// emit an undo action if needed
 		if (emit_undo) undo(new SlideRemoveUndoAction(slide));
 		
+		// disconnect title handlers
+		slide.title_changed.disconnect(on_title_changed);
+		slide.title_reset.disconnect(on_title_reset);
+		
 		Slide s;
 		var index = 0;
 		foreach (var itr in slides)
@@ -385,6 +392,42 @@ public class Ease.Document : GLib.Object, UndoSource
 	}
 	
 	/**
+	 * Updates a slide's title.
+	 */
+	internal void on_title_changed(Slide slide, string title)
+	{
+		Slide s;
+		foreach (var itr in slides)
+		{
+			slides.get(itr, COL_SLIDE, out s);
+			if (s == slide)
+			{
+				slides.set(itr, COL_TITLE, title);
+				return;
+			}
+		}
+	}
+	
+	/**
+	 * Resets a slide's title to the default.
+	 */
+	internal void on_title_reset(Slide slide)
+	{
+		debug("title reset");
+		Slide s;
+		foreach (var itr in slides)
+		{
+			slides.get(itr, COL_SLIDE, out s);
+			if (s == slide)
+			{
+				slides.set(itr, COL_TITLE,
+				           DEFAULT_TITLE.printf(index_of(slide) + 1));
+				return;
+			}
+		}
+	}
+	
+	/**
 	 * Renders this Document to a CairoSurface. Obviously, this only really
 	 * works with multi-page surfaces.
 	 *
diff --git a/ease-core/ease-slide.vala b/ease-core/ease-slide.vala
index a4335f2..6091f5e 100644
--- a/ease-core/ease-slide.vala
+++ b/ease-core/ease-slide.vala
@@ -179,6 +179,16 @@ public class Ease.Slide : GLib.Object, UndoSource
 	public signal void element_reordered(Slide self, Element element);
 	
 	/**
+	 * Updates this slide's title.
+	 */
+	internal signal void title_changed(Slide self, string title);
+	
+	/**
+	 * Resets this slide's title to its default.
+	 */
+	internal signal void title_reset(Slide self);
+	
+	/**
 	 * Create a new Slide.
 	 */
 	public Slide()
@@ -189,6 +199,17 @@ public class Ease.Slide : GLib.Object, UndoSource
 		undo.connect((item) => {
 			if (background.owns_undoitem(item)) background_changed(this);
 		});
+		
+		// update the slide's title when the title element changes
+		forwarded.connect((item) => {
+			if (item is UndoAction)
+			{
+				foreach (var pair in (item as UndoAction).pairs)
+				{
+					if (pair.property == "text") update_title(pair.object);
+				}
+			}
+		});
 	}
 	
 	/**
@@ -350,6 +371,7 @@ public class Ease.Slide : GLib.Object, UndoSource
 		elements.insert(index, e);
 		element_added(this, e, index);
 		listen(e);
+		update_title(e);
 		if (emit_undo) undo(new ElementAddUndoAction(e));
 	}
 	
@@ -381,6 +403,15 @@ public class Ease.Slide : GLib.Object, UndoSource
 		elements.remove(e);
 		element_removed(this, e, index);
 		silence(e);
+		
+		if (e is TextElement)
+		{
+			if ((e as TextElement).identifier == Theme.TITLE_TEXT ||
+			    (e as TextElement).identifier == Theme.HEADER_TEXT)
+			{
+				title_reset(this);
+			}
+		}
 	}
 	
 	/**
@@ -585,6 +616,22 @@ public class Ease.Slide : GLib.Object, UndoSource
 		
 		html += "</div>\n";
 	}
+	
+	/**
+	 * Updates the slide's title if the given object is a TextElement with the
+	 * { link Theme.TITLE_TEXT} identifier.
+	 */
+	private void update_title(GLib.Object object)
+	{
+		if (object is TextElement)
+		{
+			if ((object as TextElement).identifier == Theme.TITLE_TEXT || 
+			    (object as TextElement).identifier == Theme.HEADER_TEXT)
+			{
+				title_changed(this, (object as TextElement).text);
+			}
+		}
+	}
 
 	// foreach iteration
 	



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