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.
Ignore case in key bindings
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 SaveCallback () { 23 file_saved.connect (() => { 24 is_done = true; 25 }); 26 } 27 28 public void save_as () { 29 if (MenuTab.suppress_event) { 30 warn_if_test ("Event suppressed"); 31 return; 32 } 33 34 FileChooser fc = new FileChooser (); 35 fc.file_selected.connect ((fn) => { 36 string f; 37 string file_name; 38 File file; 39 bool saved = false; 40 Font font = BirdFont.get_current_font (); 41 int i; 42 43 if (fn != null) { 44 f = (!) fn; 45 46 if (f.has_suffix (".bf")) { 47 f = f.replace (".bf", ""); 48 } 49 50 file_name = @"$(f).bf"; 51 file = File.new_for_path (file_name); 52 i = 2; 53 while (file.query_exists ()) { 54 file_name = @"$(f)_$i.bf"; 55 file = File.new_for_path (file_name); 56 i++; 57 } 58 59 Preferences.add_recent_files (file_name); 60 61 font.font_file = file_name; 62 save (); 63 saved = true; 64 } 65 }); 66 67 MainWindow.file_chooser (t_("Save"), fc, FileChooser.SAVE); 68 } 69 70 public void save () { 71 Font f; 72 string fn; 73 74 if (MenuTab.suppress_event) { 75 warn_if_test ("Event suppressed"); 76 return; 77 } 78 79 f = BirdFont.get_current_font (); 80 81 if (f.is_bfp ()) { 82 MainWindow.native_window.save (); 83 } else { 84 f.delete_backup (); 85 fn = f.get_path (); 86 87 if (f.font_file != null && fn.has_suffix (".bf")) { 88 f.set_font_file (fn); 89 MainWindow.native_window.save (); 90 } else { 91 save_as (); 92 } 93 } 94 } 95 } 96 97 } 98