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.
Fix overwrite dialog
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 file_name = ""; 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 42 if (fn != null) { 43 f = (!) fn; 44 45 #if MAC 46 save (); 47 #else 48 if (!f.has_suffix (".bf")) { 49 f = @"$f.bf"; 50 } 51 52 file_name = @"$(f)"; 53 file = File.new_for_path (file_name); 54 if (!file.query_exists ()) { 55 save (); 56 } else { 57 dialog = new OverwriteBfFile (this); 58 MainWindow.show_dialog (dialog); 59 } 60 #endif 61 } 62 }); 63 64 fc.add_extension ("bf"); 65 MainWindow.file_chooser (t_("Save"), fc, FileChooser.SAVE); 66 } 67 68 public void save () { 69 Font f; 70 string fn; 71 72 if (MenuTab.has_suppress_event ()) { 73 warn_if_test ("Event suppressed"); 74 return; 75 } 76 77 f = BirdFont.get_current_font (); 78 79 Preferences.add_recent_files (file_name); 80 f.font_file = file_name; 81 82 if (f.is_bfp ()) { 83 MainWindow.native_window.save (); 84 } else { 85 f.delete_backup (); 86 fn = f.get_path (); 87 88 if (f.font_file != null && fn.has_suffix (".bf")) { 89 f.set_font_file (fn); 90 MainWindow.native_window.save (); 91 } else { 92 save_as (); 93 } 94 } 95 } 96 } 97 98 } 99