[ease/save] [editor] Added Save As and Save a Copy handlers.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/save] [editor] Added Save As and Save a Copy handlers.
- Date: Fri, 2 Jul 2010 17:42:04 +0000 (UTC)
commit bcdcd806cdeb77eef2256ec1429707b6dbe5d83c
Author: Nate Stedman <natesm gmail com>
Date: Fri Jul 2 13:39:49 2010 -0400
[editor] Added Save As and Save a Copy handlers.
data/ui/editor-window.ui | 2 +
src/ease-editor-window.vala | 98 +++++++++++++++++++++++++++++++++++--------
2 files changed, 82 insertions(+), 18 deletions(-)
---
diff --git a/data/ui/editor-window.ui b/data/ui/editor-window.ui
index 6793131..3b1fcde 100644
--- a/data/ui/editor-window.ui
+++ b/data/ui/editor-window.ui
@@ -53,6 +53,7 @@
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
+ <signal name="activate" handler="ease_editor_window_save_document_as"/>
</object>
</child>
<child>
@@ -62,6 +63,7 @@
<property name="use_underline">True</property>
<property name="image">image1</property>
<property name="use_stock">False</property>
+ <signal name="activate" handler="ease_editor_window_save_document_copy"/>
</object>
</child>
<child>
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 1e4b6f8..ccd98f8 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -332,29 +332,15 @@ public class Ease.EditorWindow : Gtk.Window
{
if (document.filename == null)
{
- var dialog =
- new Gtk.FileChooserDialog(_("Save Document"),
- null,
- Gtk.FileChooserAction.SAVE,
- "gtk-cancel",
- Gtk.ResponseType.CANCEL,
- "gtk-save",
- Gtk.ResponseType.ACCEPT, null);
-
- var filter = new Gtk.FileFilter();
- filter.add_pattern("*.ease");
- dialog.filter = filter;
-
- if (dialog.run() == Gtk.ResponseType.ACCEPT)
+ var filename = save_document_dialog(_("Save Document"));
+ if (filename == null)
{
- document.filename = dialog.get_filename();
+ return false;
}
else
{
- dialog.destroy();
- return false;
+ document.filename = filename;
}
- dialog.destroy();
}
try
@@ -371,6 +357,82 @@ public class Ease.EditorWindow : Gtk.Window
}
[CCode (instance_pos = -1)]
+ public void save_document_as(Gtk.Widget sender)
+ {
+ // save the old filename in case of error
+ var old = document.filename;
+
+ // request a new filename
+ var filename = save_document_dialog(_("Save Document As"));
+ if (filename == null) return;
+
+ // set the new filename
+ document.filename = filename;
+
+ // save the document
+ try
+ {
+ JSONParser.document_write(document);
+ last_saved = 0;
+ }
+ catch (GLib.Error e)
+ {
+ filename = old;
+ error_dialog(_("Error Saving Document"), e.message);
+ return;
+ }
+ }
+
+ [CCode (instance_pos = -1)]
+ public void save_document_copy(Gtk.Widget sender)
+ {
+ var old = document.filename;
+
+ // request a new filename
+ var filename = save_document_dialog(_("Save a Copy"));
+ if (filename == null) return;
+
+ // save the document
+ try
+ {
+ JSONParser.document_write(document);
+ last_saved = 0;
+ }
+ catch (GLib.Error e)
+ {
+ error_dialog(_("Error Saving Copy"), e.message);
+ }
+
+ // restore the old filename
+ document.filename = old;
+ }
+
+ private string? save_document_dialog(string title)
+ {
+ var dialog = new Gtk.FileChooserDialog(title,
+ null,
+ Gtk.FileChooserAction.SAVE,
+ "gtk-cancel",
+ Gtk.ResponseType.CANCEL,
+ "gtk-save",
+ Gtk.ResponseType.ACCEPT, null);
+
+ var filter = new Gtk.FileFilter();
+ filter.add_pattern("*.ease");
+ dialog.filter = filter;
+
+ if (dialog.run() == Gtk.ResponseType.ACCEPT)
+ {
+ var filename = dialog.get_filename();
+ dialog.destroy();
+ return filename;
+ }
+
+ dialog.destroy();
+ return null;
+ }
+
+ [CCode (instance_pos = -1)]
public void export_to_pdf(Gtk.Widget sender)
{
PDFExporter.export(document, this);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]