Cfg: Fix updating shortcut not working if shortcut is part of group

pull/620/head
gnosygnu 8 years ago
parent a96a239449
commit afd19c1619

@ -17,13 +17,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.guis.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; package gplx.xowa.guis.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Xog_bnd_box { public class Xog_bnd_box {
private Ordered_hash bnds = Ordered_hash_.New(); private final Ordered_hash key_hash = Ordered_hash_.New();
public Xog_bnd_box(int tid, String key) {this.tid = tid; this.key = key;} private final Hash_adp cmd_hash = Hash_adp_.New();
public int Tid() {return tid;} private int tid; public Xog_bnd_box(int tid, String key) {
public String Key() {return key;} private String key; this.tid = tid;
public int Len() {return bnds.Count();} this.key = key;
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 int Tid() {return tid;} private final int tid;
public Xog_bnd_itm Get_at(int i) {return (Xog_bnd_itm)bnds.Get_at(i);} public String Key() {return key;} private final String key;
public Xog_bnd_itm Get(String key) {return (Xog_bnd_itm)bnds.Get_by(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);
}
} }

@ -162,29 +162,49 @@ public class Xog_bnd_mgr implements Gfo_invk {
Add(itm); Add(itm);
return itm; return itm;
} }
public void Del(Xog_bnd_itm itm, IptArg new_ipt) { public void Del(Xog_bnd_itm new_bnd, IptArg new_ipt) {
boolean itm_has_ipt = !IptArg_.Is_null_or_none(new_ipt); boolean new_ipt_exists = !IptArg_.Is_null_or_none(new_ipt);
List_adp deleted = List_adp_.New(); List_adp deleted = List_adp_.New();
// loop over each box
for (int i = 0; i < Xog_bnd_box_.Ary_len; i++) { for (int i = 0; i < Xog_bnd_box_.Ary_len; i++) {
Xog_bnd_box old_box = boxs[i]; Xog_bnd_box old_box = boxs[i];
int old_itms_len = old_box.Len(); int old_itms_len = old_box.Len();
// loop over each bnd
for (int j = 0; j < old_itms_len; j++) { for (int j = 0; j < old_itms_len; j++) {
Xog_bnd_itm old_itm = old_box.Get_at(j); Xog_bnd_itm old_bnd = 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()); // if keys match, delete old_bnd
deleted.Add(itm.Key()); 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 // if ipts match, delete old_bnd
&& String_.Eq(old_itm.Ipt().Key(), new_ipt.Key())) { else if ( new_ipt_exists
Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_del_ipt, win, invk_mgr, old_box, old_itm, old_itm.Ipt()); && String_.Eq(old_bnd.Ipt().Key(), new_ipt.Key())) {
Xog_bnd_mgr_srl.Update_cfg(win.App(), old_itm, i, IptKey_.None); Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_del_ipt, win, invk_mgr, old_box, old_bnd, old_bnd.Ipt());
old_itm.Ipt_to_none(); 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(); int deleted_len = deleted.Count();
for (int j = 0; j < deleted_len; j++) { for (int j = 0; j < deleted_len; j++) {
String deleted_key = (String)deleted.Get_at(j); // delete from box
old_box.Del(deleted_key); 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(); deleted.Clear();
} }

Loading…
Cancel
Save