Commit 4f64c1e
Store tool selection state in tool collection
Changed files (4)
modifiedlibbirdfont/BackgroundTools.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/ToolCollection.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -65,11 +65,15 @@ public class BackgroundTools : ToolCollection { expanders.add (parts); } - public void update_tool_selection (Tool selected) {+ public override void reset_selection (Tool selected) { select_background.set_selected (false); DrawingTools.move_background.set_selected (false); DrawingTools.move_canvas.set_selected (false); DrawingTools.background_scale.set_selected (false);+ }+ + public void update_tool_selection (Tool selected) {+ reset_selection (selected); selected.set_selected (true); } @@ -97,6 +101,8 @@ public class BackgroundTools : ToolCollection { return false; }); idle.attach (null);+ + base.selected (); } public void update_parts_list (BackgroundImage current_image) {@@ -1371,18 +1371,21 @@ public class DrawingTools : ToolCollection { full_height_tool.set_tool_visibility (true); } + public override void reset_selection (Tool current_tool) {+ foreach (Tool t in draw_tools.tool) {+ if (t != current_tool) {+ t.set_selected (false);+ }+ }+ }+ public void update_drawing_and_background_tools (Tool current_tool) { IdleSource idle = new IdleSource (); idle.set_callback (() => { Glyph g = MainWindow.get_current_glyph (); - foreach (Tool t in draw_tools.tool) {- if (t != current_tool) {- t.set_selected (false);- }- }- + reset_selection (current_tool); FontDisplay display = MainWindow.get_current_display (); if (display.get_name () == "Backgrounds") {@@ -20,6 +20,7 @@ namespace BirdFont { public abstract class ToolCollection : GLib.Object { public double scroll = 0; public double content_height = 0;+ private Tool current_tool = new Tool ("no_icon"); public abstract Gee.ArrayList<Expander> get_expanders (); @@ -27,13 +28,26 @@ public abstract class ToolCollection : GLib.Object { return new Gee.ArrayList<string> (); } + public void set_current_tool (Tool tool) {+ current_tool = tool;+ }+ + public Tool get_current_tool () {+ return current_tool;+ }+ public void redraw () { foreach (Expander e in get_expanders ()) { e.redraw (); } } - public virtual void selected () { + public virtual void selected () {+ reset_selection (current_tool);+ current_tool.set_selected (true);+ }++ public virtual void reset_selection (Tool current_tool) { } } @@ -30,8 +30,6 @@ public class Toolbox : GLib.Object { public static FileTools file_tools; public static ThemeTools theme_tools; - Tool current_tool;- public Tool press_tool; public signal void redraw (int x, int y, int w, int h);@@ -57,7 +55,6 @@ public class Toolbox : GLib.Object { public Toolbox (GlyphCanvas glyph_canvas, TabBar tab_bar) { tool_sets = new Gee.ArrayList<ToolCollection> ();- current_tool = new Tool ("no_icon"); press_tool = new Tool (null); hidden_tools = new HiddenTools ();@@ -369,12 +366,12 @@ public class Toolbox : GLib.Object { public void set_current_tool (Tool tool) { if (tool.editor_events) {- current_tool = tool;+ current_set.set_current_tool (tool); } } public Tool get_current_tool () {- return current_tool;+ return current_set.get_current_tool (); } public void select_tool (Tool tool) {