Clone in a terminal:
Commit 53be19b
Johan Mattsson - 2014-07-05T13:28:55+00:00
53be19bc4fda5ef879882a355fb8d730ccaca403johan.mattsson.m@gmail.com

Undo deleting glyphs in overview tab

Changed files (4)

Diff

diff --git a/libbirdfont/GlyphCollection.vala b/libbirdfont/GlyphCollection.valaindex e927761..9da782e 100644--- a/libbirdfont/GlyphCollection.vala+++ b/libbirdfont/GlyphCollection.vala@@ -62,6 +62,22 @@ public class GlyphCollection : GLib.Object { 	public void set_selected_version (int version_id) { 		versions.set_selected_version (version_id); 	}+	+	/** Create a copy of this list. This method will copy the list data but +	 * keep pointers to the original glyphs.+	 * @return a new list with copies of pointers to the glyphs+	 */+	public GlyphCollection copy () {+		GlyphCollection n = new GlyphCollection (unicode_character, name);+		+		foreach (Glyph g in versions.glyphs) {+			n.insert_glyph (g, false);+		}+		+		n.versions.set_selected_version (versions.current_version_id);+		+		return n;+	} } 	 }diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 4dd2aa3..a290716 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -35,8 +35,11 @@ public class OverView : FontDisplay { 	string search_query = ""; 	 	Gee.ArrayList<OverViewItem> visible_items = new Gee.ArrayList<OverViewItem> ();-	List<GlyphCollection> deleted_glyphs = new List<GlyphCollection> ();-		+	+	/** List for undo commands. */+	Gee.ArrayList<GlyphCollection> deleted_glyphs = new Gee.ArrayList<GlyphCollection> ();+	+	/** Show all characters that has been drawn. */ 	bool all_available = true; 	 	/** Show unicode database info. */@@ -624,14 +627,24 @@ public class OverView : FontDisplay { 	} 	 	public override void undo () {-		Font f = BirdFont.get_current_font ();+		Font font = BirdFont.get_current_font ();+		GlyphCollection previous_collection; 		-		if (deleted_glyphs.length () == 0) {+		if (deleted_glyphs.size == 0) { 			return; 		}-			-		f.add_glyph_collection (deleted_glyphs.last ().data);-		deleted_glyphs.remove_link (deleted_glyphs.last ());+		+		previous_collection = deleted_glyphs.get (deleted_glyphs.size - 1);+		+		// remove the old glyph and add the new one+		font.delete_glyph (previous_collection);+		font.add_glyph_collection (previous_collection);+		+		deleted_glyphs.remove_at (deleted_glyphs.size - 1);+	}+	+	public void store_undo_state (GlyphCollection gc) {+		deleted_glyphs.add (gc); 	} 	 	public void scroll_to_char (unichar c) {diff --git a/libbirdfont/TestCases.vala b/libbirdfont/TestCases.valaindex d8b4b43..623a75b 100644--- a/libbirdfont/TestCases.vala+++ b/libbirdfont/TestCases.vala@@ -1227,16 +1227,6 @@ class TestCases { 		t.move_action (t, x, y); 	} -	public static void test_press_action (Tool t, int b, int x, int y) {-		Tool.yield ();-		t.press_action (t, b, x, y);-	}--	public static void test_release_action (Tool t, int b, int x, int y) {-		Tool.yield ();-		t.release_action (t, b, x, y);-	}- 	public static void test_open_next_glyph () { 		OverView o = MainWindow.get_overview (); 		@@ -1250,10 +1240,6 @@ class TestCases { 		Tool.yield (); 	} 	-	private static void add_point_on_path (Path p, int x, int y) {-		p.add (Glyph.path_coordinate_x (x), Glyph.path_coordinate_y (y));-	}-	 	private static void test_boundaries () { 		Preferences.draw_boundaries = true; 	}diff --git a/libbirdfont/VersionList.vala b/libbirdfont/VersionList.valaindex c452417..4be69a0 100644--- a/libbirdfont/VersionList.vala+++ b/libbirdfont/VersionList.vala@@ -18,7 +18,7 @@ using Math; namespace BirdFont {  public class VersionList : DropMenu {-	int current_version_id = -1;+	public int current_version_id = -1; 	GlyphCollection glyph_collection; 	 	public Gee.ArrayList<Glyph> glyphs;@@ -46,16 +46,20 @@ public class VersionList : DropMenu { 		signal_delete_item.connect ((index) => { 			int current_version; 			Font font = BirdFont.get_current_font ();+			OverView over_view = MainWindow.get_overview (); 			 			index--; // first item is the add new action 			 			// delete the entire glyph if the last remaining version is removed 			if (glyphs.size == 1) {+				over_view.store_undo_state (glyph_collection.copy ()); 				font.delete_glyph (glyph_collection); 				return; 			} 			 			return_if_fail (0 <= index < glyphs.size);+			+			over_view.store_undo_state (glyph_collection.copy ()); 			glyphs.remove_at (index); 			 			recreate_index ();

Contact

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