Clone in a terminal:
Commit 4f64c1e
Johan Mattsson - 2015-12-10T11:31:50+00:00
4f64c1e76e8d25fdb10e4e383b311172af1e91bajohan.mattsson.m@gmail.com

Store tool selection state in tool collection

Changed files (4)

Diff

diff --git a/libbirdfont/BackgroundTools.vala b/libbirdfont/BackgroundTools.valaindex ae1c62f..669b514 100644--- a/libbirdfont/BackgroundTools.vala+++ b/libbirdfont/BackgroundTools.vala@@ -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) {diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex c8ce5f0..14b6522 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -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") {diff --git a/libbirdfont/ToolCollection.vala b/libbirdfont/ToolCollection.valaindex a62866b..82aef59 100644--- a/libbirdfont/ToolCollection.vala+++ b/libbirdfont/ToolCollection.vala@@ -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) { 	} } diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 12c6d7f..fd94554 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -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) {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112