diff --git a/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_box.java b/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_box.java index 2ffc05ac2..8d8a16da4 100644 --- a/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_box.java +++ b/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_box.java @@ -17,13 +17,35 @@ along with this program. If not, see . */ package gplx.xowa.guis.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; public class Xog_bnd_box { - private Ordered_hash bnds = Ordered_hash_.New(); - public Xog_bnd_box(int tid, String key) {this.tid = tid; this.key = key;} - public int Tid() {return tid;} private int tid; - public String Key() {return key;} private String key; - public int Len() {return bnds.Count();} - public void Add(Xog_bnd_itm itm) {bnds.Add_if_dupe_use_nth(itm.Key(), itm);} // Add_if_dupe_use_nth, else Xou_user_tst.Run fails; DATE:2014-05-15 - public void Del(String key) {bnds.Del(key);} - public Xog_bnd_itm Get_at(int i) {return (Xog_bnd_itm)bnds.Get_at(i);} - public Xog_bnd_itm Get(String key) {return (Xog_bnd_itm)bnds.Get_by(key);} + private final Ordered_hash key_hash = Ordered_hash_.New(); + private final Hash_adp cmd_hash = Hash_adp_.New(); + public Xog_bnd_box(int tid, String key) { + this.tid = tid; + this.key = key; + } + public int Tid() {return tid;} private final int tid; + public String Key() {return key;} private final String key; + public int Len() {return key_hash.Count();} + public Xog_bnd_itm Get_at(int i) {return (Xog_bnd_itm)key_hash.Get_at(i);} + public void Add(Xog_bnd_itm itm) { + key_hash.Add_if_dupe_use_nth(itm.Key(), itm); // Add_if_dupe_use_nth, else Xou_user_tst.Run fails; DATE:2014-05-15 + + // add by cmd; needed b/c gfui.ipt_mgr hashes by cmd ("sandbox"), not key ("sandbox-1"); DATE:2016-12-25 + List_adp list = (List_adp)cmd_hash.Get_by(itm.Cmd()); + if (list == null) { + list = List_adp_.New(); + cmd_hash.Add(itm.Cmd(), list); + } + list.Add(itm); + } + public List_adp Get_list_by_cmd(String cmd) {return (List_adp)cmd_hash.Get_by(cmd);} + public void Del(String key) { + // delete from key_hash + Xog_bnd_itm itm = (Xog_bnd_itm)key_hash.Get_by(key); + key_hash.Del(key); + + // delete from cmd_hash + List_adp list = (List_adp)cmd_hash.Get_by(itm.Cmd()); + if (list != null) list.Del(itm); + } } diff --git a/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_mgr.java b/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_mgr.java index a539b4abd..e5d338faa 100644 --- a/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_mgr.java +++ b/400_xowa/src/gplx/xowa/guis/bnds/Xog_bnd_mgr.java @@ -162,29 +162,49 @@ public class Xog_bnd_mgr implements Gfo_invk { Add(itm); return itm; } - public void Del(Xog_bnd_itm itm, IptArg new_ipt) { - boolean itm_has_ipt = !IptArg_.Is_null_or_none(new_ipt); + public void Del(Xog_bnd_itm new_bnd, IptArg new_ipt) { + boolean new_ipt_exists = !IptArg_.Is_null_or_none(new_ipt); List_adp deleted = List_adp_.New(); + + // loop over each box for (int i = 0; i < Xog_bnd_box_.Ary_len; i++) { Xog_bnd_box old_box = boxs[i]; int old_itms_len = old_box.Len(); + + // loop over each bnd for (int j = 0; j < old_itms_len; j++) { - Xog_bnd_itm old_itm = old_box.Get_at(j); - if ( String_.Eq(old_itm.Key(), itm.Key())) { - Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_del_key, win, invk_mgr, old_box, old_itm, itm.Ipt()); - deleted.Add(itm.Key()); + Xog_bnd_itm old_bnd = old_box.Get_at(j); + + // if keys match, delete old_bnd + if ( String_.Eq(old_bnd.Key(), new_bnd.Key())) { + Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_del_key, win, invk_mgr, old_box, old_bnd, new_bnd.Ipt()); + deleted.Add(new_bnd); } - else if ( itm_has_ipt - && String_.Eq(old_itm.Ipt().Key(), new_ipt.Key())) { - Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_del_ipt, win, invk_mgr, old_box, old_itm, old_itm.Ipt()); - Xog_bnd_mgr_srl.Update_cfg(win.App(), old_itm, i, IptKey_.None); - old_itm.Ipt_to_none(); + // if ipts match, delete old_bnd + else if ( new_ipt_exists + && String_.Eq(old_bnd.Ipt().Key(), new_ipt.Key())) { + Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_del_ipt, win, invk_mgr, old_box, old_bnd, old_bnd.Ipt()); + Xog_bnd_mgr_srl.Update_cfg(win.App(), old_bnd, i, IptKey_.None); + old_bnd.Ipt_to_none(); } } + + // remove old bnd from box int deleted_len = deleted.Count(); for (int j = 0; j < deleted_len; j++) { - String deleted_key = (String)deleted.Get_at(j); - old_box.Del(deleted_key); + // delete from box + Xog_bnd_itm deleted_itm = (Xog_bnd_itm)deleted.Get_at(j); + old_box.Del(deleted_itm.Key()); + + // add back other items with same cmd but different key; needed b/c gfui.ipt_mgr hashes by cmd ("sandbox"), not key ("sandbox-1"); DATE:2016-12-25 + List_adp list = old_box.Get_list_by_cmd(deleted_itm.Cmd()); + if (list != null) { + int len = list.Len(); + for (int k = 0; k < len; k++) { + Xog_bnd_itm restore_itm = (Xog_bnd_itm)list.Get_at(k); + Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_add, win, invk_mgr, old_box, restore_itm, restore_itm.Ipt()); + } + } } deleted.Clear(); }