1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
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);}
}

View File

@@ -0,0 +1,126 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
import gplx.gfui.*; import gplx.xowa.guis.views.*; import gplx.xowa.guis.cmds.*;
public class Xog_bnd_box_ {
public static final String Key_browser = "browser", Key_browser_url = "browser.url", Key_browser_search = "browser.search", Key_browser_html = "browser.html", Key_browser_find = "browser.find", Key_browser_prog = "browser.prog", Key_browser_info = "browser.info";
public static final String Gui_browser = "Window", Gui_browser_url = "Url bar", Gui_browser_search = "Search box", Gui_browser_html = "HTML browser", Gui_browser_find = "Find box", Gui_browser_prog = "Status bar", Gui_browser_info = "System Messages box";
public static final int Tid__max = 7, Tid_browser = 0, Tid_browser_url = 1, Tid_browser_search = 2, Tid_browser_html = 3, Tid_browser_find = 4, Tid_browser_prog = 5, Tid_browser_info = 6;
public static final int Ary_len = Tid__max;
public static Xog_bnd_box[] Ary() {
if (ary != null) return ary;
ary = new Xog_bnd_box[Tid__max];
ary_init(ary, Tid_browser , Key_browser);
ary_init(ary, Tid_browser_url , Key_browser_url);
ary_init(ary, Tid_browser_search , Key_browser_search);
ary_init(ary, Tid_browser_html , Key_browser_html);
ary_init(ary, Tid_browser_find , Key_browser_find);
ary_init(ary, Tid_browser_prog , Key_browser_prog);
ary_init(ary, Tid_browser_info , Key_browser_info);
return ary;
} private static Xog_bnd_box[] ary;
private static void ary_init(Xog_bnd_box[] ary, int tid, String key) {ary[tid] = new Xog_bnd_box(tid, key);}
public static int[] Xto_sys_int_ary(String s) {
String[] ary = String_.Split(s, "|");
int len = ary.length;
int[] rv = new int[len];
for (int i = 0; i < len; i++)
rv[i] = Xto_sys_int(ary[i]);
return rv;
}
public static int Xto_sys_int(String s) {
if (String_.Eq(s, Key_browser)) return Tid_browser;
else if (String_.Eq(s, Key_browser_url)) return Tid_browser_url;
else if (String_.Eq(s, Key_browser_search)) return Tid_browser_search;
else if (String_.Eq(s, Key_browser_html)) return Tid_browser_html;
else if (String_.Eq(s, Key_browser_find)) return Tid_browser_find;
else if (String_.Eq(s, Key_browser_prog)) return Tid_browser_prog;
else if (String_.Eq(s, Key_browser_info)) return Tid_browser_info;
else throw Err_.new_unhandled(s);
}
public static String Xto_sys_str(int v) {
switch (v) {
case Tid_browser: return Key_browser;
case Tid_browser_url: return Key_browser_url;
case Tid_browser_search: return Key_browser_search;
case Tid_browser_html: return Key_browser_html;
case Tid_browser_find: return Key_browser_find;
case Tid_browser_prog: return Key_browser_prog;
case Tid_browser_info: return Key_browser_info;
default: throw Err_.new_unhandled(v);
}
}
public static String Xto_gui_str(int v) {
switch (v) {
case Tid_browser: return Gui_browser;
case Tid_browser_url: return Gui_browser_url;
case Tid_browser_search: return Gui_browser_search;
case Tid_browser_html: return Gui_browser_html;
case Tid_browser_find: return Gui_browser_find;
case Tid_browser_prog: return Gui_browser_prog;
case Tid_browser_info: return Gui_browser_info;
default: throw Err_.new_unhandled(v);
}
}
public static int Xby_gui_str(String s) {
if (String_.Eq(s, Gui_browser)) return Tid_browser;
else if (String_.Eq(s, Gui_browser_url)) return Tid_browser_url;
else if (String_.Eq(s, Gui_browser_search)) return Tid_browser_search;
else if (String_.Eq(s, Gui_browser_html)) return Tid_browser_html;
else if (String_.Eq(s, Gui_browser_find)) return Tid_browser_find;
else if (String_.Eq(s, Gui_browser_prog)) return Tid_browser_prog;
else if (String_.Eq(s, Gui_browser_info)) return Tid_browser_info;
else throw Err_.new_unhandled(s);
}
public static void Set_bnd_for_grp(byte mode, Xog_win_itm win, Xog_cmd_mgr_invk invk_mgr, Xog_bnd_box box, Xog_bnd_itm itm, IptArg ipt) {
GfuiElem box_elem = null;
String grp_key = box.Key();
if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser_html)) {Set_bnd_for_tab(mode, win.Tab_mgr(), invk_mgr, box, itm, ipt); return;}
else if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser)) box_elem = win.Win_box();
else if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser_url)) box_elem = win.Url_box();
else if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser_search)) box_elem = win.Search_box();
else if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser_find)) box_elem = win.Find_box();
else if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser_prog)) box_elem = win.Prog_box();
else if (String_.Eq(grp_key, Xog_bnd_box_.Key_browser_info)) box_elem = win.Info_box();
else throw Err_.new_wo_type("unknown box", "grp", grp_key);
Set_bnd_for_elem(mode, box, box_elem, invk_mgr, itm, ipt);
}
public static void Set_bnd_for_elem(byte mode, Xog_bnd_box box, GfuiElem box_elem, Xog_cmd_mgr_invk invk_mgr, Xog_bnd_itm itm, IptArg ipt) {
switch (mode) {
case Set_add:
if (!IptArg_.Is_null_or_none(itm.Ipt()))
IptBnd_.cmd_to_(IptCfg_.Null, box_elem, invk_mgr, itm.Cmd(), itm.Ipt());
break;
case Set_del_key:
box_elem.IptBnds().Del_by_key(itm.Cmd()); // NOTE: delete by cmd, since GfuiIpts use cmd for key
break;
case Set_del_ipt:
box_elem.IptBnds().Del_by_ipt(ipt);
break;
default: throw Err_.new_unhandled(mode);
}
}
private static void Set_bnd_for_tab(byte mode, Xog_tab_mgr tab_mgr, Xog_cmd_mgr_invk invk_mgr, Xog_bnd_box box, Xog_bnd_itm itm, IptArg ipt) {
int len = tab_mgr.Tabs_len();
for (int i = 0; i < len; i++) {
Xog_tab_itm tab_itm = tab_mgr.Tabs_get_at(i);
Set_bnd_for_elem(mode, box, tab_itm.Html_box(), invk_mgr, itm, ipt);
}
}
public static final byte Set_add = 0, Set_del_key = 1, Set_del_ipt = 2;
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
import gplx.gfui.*;
public class Xog_bnd_itm {
public Xog_bnd_itm(String key, boolean sys, String cmd, int box, IptArg ipt) {
this.key = key; this.sys = sys; this.cmd = cmd; this.box = box; this.ipt = ipt;
uid = ++Uid_next;
}
public String Key() {return key;} private String key;
public int Uid() {return uid;} private int uid;
public boolean Sys() {return sys;} private boolean sys;
public String Cmd() {return cmd;} public void Cmd_(String v) {cmd = v;} private String cmd;
public int Box() {return box;} private int box;
public IptArg Ipt() {return ipt;} public void Ipt_to_none() {ipt = IptKey_.None;} private IptArg ipt;
public void Init_by_set(int box, IptArg ipt) {this.box = box; this.ipt = ipt;}
private static int Uid_next = 0;
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
import org.junit.*; import gplx.gfui.*; import gplx.xowa.apps.cfgs.old.*;
public class Xog_bnd_itm_srl_tst {
@Before public void init() {fxt.Reset();} private Xog_bnd_itm_srl_fxt fxt = new Xog_bnd_itm_srl_fxt();
@Test public void Src_get() {
Xog_bnd_itm bnd = fxt.bnd_(Xog_bnd_box_.Tid_browser, IptKey_.A);
fxt.Test_src_get(bnd, "box='browser';ipt='key.a';");
}
@Test public void Src_set() {
fxt.Test_src_set("box='browser.html';ipt='key.b';", Xog_bnd_box_.Tid_browser_html, IptKey_.B);
}
}
class Xog_bnd_itm_srl_fxt {
private Xoae_app app;
public void Reset() {
app = Xoa_app_fxt.app_();
}
public Xog_bnd_itm bnd_(int box, IptArg ipt) {return new Xog_bnd_itm("test.key", true, "test.cmd", box, ipt);}
public void Test_src_get(Xog_bnd_itm bnd, String expd) {
Tfds.Eq(expd, Xocfg_bnd_itm_srl.Src(app, bnd.Box(), bnd.Ipt()));
}
public void Test_src_set(String src, int expd_box, IptArg expd_ipt) {
Xocfg_bnd_itm_srl itm = new Xocfg_bnd_itm_srl(app, "test.key");
Xocfg_bnd_itm_srl.Src_(app, itm, src);
Tfds.Eq(expd_box, itm.Box());
Tfds.Eq(expd_ipt.Key(), itm.Ipt().Key());
}
}

View File

@@ -0,0 +1,248 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
import gplx.gfui.*; import gplx.xowa.guis.views.*;
import gplx.xowa.guis.cmds.*; import gplx.xowa.guis.menus.dom.*;
public class Xog_bnd_mgr {
private Xog_win_itm win; private Xog_cmd_mgr_invk invk_mgr;
private Xog_bnd_box[] boxs = Xog_bnd_box_.Ary();
private List_adp startup_itms = List_adp_.new_();
private Ordered_hash regy = Ordered_hash_.New();
public Xog_bnd_mgr(Xog_win_itm win) {this.win = win; invk_mgr = win.Gui_mgr().Cmd_mgr().Invk_mgr();}
public Gfui_bnd_parser Bnd_parser() {if (bnd_parser == null) bnd_parser = Gfui_bnd_parser.new_en_(); return bnd_parser;} private Gfui_bnd_parser bnd_parser;
public int Len() {return regy.Count();}
public Xog_bnd_itm Get_at(int i) {return (Xog_bnd_itm)regy.Get_at(i);}
public Xog_bnd_itm Get_or_null(String v) {return (Xog_bnd_itm)regy.Get_by(v);}
public void Init_by_kit(Xoae_app app) {
Add_system_bnds();
Add_custom_bnds(); // NOTE: should go after Add_system_bnds in case user overrides any;
Bind_all();
app.Cfg_regy().App().Gui_mgr().Bnd_mgr().Init();
}
public Xog_bnd_itm Set(Xog_bnd_itm itm, int new_box, IptArg new_ipt) {
if (win.Win_box() == null) { // kit not built yet; occurs when restoring bindings through cfg file; DATE:2014-05-16
Xog_bnd_itm new_itm = new Xog_bnd_itm(itm.Key(), false, "", new_box, new_ipt);
startup_itms.Add(new_itm);
return new_itm;
}
Del(itm, new_ipt);
itm.Init_by_set(new_box, new_ipt);
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);
List_adp deleted = List_adp_.new_();
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();
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());
}
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();
}
}
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);
}
deleted.Clear();
}
}
private void Add(Xog_bnd_itm itm) {
Xog_bnd_box box = boxs[itm.Box()];
Xog_bnd_box_.Set_bnd_for_grp(Xog_bnd_box_.Set_add, win, invk_mgr, box, itm, itm.Ipt());
box.Add(itm);
}
public void Bind(int tid, GfuiElem box_elem) {
Xog_bnd_box box = boxs[tid];
int len = box.Len();
for (int i = 0; i < len; i++) {
Xog_bnd_itm itm = box.Get_at(i);
Xog_bnd_box_.Set_bnd_for_elem(Xog_bnd_box_.Set_add, box, box_elem, invk_mgr, itm, itm.Ipt());
}
}
public void Init() {
regy.Clear(); // clear regy, else 1 test will fail
Init_itm(Xog_cmd_itm_.Key_app_exit , Xog_bnd_box_.Tid_browser , "mod.c+key.q");
Init_itm(Xog_cmd_itm_.Key_nav_go_bwd , Xog_bnd_box_.Tid_browser , "mod.a+key.left");
Init_itm(Xog_cmd_itm_.Key_nav_go_fwd , Xog_bnd_box_.Tid_browser , "mod.a+key.right");
Init_itm(Xog_cmd_itm_.Key_nav_cfg_main , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_cfg_menu , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_wiki_main_page , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_wiki_random , Xog_bnd_box_.Tid_browser , "mod.cs+key.r");
Init_itm(Xog_cmd_itm_.Key_nav_wiki_sandbox , Xog_bnd_box_.Tid_browser , "mod.cs+key.g,mod.cs+key.s", "mod.c+key.f1");
Init_itm(Xog_cmd_itm_.Key_nav_help_help , Xog_bnd_box_.Tid_browser , "key.f1");
Init_itm(Xog_cmd_itm_.Key_nav_help_change_log , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_help_diagnostics , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_help_about , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_help_xowa_main , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_setup_import_from_list , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_setup_import_from_script , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_setup_maintenance , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_setup_download , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_system_data_log_session , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_system_data_cfg_app , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_system_data_cfg_lang , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_system_data_cfg_user , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_system_data_cfg_custom , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_system_data_usr_history , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_font_increase , Xog_bnd_box_.Tid_browser , "mod.c+key.equal");
Init_itm(Xog_cmd_itm_.Key_gui_font_decrease , Xog_bnd_box_.Tid_browser , "mod.c+key.minus");
Init_itm(Xog_cmd_itm_.Key_gui_font_reset , Xog_bnd_box_.Tid_browser , "mod.c+key.d0");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_read , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.r");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_edit , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.e");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_html , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.h", "mod.c+key.u");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_reload , Xog_bnd_box_.Tid_browser , "key.f5");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_refresh , Xog_bnd_box_.Tid_browser , "mod.s+key.f5");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_save_as , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_print , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_selection_select_all , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_selection_copy , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_selection_save_file_as , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_edit_save , Xog_bnd_box_.Tid_browser , "mod.as+key.s");
Init_itm(Xog_cmd_itm_.Key_gui_edit_save_draft , Xog_bnd_box_.Tid_browser , "mod.c+key.s");
Init_itm(Xog_cmd_itm_.Key_gui_edit_focus_edit_box , Xog_bnd_box_.Tid_browser , "mod.as+key.comma");
Init_itm(Xog_cmd_itm_.Key_gui_edit_preview , Xog_bnd_box_.Tid_browser , "mod.as+key.p");
Init_itm(Xog_cmd_itm_.Key_gui_edit_dbg_tmpl , Xog_bnd_box_.Tid_browser , "mod.c+key.e,mod.c+key.e", "mod.as+key.d,mod.as+key.d");
Init_itm(Xog_cmd_itm_.Key_gui_edit_dbg_html , Xog_bnd_box_.Tid_browser , "mod.c+key.e,mod.c+key.h");
Init_itm(Xog_cmd_itm_.Key_gui_edit_exec , Xog_bnd_box_.Tid_browser , "mod.c+key.e,mod.c+key.g");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_focus , Xog_bnd_box_.Tid_browser , "mod.a+key.d", "mod.c+key.l");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec , Xog_bnd_box_.Tid_browser_url , "key.enter", "key.keypad_enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec_new_tab_by_paste , Xog_bnd_box_.Tid_browser_url , "mod.c+key.enter", "mod.c+key.keypad_enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec_by_paste , Xog_bnd_box_.Tid_browser_url , "mouse.middle", "mod.a+key.enter", "mod.a+key.keypad_enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_restore , Xog_bnd_box_.Tid_browser_url , "mod.c+key.u");
Init_itm(Xog_cmd_itm_.Key_gui_browser_search_focus , Xog_bnd_box_.Tid_browser , "mod.ca+key.s");
Init_itm(Xog_cmd_itm_.Key_gui_browser_search_exec , Xog_bnd_box_.Tid_browser_search , "key.enter", "key.keypad_enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y , Xog_bnd_box_.Tid_browser , "mod.c+key.t");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_n , Xog_bnd_box_.Tid_browser_html , "mouse.middle");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_new_href__at_dflt__focus_y , Xog_bnd_box_.Tid_browser , "mod.c+key.g,mod.c+key.f");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_close_cur , Xog_bnd_box_.Tid_browser , "mod.c+key.w");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_close_others , Xog_bnd_box_.Tid_browser , "mod.cs+key.w,mod.cs+key.w");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_close_to_bgn , Xog_bnd_box_.Tid_browser , "mod.cs+key.w,mod.cs+key.left");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_close_to_end , Xog_bnd_box_.Tid_browser , "mod.cs+key.w,mod.cs+key.right");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_close_undo , Xog_bnd_box_.Tid_browser , "mod.cs+key.t");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_fwd , Xog_bnd_box_.Tid_browser , "mod.c+key.tab", "mod.c+key.pageDown");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_bwd , Xog_bnd_box_.Tid_browser , "mod.cs+key.tab", "mod.c+key.pageUp");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_1 , Xog_bnd_box_.Tid_browser , "mod.c+key.d1");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_2 , Xog_bnd_box_.Tid_browser , "mod.c+key.d2");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_3 , Xog_bnd_box_.Tid_browser , "mod.c+key.d3");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_4 , Xog_bnd_box_.Tid_browser , "mod.c+key.d4");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_5 , Xog_bnd_box_.Tid_browser , "mod.c+key.d5");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_6 , Xog_bnd_box_.Tid_browser , "mod.c+key.d6");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_7 , Xog_bnd_box_.Tid_browser , "mod.c+key.d7");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_8 , Xog_bnd_box_.Tid_browser , "mod.c+key.d8");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_select_by_idx_9 , Xog_bnd_box_.Tid_browser , "mod.c+key.d9");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_move_bwd , Xog_bnd_box_.Tid_browser , "mod.a+key.pageUp");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_move_fwd , Xog_bnd_box_.Tid_browser , "mod.a+key.pageDown");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_pin_toggle , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_browser_html_focus , 1, Xog_bnd_box_.Tid_browser_url , "key.escape");
Init_itm(Xog_cmd_itm_.Key_gui_browser_html_focus , 2, Xog_bnd_box_.Tid_browser_search , "key.escape");
Init_itm(Xog_cmd_itm_.Key_gui_browser_html_focus , 3, Xog_bnd_box_.Tid_browser_prog , "key.escape");
Init_itm(Xog_cmd_itm_.Key_gui_browser_html_focus , 4, Xog_bnd_box_.Tid_browser_info , "key.escape");
Init_itm(Xog_cmd_itm_.Key_gui_browser_html_selection_focus_toggle , Xog_bnd_box_.Tid_browser , "mod.c+key.g,mod.c+key.g");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_show , Xog_bnd_box_.Tid_browser , "mod.c+key.f");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_show_by_paste , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_hide , Xog_bnd_box_.Tid_browser_find , "key.escape");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_exec , Xog_bnd_box_.Tid_browser_find , "key.enter", "key.keypad_enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_find_fwd , Xog_bnd_box_.Tid_browser_find , "mod.a+key.n");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_find_bwd , Xog_bnd_box_.Tid_browser_find , "mod.a+key.p");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_case_toggle , Xog_bnd_box_.Tid_browser_find , "mod.a+key.c");
Init_itm(Xog_cmd_itm_.Key_gui_browser_find_wrap_toggle , Xog_bnd_box_.Tid_browser_find , "mod.a+key.w");
Init_itm(Xog_cmd_itm_.Key_gui_browser_prog_focus , Xog_bnd_box_.Tid_browser , "mod.ca+key.p");
Init_itm(Xog_cmd_itm_.Key_gui_browser_info_focus , Xog_bnd_box_.Tid_browser , "mod.ca+key.i");
Init_itm(Xog_cmd_itm_.Key_gui_browser_info_clear , Xog_bnd_box_.Tid_browser , "mod.ca+key.c");
Init_itm(Xog_cmd_itm_.Key_gui_browser_prog_log_show , Xog_bnd_box_.Tid_browser_prog , "mouse.middle", "mod.cs+key.p");
Init_itm(Xog_cmd_itm_.Key_html_tidy_toggle , Xog_bnd_box_.Tid_browser , "key.f7");
Init_itm(Xog_cmd_itm_.Key_usr_bookmarks_add , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_usr_bookmarks_show , Xog_bnd_box_.Tid_browser , "key.f3");
Init_itm(Xog_cmd_itm_.Key_usr_history_goto_recent , Xog_bnd_box_.Tid_browser , "mod.cs+key.l");
Init_itm(Xog_cmd_itm_.Key_usr_history_show , Xog_bnd_box_.Tid_browser , "mod.cs+key.h");
Init_itm(Xog_cmd_itm_.Key_net_enabled_n_ , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_net_enabled_y_ , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_net_enabled_x_ , Xog_bnd_box_.Tid_browser , "");
}
private void Init_itm(String cmd, int box, String... ipts) {
int ipts_len = ipts.length;
for (int i = 0; i < ipts_len; i++) {
String ipt_str = ipts[i];
Init_itm(cmd, i, box, IptArg_.parse_or_none_(ipt_str));
}
}
private void Init_itm(String cmd, int idx, int box, String ipt) {Init_itm(cmd, idx, box, IptArg_.parse_or_none_(ipt));}
private void Init_itm(String cmd, int idx, int box, IptArg ipt) {
String key = cmd + "-" + Int_.To_str(idx + List_adp_.Base1); // EX: xowa.widgets.url.focus-1 xowa.widgets.url.focus-2
Xog_bnd_itm itm = new Xog_bnd_itm(key, Bool_.Y, cmd, box, ipt);
boxs[box].Add(itm);
regy.Add(itm.Key(), itm);
}
private void Add_system_bnds() {
IptCfg null_cfg = IptCfg_.Null; IptEventType btn_event_type = IptEventType_.add_(IptEventType_.MouseUp, IptEventType_.KeyDown); IptArg[] btn_args = IptArg_.Ary(IptMouseBtn_.Left, IptKey_.Enter, IptKey_.Space);
IptBnd_.ipt_to_(null_cfg , win.Go_bwd_btn() , invk_mgr, Xog_cmd_itm_.Key_nav_go_bwd , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Go_fwd_btn() , invk_mgr, Xog_cmd_itm_.Key_nav_go_fwd , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Url_exec_btn() , invk_mgr, Xog_cmd_itm_.Key_gui_browser_url_exec , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Search_exec_btn() , invk_mgr, Xog_cmd_itm_.Key_gui_browser_search_exec , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Find_close_btn() , invk_mgr, Xog_cmd_itm_.Key_gui_browser_find_hide , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Find_fwd_btn() , invk_mgr, Xog_cmd_itm_.Key_gui_browser_find_find_fwd , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Find_bwd_btn() , invk_mgr, Xog_cmd_itm_.Key_gui_browser_find_find_bwd , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , win.Find_box() , invk_mgr, Xog_cmd_itm_.Key_gui_browser_find_type , IptEventType_.KeyUp, IptKey_.printableKeys_(IptKey_.Ary(IptKey_.Back, IptKey_.Escape), IptKey_.Ary()));
}
private void Add_custom_bnds() { // NOTE: custom bnds are stored in cfg; cfg executes before Init_by_kit when all windows elements are null; run cfg now, while Init_by_kit is called and elems are now created
int len = startup_itms.Count();
for (int i = 0; i < len; i++) {
Xog_bnd_itm new_itm = (Xog_bnd_itm)startup_itms.Get_at(i);
try {
Xog_bnd_itm cur_itm = (Xog_bnd_itm)regy.Get_by(new_itm.Key());
if (cur_itm == null) {win.Usr_dlg().Warn_many("", "", "binding no longer exists; key=~{0}", new_itm.Key());} // could happen when breaking backward compatibility
cur_itm.Init_by_set(new_itm.Box(), new_itm.Ipt());
} catch (Exception e) {win.Usr_dlg().Warn_many("", "", "failed to set custom binding; key=~{0} err=~{1}", new_itm.Key(), Err_.Message_gplx_full(e));}
}
startup_itms.Clear();
}
private void Bind_all() {
this.Bind(Xog_bnd_box_.Tid_browser , win.Win_box());
this.Bind(Xog_bnd_box_.Tid_browser_url , win.Url_box());
this.Bind(Xog_bnd_box_.Tid_browser_find , win.Find_box());
this.Bind(Xog_bnd_box_.Tid_browser_search , win.Search_box());
this.Bind(Xog_bnd_box_.Tid_browser_prog , win.Prog_box());
this.Bind(Xog_bnd_box_.Tid_browser_info , win.Info_box());
}
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
import gplx.core.primitives.*; import gplx.langs.dsvs.*; import gplx.gfui.*; import gplx.xowa.apps.cfgs.old.*;
public class Xog_bnd_mgr_srl extends Dsv_wkr_base {
private Xoae_app app;
private Xog_bnd_mgr bnd_mgr;
private int uid; private byte[] box_bry, ipt_bry;
public Xog_bnd_mgr_srl(Xoae_app app, Xog_bnd_mgr bnd_mgr) {
this.app = app;
this.bnd_mgr = bnd_mgr;
}
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Int_parser, Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser};}
@Override public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {
switch (fld_idx) {
case 0: uid = val_int; return true;
default: return false;
}
}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {
case 1: box_bry = Bry_.Mid(src, bgn, end); return true;
case 2: ipt_bry = Bry_.Mid(src, bgn, end); return true;
default: return false;
}
}
private void Init() {
uids = Ordered_hash_.New();
int len = bnd_mgr.Len();
for (int i = 0; i < len; i++) {
Xog_bnd_itm bnd = (Xog_bnd_itm)bnd_mgr.Get_at(i);
uids.Add(Int_obj_val.new_(bnd.Uid()), bnd);
}
bnd_parser = bnd_mgr.Bnd_parser();
} private Ordered_hash uids; private Gfui_bnd_parser bnd_parser;
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
if (uid == -1) throw parser.Err_row_bgn("bnd missing uid", pos);
if (box_bry == null) throw parser.Err_row_bgn("bnd missing box", pos);
if (ipt_bry == null) throw parser.Err_row_bgn("bnd missing ipt", pos);
if (uids == null) Init();
Xog_bnd_itm bnd = (Xog_bnd_itm)uids.Get_by(Int_obj_val.new_(uid));
int box = Xog_bnd_box_.Xby_gui_str(String_.new_u8(box_bry));
IptArg ipt = IptArg_.parse_or_none_(bnd_parser.Xto_gfui(String_.new_u8(ipt_bry)));
bnd_mgr.Del(bnd, ipt);
Xog_bnd_mgr_srl.Update_cfg(app, bnd, box, ipt);
uid = -1; box_bry = ipt_bry = null;
}
public static void Update_cfg(Xoae_app app, Xog_bnd_itm bnd, int box, IptArg ipt) {
String src = Xocfg_bnd_itm_srl.Src(app, box, ipt);
String cfg_key = String_.Concat("app.cfg.get.gui.bnds.init('", bnd.Key(), "').src");
app.Cfg_mgr().Set_by_app(cfg_key, src);
}
}

