[ease] [editor] Allow the user to insert images.



commit 34a57bf263e538e05b9955b6ecb113cc2217fe99
Author: Nate Stedman <natesm gmail com>
Date:   Fri Jul 2 09:46:12 2010 -0400

    [editor] Allow the user to insert images.

 data/ui/editor-window.ui    |    4 ++-
 src/ease-editor-embed.vala  |    8 +++++++
 src/ease-editor-window.vala |   48 +++++++++++++++++++++++++++++++++++++++++++
 src/ease-json-parser.vala   |    4 +-
 src/ease-slide-set.vala     |   19 +++++++++++++++++
 5 files changed, 80 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/editor-window.ui b/data/ui/editor-window.ui
index 34e1e94..6793131 100644
--- a/data/ui/editor-window.ui
+++ b/data/ui/editor-window.ui
@@ -171,10 +171,11 @@
                     <property name="visible">True</property>
                     <property name="label" translatable="yes">_Image</property>
                     <property name="use_underline">True</property>
+                    <signal name="activate" handler="ease_editor_window_insert_image"/>
                   </object>
                 </child>
                 <child>
-                  <object class="GtkMenuItem" id="menuitem3">
+                  <object class="GtkMenuItem" id="Insert Video">
                     <property name="visible">True</property>
                     <property name="label" translatable="yes">_Video</property>
                     <property name="use_underline">True</property>
@@ -189,6 +190,7 @@
             <property name="visible">True</property>
             <property name="label" translatable="yes">_View</property>
             <property name="use_underline">True</property>
+            <signal name="activate" handler="ease_editor_window_insert_video"/>
             <child type="submenu">
               <object class="GtkMenu" id="menu3">
                 <property name="visible">True</property>
diff --git a/src/ease-editor-embed.vala b/src/ease-editor-embed.vala
index 067b5ce..c299f28 100644
--- a/src/ease-editor-embed.vala
+++ b/src/ease-editor-embed.vala
@@ -362,6 +362,14 @@ public class Ease.EditorEmbed : ScrollableEmbed
 	}
 	
 	/**
+	 * Recreates the current SlideActor.
+	 */
+	public void recreate_slide()
+	{
+		set_slide(slide_actor.slide);
+	}
+	
+	/**
 	 * Signal handler for clicking on { link Actor}s.
 	 * 
 	 * This handler is attached to the button_press_event of all
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 6142f54..7d06e4f 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -268,6 +268,54 @@ public class Ease.EditorWindow : Gtk.Window
 	}
 	
 	[CCode (instance_pos = -1)]
+	public void insert_image(Gtk.Widget sender)
+	{
+		var dialog = new Gtk.FileChooserDialog(_("Insert Image"),
+		                                       null,
+		                                       Gtk.FileChooserAction.OPEN,
+		                                       "gtk-cancel",
+		                                       Gtk.ResponseType.CANCEL,
+		                                       "gtk-open",
+		                                       Gtk.ResponseType.ACCEPT);
+
+		if (dialog.run() == Gtk.ResponseType.ACCEPT)
+		{
+			try
+			{
+				var img = new Clutter.Texture.from_file(dialog.get_filename());
+				var e = new ImageElement();
+				
+				// set the size and position of the element
+				int width = 0, height = 0;
+				img.get_base_size(out width, out height);
+				
+				e.width = width;
+				e.height = height;
+				e.x = document.width / 2 - width / 2;
+				e.y = document.height / 2 - width / 2;
+				
+				e.element_type = JSONParser.IMAGE_TYPE;
+				e.filename = document.add_media_file(dialog.get_filename());
+				
+				// add the element
+				slide.add_element(0, e);
+				embed.recreate_slide();
+			}
+			catch (Error e)
+			{
+				error_dialog(_("Error Inserting Image"), e.message);
+			}
+		}
+		dialog.destroy();
+	}
+	
+	[CCode (instance_pos = -1)]
+	public void insert_video(Gtk.Widget sender)
+	{
+		
+	}
+	
+	[CCode (instance_pos = -1)]
 	public void zoom_in(Gtk.Widget sender)
 	{
 		zoom_slider.zoom_in();
diff --git a/src/ease-json-parser.vala b/src/ease-json-parser.vala
index 34ac452..2c9d484 100644
--- a/src/ease-json-parser.vala
+++ b/src/ease-json-parser.vala
@@ -20,8 +20,8 @@
  */
 public static class Ease.JSONParser
 {
-	private const string VIDEO_TYPE = "EaseVideoElement";
-	private const string IMAGE_TYPE = "EaseImageElement";
+	public const string VIDEO_TYPE = "EaseVideoElement";
+	public const string IMAGE_TYPE = "EaseImageElement";
 
 	/**
 	 * Parses a document JSON file, creating a { link Document}.
diff --git a/src/ease-slide-set.vala b/src/ease-slide-set.vala
index 7f179cb..1aa5593 100644
--- a/src/ease-slide-set.vala
+++ b/src/ease-slide-set.vala
@@ -112,5 +112,24 @@ public abstract class Ease.SlideSet : Object
 		// TODO: non-system implementation of recursive copy
 		Posix.system("cp -r %s %s".printf(origin_path, target_path));
 	}
+	
+	/**
+	 * Copies a media file to the temporary directory.
+	 *
+	 * Returns the path to the new file, as it should be stored in the
+	 * document when saved.
+	 *
+	 * @param file The path to the file that will be copied.
+	 */
+	public string add_media_file(string file) throws GLib.Error
+	{
+		var orig = File.new_for_path(file);
+		var dest = File.new_for_path(Path.build_filename(path,
+		                                                 MEDIA_PATH,
+		                                                 orig.get_basename()));
+		orig.copy(dest, 0, null, null);
+		
+		return Path.build_filename(MEDIA_PATH, orig.get_basename());
+	}
 }
 



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