[ease] [editor] Fix "Open".



commit c311f790046553e7cac0e27b1a3124a3934c0adb
Author: Nate Stedman <natesm gmail com>
Date:   Sat Aug 7 03:48:40 2010 -0400

    [editor] Fix "Open".
    
    - Opening documents works again
    - New "Dialogs" namespace in ease-core
    - Removed OpenDialog class, Dialog.open and Dialog.close
      are functions.

 data/ui/editor-window.ui      |    3 +-
 ease-core/ease-dialogs.vala   |   89 ++++++++++++++++++++---------------------
 ease-core/ease-document.vala  |    8 ++--
 ease-core/ease-utilities.vala |    2 +-
 ease/ease-editor-window.vala  |    8 ++++
 ease/ease-main.vala           |    2 +-
 ease/ease-welcome-window.vala |    3 +-
 7 files changed, 60 insertions(+), 55 deletions(-)
---
diff --git a/data/ui/editor-window.ui b/data/ui/editor-window.ui
index 5cb7053..4d445c9 100644
--- a/data/ui/editor-window.ui
+++ b/data/ui/editor-window.ui
@@ -4,7 +4,6 @@
   <!-- 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>
@@ -33,7 +32,7 @@
                     <property name="use_underline">True</property>
                     <property name="use_stock">True</property>
                     <property name="accel_group">accel-group</property>
-                    <signal name="activate" handler="ease_open_dialog_run"/>
+                    <signal name="activate" handler="ease_editor_window_on_open"/>
                   </object>
                 </child>
                 <child>
diff --git a/ease-core/ease-dialogs.vala b/ease-core/ease-dialogs.vala
index eecc9e5..072394d 100644
--- a/ease-core/ease-dialogs.vala
+++ b/ease-core/ease-dialogs.vala
@@ -16,65 +16,62 @@
 */
 
 /**
- * Creates "open file" windows.
+ * Common dialog windows used in Ease.
  */
-public class Ease.OpenDialog : GLib.Object
+namespace Ease.Dialogs
 {
 	/**
-	 * Displays an "Open" dialog.
-	 * 
-	 * Used for loading previously saved files. This is a static method.
+	 * Displays an "Open" dialog with the specified 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 static void run()
+	public string? open(string title, Gtk.Window? modal)
 	{
-		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;
+		var dialog = new Gtk.FileChooserDialog(title,
+			                                   modal,
+			                                   Gtk.FileChooserAction.OPEN,
+			                                   "gtk-cancel",
+			                                   Gtk.ResponseType.CANCEL,
+			                                   "gtk-open",
+			                                   Gtk.ResponseType.ACCEPT);
 
 		if (dialog.run() == Gtk.ResponseType.ACCEPT)
 		{
-			//Main.open_file(dialog.get_filename() + "/");
+			string name = dialog.get_filename();
+			dialog.destroy();
+			return name;
 		}
 		dialog.destroy();
+		return null;
 	}
-}
 
-/**
- * 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
+	/**
+	 * 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(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;
+		}
 		dialog.destroy();
 		return null;
 	}
diff --git a/ease-core/ease-document.vala b/ease-core/ease-document.vala
index b30fd19..39a2495 100644
--- a/ease-core/ease-document.vala
+++ b/ease-core/ease-document.vala
@@ -454,9 +454,9 @@ public class Ease.Document : GLib.Object, UndoSource
 	 *
 	 * @param win The window that dialogs should be modal for.
 	 */
-	public void export_as_pdf(Gtk.Window win)
+	public void export_as_pdf(Gtk.Window? win)
 	{
-		string path = save_dialog(_("Export as PDF"), win);
+		string path = Dialogs.save(_("Export as PDF"), win);
 		if (path == null) return;	
 		
 		try
@@ -475,9 +475,9 @@ public class Ease.Document : GLib.Object, UndoSource
 	 *
 	 * @param win The window that dialogs should be modal for.
 	 */
-	public void export_as_postscript(Gtk.Window win)
+	public void export_as_postscript(Gtk.Window? win)
 	{
-		string path = save_dialog(_("Export as PostScript"), win);
+		string path = Dialogs.save(_("Export as PostScript"), win);
 		if (path == null) return;	
 		
 		try
diff --git a/ease-core/ease-utilities.vala b/ease-core/ease-utilities.vala
index 44412a7..183cd47 100644
--- a/ease-core/ease-utilities.vala
+++ b/ease-core/ease-utilities.vala
@@ -295,7 +295,7 @@ namespace Ease
 	/**
 	 * Returns an absolute path for the given path.
 	 */
-	private static string absolute_path(string path)
+	public static string absolute_path(string path)
 	{
 		var file = GLib.File.new_for_path(path);
 		return file.resolve_relative_path(".").get_path();
diff --git a/ease/ease-editor-window.vala b/ease/ease-editor-window.vala
index 920b8e8..63cabc8 100644
--- a/ease/ease-editor-window.vala
+++ b/ease/ease-editor-window.vala
@@ -313,6 +313,14 @@ internal class Ease.EditorWindow : Gtk.Window
 	
 	// signal handlers
 	[CCode (instance_pos = -1)]
+	internal void on_open(Gtk.Widget sender)
+	{
+		var filename = Dialogs.open(_("Open Document"), this);
+		if (filename != null) Main.open_file(filename);
+	}
+	
+	
+	[CCode (instance_pos = -1)]
 	internal void on_quit(Gtk.Widget sender)
 	{
 		Gtk.main_quit ();
diff --git a/ease/ease-main.vala b/ease/ease-main.vala
index b89aa76..763b23a 100644
--- a/ease/ease-main.vala
+++ b/ease/ease-main.vala
@@ -147,7 +147,7 @@ internal class Ease.Main : GLib.Object
 	{
 		foreach (var w in windows)
 		{
-			if (w.document.path == path)
+			if (absolute_path(w.document.filename) == absolute_path(path))
 			{
 				w.present();
 				return;
diff --git a/ease/ease-welcome-window.vala b/ease/ease-welcome-window.vala
index 1cb08e2..3168a65 100644
--- a/ease/ease-welcome-window.vala
+++ b/ease/ease-welcome-window.vala
@@ -269,7 +269,8 @@ internal class Ease.WelcomeWindow : Gtk.Window
 	[CCode (instance_pos = -1)]
 	internal void on_open_pres_button_clicked (Gtk.Widget sender)
 	{
-		OpenDialog.run();
+		var filename = Dialogs.open(_("Open Document"), this);
+		if (filename != null) Main.open_file(filename);
 	}
 
 	[CCode (instance_pos = -1)]



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