The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

ThemeTab.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/ThemeTab.vala.
Parse more style attributes in SVG files
1 /* 2 Copyright (C) 2014 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 ThemeTab : SettingsDisplay { 21 static ThemeTab singleton; 22 ColorTool color_tool; 23 24 public ThemeTab () { 25 base (); 26 color_tool = new ColorTool (); 27 singleton = this; 28 create_setting_items (); 29 } 30 31 public static ThemeTab get_instance () { 32 return singleton; 33 } 34 35 public void color_updated (Color c) { 36 color_tool.set_color (c); 37 } 38 39 public override void create_setting_items () { 40 tools.clear (); 41 42 tools.add (new SettingsItem.head_line (t_("Themes"))); 43 44 Gee.ArrayList<Tool> theme_buttons = new Gee.ArrayList<Tool> (); 45 46 foreach (string theme in Theme.themes) { 47 string label; 48 Tool select_theme = new Tool (theme); 49 50 select_theme.deselect_action.connect((self) => { 51 self.set_active (false); 52 }); 53 54 select_theme.select_action.connect((self) => { 55 string theme_file = self.get_name (); 56 TabBar tb; 57 Toolbox toolbox; 58 59 Preferences.set ("theme", theme_file); 60 Theme.load_theme (theme_file); 61 62 foreach (Tool t in theme_buttons) { 63 t.set_selected (false); 64 t.set_active (false); 65 } 66 67 self.set_selected (true); 68 create_setting_items (); 69 70 toolbox = MainWindow.get_toolbox (); 71 foreach (ToolCollection tc in toolbox.tool_sets) { 72 tc.redraw (); 73 } 74 75 foreach (Expander e in Toolbox.current_set.get_expanders ()) { 76 e.redraw (); 77 } 78 79 Toolbox.redraw_tool_box (); 80 81 GlyphCanvas.redraw (); 82 83 tb = MainWindow.get_tab_bar (); 84 tb.redraw (0, 0, tb.width, tb.height); 85 86 OverViewItem.label_background = null; 87 OverViewItem.selected_label_background = null; 88 OverViewItem.label_background_no_menu = null; 89 OverViewItem.selected_label_background_no_menu = null; 90 }); 91 92 select_theme.set_icon ("theme"); 93 94 label = get_label_from_file_name (theme); 95 96 tools.add (new SettingsItem (select_theme, label)); 97 theme_buttons.add (select_theme); 98 99 if (select_theme.get_name () == Theme.current_theme) { 100 select_theme.set_selected (true); 101 } 102 } 103 104 foreach (Tool t in theme_buttons) { 105 t.set_selected (t.name == Theme.current_theme); 106 } 107 108 Tool add_theme = new Tool ("add_new_theme"); 109 add_theme.select_action.connect((self) => { 110 foreach (Tool t in theme_buttons) { 111 t.set_selected (false); 112 } 113 114 self.set_selected (false); 115 Theme.add_new_theme (this); 116 GlyphCanvas.redraw (); 117 }); 118 tools.add (new SettingsItem (add_theme, t_("Add new theme"))); 119 120 tools.add (new SettingsItem.head_line (t_("Colors"))); 121 122 foreach (string color in Theme.color_list) { 123 SettingsItem s = new SettingsItem.color (color); 124 ColorTool c = (ColorTool) ((!) s.button); 125 126 tools.add (s); 127 128 c.select_action.connect((self) => { 129 color_tool = (ColorTool) self; 130 }); 131 132 c.deselect_action.connect((self) => { 133 color_tool = new ColorTool (); 134 }); 135 136 c.color_updated.connect (() => { 137 create_setting_items (); 138 GlyphCanvas.redraw (); 139 }); 140 } 141 } 142 143 public static string get_label_from_file_name (string theme) { 144 string label; 145 146 if (theme == "dark.theme") { 147 label = t_("Dark"); 148 } else if (theme == "bright.theme") { 149 label = t_("Bright"); 150 } else if (theme == "high_contrast.theme") { 151 label = t_("High contrast"); 152 } else if (theme == "custom.theme") { 153 label = t_("Custom"); 154 } else { 155 label = theme.replace (".theme", ""); 156 } 157 158 return label; 159 } 160 161 public override string get_label () { 162 return t_("Themes"); 163 } 164 165 public override string get_name () { 166 return "Themes"; 167 } 168 } 169 170 } 171