[ease/themes] [editor] Allow removal of slides.



commit 52dff0246f421cf2caec04473bbdccb1200104d4
Author: Nate Stedman <natesm gmail com>
Date:   Thu Jul 22 16:48:01 2010 -0400

    [editor] Allow removal of slides.

 data/ui/editor-window.ui         |    3 ++
 src/ease-document.vala           |   17 ++++++++++++++++
 src/ease-editor-window.vala      |   14 +++++++++++-
 src/ease-slide-button-panel.vala |   39 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/editor-window.ui b/data/ui/editor-window.ui
index 58a26f8..12bf8ec 100644
--- a/data/ui/editor-window.ui
+++ b/data/ui/editor-window.ui
@@ -4,6 +4,7 @@
   <!-- interface-naming-policy project-wide -->
   <object class="GtkVBox" id="Editor Widget">
     <property name="visible">True</property>
+    <property name="orientation">vertical</property>
     <child>
       <object class="GtkMenuBar" id="Menu Bar">
         <property name="visible">True</property>
@@ -267,6 +268,7 @@
             <property name="label" translatable="yes">Remove Slide</property>
             <property name="use_underline">True</property>
             <property name="stock_id">gtk-remove</property>
+            <signal name="clicked" handler="ease_editor_window_remove_slide"/>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -441,6 +443,7 @@
         <child>
           <object class="GtkAlignment" id="Slides Align">
             <property name="visible">True</property>
+            <property name="right_padding">4</property>
             <child>
               <placeholder/>
             </child>
diff --git a/src/ease-document.vala b/src/ease-document.vala
index 5262575..b6c70c3 100644
--- a/src/ease-document.vala
+++ b/src/ease-document.vala
@@ -121,6 +121,23 @@ public class Ease.Document : SlideSet
 	}
 	
 	/**
+	 * Removes the specified { link Slide}, returning an Slide that the editor
+	 * can safely jump to.
+	 *
+	 * @param s The slide to remove.
+	 */
+	public Slide rm_slide(Slide s)
+	{
+		int ind = index_of(s);
+		
+		slides.remove(s);
+		slide_deleted(s, ind);
+		
+		if (ind == 0) return slides.get(0);
+		return slides.get(ind - 1);
+	}
+	
+	/**
 	 * Returns whether or not the Document has a { link Slide} after the
 	 * passed in { link Slide}.
 	 */
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 30db27a..b4f8b60 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -185,7 +185,7 @@ public class Ease.EditorWindow : Gtk.Window
 
 		hide.connect(() => Main.remove_window(this));
 		
-		load_slide(0);
+		set_slide(0);
 		update_undo();
 	}
 	
@@ -194,7 +194,7 @@ public class Ease.EditorWindow : Gtk.Window
 	 *
 	 * @param filename The index of the slide.
 	 */
-	public void load_slide(int index)
+	public void set_slide(int index)
 	{
 		slide = document.slides.get(index);
 		
@@ -251,6 +251,16 @@ public class Ease.EditorWindow : Gtk.Window
 	}
 	
 	[CCode (instance_pos = -1)]
+	public void remove_slide(Gtk.Widget? sender)
+	{
+		// don't remove the last slide in a document
+		if (document.length < 2) return;
+		
+		// set the slide to something safe
+		slide_button_panel.select_slide(document.rm_slide(slide));
+	}
+	
+	[CCode (instance_pos = -1)]
 	public void play_handler(Gtk.Widget sender)
 	{
 		player = new Player(document);
diff --git a/src/ease-slide-button-panel.vala b/src/ease-slide-button-panel.vala
index a7e3614..4802a68 100644
--- a/src/ease-slide-button-panel.vala
+++ b/src/ease-slide-button-panel.vala
@@ -104,7 +104,7 @@ public class Ease.SlideButtonPanel : Gtk.ScrolledWindow
 			slides.get_selection().selected_foreach((m, p, itr) => {
 				Slide s = new Slide();
 				m.get(itr, 1, ref s);
-				owner.load_slide(document.slides.index_of(s));
+				owner.set_slide(document.slides.index_of(s));
 			});
 		});
 		
@@ -117,6 +117,22 @@ public class Ease.SlideButtonPanel : Gtk.ScrolledWindow
 			list_store.set(itr, 0, pb, 1, slide, 2, path);
 		});
 		
+		// handle the removal of slides
+		document.slide_deleted.connect((slide, index) => {
+			Gtk.TreeIter itr;
+			Slide s = new Slide();
+			if (!list_store.get_iter_first(out itr)) return;
+			do
+			{
+				list_store.get(itr, 1, ref s);
+				if (s == slide)
+				{
+					list_store.remove(itr);
+					break;
+				}
+			} while (list_store.iter_next(ref itr));
+		});
+		
 		// redraw all slides when the size allocation changes
 		/*viewport.size_allocate.connect((sender, alloc) => {
 			var width = alloc.width - 2 * PADDING;
@@ -133,6 +149,27 @@ public class Ease.SlideButtonPanel : Gtk.ScrolledWindow
 	}
 	
 	/**
+	 * Selects a specified { link Slide}.
+	 *
+	 * @param s The slide to select.
+	 */
+	public void select_slide(Slide slide)
+	{
+		Gtk.TreeIter itr;
+		Slide s = new Slide();
+		if (!list_store.get_iter_first(out itr)) return;
+		do
+		{
+			list_store.get(itr, 1, ref s);
+			if (s == slide)
+			{
+				slides.get_selection().select_iter(itr);
+				break;
+			}
+		} while (list_store.iter_next(ref itr));
+	}
+	
+	/**
 	 * Creates a Gdk.Pixbuf for a given slide.
 	 *
 	 * @param slide The slide to create a pixbuf of.



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