Commit 53be19b
Undo deleting glyphs in overview tab
Changed files (4)
modifiedlibbirdfont/GlyphCollection.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/TestCases.valamodifiedlibbirdfont/VersionList.vala
Diff
@@ -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;+ } } }@@ -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) {@@ -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; }@@ -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 ();