.
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.file_exported.connect (signal_preview_updated);
53 MenuTab.export_callback.export_fonts_in_background ();
54 }
55
56 private static void signal_preview_updated () {
57 IdleSource idle = new IdleSource ();
58
59 idle.set_callback (() => {
60 if (!Preview.has_html_document ()) {
61 Preview.generate_html_document ();
62 }
63
64 MainWindow.tabs.select_tab_name ("Preview");
65 return false;
66 });
67
68 idle.attach (null);
69 }
70
71 /** Generate the preview document. */
72 public static void generate_html_document () {
73 Preview.delete_html_document ();
74 Preview.generate_html_document ();
75 }
76
77 public override Gee.ArrayList<Expander> get_expanders () {
78 return expanders;
79 }
80
81 public override Gee.ArrayList<string> get_displays () {
82 Gee.ArrayList<string> d = new Gee.ArrayList<string> ();
83 d.add ("Preview");
84 return d;
85 }
86 }
87
88 }
89