View File

@@ -0,0 +1,90 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
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.*;
import gplx.gfui.*;
public class Xog_bnd_win implements GfoInvkAble {
private GfuiWin win;
private GfuiTextBox shortcut_txt, binding_txt, keycode_txt;
private GfuiBtn ok_btn, cxl_btn;
private Gfui_bnd_parser bnd_parser;
public void Show(Gfui_kit kit, GfuiWin owner_win, Gfui_bnd_parser bnd_parser, String shortcut_text, String binding_text) {
// create controls
this.win = kit.New_win_utl("shortcut_win", owner_win); win.BackColor_(ColorAdp_.White).Size_(200, 120);
this.bnd_parser = bnd_parser;
GfuiLbl shortcut_lbl = Make_lbl(kit, win, "shortcut_lbl" , "Shortcut:");
GfuiLbl binding_lbl = Make_lbl(kit, win, "binding_lbl" , "Binding:");
GfuiLbl keycode_lbl = Make_lbl(kit, win, "keycode_lbl" , "Keycode:");
this.shortcut_txt = Make_txt(kit, win, "shortcut_txt" , shortcut_text);
this.binding_txt = Make_txt(kit, win, "binding_txt" , binding_text);
this.keycode_txt = Make_txt(kit, win, "keycode_txt" , "");
this.ok_btn = Make_btn(kit, win, "ok_btn" , "Ok");
this.cxl_btn = Make_btn(kit, win, "cxl_btn" , "Cancel");
// layout controls
Layout( 0, shortcut_lbl , shortcut_txt);
Layout(20, binding_lbl , binding_txt);
Layout(40, keycode_lbl , keycode_txt);
ok_btn.Pos_(110, 70); cxl_btn.Pos_(150, 70);
// hookup events
IptCfg null_cfg = IptCfg_.Null; IptEventType btn_event_type = IptEventType_.add_(IptEventType_.MouseDown, IptEventType_.KeyDown); IptArg[] btn_args = IptArg_.Ary(IptMouseBtn_.Left, IptKey_.Enter, IptKey_.Space);
IptBnd_.ipt_to_(null_cfg , binding_txt , this, Invk_when_key_down , IptEventType_.KeyDown, IptArg_.Wildcard);
IptBnd_.ipt_to_(null_cfg , binding_txt , this, Invk_when_key_up , IptEventType_.KeyUp, IptArg_.Wildcard);
IptBnd_.ipt_to_(null_cfg , ok_btn , this, "when_ok" , btn_event_type, btn_args);
IptBnd_.ipt_to_(null_cfg , cxl_btn , this, "when_cxl" , btn_event_type, btn_args);
// open
win.Pos_(SizeAdp_.center_(ScreenAdp_.Primary.Size(), win.Size()));
win.Show();
binding_txt.Focus();
}
private void When_key_down(GfoMsg m) {
IptEventData event_data = (IptEventData)m.Args_getAt(0).Val();
int keycode = event_data.Key().Val();
binding_txt.Text_(bnd_parser.Xto_norm(IptKey_.To_str(keycode)));
keycode_txt.Text_(Int_.To_str(keycode));
event_data.Handled_on();
}
private void When_key_up(GfoMsg m) {
IptEventData event_data = (IptEventData)m.Args_getAt(0).Val();
event_data.Handled_on();
}
private GfuiLbl Make_lbl(Gfui_kit kit, GfuiWin owner_win, String key, String text) {
return (GfuiLbl)kit.New_lbl(key, owner_win).Text_(text).Size_(80, 20).BackColor_(ColorAdp_.White);
}
private GfuiTextBox Make_txt(Gfui_kit kit, GfuiWin owner_win, String key, String text) {
return (GfuiTextBox)kit.New_text_box(key, owner_win).Text_(text).Size_(120, 20).Border_on_();
}
private GfuiBtn Make_btn(Gfui_kit kit, GfuiWin owner_win, String key, String text) {
return (GfuiBtn)kit.New_btn(key, owner_win).Text_(text).Size_(40, 20).Focus_able_(true);
}
private void Layout(int y, GfuiElem elem_1, GfuiElem elem_2) {
elem_1.Y_(y);
elem_2.Y_(y);
elem_2.X_(elem_1.X_max());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_when_key_down)) When_key_down(m);
else if (ctx.Match(k, Invk_when_key_press)) When_key_up(m);
else if (ctx.Match(k, Invk_when_key_up)) When_key_up(m);
else if (ctx.Match(k, Invk_when_ok)) {win.Close();}
else if (ctx.Match(k, Invk_when_cxl)) {win.Close();}
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_when_key_down = "when_key_down", Invk_when_key_press = "when_key_press", Invk_when_key_up = "when_key_up"
, Invk_when_ok = "when_ok", Invk_when_cxl = "when_cxl"
;
}