Clone in a terminal:
Commit 26d9314
Johan Mattsson - 2013-01-09T13:45:36+00:00
26d9314d1252ae2689d7ab6f202a540e2398a6d3johan.mattsson.m@gmail.com

update tab instead of closing it when a new version is selected

Changed files (5)

Diff

diff --git a/libbirdfont/ExportTool.vala b/libbirdfont/ExportTool.valaindex 86bb226..dfd9b46 100644--- a/libbirdfont/ExportTool.vala+++ b/libbirdfont/ExportTool.vala@@ -419,12 +419,6 @@ os.put_string ( 			async = false; 		} 		-		/* // This ugly hack causes problems; TODO: fix it-		if (Supplement.win32) {-			VersionList.set_suppress_signal (true);-		}-		*/-		 		try { 			// create a copy of current font and use it in a separate  			// export thread@@ -466,10 +460,6 @@ os.put_string ( 			done = false; 		} -		if (Supplement.win32) {-			VersionList.set_suppress_signal (false);-		}-		 		return done;		 	} 	diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 5ae2425..64d0516 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -1121,7 +1121,7 @@ public class Path { 				position = t; 			} 		}-			+ 		bezier_vector (position, start.x, start.get_right_handle ().x (), stop.get_left_handle ().x (), stop.x, out x0, out x1); 		bezier_vector (position, start.y, start.get_right_handle ().y (), stop.get_left_handle ().y (), stop.y, out y0, out y1); diff --git a/libbirdfont/Tab.vala b/libbirdfont/Tab.valaindex fc9a582..4458543 100644--- a/libbirdfont/Tab.vala+++ b/libbirdfont/Tab.vala@@ -33,6 +33,10 @@ public class Tab : GLib.Object { 		return !always_open; 	} +	public void set_display (FontDisplay fd) {+		display = fd;+	}+ 	public FontDisplay get_display () { 		return display; 	}diff --git a/libbirdfont/TabBar.vala b/libbirdfont/TabBar.valaindex 02f700a..719beb3 100644--- a/libbirdfont/TabBar.vala+++ b/libbirdfont/TabBar.vala@@ -240,6 +240,14 @@ public class TabBar : GLib.Object { 		return false; 	} +	public Tab? get_nth (int i) {+		if (!(0 <= i < get_length ())) {+			return null;+		}+		+		return tabs.nth (i).data;+	}+ 	public Tab? get_tab (string name) { 		foreach (var n in tabs) { 			if (n.get_label () == name) {@@ -263,7 +271,7 @@ public class TabBar : GLib.Object { 		 		return false; 	}-		+	 	public Tab get_selected_tab () { 		return tabs.nth (get_selected ()).data; 	}diff --git a/libbirdfont/VersionList.vala b/libbirdfont/VersionList.valaindex 3f11a88..6655a21 100644--- a/libbirdfont/VersionList.vala+++ b/libbirdfont/VersionList.vala@@ -24,7 +24,6 @@ public class VersionList : DropMenu { 	int versions = 1; 	int current_version = 0; 	public List<Glyph> glyphs = new List<Glyph> ();-	public static bool suppress_signal = false;  	public VersionList (Glyph? g = null) { 		base ("version");@@ -46,10 +45,6 @@ public class VersionList : DropMenu { 		} 	} 	-	public static void set_suppress_signal (bool s) {-		suppress_signal = s;-	}-	 	public Glyph get_current () { 		if (unlikely (current_version >= glyphs.length ())) { 			warning (@"current_version >= glyphs.length ($current_version >= $(glyphs.length ()))");@@ -75,11 +70,61 @@ public class VersionList : DropMenu { 		return_if_fail (ma.parent != null); 		 		((!)ma.parent).deselect_all ();-		ma.set_selected (true);		+		ma.set_selected (true); 		-		if (!is_null (MainWindow.get_tab_bar ())) {-			MainWindow.get_tab_bar ().close_by_name (get_current ().name);-		}	+		reload_all_open_glyphs ();+	}+	+	/** Reload a glyph when a new version is selected. Updates the path+	 * in glyph view, not from disk but from the glyph table.+	 */+	void reload_all_open_glyphs () {+		TabBar b;+		Tab tab;+		Tab? tn;+		Glyph glyph;+		Glyph updated_glyph;+		Glyph? ug;+		Font font = Supplement.get_current_font ();+		StringBuilder uni = new StringBuilder ();+		+		if (is_null (MainWindow.get_tab_bar ())) {+			return;+		}+		+		b = MainWindow.get_tab_bar ();+		+		for (int i = 0; i < b.get_length (); i++) {+			tn = b.get_nth (i);+			+			if (tn == null) {+				warning ("tab is null");+				return;+			}++			tab = (!) tn;++			if (! (tab.get_display () is Glyph)) {+				continue; +			}+			+			glyph = (Glyph) tab.get_display ();+			uni.truncate (0);+			uni.append_unichar (glyph.unichar_code);+			ug = font.get_glyph (uni.str);+			+			if (ug == null) {+				warning ("display is null");+				return;+			}+			+			updated_glyph = (!) ug;+			tab.set_display (updated_glyph);+			updated_glyph.view_zoom = glyph.view_zoom;+			updated_glyph.view_offset_x = glyph.view_offset_x;+			updated_glyph.view_offset_y = glyph.view_offset_y;+			updated_glyph.close_path ();+		} 	} 	 	public void add_glyph (Glyph new_version, bool selected = true) {@@ -94,16 +139,12 @@ public class VersionList : DropMenu { 		ma.action = (self) => { 			Font font; 			-			if (suppress_signal) {-				return;-			}-			 			font = Supplement.get_current_font (); 			set_selected_item (self); 			font.touch (); 		}; -		if (selected && !suppress_signal) {+		if (selected) { 			set_selected_item (ma); 		} 	}

Contact

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