Commit d55d2c4
Use GTK save dialog.
Changed files (7)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/GridTool.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/NativeWindow.valaaddedlibbirdfont/OverWriteDialogListener.valadeletedlibbirdfont/SaveDialog.valaaddedlibbirdfont/SaveDialogListener.vala
Diff
@@ -274,6 +274,31 @@ public class GtkWindow : Gtk.Window, NativeWindow { hide_text_input (); } + public void set_save_dialog (SaveDialogListener d) {+ Gtk.Dialog dialog = new Gtk.Dialog.with_buttons (d.message, null, 0);+ + dialog.add_button (d.save_message, 0);+ dialog.add_button (d.discard_message, 1);+ + dialog.response.connect ((respons) => {+ switch (respons) {+ case 0:+ d.save ();+ break;+ case 1:+ d.discard ();+ break;+ }+ dialog.destroy ();+ }); + + dialog.show_all ();+ }++ public void set_overwrite_dialog (OverWriteDialogListener d) {+ + }+ public void spawn (string command) { Process.spawn_command_line_async (command); }@@ -705,26 +730,29 @@ public class GtkWindow : Gtk.Window, NativeWindow { } public bool quit () {- bool added;+ SaveDialogListener dialog = new SaveDialogListener (); Font font = BirdFont.get_current_font ();- SaveDialog save_tab = new SaveDialog ();- - if (BirdFont.get_current_font ().is_modified ()) {- added = MainWindow.get_tab_bar ().add_unique_tab (save_tab, 50);+ bool modified = BirdFont.get_current_font ().is_modified ();++ if (modified) {+ dialog.signal_discard.connect (() => {+ font.delete_backup ();+ Gtk.main_quit ();+ });++ dialog.signal_save.connect (() => {+ MenuTab.save ();+ font.delete_backup ();+ Gtk.main_quit ();+ });+ + set_save_dialog (dialog); } else {- added = false;- }- - if (!added) { font.delete_backup ();- Gtk.main_quit ();+ Gtk.main_quit (); } - save_tab.finished.connect (() => {- font.delete_backup ();- Gtk.main_quit ();- });- + return true; } @@ -210,10 +210,6 @@ class GridTool : Tool { y = -ymin.get_pos (); } }-- public static void set_visible (bool v) {- visible = v;- } public static bool is_visible () { return visible;@@ -258,14 +258,16 @@ c.append (""" } public void load_font (string fn) {- Font font = BirdFont.get_current_font ();+ Font font;+ SaveDialogListener dialog = new SaveDialogListener (); if (suppress_event) { return; }- - SaveDialog save = new SaveDialog ();- save.finished.connect (() => {+ + font = BirdFont.get_current_font ();+ + dialog.signal_discard.connect (() => { Font f; bool loaded; @@ -293,11 +295,16 @@ c.append (""" select_overview (); });++ dialog.signal_save.connect (() => {+ MenuTab.save ();+ dialog.signal_discard ();+ }); - if (font.is_modified ()) {- MainWindow.get_tab_bar ().add_unique_tab (save, 80);+ if (!font.is_modified ()) {+ dialog.signal_discard (); } else {- save.finished ();+ MainWindow.native_window.set_save_dialog (dialog); } } @@ -375,16 +382,15 @@ c.append (""" public static void new_file () { Font font;- SaveDialog save;+ SaveDialogListener dialog = new SaveDialogListener (); if (suppress_event) { return; }-- save = new SaveDialog ();+ font = BirdFont.get_current_font (); - save.finished.connect (() => {+ dialog.signal_discard.connect (() => { BirdFont.new_font (); MainWindow.close_all_tabs (); @@ -396,30 +402,42 @@ c.append (""" select_overview (); });- - MainWindow.get_tab_bar ().add_unique_tab (save, 80);++ dialog.signal_save.connect (() => {+ MenuTab.save ();+ dialog.signal_discard ();+ }); if (!font.is_modified ()) {- save.finished ();+ dialog.signal_discard ();+ } else {+ MainWindow.native_window.set_save_dialog (dialog); }+ + return; } public static void load () {- SaveDialog save = new SaveDialog ();+ SaveDialogListener dialog = new SaveDialogListener (); Font font = BirdFont.get_current_font ();-+ if (suppress_event) { return; }-- save.finished.connect (() => {+ + dialog.signal_discard.connect (() => { load_new_font (); }); - if (font.is_modified ()) {- MainWindow.get_tab_bar ().add_unique_tab (save, 80);+ dialog.signal_save.connect (() => {+ MenuTab.save ();+ dialog.signal_discard ();+ });+ + if (!font.is_modified ()) {+ dialog.signal_discard (); } else {- save.finished ();+ MainWindow.native_window.set_save_dialog (dialog); } } @@ -44,6 +44,12 @@ public interface NativeWindow : GLib.Object { /** Remove the text listener and hode the text area. */ public abstract void hide_text_input ();++ /** Show save dialog */+ public abstract void set_save_dialog (SaveDialogListener dialog);++ /** Show overwrite dialog */+ public abstract void set_overwrite_dialog (OverWriteDialogListener dialog); protected void webkit_callback (string s) { FontDisplay fd = MainWindow.get_current_display ();new file mode 100644@@ -0,0 +1,27 @@+/*+ Copyright (C) 2013 Johan Mattsson++ 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/>.+*/++namespace BirdFont {++public class OverWriteDialogListener : GLib.Object {+ + public OverWriteDialogListener () {+ }+ +}++}deleted file mode 100644@@ -1,97 +0,0 @@-/*- Copyright (C) 2012 Johan Mattsson-- 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/>.-*/--using Cairo;--namespace BirdFont {--public class SaveDialog : FontDisplay {-- public signal void finished ();-- public SaveDialog () {- add_html_callback ("save_dialog", (val) => {- if (val == "save") {- if (MenuTab.save ()) {- finished ();- }- }- - if (val == "save_as") {- if (MenuTab.save_as ()) {- finished ();- }- }- - if (val == "discard") {- // discard it- finished ();- }- - if (val == "cancel") {- MainWindow.get_tab_bar ().close_display (this);- } - - });- }-- public override string get_name () {- return "Save?";- }-- public override bool is_html_canvas () {- return true;- }-- public override string get_html () {- Font f = BirdFont.get_current_font ();- string fn = f.get_file_name ();- - if (fn == "") {- fn = f.get_name () + ".ffi";- }-- // FIXME: tell xgettext to extract this:- _("Save?");- - return """-<html>-<head>- <script type="text/javascript" src="supplement.js"></script>- <style type="text/css">@import url("style.css");</style>-</head>-<body>- - <div style="width:300px; margin: 50px auto 0 auto;">- <div class="heading"><h2>""" + _("Save?") + """</h2></div>- - <p>""" + fn + """</p>- - <form>- <input class="button" type="button" value=""" + "\"" + _("Save") + "\"" + """ onclick="call ('save_dialog:save');"/>- <input class="button" type="button" value=""" + "\"" + _("Save as") + "\"" + """ onclick="call ('save_dialog:save_as');"/>- <input class="button" type="button" value=""" + "\"" + _("Discard") + "\"" + """ onclick="call ('save_dialog:discard');"/>- <input class="button" type="button" value=""" + "\"" + _("Cancel") + "\"" + """ onclick="call ('save_dialog:cancel');"/>- <br />- </form>- </div>-</body>-</html>""";- }-}- -}new file mode 100644@@ -0,0 +1,44 @@+/*+ Copyright (C) 2013 Johan Mattsson++ 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/>.+*/++namespace BirdFont {++public class SaveDialogListener : GLib.Object {+ + public signal void signal_save ();+ public signal void signal_discard ();+ + public string message;+ public string discard_message;+ public string save_message;+ + public SaveDialogListener () {+ this.message = _("Save?");+ this.save_message = _("Save");+ this.discard_message = _("Discard");+ }+ + public void save () {+ signal_save ();+ }++ public void discard () {+ signal_discard ();+ }+}++}