The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

FileTools.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2015 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 using Cairo; 16 using Math; 17 18 namespace BirdFont { 19 20 public class FileTools : ToolCollection { 21 public static Gee.ArrayList<Expander> expanders; 22 23 public FileTools () { 24 expanders = new Gee.ArrayList<Expander> (); 25 26 Expander font_name = new Expander (); 27 font_name.add_tool (new FontName ()); 28 29 Expander file_tools = new Expander (); 30 31 Tool new_font = new Tool ("new_font", t_("New font")); 32 new_font.select_action.connect ((self) => { 33 MenuTab.new_file (); 34 }); 35 file_tools.add_tool (new_font); 36 37 Tool open_font = new Tool ("open_font", t_("Open font")); 38 open_font.select_action.connect ((self) => { 39 MenuTab.load (); 40 }); 41 file_tools.add_tool (open_font); 42 43 Tool save_font = new Tool ("save_font", t_("Save font")); 44 save_font.select_action.connect ((self) => { 45 MenuTab.save (); 46 }); 47 file_tools.add_tool (save_font); 48 49 Tool settings = new Tool ("settings", t_("Settings")); 50 settings.select_action.connect ((self) => { 51 MenuTab.show_settings_tab (); 52 }); 53 file_tools.add_tool (settings); 54 55 Expander themes = new Expander (t_("Themes")); 56 57 foreach (string theme in Theme.themes) { 58 string label; 59 LabelTool theme_label; 60 61 label = ThemeTab.get_label_from_file_name (theme); 62 63 theme_label = new LabelTool (label); 64 theme_label.data = theme; 65 66 theme_label.select_action.connect((self) => { 67 LabelTool s = (LabelTool) self; 68 Toolbox toolbox = MainWindow.get_toolbox (); 69 string theme_file = s.data; 70 TabBar tb = MainWindow.get_tab_bar (); 71 72 Preferences.set ("theme", theme_file); 73 Theme.load_theme (theme_file); 74 75 Toolbox.redraw_tool_box (); 76 GlyphCanvas.redraw (); 77 78 file_tools.clear_cache (); 79 font_name.clear_cache (); 80 themes.clear_cache (); 81 82 tb.redraw (0, 0, tb.width, tb.height); 83 84 foreach (ToolCollection tc in toolbox.tool_sets) { 85 tc.clear_cache (); 86 } 87 88 OverViewItem.label_background = null; 89 OverViewItem.selected_label_background = null; 90 OverViewItem.label_background_no_menu = null; 91 OverViewItem.selected_label_background_no_menu = null; 92 93 foreach (Tool t in themes.tool) { 94 t.set_selected (false); 95 } 96 97 self.set_selected (true); 98 themes.clear_cache (); 99 }); 100 101 if (!theme.has_prefix ("generated_")) { 102 themes.add_tool (theme_label); 103 } 104 } 105 106 string theme_in_use = Preferences.get ("theme"); 107 foreach (Tool t in themes.tool) { 108 if (t is LabelTool) { 109 LabelTool lt = (LabelTool) t; 110 t.set_selected (theme_in_use == lt.data); 111 } 112 } 113 114 expanders.add (font_name); 115 expanders.add (file_tools); 116 expanders.add (themes); 117 } 118 119 public override Gee.ArrayList<string> get_displays () { 120 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 121 return d; 122 } 123 124 public override Gee.ArrayList<Expander> get_expanders () { 125 return expanders; 126 } 127 } 128 129 } 130