.
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 }
25
26 public void load () {
27 if (MenuTab.suppress_event) {
28 warn_if_test ("Event suppressed");
29 return;
30 }
31
32 dialog = new SaveDialogListener ();
33 font = BirdFont.get_current_font ();
34
35 dialog.signal_discard.connect (() => {
36 MainWindow.close_all_tabs ();
37 load_new_font ();
38 });
39
40 dialog.signal_save.connect (() => {
41 MainWindow.close_all_tabs ();
42 MenuTab.set_save_callback (new SaveCallback ());
43 MenuTab.save_callback.file_saved.connect (load_new_font);
44 MenuTab.save_callback.save (); // background thread
45 });
46
47 dialog.signal_cancel.connect (() => {
48 MainWindow.hide_dialog ();
49 });
50
51 if (!font.is_modified ()) {
52 dialog.signal_discard ();
53 } else {
54 MainWindow.show_dialog (new SaveDialog (dialog));
55 }
56 }
57
58 private void load_new_font () {
59 FileChooser fc = new FileChooser ();
60
61 if (MenuTab.suppress_event) {
62 warn_if_test ("Event suppressed");
63 return;
64 }
65
66 fc.file_selected.connect((fn) => {
67 Font f = BirdFont.get_current_font ();
68
69 if (fn != null) {
70 f.delete_backup ();
71
72 f = BirdFont.new_font ();
73
74 MainWindow.clear_glyph_cache ();
75
76 f.set_file ((!) fn);
77 Preferences.add_recent_files ((!) fn);
78 MainWindow.native_window.load ();
79
80 file_loaded.connect (() => {
81 KerningTools.update_kerning_classes ();
82 MenuTab.show_all_available_characters ();
83 });
84 }
85 });
86
87 MainWindow.file_chooser (t_("Open"), fc, FileChooser.LOAD);
88 }
89 }
90
91 }
92