The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

LoadCallback.vala in /libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* 2 Copyright (C) 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public class LoadCallback : GLib.Object { 18 SaveDialogListener dialog; 19 Font font; 20 21 public signal void file_loaded (); 22 23 public LoadCallback () { 24 file_loaded.connect (() => { 25 Font f = BirdFont.get_current_font (); 26 27 if (!f.has_compatible_format ()) { 28 if (f.newer_format ()) { 29 MainWindow.show_message (t_("This font was made with a newer version of Birdfont.") 30 + " " + t_("You need to upgrade your version of Birdfont.")); 31 } 32 33 if (f.older_format ()) { 34 MainWindow.show_message (t_("This font was made with an old version of Birdfont.") 35 + " " + t_("You need an older version of Birdfont to open it.")); 36 } 37 } 38 }); 39 } 40 41 public void load () { 42 if (MenuTab.has_suppress_event ()) { 43 warn_if_test ("Event suppressed"); 44 return; 45 } 46 47 dialog = new SaveDialogListener (); 48 font = BirdFont.get_current_font (); 49 50 dialog.signal_discard.connect (() => { 51 MainWindow.close_all_tabs (); 52 load_new_font (); 53 }); 54 55 dialog.signal_save.connect (() => { 56 MainWindow.close_all_tabs (); 57 MenuTab.set_save_callback (new SaveCallback ()); 58 MenuTab.save_callback.file_saved.connect (load_new_font); 59 MenuTab.save_callback.save (); // background thread 60 }); 61 62 dialog.signal_cancel.connect (() => { 63 MainWindow.hide_dialog (); 64 }); 65 66 if (!font.is_modified ()) { 67 dialog.signal_discard (); 68 } else { 69 MainWindow.show_dialog (new SaveDialog (dialog)); 70 } 71 } 72 73 private void load_new_font () { 74 FileChooser fc = new FileChooser (); 75 76 if (MenuTab.has_suppress_event ()) { 77 warn_if_test ("Event suppressed"); 78 return; 79 } 80 81 fc.file_selected.connect((fn) => { 82 Font f = BirdFont.get_current_font (); 83 84 if (fn != null) { 85 f.delete_backup (); 86 87 f = BirdFont.new_font (); 88 89 f.set_file ((!) fn); 90 Preferences.add_recent_files ((!) fn); 91 MainWindow.native_window.load (); 92 93 file_loaded.connect (() => { 94 KerningTools.update_kerning_classes (); 95 MenuTab.show_all_available_characters (); 96 }); 97 } 98 }); 99 100 MainWindow.file_chooser (t_("Open"), fc, FileChooser.LOAD); 101 } 102 } 103 104 } 105