The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

PreviewTools.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/PreviewTools.vala.
Merge branch 'master' of github.com:johanmattssonm/birdfont
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 PreviewTools : ToolCollection { 18 public Gee.ArrayList<Expander> expanders = new Gee.ArrayList<Expander> (); 19 public Expander classes; 20 21 public PreviewTools () { 22 Expander webview_tools = new Expander (); 23 24 Expander font_name = new Expander (); 25 font_name.add_tool (new FontName ()); 26 27 Tool update_webview_button = new Tool ("update_webview", t_("Reload webview")); 28 update_webview_button.select_action.connect ((self) => { 29 update_preview (); 30 }); 31 webview_tools.add_tool (update_webview_button); 32 33 Tool export_fonts_button = new Tool ("export_fonts", t_("Export fonts")); 34 export_fonts_button.select_action.connect ((self) => { 35 MenuTab.export_fonts_in_background (); 36 }); 37 webview_tools.add_tool (export_fonts_button); 38 39 Tool generate_html_button = new Tool ("generate_html_document", t_("Generate html document")); 40 generate_html_button.select_action.connect ((self) => { 41 generate_html_document (); 42 }); 43 webview_tools.add_tool (generate_html_button); 44 45 expanders.add (font_name); 46 expanders.add (webview_tools); 47 } 48 49 /** Export fonts and update html canvas. */ 50 public static void update_preview () { 51 MenuTab.export_callback = new ExportCallback (); 52 MenuTab.export_callback.preview = true; 53 MenuTab.export_callback.file_exported.connect (signal_preview_updated); 54 MenuTab.export_callback.export_fonts_in_background (); 55 } 56 57 private static void signal_preview_updated () { 58 IdleSource idle = new IdleSource (); 59 60 idle.set_callback (() => { 61 if (!Preview.has_html_document ()) { 62 Preview.generate_html_document (); 63 } 64 65 if (ExportTool.error_message == null) { 66 MainWindow.tabs.select_tab_name ("Preview"); 67 } 68 69 return false; 70 }); 71 72 idle.attach (null); 73 } 74 75 /** Generate the preview document. */ 76 public static void generate_html_document () { 77 Preview.delete_html_document (); 78 Preview.generate_html_document (); 79 } 80 81 public override Gee.ArrayList<Expander> get_expanders () { 82 return expanders; 83 } 84 85 public override Gee.ArrayList<string> get_displays () { 86 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 87 d.add ("Preview"); 88 return d; 89 } 90 } 91 92 } 93