[ease] [editor] Add PostScript export



commit 50be46cef3fc645bfcd73a1e594a142e7c62e544
Author: Nate Stedman <natesm gmail com>
Date:   Mon Jul 26 00:20:22 2010 -0400

    [editor] Add PostScript export
    
    Basically just a reuse of the PDF export, so all of that
    was moved to functions.

 Makefile.am                 |    2 +-
 data/ui/editor-window.ui    |   12 +++++-
 src/ease-dialogs.vala       |   81 +++++++++++++++++++++++++++++++++++++++++
 src/ease-document.vala      |   83 ++++++++++++++++++++++++------------------
 src/ease-editor-window.vala |   23 ++++++++----
 5 files changed, 154 insertions(+), 47 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 266b630..34ed6a1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,7 @@ ease_SOURCES = \
 	src/ease-close-confirm-dialog.vala \
 	src/ease-clutter-iterables.vala \
 	src/ease-color.vala \
+	src/ease-dialogs.vala \
 	src/ease-document.vala \
 	src/ease-editor-embed.vala \
 	src/ease-editor-window.vala \
@@ -34,7 +35,6 @@ ease_SOURCES = \
 	src/ease-inspector-window.vala \
 	src/ease-iterables.vala \
 	src/ease-media-element.vala \
-	src/ease-open-dialog.vala \
 	src/ease-player.vala \
 	src/ease-scrollable-embed.vala \
 	src/ease-selection-rectangle.vala \
diff --git a/data/ui/editor-window.ui b/data/ui/editor-window.ui
index 7ec97db..377fa15 100644
--- a/data/ui/editor-window.ui
+++ b/data/ui/editor-window.ui
@@ -87,7 +87,15 @@
                             <property name="visible">True</property>
                             <property name="label" translatable="yes">_PDF</property>
                             <property name="use_underline">True</property>
-                            <signal name="activate" handler="ease_editor_window_export_to_pdf"/>
+                            <signal name="activate" handler="ease_editor_window_export_as_pdf"/>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkMenuItem" id="PostScript">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Post_Script</property>
+                            <property name="use_underline">True</property>
+                            <signal name="activate" handler="ease_editor_window_export_as_postscript"/>
                           </object>
                         </child>
                         <child>
@@ -95,7 +103,7 @@
                             <property name="visible">True</property>
                             <property name="label" translatable="yes">_HTML</property>
                             <property name="use_underline">True</property>
-                            <signal name="activate" handler="ease_editor_window_export_to_html"/>
+                            <signal name="activate" handler="ease_editor_window_export_as_html"/>
                           </object>
                         </child>
                       </object>
diff --git a/src/ease-dialogs.vala b/src/ease-dialogs.vala
new file mode 100644
index 0000000..a327a11
--- /dev/null
+++ b/src/ease-dialogs.vala
@@ -0,0 +1,81 @@
+/*  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/>.
+*/
+
+/**
+ * Creates "open file" windows.
+ */
+public class Ease.OpenDialog : GLib.Object
+{
+	/**
+	 * Displays an "Open" dialog.
+	 * 
+	 * Used for loading previously saved files. This is a static method.
+	 */
+	public static void run()
+	{
+		var dialog = new Gtk.FileChooserDialog(_("Open File"),
+		                                       null,
+		                                       Gtk.FileChooserAction.OPEN,
+		                                       "gtk-cancel",
+		                                       Gtk.ResponseType.CANCEL,
+		                                       "gtk-open",
+		                                       Gtk.ResponseType.ACCEPT);
+		
+		// filter to only .ease files
+		var filter = new Gtk.FileFilter();
+		filter.add_pattern("*.ease");
+		dialog.filter = filter;
+
+		if (dialog.run() == Gtk.ResponseType.ACCEPT)
+		{
+			Main.open_file(dialog.get_filename() + "/");
+		}
+		dialog.destroy();
+	}
+}
+
+/**
+ * Creates and runs a "save" dialog with the given title. Returns null if
+ * cancelled, otherwise returns the selected path
+ *
+ * @param title The dialog's title.
+ * @param modal The window that the dialog should be modal for.
+ */
+public string? save_dialog(string title, Gtk.Window? modal)
+{
+	var dialog = new Gtk.FileChooserDialog(title,
+	                                       modal,
+	                                       Gtk.FileChooserAction.SAVE,
+	                                       "gtk-save",
+	                                       Gtk.ResponseType.ACCEPT,
+	                                       "gtk-cancel",
+	                                       Gtk.ResponseType.CANCEL,
+	                                       null);
+		
+	if (dialog.run() == Gtk.ResponseType.ACCEPT)
+	{
+		// clean up the file dialog
+		string path = dialog.get_filename();
+		dialog.destroy();
+		return path;
+	}
+	else
+	{
+		dialog.destroy();
+		return null;
+	}
+}
diff --git a/src/ease-document.vala b/src/ease-document.vala
index 641be11..96cf518 100644
--- a/src/ease-document.vala
+++ b/src/ease-document.vala
@@ -356,55 +356,66 @@ public class Ease.Document : GLib.Object
 	}
 	
 	/**
-	 * Exports this as a PDF file.
+	 * Renders this Document to a CairoSurface. Obviously, this only really
+	 * works with multi-page surfaces.
+	 *
+	 * @param surface The surface to render to.
+	 */
+	public void cairo_render(Cairo.Surface surface) throws GLib.Error
+	{
+		var context = new Cairo.Context(surface);
+		
+		Slide s;
+		foreach (var itr in slides)
+		{
+			slides.get(itr, COL_SLIDE, out s);
+			s.cairo_render(context);
+			context.show_page();
+		}
+	
+		surface.flush();
+		surface.finish();
+	}
+	
+	/**
+	 * Exports this Document as a PDF file.
 	 *
 	 * @param win The window that dialogs should be modal for.
 	 */
