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

Revisions

View the latest version of libbirdfont/LoadCallback.vala.
Tip for deleting points
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 if (f.has_svg) { 40 MainWindow.show_message (t_("This font has color glyphs but your version of BirdFont does not have color support.") 41 + " " + t_("Check birdfont.org for other versions.")); 42 } 43 }); 44 } 45 46 public void load () { 47 if (MenuTab.has_suppress_event ()) { 48 warn_if_test ("Event suppressed"); 49 return; 50 } 51 52 dialog = new SaveDialogListener (); 53 font = BirdFont.get_current_font (); 54 55 dialog.signal_discard.connect (() => { 56 MainWindow.close_all_tabs (); 57 load_new_font (); 58 }); 59 60 dialog.signal_save.connect (() => { 61 MainWindow.close_all_tabs (); 62 MenuTab.set_save_callback (new SaveCallback ()); 63 MenuTab.save_callback.file_saved.connect (load_new_font); 64 MenuTab.save_callback.save (); // background thread 65 }); 66 67 dialog.signal_cancel.connect (() => { 68 MainWindow.hide_dialog (); 69 }); 70 71 if (!font.is_modified ()) { 72 dialog.signal_discard (); 73 } else { 74 MainWindow.show_dialog (new SaveDialog (dialog)); 75 } 76 } 77 78 private void load_new_font () { 79 FileChooser fc = new FileChooser (); 80 81 if (MenuTab.has_suppress_event ()) { 82 warn_if_test ("Event suppressed"); 83 return; 84 } 85 86 fc.file_selected.connect((fn) => { 87 Font f = BirdFont.get_current_font (); 88 89 if (fn != null) { 90 f.delete_backup (); 91 92 f = BirdFont.new_font (); 93 94 f.set_file ((!) fn); 95 Preferences.add_recent_files ((!) fn); 96 MainWindow.native_window.load (); 97 98 file_loaded.connect (() => { 99 KerningTools.update_kerning_classes (); 100 MenuTab.show_all_available_characters (); 101 }); 102 } 103 }); 104 105 MainWindow.file_chooser (t_("Open"), fc, FileChooser.LOAD); 106 } 107 } 108 109 } 110