The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SaveCallback.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/SaveCallback.vala.
Don't add saved filed to recent files
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 SaveCallback : GLib.Object { 18 19 public signal void file_saved (); 20 public bool is_done = false; 21 22 public string font_file_path = ""; 23 24 public SaveCallback () { 25 file_saved.connect (() => { 26 is_done = true; 27 }); 28 } 29 30 public void save_as () { 31 if (MenuTab.has_suppress_event ()) { 32 warn_if_test ("Event suppressed"); 33 return; 34 } 35 36 FileChooser fc = new FileChooser (); 37 fc.file_selected.connect ((fn) => { 38 string f; 39 File file; 40 OverwriteBfFile dialog; 41 string file_name; 42 43 if (fn != null) { 44 f = (!) fn; 45 46 #if MAC 47 font_file_path = f; 48 save (); 49 #else 50 if (!f.has_suffix (".bf")) { 51 f = @"$f.bf"; 52 } 53 54 file_name = @"$(f)"; 55 file = File.new_for_path (file_name); 56 font_file_path = (!) file.get_path (); 57 if (!file.query_exists ()) { 58 save (); 59 } else { 60 dialog = new OverwriteBfFile (this); 61 MainWindow.show_dialog (dialog); 62 } 63 #endif 64 } 65 }); 66 67 fc.add_extension ("bf"); 68 MainWindow.file_chooser (t_("Save"), fc, FileChooser.SAVE); 69 } 70 71 public void save () { 72 Font f; 73 string fn; 74 75 if (MenuTab.has_suppress_event ()) { 76 warn_if_test ("Event suppressed"); 77 return; 78 } 79 80 f = BirdFont.get_current_font (); 81 82 if (font_file_path != "") { 83 f.font_file = font_file_path; 84 } 85 86 Preferences.add_recent_files (f.get_path ()); 87 88 if (f.is_bfp ()) { 89 MainWindow.native_window.save (); 90 } else { 91 f.delete_backup (); 92 fn = f.get_path (); 93 94 if (f.font_file != null && fn.has_suffix (".bf")) { 95 f.set_font_file (fn); 96 MainWindow.native_window.save (); 97 } else { 98 save_as (); 99 } 100 } 101 } 102 } 103 104 } 105