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
Circle boundaries heads/master
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 Toolbox toolbox; 57 58 Preferences.set ("theme", theme_file); 59 Theme.load_theme (theme_file); 60 61 foreach (Tool t in theme_buttons) { 62 t.set_selected (false); 63 t.set_active (false); 64 } 65 66 self.set_selected (true); 67 create_setting_items (); 68 69 toolbox = MainWindow.get_toolbox (); 70 foreach (ToolCollection tc in toolbox.tool_sets) { 71 tc.redraw (); 72 } 73 74 foreach (Expander e in Toolbox.current_set.get_expanders ()) { 75 e.redraw (); 76 } 77 78 redraw_ui (); 79 }); 80 81 select_theme.set_icon ("theme"); 82 83 label = get_label_from_file_name (theme); 84 85 tools.add (new SettingsItem (select_theme, label)); 86 theme_buttons.add (select_theme); 87 88 if (select_theme.get_name () == Theme.current_theme) { 89 select_theme.set_selected (true); 90 } 91 } 92 93 foreach (Tool t in theme_buttons) { 94 t.set_selected (t.name == Theme.current_theme); 95 } 96 97 Tool add_theme = new Tool ("add_new_theme"); 98 add_theme.select_action.connect((self) => { 99 foreach (Tool t in theme_buttons) { 100 t.set_selected (false); 101 } 102 103 self.set_selected (false); 104 Theme.add_new_theme (this); 105 GlyphCanvas.redraw (); 106 }); 107 tools.add (new SettingsItem (add_theme, t_("Add new theme"))); 108 109 tools.add (new SettingsItem.head_line (t_("Colors"))); 110 111 foreach (string color in Theme.color_list) { 112 SettingsItem s = new SettingsItem.color (color); 113 ColorTool c = (ColorTool) ((!) s.button); 114 115 tools.add (s); 116 117 c.select_action.connect((self) => { 118 color_tool = (ColorTool) self; 119 }); 120 121 c.deselect_action.connect((self) => { 122 color_tool = new ColorTool (); 123 }); 124 125 c.color_updated.connect (() => { 126 create_setting_items (); 127 GlyphCanvas.redraw (); 128 }); 129 } 130 } 131 132 public static void redraw_ui (){ 133 TabBar tb; 134 135 Toolbox.redraw_tool_box (); 136 137 GlyphCanvas.redraw (); 138 139 tb = MainWindow.get_tab_bar (); 140 tb.redraw (0, 0, tb.width, tb.height); 141 142 OverViewItem.label_background = null; 143 OverViewItem.selected_label_background = null; 144 OverViewItem.label_background_no_menu = null; 145 OverViewItem.selected_label_background_no_menu = null; 146 } 147 148 public static string get_label_from_file_name (string theme) { 149 string label; 150 151 if (theme == "dark.theme") { 152 label = t_("Dark"); 153 } else if (theme == "bright.theme") { 154 label = t_("Bright"); 155 } else if (theme == "high_contrast.theme") { 156 label = t_("High contrast"); 157 } else if (theme == "custom.theme") { 158 label = t_("Custom"); 159 } else { 160 label = theme.replace (".theme", ""); 161 } 162 163 return label; 164 } 165 166 public override string get_label () { 167 return t_("Themes"); 168 } 169 170 public override string get_name () { 171 return "Themes"; 172 } 173 } 174 175 } 176