The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Separate theme tab

These changes was commited to the Birdfont repository Fri, 17 Apr 2015 21:28:07 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 17 Apr 2015 21:28:07 +0000 (23:28 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 17 Apr 2015 21:28:07 +0000 (23:28 +0200)
commit c69666c4d5f74c0b3ef839af6d014b19980e524d
tree fccb8294910042b0fdb3f7099e63e015eaf6a3a6
parent 9316154e797dfeb579b0eff8e9693bf361b166c2
Separate theme tab

15 files changed:
libbirdfont/BackgroundTools.vala
libbirdfont/Glyph.vala
libbirdfont/LanguageSelectionTab.vala
libbirdfont/MenuTab.vala
libbirdfont/OverView.vala
libbirdfont/OverViewItem.vala
libbirdfont/SettingsDisplay.vala
libbirdfont/SettingsItem.vala
libbirdfont/SettingsTab.vala [new ]
libbirdfont/SpacingTab.vala
libbirdfont/TabBar.vala
libbirdfont/TabContent.vala
libbirdfont/Theme.vala
libbirdfont/ThemeTab.vala [new ]
--- a/libbirdfont/BackgroundTools.vala +++ b/libbirdfont/BackgroundTools.vala @@ -101,7 +101,6 @@ } set_new_background_image (gc, bpl); - g.set_background_visible (true); }); gs.open_new_glyph_signal.connect ((character) => { @@ -152,9 +151,13 @@ } void set_new_background_image (GlyphCollection gc, BackgroundPartLabel bpl) { + Glyph g; + + g = gc.get_current (); bpl.selection.assigned_glyph = gc.get_name (); bpl.label = gc.get_name (); - gc.get_current ().set_background_image (bpl.selection.image); + g.set_background_image (bpl.selection.image); + g.set_background_visible (true); if (bpl.selection.image != null) { ((!) bpl.selection.image).center_in_glyph (gc.get_current ());
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -1479,7 +1479,7 @@ } private void draw_coordinate (Context cr) { - Theme.color (cr, "Foreground 3"); + Theme.color (cr, "Table Border"); cr.set_font_size (12); cr.move_to (0, 10); cr.show_text (@"($motion_x, $motion_y)"); @@ -1601,7 +1601,7 @@ private void draw_zoom_area(Context cr) { cr.save (); cr.set_line_width (2.0); - Theme.color (cr, "Foreground 4"); + Theme.color (cr, "Selection Border"); cr.rectangle (Math.fmin (zoom_x1, zoom_x2), Math.fmin (zoom_y1, zoom_y2), Math.fabs (zoom_x1 - zoom_x2), Math.fabs (zoom_y1 - zoom_y2)); cr.stroke (); cr.restore (); @@ -1611,7 +1611,7 @@ if (opacity > 0) { cr.save (); cr.rectangle (0, 0, allocation.width, allocation.height); - Theme.color (cr, "Background 1"); + Theme.color (cr, "Canvas Background"); cr.fill (); cr.restore (); }
--- a/libbirdfont/LanguageSelectionTab.vala +++ b/libbirdfont/LanguageSelectionTab.vala @@ -78,7 +78,7 @@ if (color) { cr.save (); - Theme.color (cr, "Background 6"); + Theme.color (cr, "Table Background 2"); cr.rectangle (0, y - 14, allocation.width, 18); cr.fill (); cr.restore ();
--- a/libbirdfont/MenuTab.vala +++ b/libbirdfont/MenuTab.vala @@ -637,9 +637,13 @@ } public static void show_settings_tab () { - MainWindow.get_tab_bar ().add_unique_tab (new SettingsDisplay ()); + MainWindow.get_tab_bar ().add_unique_tab (new SettingsTab ()); } + public static void show_theme_tab () { + MainWindow.get_tab_bar ().add_unique_tab (new ThemeTab ()); + } + public static void show_guide_tab () { MainWindow.get_tab_bar ().add_unique_tab (new GuideTab ()); }
--- a/libbirdfont/OverView.vala +++ b/libbirdfont/OverView.vala @@ -466,7 +466,7 @@ void draw_empty_canvas (WidgetAllocation allocation, Context cr) { cr.save (); - Theme.color (cr, "Background 7"); + Theme.color (cr, "Default Background"); cr.move_to (30, 40); cr.set_font_size (18); cr.show_text (t_("No glyphs in this view."));
--- a/libbirdfont/OverViewItem.vala +++ b/libbirdfont/OverViewItem.vala @@ -198,7 +198,7 @@ } else { c.save (); fallback = new Text (); - Theme.text_color (fallback, "Foreground 7"); + Theme.text_color (fallback, "Overview Glyph"); fallback.set_text ((!) character.to_string ()); font_size = height * 0.8; fallback.set_font_size (font_size);
--- a/libbirdfont/SettingsDisplay.vala +++ b/libbirdfont/SettingsDisplay.vala @@ -17,12 +17,12 @@ namespace BirdFont { - public class SettingsDisplay : FontDisplay { + public abstract class SettingsDisplay : FontDisplay { double scroll = 0; double content_height = 1; WidgetAllocation allocation; - Gee.ArrayList<SettingsItem> tools; + public Gee.ArrayList<SettingsItem> tools; public static SpinButton precision; @@ -34,213 +34,9 @@ tools = new Gee.ArrayList<SettingsItem> (); content_height = 200; precision = new SpinButton ("precision"); - create_setting_items (); } - public void create_setting_items () { - tools.clear (); - // setting items - tools.add (new SettingsItem.head_line (t_("Settings"))); - - SpinButton stroke_width = new SpinButton ("stroke_width"); - tools.add (new SettingsItem (stroke_width, t_("Stroke width"))); - - stroke_width.set_max (4); - stroke_width.set_min (0.002); - stroke_width.set_value_round (1); - - if (Preferences.get ("stroke_width_for_open_paths") != "") { - stroke_width.set_value (Preferences.get ("stroke_width_for_open_paths")); - } - - stroke_width.new_value_action.connect ((self) => { - Glyph g = MainWindow.get_current_glyph (); - Path.stroke_width = stroke_width.get_value (); - g.redraw_area (0, 0, g.allocation.width, g.allocation.height); - Preferences.set ("stroke_width_for_open_paths", stroke_width.get_display_value ()); - MainWindow.get_toolbox ().redraw ((int) stroke_width.x, (int) stroke_width.y, 70, 70); - }); - - Path.stroke_width = stroke_width.get_value (); - - // adjust precision - string precision_value = Preferences.get ("precision"); - - if (precision_value != "") { - precision.set_value (precision_value); - } else { - #if ANDROID - precision.set_value_round (0.5); - #else - precision.set_value_round (1); - #endif - } - - precision.new_value_action.connect ((self) => { - MainWindow.get_toolbox ().select_tool (precision); - Preferences.set ("precision", self.get_display_value ()); - MainWindow.get_toolbox ().redraw ((int) precision.x, (int) precision.y, 70, 70); - }); - - precision.select_action.connect((self) => { - DrawingTools.pen_tool.set_precision (((SpinButton)self).get_value ()); - }); - - precision.set_min (0.001); - precision.set_max (1); - - tools.add (new SettingsItem (precision, t_("Precision for pen tool"))); - - Tool show_all_line_handles = new Tool ("show_all_line_handles"); - show_all_line_handles.select_action.connect((self) => { - Path.show_all_line_handles = !Path.show_all_line_handles; - Glyph g = MainWindow.get_current_glyph (); - g.redraw_area (0, 0, g.allocation.width, g.allocation.height); - }); - tools.add (new SettingsItem (show_all_line_handles, t_("Show or hide control point handles"))); - - Tool fill_open_path = new Tool ("fill_open_path"); - fill_open_path.select_action.connect((self) => { - Path.fill_open_path = !Path.fill_open_path; - Glyph g = MainWindow.get_current_glyph (); - g.redraw_area (0, 0, g.allocation.width, g.allocation.height); - }); - tools.add (new SettingsItem (fill_open_path, t_("Fill open paths."))); - - Tool ttf_units = new Tool ("ttf_units"); - ttf_units.select_action.connect((self) => { - GridTool.ttf_units = !GridTool.ttf_units; - Preferences.set ("ttf_units", @"$(GridTool.ttf_units)"); - }); - tools.add (new SettingsItem (ttf_units, t_("Use TTF units."))); - - SpinButton freehand_samples = new SpinButton ("freehand_samples_per_point"); - tools.add (new SettingsItem (freehand_samples, t_("Number of points added by the freehand tool"))); - - freehand_samples.set_max (9); - freehand_samples.set_min (0.002); - - if (BirdFont.android) { - freehand_samples.set_value_round (2.5); - } else { - freehand_samples.set_value_round (1); - } - - if (Preferences.get ("freehand_samples") != "") { - freehand_samples.set_value (Preferences.get ("freehand_samples")); - DrawingTools.track_tool.set_samples_per_point (freehand_samples.get_value ()); - } - - freehand_samples.new_value_action.connect ((self) => { - DrawingTools.track_tool.set_samples_per_point (freehand_samples.get_value ()); - }); - - SpinButton simplification_threshold = new SpinButton ("simplification_threshold"); - simplification_threshold.set_value_round (0.5); - tools.add (new SettingsItem (simplification_threshold, t_("Path simplification threshold"))); - - simplification_threshold.set_max (5); - freehand_samples.set_min (0.002); - - if (Preferences.get ("simplification_threshold") != "") { - freehand_samples.set_value (Preferences.get ("simplification_threshold")); - DrawingTools.pen_tool.set_simplification_threshold (simplification_threshold.get_value ()); - } - - freehand_samples.new_value_action.connect ((self) => { - DrawingTools.pen_tool.set_simplification_threshold (simplification_threshold.get_value ()); - }); - - tools.add (new SettingsItem.head_line (t_("Key Bindings"))); - - foreach (MenuItem menu_item in MainWindow.get_menu ().sorted_menu_items) { - tools.add (new SettingsItem.key_binding (menu_item)); - } - - tools.add (new SettingsItem.head_line (t_("Themes"))); - - Gee.ArrayList<Tool> theme_buttons = new Gee.ArrayList<Tool> (); - - foreach (string theme in Theme.themes) { - string label; - Tool select_theme = new Tool (theme); - - select_theme.deselect_action.connect((self) => { - self.set_active (false); - }); - - select_theme.select_action.connect((self) => { - string theme_file = self.get_name (); - TabBar tb; - - Preferences.set ("theme", theme_file); - Theme.load_theme (theme_file); - - foreach (Tool t in theme_buttons) { - t.set_selected (false); - t.set_active (false); - } - - self.set_selected (true); - create_setting_items (); - - Toolbox.redraw_tool_box (); - GlyphCanvas.redraw (); - - tb = MainWindow.get_tab_bar (); - tb.redraw (0, 0, tb.width, tb.height); - }); - - select_theme.set_icon ("theme"); - - if (theme == "default.theme") { - label = t_("Default theme"); - } else if (theme == "high_contrast.theme") { - label = t_("High contrast theme"); - } else if (theme == "custom.theme") { - label = t_("Custom theme"); - } else { - label = theme.replace (".theme", ""); - } - - tools.add (new SettingsItem (select_theme, label)); - theme_buttons.add (select_theme); - - if (select_theme.get_name () == Theme.current_theme) { - select_theme.set_selected (true); - } - } - - foreach (Tool t in theme_buttons) { - t.set_selected (t.name == Theme.current_theme); - } - - Tool add_theme = new Tool ("add_new_theme"); - add_theme.select_action.connect((self) => { - foreach (Tool t in theme_buttons) { - t.set_selected (false); - } - - self.set_selected (false); - Theme.add_new_theme (this); - GlyphCanvas.redraw (); - }); - tools.add (new SettingsItem (add_theme, t_("Add new theme"))); - - tools.add (new SettingsItem.head_line (t_("Colors"))); - - foreach (string color in Theme.color_list) { - SettingsItem s = new SettingsItem.color (color); - ColorTool c = (ColorTool) ((!) s.button); - - tools.add (s); - - c.color_updated.connect (() => { - create_setting_items (); - GlyphCanvas.redraw (); - }); - } - } + public abstract void create_setting_items (); public override void draw (WidgetAllocation allocation, Context cr) { this.allocation = allocation;
--- a/libbirdfont/SettingsItem.vala +++ b/libbirdfont/SettingsItem.vala @@ -17,7 +17,7 @@ namespace BirdFont { - class SettingsItem : GLib.Object { + public class SettingsItem : GLib.Object { public bool handle_events; public bool key_bindings = false; public double y = 0;
--- /dev/null +++ b/libbirdfont/SettingsTab.vala @@ -1,1 +1,167 @@ + /* + Copyright (C) 2014 2015 Johan Mattsson + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + */ + + using Cairo; + using Math; + + namespace BirdFont { + + public class SettingsTab : SettingsDisplay { + + public SettingsTab () { + base (); + create_setting_items (); + } + + public override void create_setting_items () { + tools.clear (); + + // setting items + tools.add (new SettingsItem.head_line (t_("Settings"))); + + SpinButton stroke_width = new SpinButton ("stroke_width"); + tools.add (new SettingsItem (stroke_width, t_("Stroke width"))); + + stroke_width.set_max (4); + stroke_width.set_min (0.002); + stroke_width.set_value_round (1); + + if (Preferences.get ("stroke_width_for_open_paths") != "") { + stroke_width.set_value (Preferences.get ("stroke_width_for_open_paths")); + } + + stroke_width.new_value_action.connect ((self) => { + Glyph g = MainWindow.get_current_glyph (); + Path.stroke_width = stroke_width.get_value (); + g.redraw_area (0, 0, g.allocation.width, g.allocation.height); + Preferences.set ("stroke_width_for_open_paths", stroke_width.get_display_value ()); + MainWindow.get_toolbox ().redraw ((int) stroke_width.x, (int) stroke_width.y, 70, 70); + }); + + Path.stroke_width = stroke_width.get_value (); + + // adjust precision + string precision_value = Preferences.get ("precision"); + + if (precision_value != "") { + precision.set_value (precision_value); + } else { + #if ANDROID + precision.set_value_round (0.5); + #else + precision.set_value_round (1); + #endif + } + + precision.new_value_action.connect ((self) => { + MainWindow.get_toolbox ().select_tool (precision); + Preferences.set ("precision", self.get_display_value ()); + MainWindow.get_toolbox ().redraw ((int) precision.x, (int) precision.y, 70, 70); + }); + + precision.select_action.connect((self) => { + DrawingTools.pen_tool.set_precision (((SpinButton)self).get_value ()); + }); + + precision.set_min (0.001); + precision.set_max (1); + + tools.add (new SettingsItem (precision, t_("Precision for pen tool"))); + + Tool show_all_line_handles = new Tool ("show_all_line_handles"); + show_all_line_handles.select_action.connect((self) => { + Path.show_all_line_handles = !Path.show_all_line_handles; + Glyph g = MainWindow.get_current_glyph (); + g.redraw_area (0, 0, g.allocation.width, g.allocation.height); + }); + tools.add (new SettingsItem (show_all_line_handles, t_("Show or hide control point handles"))); + + Tool fill_open_path = new Tool ("fill_open_path"); + fill_open_path.select_action.connect((self) => { + Path.fill_open_path = !Path.fill_open_path; + Glyph g = MainWindow.get_current_glyph (); + g.redraw_area (0, 0, g.allocation.width, g.allocation.height); + }); + tools.add (new SettingsItem (fill_open_path, t_("Fill open paths."))); + + Tool ttf_units = new Tool ("ttf_units"); + ttf_units.select_action.connect((self) => { + GridTool.ttf_units = !GridTool.ttf_units; + Preferences.set ("ttf_units", @"$(GridTool.ttf_units)"); + }); + tools.add (new SettingsItem (ttf_units, t_("Use TTF units."))); + + SpinButton freehand_samples = new SpinButton ("freehand_samples_per_point"); + tools.add (new SettingsItem (freehand_samples, t_("Number of points added by the freehand tool"))); + + freehand_samples.set_max (9); + freehand_samples.set_min (0.002); + + if (BirdFont.android) { + freehand_samples.set_value_round (2.5); + } else { + freehand_samples.set_value_round (1); + } + + if (Preferences.get ("freehand_samples") != "") { + freehand_samples.set_value (Preferences.get ("freehand_samples")); + DrawingTools.track_tool.set_samples_per_point (freehand_samples.get_value ()); + } + + freehand_samples.new_value_action.connect ((self) => { + DrawingTools.track_tool.set_samples_per_point (freehand_samples.get_value ()); + }); + + SpinButton simplification_threshold = new SpinButton ("simplification_threshold"); + simplification_threshold.set_value_round (0.5); + tools.add (new SettingsItem (simplification_threshold, t_("Path simplification threshold"))); + + simplification_threshold.set_max (5); + freehand_samples.set_min (0.002); + + if (Preferences.get ("simplification_threshold") != "") { + freehand_samples.set_value (Preferences.get ("simplification_threshold")); + DrawingTools.pen_tool.set_simplification_threshold (simplification_threshold.get_value ()); + } + + freehand_samples.new_value_action.connect ((self) => { + DrawingTools.pen_tool.set_simplification_threshold (simplification_threshold.get_value ()); + }); + + Tool themes = new Tool ("open_theme_tab"); + themes.set_icon ("theme"); + themes.select_action.connect((self) => { + MenuTab.show_theme_tab (); + }); + tools.add (new SettingsItem (themes, t_("Color theme"))); + + tools.add (new SettingsItem.head_line (t_("Key Bindings"))); + + foreach (MenuItem menu_item in MainWindow.get_menu ().sorted_menu_items) { + tools.add (new SettingsItem.key_binding (menu_item)); + } + } + + public override string get_label () { + return t_("Settings"); + } + + public override string get_name () { + return "Settings"; + } + + } + + }
--- a/libbirdfont/SpacingTab.vala +++ b/libbirdfont/SpacingTab.vala @@ -59,7 +59,7 @@ // character bar cr.save (); - Theme.color (cr, "Foreground 3"); + Theme.color (cr, "Table Border"); cr.set_line_width (0.8); cr.move_to (0, allocation.height - height); cr.line_to (allocation.width, allocation.height - height); @@ -113,7 +113,7 @@ c = g.get_unichar (); cap = new Text ((!) c.to_string (), 17); - Theme.text_color (cap, "Foreground 3"); + Theme.text_color (cap, "Table Border"); cap.widget_x = middle - cap.get_extent () / 2.0; cap.widget_y = allocation.height - height + character_height - 4 * MainWindow.units; cap.draw_at_baseline (cr, cap.widget_x, cap.widget_y); @@ -137,7 +137,7 @@ } right = new Text (truncate (r, 5), 17); - Theme.text_color (right, "Foreground 3"); + Theme.text_color (right, "Table Border"); right.widget_x = end - (box_size / 2.0 - right.get_extent ()) / 2.0 - right.get_extent (); right.widget_y = allocation.height - 7 * MainWindow.units; right.draw_at_baseline (cr, right.widget_x, right.widget_y);
--- a/libbirdfont/TabBar.vala +++ b/libbirdfont/TabBar.vala @@ -670,7 +670,7 @@ } else { // menu icon if (MainWindow.get_menu ().show_menu) { - Theme.color (cr, "Background 3"); + Theme.color (cr, "Menu Background"); cr.rectangle (w - 33 / scale, 0, 33 / scale, h); cr.fill (); }
--- a/libbirdfont/TabContent.vala +++ b/libbirdfont/TabContent.vala @@ -291,6 +291,7 @@ public static void draw_text_input (WidgetAllocation allocation, Context cr) { cr.save (); + Theme.color (cr, "Default Background"); cr.rectangle (0, 0, allocation.width, TEXT_INPUT_HEIGHT); cr.fill ();
--- a/libbirdfont/Theme.vala +++ b/libbirdfont/Theme.vala @@ -97,6 +97,7 @@ add_theme_files (); + Theme.set_default_color ("Canvas Background", 1, 1, 1, 1); Theme.set_default_color ("Stroke Color", 0, 0, 0, 1); Theme.set_default_color ("Handle Color", 0, 0, 0, 1); Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1); @@ -108,22 +109,14 @@ Theme.set_default_color ("Default Background", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); Theme.set_default_color ("Headline Background", 110 / 255.0, 113 / 255.0, 130 / 255.0, 1); Theme.set_default_color ("Empty Tool Box", 110 / 255.0, 113 / 255.0, 130 / 255.0, 1); - - Theme.set_default_color ("Background 6", 224/255.0, 224/255.0, 224/255.0, 1); - Theme.set_default_color ("Background 7", 56 / 255.0, 59 / 255.0, 65 / 255.0, 1); - Theme.set_default_color ("Background 8", 55/255.0, 55/255.0, 55/255.0, 1); - Theme.set_default_color ("Background 9", 72/255.0, 72/255.0, 72/255.0, 1); - Theme.set_default_color ("Background 10", 223/255.0, 223/255.0, 223/255.0, 1); Theme.set_default_color ("Checkbox Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); Theme.set_default_color ("Text Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); - Theme.set_default_color ("Foreground 3", 26 / 255.0, 30 / 255.0, 32 / 255.0, 1); - Theme.set_default_color ("Foreground 4", 40 / 255.0, 57 / 255.0, 65 / 255.0, 1); - Theme.set_default_color ("Foreground 5", 70 / 255.0, 77 / 255.0, 83 / 255.0, 1); - Theme.set_default_color ("Foreground 6", 45 / 255.0, 45 / 255.0, 45 / 255.0, 1); - Theme.set_default_color ("Foreground 7", 219 / 255.0, 221 / 255.0, 233 / 255.0, 1); + Theme.set_default_color ("Table Border", 26 / 255.0, 30 / 255.0, 32 / 255.0, 1); + Theme.set_default_color ("Selection Border", 40 / 255.0, 57 / 255.0, 65 / 255.0, 1); + Theme.set_default_color ("Overview Glyph", 219 / 255.0, 221 / 255.0, 233 / 255.0, 1); Theme.set_default_color ("Table Background 1", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); Theme.set_default_color ("Table Background 2", 210 / 255.0, 212 / 255.0, 223 / 255.0, 1); @@ -206,6 +199,7 @@ current_theme = "generated_theme.theme"; write_theme (); + t_("Canvas Background"); t_("Stroke Color"); t_("Handle Color"); t_("Fill Color"); @@ -215,20 +209,14 @@ t_("Dialog Background"); t_("Menu Background"); t_("Default Background"); - t_("Background 6"); - t_("Background 7"); - t_("Background 8"); - t_("Background 9"); t_("Checkbox Background"); t_("Foreground 1"); t_("Text Foreground"); - t_("Foreground 3"); - t_("Foreground 4"); - t_("Foreground 5"); - t_("Foreground 6"); - t_("Foreground 7"); + t_("Table Border"); + t_("Selection Border"); + t_("Overview Glyph"); t_("Foreground Inverted"); t_("Menu Foreground"); t_("Selected Tab Foreground");
diff --git libbirdfont/ThemeTab.vala(new)
--- /dev/null +++ b/libbirdfont/ThemeTab.vala @@ -1,1 +1,124 @@ + /* + Copyright (C) 2014 2015 Johan Mattsson + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + */ + + using Cairo; + using Math; + + namespace BirdFont { + + public class ThemeTab : SettingsDisplay { + + public ThemeTab () { + base (); + create_setting_items (); + } + + public override void create_setting_items () { + tools.clear (); + tools.add (new SettingsItem.head_line (t_("Themes"))); + + Gee.ArrayList<Tool> theme_buttons = new Gee.ArrayList<Tool> (); + + foreach (string theme in Theme.themes) { + string label; + Tool select_theme = new Tool (theme); + + select_theme.deselect_action.connect((self) => { + self.set_active (false); + }); + + select_theme.select_action.connect((self) => { + string theme_file = self.get_name (); + TabBar tb; + + Preferences.set ("theme", theme_file); + Theme.load_theme (theme_file); + + foreach (Tool t in theme_buttons) { + t.set_selected (false); + t.set_active (false); + } + + self.set_selected (true); + create_setting_items (); + + Toolbox.redraw_tool_box (); + GlyphCanvas.redraw (); + + tb = MainWindow.get_tab_bar (); + tb.redraw (0, 0, tb.width, tb.height); + }); + + select_theme.set_icon ("theme"); + + if (theme == "default.theme") { + label = t_("Default theme"); + } else if (theme == "high_contrast.theme") { + label = t_("High contrast theme"); + } else if (theme == "custom.theme") { + label = t_("Custom theme"); + } else { + label = theme.replace (".theme", ""); + } + + tools.add (new SettingsItem (select_theme, label)); + theme_buttons.add (select_theme); + + if (select_theme.get_name () == Theme.current_theme) { + select_theme.set_selected (true); + } + } + + foreach (Tool t in theme_buttons) { + t.set_selected (t.name == Theme.current_theme); + } + + Tool add_theme = new Tool ("add_new_theme"); + add_theme.select_action.connect((self) => { + foreach (Tool t in theme_buttons) { + t.set_selected (false); + } + + self.set_selected (false); + Theme.add_new_theme (this); + GlyphCanvas.redraw (); + }); + tools.add (new SettingsItem (add_theme, t_("Add new theme"))); + + tools.add (new SettingsItem.head_line (t_("Colors"))); + + foreach (string color in Theme.color_list) { + SettingsItem s = new SettingsItem.color (color); + ColorTool c = (ColorTool) ((!) s.button); + + tools.add (s); + + c.color_updated.connect (() => { + create_setting_items (); + GlyphCanvas.redraw (); + }); + } + } + + public override string get_label () { + return t_("Themes"); + } + + public override string get_name () { + return "Themes"; + } + } + + }