-	public void export_to_pdf(Gtk.Window win)
+	public void export_as_pdf(Gtk.Window win)
 	{
-		string path;
-		
-		var dialog = new Gtk.FileChooserDialog(_("Export to PDF"),
-		                                       win,
-		                                       Gtk.FileChooserAction.SAVE,
-		                                       "gtk-save",
-		                                       Gtk.ResponseType.ACCEPT,
-		                                       "gtk-cancel",
-		                                       Gtk.ResponseType.CANCEL,
-		                                       null);
-		
-		if (dialog.run() == Gtk.ResponseType.ACCEPT)
+		string path = save_dialog(_("Export as PDF"), win);
+		if (path == null) return;	
+		
+		try
 		{
-			// clean up the file dialog
-			path = dialog.get_filename();
-			dialog.destroy();
+			// create a PDF surface and render
+			cairo_render(new Cairo.PdfSurface(path, width, height));
 		}
-		else
+		catch (Error e)
 		{
-			dialog.destroy();
-			return;
+			error_dialog(_("Error Exporting to PDF"), e.message);
 		}
+	}
+	
+	/**
+	 * Exports this Document as a PostScript file.
+	 *
+	 * @param win The window that dialogs should be modal for.
+	 */
+	public void export_as_postscript(Gtk.Window win)
+	{
+		string path = save_dialog(_("Export as PostScript"), win);
+		if (path == null) return;	
 		
 		try
 		{
-			// create a PDF surface
-			var surface = new Cairo.PdfSurface(path, width, height);
-			var context = new Cairo.Context(surface);
-		
-			Slide s;
-			foreach (var itr in slides)
-			{
-				slides.get(itr, COL_SLIDE, out s);
-				s.cairo_render(context);
-				context.show_page();
-			}
-		
-			surface.flush();
-			surface.finish();
+			// create a postscript surface and render
+			cairo_render(new Cairo.PsSurface(path, width, height));
 		}
 		catch (Error e)
 		{
-			error_dialog(_("Error Exporting to PDF"), e.message);
+			error_dialog(_("Error Exporting to PostScript"), e.message);
 		}
 	}
 	
@@ -413,7 +424,7 @@ public class Ease.Document : GLib.Object
 	 *
 	 * @param window The window that the progress dialog should be modal for.
 	 */
-	public void export_to_html(Gtk.Window window)
+	public void export_as_html(Gtk.Window window)
 	{
 		// make an HTMLExporter
 		var exporter = new HTMLExporter();
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index d16ba6f..947abee 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -462,10 +462,23 @@ public class Ease.EditorWindow : Gtk.Window
 		return true;
 	}
 	
+	// export menu
 	[CCode (instance_pos = -1)]
-	public void export_to_pdf(Gtk.Widget sender)
+	public void export_as_pdf(Gtk.Widget sender)
 	{
-		document.export_to_pdf(this);
+		document.export_as_pdf(this);
+	}
+	
+	[CCode (instance_pos = -1)]
+	public void export_as_postscript(Gtk.Widget sender)
+	{
+		document.export_as_postscript(this);
+	}
+	
+	[CCode (instance_pos = -1)]
+	public void export_as_html(Gtk.Widget sender)
+	{
+		document.export_as_html(this);
 	}
 	
 	[CCode (instance_pos = -1)]
@@ -482,12 +495,6 @@ public class Ease.EditorWindow : Gtk.Window
 	}
 	
 	[CCode (instance_pos = -1)]
-	public void export_to_html(Gtk.Widget sender)
-	{
-		document.export_to_html(this);
-	}
-	
-	[CCode (instance_pos = -1)]
 	public void show_color_dialog(Gtk.Widget sender)
 	{
 		// if nothing is selected, don't display the dialog



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