1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2014-06-30 00:04:32 -04:00
parent 85594d3cdd
commit bae88e739c
2482 changed files with 198730 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
/*
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.gui; import gplx.*; import gplx.xowa.*;
import gplx.gfui.*; import gplx.xowa.specials.search.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.cmds.*; import gplx.xowa.cfgs.gui.*;
import gplx.xowa.gui.bnds.*; import gplx.xowa.gui.views.*; import gplx.xowa.gui.urls.url_macros.*;
public class Xoa_gui_mgr implements GfoInvkAble {
public Xoa_gui_mgr(Xoa_app app) {
this.app = app;
browser_win = new Xog_win_itm(app, this);
bnd_mgr = new Xog_bnd_mgr(browser_win);
win_cfg = new Xocfg_win(app);
html_mgr = new Xog_html_mgr(app);
menu_mgr = new Xog_menu_mgr(this);
search_suggest_mgr = new Xog_search_suggest_mgr(this);
}
public Xoa_app App() {return app;} private Xoa_app app;
public Xog_win_itm Browser_win() {return browser_win;} private Xog_win_itm browser_win;
public IptCfgRegy Ipt_cfgs() {return ipt_cfgs;} IptCfgRegy ipt_cfgs = new IptCfgRegy();
public Xog_bnd_mgr Bnd_mgr() {return bnd_mgr;} private Xog_bnd_mgr bnd_mgr;
public Gfui_kit Kit() {return kit;} private Gfui_kit kit = Gfui_kit_.Mem();
public Xog_cmd_mgr Cmd_mgr() {return cmd_mgr;} private Xog_cmd_mgr cmd_mgr = new Xog_cmd_mgr();
public Xocfg_win Win_cfg() {return win_cfg;} private Xocfg_win win_cfg;
public Xog_layout Layout() {return layout;} private Xog_layout layout = new Xog_layout();
public Xog_html_mgr Html_mgr() {return html_mgr;} private Xog_html_mgr html_mgr;
public Xog_search_suggest_mgr Search_suggest_mgr() {return search_suggest_mgr;} private Xog_search_suggest_mgr search_suggest_mgr;
public Xog_menu_mgr Menu_mgr() {return menu_mgr;} private Xog_menu_mgr menu_mgr;
public Xog_url_macro_mgr Url_macro_mgr() {return url_macro_mgr;} private Xog_url_macro_mgr url_macro_mgr = new Xog_url_macro_mgr();
public void Show_prog() {
GfuiWin memo_win = kit.New_win_utl("memo_win", browser_win.Win_box());
GfuiTextBox memo_txt = kit.New_text_box("memo_txt", memo_win, KeyVal_.new_(GfuiTextBox_.Ctor_Memo, true));
RectAdp prog_box_rect = browser_win.Prog_box().Rect();
memo_win.Rect_set(RectAdp_.new_(prog_box_rect.X(), prog_box_rect.Y() - 75, prog_box_rect.Width(), 100));
memo_txt.Size_(memo_win.Size().Op_add(-8, -30));
memo_txt.Text_(String_.Concat_lines_nl(browser_win.Usr_dlg().Ui_wkr().Prog_msgs().Xto_str_ary()));
memo_win.Show();
memo_win.Focus();
}
public void Init_by_app() {
layout_Init();
bnd_mgr.Init();
menu_mgr.Init_by_app(app);
}
public void Kit_(Gfui_kit kit) {
this.kit = kit;
kit.Kit_init(browser_win.Usr_dlg());
kit.Kit_term_cbk_(GfoInvkAbleCmd.new_(app, Xoa_app.Invk_term_cbk));
browser_win.Init_by_kit(kit);
layout.Init(browser_win);
cmd_mgr.Init_by_kit(app);
app.Api_root().Init_by_kit(app);
menu_mgr.Menu_bldr().Init_by_kit(app, kit, app.User().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "menu"));
menu_mgr.Init_by_kit();
browser_win.Tab_mgr().Tabs_new_init();
bnd_mgr.Init_by_kit(app);
}
public void Lang_changed(Xol_lang lang) {
menu_mgr.Lang_changed(lang);
browser_win.Lang_changed(lang);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_kit)) return kit;
else if (ctx.Match(k, Invk_kit_)) this.kit = Gfui_kit_.Get_by_key(m.ReadStrOr("v", Gfui_kit_.Swt().Key()));
else if (ctx.Match(k, Invk_run)) Run();
else if (ctx.Match(k, Invk_browser_type)) kit.Cfg_set("HtmlBox", "BrowserType", gplx.gfui.Swt_kit.Cfg_Html_BrowserType_parse(m.ReadStr("v")));
else if (ctx.Match(k, Invk_xul_runner_path_)) kit.Cfg_set("HtmlBox", "XulRunnerPath", Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("v")).Xto_api());
else if (ctx.Match(k, Invk_bnds)) return bnd_mgr;
else if (ctx.Match(k, Invk_bindings)) return ipt_cfgs;
else if (ctx.MatchIn(k, Invk_main_win, Invk_browser_win))
return browser_win;
else if (ctx.Match(k, Invk_win_opts)) return win_cfg;
else if (ctx.Match(k, Invk_layout)) return layout;
else if (ctx.Match(k, Invk_html)) return html_mgr;
else if (ctx.Match(k, Invk_search_suggest)) return search_suggest_mgr;
else if (ctx.Match(k, Invk_menus)) return menu_mgr;
else if (ctx.Match(k, Invk_cmds)) return cmd_mgr;
else if (ctx.Match(k, Invk_url_macros)) return url_macro_mgr;
else throw Err_mgr._.unhandled_(k);
return this;
}
private static final String
Invk_kit = "kit", Invk_kit_ = "kit_", Invk_browser_type = "browser_type_", Invk_xul_runner_path_ = "xul_runner_path_", Invk_run = "run"
, Invk_main_win = "main_win", Invk_browser_win = "browser_win", Invk_bnds = "bnds"
, Invk_bindings = "bindings", Invk_win_opts = "win_opts", Invk_layout = "layout", Invk_html = "html"
, Invk_search_suggest = "search_suggest", Invk_menus = "menus", Invk_cmds = "cmds", Invk_url_macros = "url_macros";
public void Run() {
Gfo_log_bfr log_bfr = app.Log_bfr();
try {
Xoa_gui_mgr ui_mgr = app.Gui_mgr();
Gfui_kit kit = ui_mgr.Kit();
ui_mgr.Kit_(kit); log_bfr.Add("app.gui.kit_init.done");
Xog_win_itm main_win = ui_mgr.Browser_win();
Xog_win_itm_.Show_win(main_win); log_bfr.Add("app.gui.win_load.done");
Xog_tab_itm_read_mgr.Launch(main_win);
app.Log_wtr().Log_msg_to_session_direct(log_bfr.Xto_str());
kit.Kit_run(); // NOTE: enters thread-loop
} catch (Exception e) {
app.Usr_dlg().Warn_many("", "", "run_failed: ~{0} ~{1}", log_bfr.Xto_str(), Err_.Message_gplx(e));
if (app.Gui_mgr().Kit() != null) app.Gui_mgr().Kit().Ask_ok("", "", Err_.Message_gplx(e));
}
}
private void layout_Init() {
Op_sys os = Op_sys.Cur();
int html_box_w = -8; int html_box_h = -30; // default adjustments since version 0.0.0.0; seems to work on XP and LNX
switch (os.Tid()) {
case Op_sys.Tid_wnt:
switch (os.Sub_tid()) {
case Op_sys.Sub_tid_win_xp: break; // NOOP; will keep values as above
default: // for all else, use Windows 7 border; note that Windows 8 is being detected as "Windows NT (unknown)", so need to use default; this may not work with Windows 2000
html_box_w = -16; html_box_h = -40; // Windows 7 has a thicker windows border and the html_box must be smaller else scroll bar gets cut off
break;
}
break;
default:
break;
}
layout.Html_box().W_rel_(html_box_w).H_rel_(html_box_h);
}
}

View File

@@ -0,0 +1,40 @@
/*
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.gui; import gplx.*; import gplx.xowa.*;
import gplx.xowa.html.portal.*;
public class Xog_html_mgr implements GfoInvkAble {
public Xog_html_mgr(Xoa_app app) {this.app = app; portal_mgr = new Xoa_portal_mgr(app);} private Xoa_app app;
public Xoa_portal_mgr Portal_mgr() {return portal_mgr;} private Xoa_portal_mgr portal_mgr;
public boolean Javascript_enabled() {return javascript_enabled;} private boolean javascript_enabled = true;
private void Javascript_enabled_(boolean v) {
javascript_enabled = v;
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_javascript_enabled_(v);
}
public String Auto_focus_id() {return auto_focus_id;} private String auto_focus_id = "";
public byte[] Css_xtn() {return css_xtn;} public void Css_xtn_(byte[] v) {css_xtn = v;} private byte[] css_xtn = Bry_.Empty;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_javascript_enabled)) return Yn.X_to_str(javascript_enabled);
else if (ctx.Match(k, Invk_javascript_enabled_)) Javascript_enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_auto_focus_id_)) auto_focus_id = m.ReadStr("v");
else if (ctx.Match(k, Invk_css_xtn)) return css_xtn;
else if (ctx.Match(k, Invk_css_xtn_)) css_xtn = m.ReadBry("v");
else if (ctx.Match(k, Invk_portal)) return portal_mgr;
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_javascript_enabled = "javascript_enabled", Invk_javascript_enabled_ = "javascript_enabled_", Invk_auto_focus_id_ = "auto_focus_id_", Invk_css_xtn = "css_xtn", Invk_css_xtn_ = "css_xtn_", Invk_portal = "portal";
}

View File

@@ -0,0 +1,21 @@
/*
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.gui; import gplx.*; import gplx.xowa.*;
public class Xog_page_mode {
public static final byte Tid_read = 0, Tid_edit = 1, Tid_html = 2;
}

View File

@@ -0,0 +1,114 @@
/*
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.gui; import gplx.*; import gplx.xowa.*;
import gplx.gfui.*; import gplx.xowa.users.*; import gplx.xowa.gui.views.*;
public class Xog_resizer {
public void Exec_win_resize(Xoa_app app, int main_w, int main_h) {
Xog_layout layout = app.Gui_mgr().Layout();
Xog_win_itm main_win = app.Gui_mgr().Browser_win();
GfuiBtn go_bwd_btn = main_win.Go_bwd_btn(), go_fwd_btn = main_win.Go_fwd_btn(), url_exec_btn = main_win.Url_exec_btn(), search_exec_btn = main_win.Search_exec_btn(), find_fwd_btn = main_win.Find_fwd_btn(), find_bwd_btn = main_win.Find_bwd_btn(), find_close_btn = main_win.Find_close_btn();
GfuiTextBox url_box = main_win.Url_box(), search_box = main_win.Search_box(), find_box = main_win.Find_box(), prog_box = main_win.Prog_box(), note_box = main_win.Info_box();
Gfui_tab_mgr tab_mgr = main_win.Tab_mgr().Tab_mgr();
int txt_dim = layout.Box_height_calc(app.Gui_mgr().Kit(), url_box);
int btn_dim = 25; // txt_dim + 1;
if (txt_dim < 25) {
txt_margin_v = (25 - txt_dim) / 2;
txt_dim = 25;
}
else
txt_margin_v = 0;
int txt_dif = 0, btn_dif = 0;
int bar_dim = btn_dim > txt_dim ? btn_dim : txt_dim;
if (txt_dim < 25) {txt_dif = (25 - txt_dim) / 2;}
else {btn_dif = (txt_dim - 25) / 2;}
boolean menu_bar_enabled = app.Gui_mgr().Menu_mgr().Window().Get_or_new("main_win").Enabled();
int menu_bar_adj = menu_bar_enabled ? 20 : 2; // 2, else linux progress bar abuts bottom of screen
RectAdp prv_elem_rect = (Op_sys.Cur().Tid_is_wnt() && Op_sys.Cur().Sub_tid() == Op_sys.Sub_tid_win_7) && menu_bar_enabled
? Prv_elem_rect_win_7 // NOTE: if windows 7 and menu bar enabled, shift everything up by 1 pixel; else ugly gap at top border of url box; only affects win 7; DATE:2013-08-31
: Prv_elem_rect_initial
;
Exec_win_resize_elem(layout.Go_bwd_btn() , go_bwd_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), prv_elem_rect, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Go_fwd_btn() , go_fwd_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), go_bwd_btn, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Url_box() , url_box , new Rect_ref(0, 0, main_w - (btn_dim * 5) - 200 , txt_dim ), go_fwd_btn, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Url_exec_btn() , url_exec_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), url_box, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Search_box() , search_box , new Rect_ref(0, 0, 190 , txt_dim ), url_exec_btn, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Search_exec_btn() , search_exec_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), search_box, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Html_box() , tab_mgr , new Rect_ref(0, 0, main_w , main_h + -(bar_dim * 2) - menu_bar_adj), go_bwd_btn, Xog_resizer.Layout_below_left); // -40:btn_dim(url bar) + btn_dim (find box)
Xoc_layout_mgr layout_mgr = app.User().Cfg_mgr().Layout_mgr();
switch (layout_mgr.Html_box_adj_type()) {
case Xoc_layout_mgr.Html_box_adj_type_none_byte: break;
case Xoc_layout_mgr.Html_box_adj_type_abs_byte: tab_mgr.Rect_set(layout_mgr.Html_box_adj_rect()); break;
case Xoc_layout_mgr.Html_box_adj_type_rel_byte: tab_mgr.Rect_set(tab_mgr.Rect().Op_add(layout_mgr.Html_box_adj_rect())); break;
}
Exec_win_resize_elem(layout.Find_close_btn() , find_close_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), tab_mgr, Xog_resizer.Layout_below_left);
Exec_win_resize_elem(layout.Find_box() , find_box , new Rect_ref(0, 0, 102 , txt_dim ), find_close_btn, Xog_resizer.Layout_right_top);
find_box.Y_(tab_mgr.Y_max());
Exec_win_resize_elem(layout.Find_fwd_btn() , find_fwd_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), find_box, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Find_bwd_btn() , find_bwd_btn , new Rect_ref(0, 0, btn_dim , btn_dim ), find_fwd_btn, Xog_resizer.Layout_right_top);
Exec_win_resize_elem(layout.Prog_box() , prog_box , new Rect_ref(0, 0, (main_w - 102 - 200 - (bar_dim * 3)), txt_dim ), find_bwd_btn, Xog_resizer.Layout_right_top); // -200=200(find_box) - 200 (note_box)
Exec_win_resize_elem(layout.Note_box() , note_box , new Rect_ref(0, 0, 200 , txt_dim ), prog_box, Xog_resizer.Layout_right_top); // -200=200(find_box)
if (txt_dif > 0) {
GfuiElem_.Y_adj(txt_dif, url_box, search_box);
GfuiElem_.Y_adj(txt_dif, find_box, prog_box, note_box);
}
if (btn_dif > 0) {
GfuiElem_.Y_adj(btn_dif, go_bwd_btn, go_fwd_btn, url_exec_btn, find_close_btn, search_exec_btn);
GfuiElem_.Y_adj(btn_dif, find_fwd_btn, find_bwd_btn);
}
}
private static RectAdp Prv_elem_rect_initial = RectAdp_.Zero, Prv_elem_rect_win_7 = RectAdp_.new_(0, -1, 0, 0);
private static void Exec_win_resize_elem(Xog_layout_box box, GfuiElem cur_elem, Rect_ref cur_elem_rect, GfuiElem prv_elem, byte layout) {Exec_win_resize_elem(box, cur_elem, cur_elem_rect, prv_elem.Rect(), layout);}
private static void Exec_win_resize_elem(Xog_layout_box box, GfuiElem cur_elem, Rect_ref cur_elem_rect, RectAdp prv_elem_rect, byte layout) {
if (ClassAdp_.Eq_typeSafe(cur_elem, GfuiTextBox.class)) {
try {
GfuiTextBox cur_box = (GfuiTextBox)cur_elem;
cur_box.Margins_set(0, txt_margin_v, 0, txt_margin_v);
} catch (Exception e) {Err_.Noop(e);}
}
if (box.Mode() == Xog_layout_box.Mode_abs) // absolute mode; set dimensions manually
cur_elem_rect.X_(box.X_abs()).Y_(box.Y_abs()).W_(box.W_abs()).H_(box.H_abs());
else {
box.Adj_size(cur_elem_rect);
Set_pos_by_prv(layout, cur_elem_rect, Rect_ref.rectAdp_(prv_elem_rect));
box.Adj_pos(cur_elem_rect);
}
cur_elem.Rect_set(cur_elem_rect.XtoRectAdp());
if (ClassAdp_.Eq_typeSafe(cur_elem, GfuiBtn.class)) {
GfuiBtn cur_btn = (GfuiBtn)cur_elem;
cur_btn.Btn_img_(cur_btn.Btn_img());
}
}
private static void Set_pos_by_prv(byte layout, Rect_ref cur_elem_rect, Rect_ref prv_elem_rect) {
switch (layout) {
case Xog_resizer.Layout_right_top:
cur_elem_rect.X_(prv_elem_rect.X_max());
cur_elem_rect.Y_(prv_elem_rect.Y());
break;
case Xog_resizer.Layout_right_bot:
cur_elem_rect.X_(prv_elem_rect.X_max());
cur_elem_rect.Y_(prv_elem_rect.Y_max() - cur_elem_rect.H()); // cur_elem.Height
break;
case Xog_resizer.Layout_below_left:
cur_elem_rect.X_(prv_elem_rect.X());
cur_elem_rect.Y_(prv_elem_rect.Y_max());
break;
}
}
public static final byte Layout_init = 0, Layout_right_top = 1, Layout_right_bot = 2, Layout_below_left = 3;
private static int txt_margin_v = 0;
}

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.gui.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_bnd_box {
private OrderedHash bnds = OrderedHash_.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.AddReplace(itm.Key(), itm);} // AddReplace, 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.FetchAt(i);}
public Xog_bnd_itm Get(String key) {return (Xog_bnd_itm)bnds.Fetch(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.gui.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*; import gplx.xowa.gui.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[] X_to_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] = X_to_sys_int(ary[i]);
return rv;
}
public static int X_to_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_.unhandled(s);
}
public static String X_to_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_.unhandled(v);
}
}
public static String X_to_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_.unhandled(v);
}
}
public static int X_by_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_.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_fmt_("unknown box: {0}", 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_.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.gui.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
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.gui.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import org.junit.*; import gplx.gfui.*; import gplx.xowa.cfgs2.*;
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 Xoa_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,245 @@
/*
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.gui.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
import gplx.xowa.gui.cmds.*; import gplx.xowa.gui.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 ListAdp startup_itms = ListAdp_.new_();
private OrderedHash regy = OrderedHash_.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.FetchAt(i);}
public Xog_bnd_itm Get_or_null(String v) {return (Xog_bnd_itm)regy.Fetch(v);}
public void Init_by_kit(Xoa_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);
ListAdp deleted = ListAdp_.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.FetchAt(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_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");
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");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec_new_tab_by_paste , Xog_bnd_box_.Tid_browser_url , "mod.c+key.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");
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");
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");
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_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");
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_.XtoStr(idx + ListAdp_.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.FetchAt(i);
try {
Xog_bnd_itm cur_itm = (Xog_bnd_itm)regy.Fetch(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_brief(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.gui.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.srls.dsvs.*; import gplx.gfui.*; import gplx.xowa.cfgs2.*;
public class Xog_bnd_mgr_srl extends Dsv_wkr_base {
private Xoa_app app;
private Xog_bnd_mgr bnd_mgr;
private int uid; private byte[] box_bry, ipt_bry;
public Xog_bnd_mgr_srl(Xoa_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 = OrderedHash_.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 OrderedHash 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.Fetch(Int_obj_val.new_(uid));
int box = Xog_bnd_box_.X_by_gui_str(String_.new_utf8_(box_bry));
IptArg ipt = IptArg_.parse_or_none_(bnd_parser.X_to_gfui(String_.new_utf8_(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(Xoa_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,71 @@
/*
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.gui.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_cmd_ctg {
public Xog_cmd_ctg(int tid, String key_str) {this.tid = tid; this.key_str = key_str; this.key_bry = Bry_.new_utf8_(key_str);}
public int Tid() {return tid;} private int tid;
public String Key_str() {return key_str;} private String key_str;
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public String Name() {return name;} public Xog_cmd_ctg Name_(String v) {name = v; return this;} private String name;
public String Info() {return info;} public Xog_cmd_ctg Info_(String v) {info = v; return this;} private String info;
}
class Xog_ctg_itm_ {
public static final int
Tid__max = 15
, Tid_null = 0
, Tid_app = 1
, Tid_nav = 1
, Tid_nav_pages = 2
, Tid_font = 3
, Tid_page = 4
, Tid_edit = 5
, Tid_selection = 6
, Tid_browser = 7
, Tid_tabs = 8
, Tid_html = 9
, Tid_net = 10
, Tid_bookmarks = 11
, Tid_history = 12
, Tid_xtns = 13
, Tid_custom = 14
;
public static final Xog_cmd_ctg[] Ary = new Xog_cmd_ctg[Tid__max];
public static final Xog_cmd_ctg
Itm_null = new_(Tid_null , "xowa.null")
, Itm_app = new_(Tid_app , "xowa.app")
, Itm_nav = new_(Tid_nav , "xowa.nav")
, Itm_nav_pages = new_(Tid_nav_pages , "xowa.nav.pages")
, Itm_font = new_(Tid_font , "xowa.font")
, Itm_page = new_(Tid_page , "xowa.page")
, Itm_edit = new_(Tid_edit , "xowa.edit")
, Itm_selection = new_(Tid_selection , "xowa.selection")
, Itm_browser = new_(Tid_browser , "xowa.browser")
, Itm_tabs = new_(Tid_tabs , "xowa.tabs")
, Itm_html = new_(Tid_html , "xowa.html")
, Itm_net = new_(Tid_net , "xowa.net")
, Itm_bookmarks = new_(Tid_bookmarks , "xowa.bookmarks")
, Itm_history = new_(Tid_history , "xowa.history")
, Itm_xtns = new_(Tid_xtns , "xowa.xtns")
, Itm_custom = new_(Tid_custom , "custom")
;
private static Xog_cmd_ctg new_(int tid, String code) {
Xog_cmd_ctg rv = new Xog_cmd_ctg(tid, code);
Ary[tid] = rv;
return rv;
}
}

View File

@@ -0,0 +1,35 @@
/*
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.gui.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_cmd_itm {
public Xog_cmd_itm(String key, Xog_cmd_ctg ctg, String cmd) {
this.key = key; this.ctg = ctg; this.cmd = cmd;
this.key_bry = Bry_.new_utf8_(key);
this.uid = ++Uid_next;
}
public int Uid() {return uid;} private int uid;
public String Key() {return key;} private String key;
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public Xog_cmd_ctg Ctg() {return ctg;} private Xog_cmd_ctg ctg;
public String Cmd() {return cmd;} public Xog_cmd_itm Cmd_(String v) {cmd = v; return this;} private String cmd;
public String Name() {return name;} public Xog_cmd_itm Name_(String v) {name = v; return this;} private String name;
public String Name_or_missing() {return name == null ? "<" + name + ">" : name;}
public String Tip() {return tip;} public Xog_cmd_itm Tip_(String v) {tip = v; return this;} private String tip;
public String Tip_or_missing() {return tip == null ? "<" + tip + ">" : tip;}
private static int Uid_next = 0;
}

View File

@@ -0,0 +1,168 @@
/*
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.gui.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_cmd_itm_ {
private static final OrderedHash regy = OrderedHash_.new_(); // NOTE: must be defined at top
public static final String
Key_app_exit = new_dflt_(Xog_ctg_itm_.Tid_app , "xowa.app.exit")
, Key_nav_go_bwd = new_dflt_(Xog_ctg_itm_.Tid_nav , "xowa.nav.go_bwd")
, Key_nav_go_fwd = new_dflt_(Xog_ctg_itm_.Tid_nav , "xowa.nav.go_fwd")
, Key_nav_cfg_main = new_page_(Xog_ctg_itm_.Tid_nav , "xowa.nav.cfg.main" , "home/wiki/Help:Options")
, Key_nav_cfg_menu = new_page_(Xog_ctg_itm_.Tid_nav , "xowa.nav.cfg.menus" , "home/wiki/Help:Options/Menus")
, Key_nav_wiki_main_page = new_dflt_(Xog_ctg_itm_.Tid_nav , "xowa.nav.wiki.main_page")
, Key_nav_wiki_sandbox = new_dflt_(Xog_ctg_itm_.Tid_nav , "xowa.nav.wiki.sandbox")
, Key_nav_wiki_random = new_dflt_(Xog_ctg_itm_.Tid_nav , "xowa.nav.wiki.random")
, Key_nav_help_help = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.help" , "home/wiki/Help:Contents")
, Key_nav_help_about = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.about" , "home/wiki/Help:About")
, Key_nav_help_change_log = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.change_log" , "home/wiki/Help:Change_log")
, Key_nav_help_diagnostics = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.diagnostics" , "home/wiki/Help:Diagnostics")
, Key_nav_setup_import_from_list = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.setup.import_from_list" , "home/wiki/Help:Import/List")
, Key_nav_setup_import_from_script = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.setup.import_from_script" , "home/wiki/Help:Import/Script")
, Key_nav_setup_maintenance = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.setup.maintenance" , "home/wiki/Help:Wiki_maintenance")
, Key_nav_setup_download = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.setup.download" , "home/wiki/Help:Download")
, Key_nav_system_data_log_session = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.system_data.log_session" , "Special:XowaSystemData?type=log_session")
, Key_nav_system_data_cfg_app = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.system_data.cfg_app" , "Special:XowaSystemData?type=cfg_app")
, Key_nav_system_data_cfg_lang = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.system_data.cfg_lang" , "Special:XowaSystemData?type=cfg_lang")
, Key_nav_system_data_cfg_user = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.system_data.cfg_user" , "Special:XowaSystemData?type=cfg_user")
, Key_nav_system_data_cfg_custom = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.system_data.cfg_custom" , "Special:XowaSystemData?type=cfg_custom")
, Key_nav_system_data_usr_history = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.system_data.usr_history" , "Special:XowaSystemData?type=usr_history")
, Key_gui_font_increase = new_dflt_(Xog_ctg_itm_.Tid_font , "xowa.gui.font.increase")
, Key_gui_font_decrease = new_dflt_(Xog_ctg_itm_.Tid_font , "xowa.gui.font.decrease")
, Key_gui_font_reset = new_dflt_(Xog_ctg_itm_.Tid_font , "xowa.gui.font.reset")
, Key_gui_page_view_mode_read = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.mode_read")
, Key_gui_page_view_mode_edit = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.mode_edit")
, Key_gui_page_view_mode_html = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.mode_html")
, Key_gui_page_view_refresh = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.refresh")
, Key_gui_page_view_reload = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.reload")
, Key_gui_page_view_save_as = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.save_as")
, Key_gui_page_view_print = new_dflt_(Xog_ctg_itm_.Tid_page , "xowa.gui.page.view.print")
, Key_gui_page_selection_select_all = new_dflt_(Xog_ctg_itm_.Tid_selection , "xowa.gui.page.selection.select_all")
, Key_gui_page_selection_copy = new_dflt_(Xog_ctg_itm_.Tid_selection , "xowa.gui.page.selection.copy")
, Key_gui_page_selection_save_file_as = new_dflt_(Xog_ctg_itm_.Tid_selection , "xowa.gui.page.selection.save_file_as")
, Key_gui_edit_save = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.save")
, Key_gui_edit_save_draft = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.save_draft")
, Key_gui_edit_focus_edit_box = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.focus_edit_box")
, Key_gui_edit_preview = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.preview")
, Key_gui_edit_dbg_tmpl = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.dbg_tmpl")
, Key_gui_edit_dbg_html = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.dbg_html")
, Key_gui_edit_exec = new_dflt_(Xog_ctg_itm_.Tid_edit , "xowa.gui.page.edit.exec")
, Key_gui_browser_url_focus = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.focus")
, Key_gui_browser_url_exec = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.exec")
, Key_gui_browser_url_exec_by_paste = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.exec_by_paste")
, Key_gui_browser_url_exec_new_tab_by_paste = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.exec_new_tab_by_paste")
, Key_gui_browser_search_focus = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.search.focus")
, Key_gui_browser_search_exec = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.search.exec")
, Key_gui_browser_tabs_new_dflt__at_dflt__focus_y = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.new_dflt__at_dflt__focus_y")
, Key_gui_browser_tabs_new_link__at_dflt__focus_n = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.new_link__at_dflt__focus_n")
, Key_gui_browser_tabs_new_link__at_dflt__focus_y = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.new_link__at_dflt__focus_y")
, Key_gui_browser_tabs_new_href__at_dflt__focus_y = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.new_href__at_dflt__focus_y")
, Key_gui_browser_tabs_new_dupe__at_dflt__focus_y = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.new_dupe__at_dflt__focus_y")
, Key_gui_browser_tabs_select_bwd = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_bwd")
, Key_gui_browser_tabs_select_fwd = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_fwd")
, Key_gui_browser_tabs_select_by_idx_1 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_1")
, Key_gui_browser_tabs_select_by_idx_2 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_2")
, Key_gui_browser_tabs_select_by_idx_3 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_3")
, Key_gui_browser_tabs_select_by_idx_4 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_4")
, Key_gui_browser_tabs_select_by_idx_5 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_5")
, Key_gui_browser_tabs_select_by_idx_6 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_6")
, Key_gui_browser_tabs_select_by_idx_7 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_7")
, Key_gui_browser_tabs_select_by_idx_8 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_8")
, Key_gui_browser_tabs_select_by_idx_9 = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.select_by_idx_9")
, Key_gui_browser_tabs_move_bwd = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.move_bwd")
, Key_gui_browser_tabs_move_fwd = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.move_fwd")
, Key_gui_browser_tabs_close_cur = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.close_cur")
, Key_gui_browser_tabs_close_others = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.close_others")
, Key_gui_browser_tabs_close_to_bgn = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.close_to_bgn")
, Key_gui_browser_tabs_close_to_end = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.close_to_end")
, Key_gui_browser_tabs_close_undo = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.close_undo")
, Key_gui_browser_tabs_pin_toggle = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.pin_toggle")
, Key_gui_browser_html_focus = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.html.focus")
, Key_gui_browser_find_show = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.show")
, Key_gui_browser_find_show_by_paste = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.show_by_paste")
, Key_gui_browser_find_hide = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.hide")
, Key_gui_browser_find_exec = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.exec")
, Key_gui_browser_find_type = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.type")
, Key_gui_browser_find_find_fwd = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.find_fwd")
, Key_gui_browser_find_find_bwd = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.find_bwd")
, Key_gui_browser_find_case_toggle = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.case_toggle")
, Key_gui_browser_find_wrap_toggle = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.find.wrap_toggle")
, Key_gui_browser_prog_focus = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.prog.focus")
, Key_gui_browser_prog_log_show = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.prog_log.show")
, Key_gui_browser_info_focus = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.info.focus")
, Key_gui_browser_info_clear = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.info.clear")
, Key_gui_menus_group_file = "xowa.gui.menus.group.file"
, Key_gui_menus_group_edit = "xowa.gui.menus.group.edit"
, Key_gui_menus_group_view = "xowa.gui.menus.group.view"
, Key_gui_menus_group_history = "xowa.gui.menus.group.history"
, Key_gui_menus_group_bookmarks = "xowa.gui.menus.group.bookmarks"
, Key_gui_menus_group_tools = "xowa.gui.menus.group.tools"
, Key_gui_menus_group_tools_wikis = "xowa.gui.menus.group.tools.wikis"
, Key_gui_menus_group_help = "xowa.gui.menus.group.help"
, Key_gui_menus_group_system_data = "xowa.gui.menus.group.system_data"
, Key_gui_menus_group_tabs = "xowa.gui.menus.group.tabs"
, Key_html_tidy_toggle = new_dflt_(Xog_ctg_itm_.Tid_html , "xowa.html.tidy.toggle")
, Key_html_tidy_engine_tidy_ = new_dflt_(Xog_ctg_itm_.Tid_html , "xowa.html.tidy.engine_tidy_")
, Key_html_tidy_engine_jtidy_ = new_dflt_(Xog_ctg_itm_.Tid_html , "xowa.html.tidy.engine_jtidy_")
, Key_net_enabled = new_dflt_(Xog_ctg_itm_.Tid_net , "xowa.net.enabled")
, Key_net_enabled_n_ = new_dflt_(Xog_ctg_itm_.Tid_net , "xowa.net.enabled_n_")
, Key_net_enabled_y_ = new_dflt_(Xog_ctg_itm_.Tid_net , "xowa.net.enabled_y_")
, Key_net_enabled_x_ = new_dflt_(Xog_ctg_itm_.Tid_net , "xowa.net.enabled_x_")
, Key_usr_bookmarks_add = new_dflt_(Xog_ctg_itm_.Tid_bookmarks , "xowa.usr.bookmarks.add")
, Key_usr_bookmarks_show = new_dflt_(Xog_ctg_itm_.Tid_bookmarks , "xowa.usr.bookmarks.show")
, Key_usr_history_goto_recent = new_dflt_(Xog_ctg_itm_.Tid_history , "xowa.usr.history.goto_recent")
, Key_usr_history_show = new_page_(Xog_ctg_itm_.Tid_history , "xowa.usr.history.show" , "home/wiki/Special:XowaPageHistory")
, Key_xtns_scribunto_engine_lua_ = new_dflt_(Xog_ctg_itm_.Tid_xtns , "xowa.xtns.scribunto.engine_lua_")
, Key_xtns_scribunto_engine_luaj_ = new_dflt_(Xog_ctg_itm_.Tid_xtns , "xowa.xtns.scribunto.engine_luaj_")
;
private static String new_dflt_(int ctg, String key) {return new_text_(ctg, key, "app.api." + String_.Mid(key, 5) + ";");} // 5 to skip "xowa."
private static String new_page_(int ctg, String key, String page) {return new_text_(ctg, key, "app.api.nav.goto(\"" + page + "\");");}
private static String new_text_(int ctg, String key, String text) {
Xog_cmd_ctg ctg_itm = Xog_ctg_itm_.Ary[ctg];
regy.Add(key, new Xog_cmd_itm(key, ctg_itm, text));
return key;
}
public static int Regy_len() {return regy.Count();}
public static Xog_cmd_itm Regy_get_at(int i) {return (Xog_cmd_itm)regy.FetchAt(i);}
public static Xog_cmd_itm Regy_get_or_null(String key) {return (Xog_cmd_itm)regy.Fetch(key);}
public static void Regy_add(Xog_cmd_itm itm) {regy.Add(itm.Key(), itm);}
public static final byte[]
Msg_pre_api = Bry_.new_ascii_("api-")
, Msg_pre_ctg = Bry_.new_ascii_("api.ctg-")
, Msg_suf_name = Bry_.new_ascii_("-name")
, Msg_suf_tip = Bry_.new_ascii_("-tip")
, Msg_suf_letter = Bry_.new_ascii_("-letter")
, Msg_suf_image = Bry_.new_ascii_("-image")
;
}

View File

@@ -0,0 +1,57 @@
/*
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.gui.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.xowa.apis.xowa.*;
public class Xog_cmd_mgr {
public void Init_by_kit(Xoa_app app) {
invk_mgr.Ctor(app, this);
Load_ctg_msgs(app);
Load_cmd_msgs(app);
}
public Xog_cmd_mgr_invk Invk_mgr() {return invk_mgr;} private Xog_cmd_mgr_invk invk_mgr = new Xog_cmd_mgr_invk();
private void Load_ctg_msgs(Xoa_app app) {
Xog_cmd_ctg[] ary = Xog_ctg_itm_.Ary;
int len = ary.length;
Xol_lang lang = app.User().Lang();
for (int i = 0; i < len; i++) {
Xog_cmd_ctg itm = ary[i];
itm.Name_(Pf_msg_mgr.Get_msg_val_gui_or_null(lang, Xog_cmd_itm_.Msg_pre_ctg, itm.Key_bry(), Xog_cmd_itm_.Msg_suf_name));
}
}
private void Load_cmd_msgs(Xoa_app app) {
int len = this.Len();
Xol_lang lang = app.User().Lang();
for (int i = 0; i < len; i++) {
Xog_cmd_itm itm = this.Get_at(i);
itm.Name_(Pf_msg_mgr.Get_msg_val_gui_or_null(lang, Xog_cmd_itm_.Msg_pre_api, itm.Key_bry(), Xog_cmd_itm_.Msg_suf_name));
itm.Tip_(Pf_msg_mgr.Get_msg_val_gui_or_null(lang, Xog_cmd_itm_.Msg_pre_api, itm.Key_bry(), Xog_cmd_itm_.Msg_suf_tip));
}
}
public int Len() {return Xog_cmd_itm_.Regy_len();}
public Xog_cmd_itm Get_at(int i) {return Xog_cmd_itm_.Regy_get_at(i);}
public Xog_cmd_itm Get_or_null(String key) {return Xog_cmd_itm_.Regy_get_or_null(key);}
public Xog_cmd_itm Get_or_make(String key) {
Xog_cmd_itm rv = Xog_cmd_itm_.Regy_get_or_null(key);
if (rv == null) {
rv = new Xog_cmd_itm(key, Xog_ctg_itm_.Itm_custom, null); // pass null for cmd; will be filled in
Xog_cmd_itm_.Regy_add(rv);
}
return rv;
}
// public Xog_cmd_regy Regy() {return regy;} private Xog_cmd_regy regy = new Xog_cmd_regy();
}

View File

@@ -0,0 +1,27 @@
/*
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.gui.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_cmd_mgr_invk implements GfoInvkAble {
private Xoa_app app; private Xog_cmd_mgr cmd_mgr;
public void Ctor(Xoa_app app, Xog_cmd_mgr cmd_mgr) {this.app = app; this.cmd_mgr = cmd_mgr;}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
Xog_cmd_itm cmd_itm = cmd_mgr.Get_or_null(k);
if (cmd_itm == null) return GfoInvkAble_.Rv_unhandled;
return app.Gfs_mgr().Run_str(cmd_itm.Cmd());
}
}

View File

@@ -0,0 +1,52 @@
/*
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.gui.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_history_itm {
public Xog_history_itm(Xoa_page page) {
this.wiki_key = page.Wiki().Domain_bry();
this.page_key = page.Ttl().Full_url(); // get page_name only (no anchor; no query args)
this.anch_key = page.Url().Anchor_bry();
this.qarg_key = page.Url().Args_all_as_bry();
this.redirect_force = page.Url().Redirect_force() ? Bool_.Y_bry : Bool_.N_bry;
this.key = Xog_history_itm.Build_key(wiki_key, page_key, anch_key, qarg_key, redirect_force);
this.html_doc_pos = page.Html_data().Bmk_pos();
if (this.html_doc_pos == null)
this.html_doc_pos = Html_doc_pos_toc; // never allow null doc_pos; set to top
}
public byte[] Key() {return key;} private byte[] key;
public byte[] Wiki_key() {return wiki_key;} private byte[] wiki_key;
public byte[] Page_key() {return page_key;} private byte[] page_key;
public byte[] Anch_key() {return anch_key;} private byte[] anch_key;
public byte[] Qarg_key() {return qarg_key;} private byte[] qarg_key;
public byte[] Redirect_force() {return redirect_force;} private byte[] redirect_force;
public String Html_doc_pos() {return html_doc_pos;} private String html_doc_pos;
public void Html_doc_pos_(String v) {html_doc_pos = v;}
public boolean Eq_except_bmk(Xog_history_itm comp) {
return Bry_.Eq(wiki_key, comp.Wiki_key())
&& Bry_.Eq(page_key, comp.Page_key())
&& Bry_.Eq(anch_key, comp.Anch_key())
&& Bry_.Eq(qarg_key, comp.Qarg_key())
&& Bry_.Eq(redirect_force, comp.Redirect_force())
;
}
public static byte[] Build_key(byte[] wiki_key, byte[] page_key, byte[] anch_key, byte[] qarg_key, byte[] redirect_force) {
return Bry_.Add_w_dlm(Byte_ascii.Pipe, wiki_key, page_key, anch_key, qarg_key, redirect_force);
}
public static final String Html_doc_pos_toc = "top";
public static final Xog_history_itm Null = new Xog_history_itm(); private Xog_history_itm() {}
}

View File

@@ -0,0 +1,53 @@
/*
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.gui.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_history_mgr {
private OrderedHash hash = OrderedHash_.new_bry_();
private Xog_history_stack itm_stack = new Xog_history_stack();
public int Count() {return hash.Count();}
public void Add(Xoa_page page) {
itm_stack.Add(page);
byte[] page_key = Build_page_key(page);
if (!hash.Has(page_key))
hash.Add(page_key, page);
}
public void Update_html_doc_pos(Xoa_page page, byte history_nav_type) {
itm_stack.Update_html_doc_pos(page, history_nav_type);
}
public Xoa_page Cur_page(Xow_wiki wiki) {return Get_or_fetch(wiki, itm_stack.Cur_itm());}
public Xoa_page Go_bwd(Xow_wiki wiki) {return Go_by_dir(wiki, Bool_.N);}
public Xoa_page Go_fwd(Xow_wiki wiki) {return Go_by_dir(wiki, Bool_.Y);}
public Xoa_page Go_by_dir(Xow_wiki wiki, boolean fwd) {
Xog_history_itm itm = fwd ? itm_stack.Go_fwd() : itm_stack.Go_bwd();
if (itm == Xog_history_itm.Null) return Xoa_page.Empty;
Xoa_page rv = Get_or_fetch(wiki, itm);
byte[] anch_key = itm.Anch_key();
rv.Url().Anchor_bry_(anch_key); // must override anchor as it may be different for cached page
rv.Html_data().Bmk_pos_(itm.Html_doc_pos());
return rv;
}
private Xoa_page Get_or_fetch(Xow_wiki wiki, Xog_history_itm itm) {
byte[] page_key = Build_page_key(itm.Wiki_key(), itm.Page_key(), itm.Qarg_key());
Xoa_page rv = (Xoa_page)hash.Fetch(page_key);
if (rv != null) return rv;
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, itm.Page_key());
return wiki.Data_mgr().Get_page(ttl, false);
}
private static byte[] Build_page_key(Xoa_page page) {return Build_page_key(page.Wiki().Domain_bry(), page.Ttl().Full_url(), page.Url().Args_all_as_bry());}
private static byte[] Build_page_key(byte[] wiki_key, byte[] page_key, byte[] args_key) {return Bry_.Add_w_dlm(Byte_ascii.Pipe, wiki_key, page_key, args_key);}
}

View File

@@ -0,0 +1,72 @@
/*
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.gui.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_history_stack {
private ListAdp list = ListAdp_.new_();
public int Stack_pos() {return list_pos;} private int list_pos = 0;
public int Count() {return list.Count();}
public void Clear() {list.Clear(); list_pos = 0;}
public Xog_history_itm Cur_itm() {return list.Count() == 0 ? Xog_history_itm.Null : (Xog_history_itm)list.FetchAt(list_pos);}
public Xog_history_itm Add(Xoa_page page) {
Xog_history_itm new_itm = new Xog_history_itm(page);
Xog_history_itm cur_itm = this.Cur_itm();
if ( cur_itm != Xog_history_itm.Null
&& cur_itm.Eq_except_bmk(new_itm)
)
return Xog_history_itm.Null; // do not add if last itm is same;
Del_all_from(list_pos + 1);
list.Add(new_itm);
list_pos = list.Count() - 1;
return new_itm;
}
public void Update_html_doc_pos(Xoa_page page, byte history_nav_type) {
Xog_history_itm itm = Get_recent(page, history_nav_type);
if (itm != null) itm.Html_doc_pos_(page.Html_data().Bmk_pos());
}
private Xog_history_itm Get_recent(Xoa_page page, byte history_nav_type) {
int pos = -1;
switch (history_nav_type) {
case Xog_history_stack.Nav_fwd: pos = list_pos - 1; break;
case Xog_history_stack.Nav_bwd: pos = list_pos + 1; break;
case Xog_history_stack.Nav_by_anchor: pos = list_pos; break;
}
if (pos < 0 || pos >= list.Count()) return null;
Xog_history_itm recent = (Xog_history_itm)list.FetchAt(pos);
Xog_history_itm page_itm = new Xog_history_itm(page);
return page_itm.Eq_except_bmk(recent) ? recent : null; // check that recent page actually matches current; DATE:2014-05-10
}
public Xog_history_itm Go_bwd() {
if (list.Count() == 0) return Xog_history_itm.Null;
--list_pos;
if (list_pos < 0) list_pos = 0;
return this.Cur_itm();
}
public Xog_history_itm Go_fwd() {
int list_count = list.Count();
if (list_count == 0) return Xog_history_itm.Null;
++list_pos;
if (list_pos == list_count) list_pos = list_count - 1;
return this.Cur_itm();
}
private void Del_all_from(int from) {
int list_count = list.Count();
if (from <= list_count - 1)
list.Del_range(from, list_count - 1);
}
public static final byte Nav_fwd = 1, Nav_bwd = 2, Nav_by_anchor = 3;
}

View File

@@ -0,0 +1,87 @@
/*
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.gui.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import org.junit.*;
public class Xog_history_stack_tst {
@Before public void init() {fxt.Clear();} private Xog_history_stack_fxt fxt = new Xog_history_stack_fxt();
@Test public void Init() {fxt.Test_cur(null);}
@Test public void Add_1() {fxt.Exec_add_many("A").Test_cur("A").Test_len(1).Test_pos(0);}
@Test public void Add_same() {fxt.Exec_add_many("A", "A").Test_cur("A").Test_len(1).Test_pos(0);}
@Test public void Add_3() {fxt.Exec_add_many("A", "B", "C").Test_cur("C").Test_len(3).Test_pos(2);}
@Test public void Add_3_bwd() {fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Test_cur("B").Test_pos(1);}
@Test public void Add_3_bwd_fwd() {fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Exec_go_fwd().Test_cur("C").Test_pos(2);}
@Test public void Add_3_bwd_add() {fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Exec_add_many("D").Test_len(3).Test_cur("D").Test_pos(2);}
@Test public void Add_3_bwd_bwd_add() {fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Exec_go_bwd().Exec_add_many("D").Test_len(2).Test_cur("D").Test_pos(1);}
@Test public void Add_dif_ns() {fxt.Exec_add_many("A", "Help:A").Test_cur("Help:A");} // PURPOSE.fix: page_stack was only differtiating by Page_db, not Full; EX: Unicode -> Category:Unicode
@Test public void Add_qargs() {// PURPOSE.fix: page_stack was only differtiating by qtxt args
fxt .Exec_add_one("Special:AllPages", "?from=A")
.Exec_add_one("Special:AllPages", "?from=B")
.Exec_add_many("B")
.Exec_go_bwd()
.Test_cur("Special:AllPages")
.Test_cur_qargs("?from=B")
;
}
}
class Xog_history_stack_fxt {
public Xog_history_stack_fxt Clear() {
stack.Clear();
if (app == null) {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
url_parser = app.Url_parser();
}
return this;
} private Xoa_app app; private Xow_wiki wiki; private Xog_history_stack stack = new Xog_history_stack(); private Xoa_url_parser url_parser;
public Xog_history_stack_fxt Test_cur(String expd) {
Xog_history_itm page = stack.Cur_itm();
String actl = page == null ? null : String_.new_utf8_(page.Page_key());
Tfds.Eq(expd, actl, "cur");
return this;
}
public Xog_history_stack_fxt Test_cur_qargs(String expd) {
Xog_history_itm page = stack.Cur_itm();
String actl = page == null ? null : String_.new_utf8_(page.Qarg_key());
Tfds.Eq(expd, actl, "cur_qargs");
return this;
}
public Xog_history_stack_fxt Exec_go_bwd() {stack.Go_bwd(); return this;}
public Xog_history_stack_fxt Exec_go_fwd() {stack.Go_fwd(); return this;}
public Xog_history_stack_fxt Exec_add_many(String... ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
String ttl = ary[i];
Exec_add_one(ttl, null);
}
return this;
}
public Xog_history_stack_fxt Exec_add_one(String ttl_str, String arg_str) {
byte[] ttl_bry = Bry_.new_utf8_(ttl_str);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
Xoa_page page = Xoa_page.test_(wiki, ttl);
byte[] url_bry = ttl_bry;
if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_utf8_(arg_str));
Xoa_url url = new Xoa_url();
url_parser.Parse(url, url_bry);
page.Url_(url); // set url b/c history_mgr.Add uses url
stack.Add(page);
return this;
}
public Xog_history_stack_fxt Test_pos(int expd) {Tfds.Eq(expd, stack.Stack_pos(), "pos"); return this;}
public Xog_history_stack_fxt Test_len(int expd) {Tfds.Eq(expd, stack.Count(), "len"); return this;}
}

View File

@@ -0,0 +1,49 @@
/*
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.gui.menus; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.xowa.gui.menus.dom.*;
public class Xog_menu_mgr implements GfoInvkAble {
public Xog_menu_mgr(Xoa_gui_mgr gui_mgr) {
menu_bldr = new Xog_mnu_bldr();
regy = new Xog_mnu_regy(gui_mgr);
popup_mnu_mgr = new Xog_popup_mnu_mgr(gui_mgr, this);
window_mnu_mgr = new Xog_window_mnu_mgr(gui_mgr, this);
}
public Xog_mnu_regy Regy() {return regy;} private Xog_mnu_regy regy;
public Xog_popup_mnu_mgr Popup() {return popup_mnu_mgr;} private Xog_popup_mnu_mgr popup_mnu_mgr;
public Xog_window_mnu_mgr Window() {return window_mnu_mgr;} private Xog_window_mnu_mgr window_mnu_mgr;
public Xog_mnu_bldr Menu_bldr() {return menu_bldr;} private Xog_mnu_bldr menu_bldr;
public void Init_by_app(Xoa_app app) {
this.app = app;
regy.Init_by_app(app);
} private Xoa_app app;
public void Init_by_kit() {
popup_mnu_mgr.Init_by_kit();
window_mnu_mgr.Init_by_kit();
Lang_changed(app.User().Lang());
}
public void Lang_changed(Xol_lang lang) {
window_mnu_mgr.Lang_changed(lang);
popup_mnu_mgr.Lang_changed(lang);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_contexts)) return popup_mnu_mgr;
else if (ctx.Match(k, Invk_windows)) return window_mnu_mgr;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_contexts = "contexts", Invk_windows = "windows";
}

View File

@@ -0,0 +1,245 @@
/*
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.gui.menus; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.xowa.gui.cmds.*;
class Xog_menu_mgr_src {
public static final String Browser_win
= Xog_menu_bldr._
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_file)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_cur)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_save_as)
// . Add_btn(Xog_cmd_itm_.Key_gui_page_view_print)
. Add_btn(Xog_cmd_itm_.Key_app_exit)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_edit)
. Add_btn(Xog_cmd_itm_.Key_gui_page_selection_select_all)
. Add_btn(Xog_cmd_itm_.Key_gui_page_selection_copy)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_find_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_view)
. Add_btn(Xog_cmd_itm_.Key_gui_font_increase)
. Add_btn(Xog_cmd_itm_.Key_gui_font_decrease)
. Add_btn(Xog_cmd_itm_.Key_gui_font_reset)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_mode_read)
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_mode_edit)
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_mode_html)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_reload)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_prog_log_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_history)
. Add_btn(Xog_cmd_itm_.Key_nav_go_bwd)
. Add_btn(Xog_cmd_itm_.Key_nav_go_fwd)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_usr_history_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_bookmarks)
. Add_btn(Xog_cmd_itm_.Key_nav_wiki_main_page)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_usr_bookmarks_add)
. Add_btn(Xog_cmd_itm_.Key_usr_bookmarks_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_tools)
. Add_btn(Xog_cmd_itm_.Key_nav_cfg_main)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_nav_setup_import_from_list)
. Add_btn(Xog_cmd_itm_.Key_nav_setup_import_from_script)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_nav_setup_maintenance)
. Add_btn(Xog_cmd_itm_.Key_nav_setup_download)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_change_log)
. Add_btn(Xog_cmd_itm_.Key_nav_help_diagnostics)
. Add_btn(Xog_cmd_itm_.Key_nav_cfg_menu)
. Add_spr()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_system_data)
. Add_btn(Xog_cmd_itm_.Key_nav_system_data_log_session)
. Add_btn(Xog_cmd_itm_.Key_nav_system_data_cfg_app)
. Add_btn(Xog_cmd_itm_.Key_nav_system_data_cfg_lang)
. Add_btn(Xog_cmd_itm_.Key_nav_system_data_cfg_user)
. Add_btn(Xog_cmd_itm_.Key_nav_system_data_cfg_custom)
. Add_btn(Xog_cmd_itm_.Key_nav_system_data_usr_history)
. Add_grp_end()
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_nav_help_about)
. Add_grp_end()
. Gen_str();
public static final String Html_page
= Xog_menu_bldr._
. Add_btn(Xog_cmd_itm_.Key_nav_go_bwd)
. Add_btn(Xog_cmd_itm_.Key_nav_go_fwd)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_reload)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_selection_select_all)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_font_increase)
. Add_btn(Xog_cmd_itm_.Key_gui_font_decrease)
. Add_btn(Xog_cmd_itm_.Key_gui_font_reset)
. Add_spr()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_file)
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_save_as)
// . Add_btn(Xog_cmd_itm_.Key_gui_page_view_print)
. Add_btn(Xog_cmd_itm_.Key_app_exit)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_tabs)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_dupe__at_dflt__focus_y)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_cur)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_select_fwd)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_select_bwd)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_move_fwd)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_move_bwd)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_others)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_to_bgn)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_to_end)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_undo)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_view)
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_mode_read)
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_mode_edit)
. Add_btn(Xog_cmd_itm_.Key_gui_page_view_mode_html)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_prog_log_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_history)
. Add_btn(Xog_cmd_itm_.Key_usr_history_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_bookmarks)
. Add_btn(Xog_cmd_itm_.Key_nav_wiki_main_page)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_usr_bookmarks_add)
. Add_btn(Xog_cmd_itm_.Key_usr_bookmarks_show)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_tools)
. Add_btn(Xog_cmd_itm_.Key_nav_cfg_main)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_nav_setup_import_from_list)
. Add_btn(Xog_cmd_itm_.Key_nav_setup_import_from_script)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_nav_setup_maintenance)
. Add_btn(Xog_cmd_itm_.Key_nav_setup_download)
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_change_log)
. Add_btn(Xog_cmd_itm_.Key_nav_help_diagnostics)
. Add_btn(Xog_cmd_itm_.Key_nav_cfg_menu)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_nav_help_about)
. Add_grp_end()
. Gen_str();
public static final String Html_link
= Xog_menu_bldr._
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_n)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_y)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_selection_copy)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_find_show_by_paste)
. Gen_str();
public static final String Html_file
= Xog_menu_bldr._
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_n)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_y)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_page_selection_save_file_as)
. Gen_str();
public static final String Tabs_btns
= Xog_menu_bldr._
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_new_dupe__at_dflt__focus_y)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_cur)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_select_fwd)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_select_bwd)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_move_fwd)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_move_bwd)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_others)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_to_bgn)
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_to_end)
. Add_spr()
. Add_btn(Xog_cmd_itm_.Key_gui_browser_tabs_close_undo)
. Gen_str();
public static final String Prog
= Xog_menu_bldr._
. Add_btn(Xog_cmd_itm_.Key_gui_browser_prog_log_show)
. Gen_str();
public static final String Info = String_.Concat_lines_nl
( ""
);
}
class Xog_menu_bldr {
private int indent = 0;
private Bry_bfr bfr = Bry_bfr.reset_(0);
public String Gen_str() {return bfr.XtoStrAndClear();}
private Xog_menu_bldr Indent_add() {indent += 2; return this;}
private Xog_menu_bldr Indent_del() {indent -= 2; return this;}
private void Indent() {
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent);
}
public Xog_menu_bldr Add_spr() {
Indent();
bfr.Add(Const_spr);
return this;
}
public Xog_menu_bldr Add_grp_bgn(String key) {
Indent();
bfr.Add(Const_itm_grp_bgn_lhs);
bfr.Add_str(key);
bfr.Add(Const_itm_grp_bgn_rhs);
Indent_add();
return this;
}
public Xog_menu_bldr Add_grp_end() {
Indent_del();
Indent();
bfr.Add(Const_itm_grp_end);
return this;
}
public Xog_menu_bldr Add_btn(String key) {
Indent();
bfr.Add(Const_itm_btn_bgn_lhs);
bfr.Add_str(key);
bfr.Add(Const_itm_btn_bgn_rhs);
return this;
}
private static final byte[]
Const_spr = Bry_.new_ascii_("add_spr;\n")
, Const_itm_btn_bgn_lhs = Bry_.new_ascii_("add_btn_default('")
, Const_itm_btn_bgn_rhs = Bry_.new_ascii_("');\n")
, Const_itm_grp_bgn_lhs = Bry_.new_ascii_("add_grp_default('")
, Const_itm_grp_bgn_rhs = Bry_.new_ascii_("') {\n")
, Const_itm_grp_end = Bry_.new_ascii_("}\n")
;
public static final Xog_menu_bldr _ = new Xog_menu_bldr(); Xog_menu_bldr() {}
}

View File

@@ -0,0 +1,68 @@
/*
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.gui.menus; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.xowa.gui.menus.dom.*;
public class Xog_popup_mnu_mgr implements GfoInvkAble {
private OrderedHash hash = OrderedHash_.new_();
private Xoa_gui_mgr gui_mgr;
private Xog_mnu_grp[] mnus = new Xog_mnu_grp[6];
public Xog_popup_mnu_mgr(Xoa_gui_mgr gui_mgr, Xog_menu_mgr menu_mgr) {
this.gui_mgr = gui_mgr;
html_page = Ctor(0, Root_key_html_page, Xog_menu_mgr_src.Html_page); // NOTE: default menu; always build first; NOTE: set default here (fires before cfg)
html_link = Ctor(1, Root_key_html_link, Xog_menu_mgr_src.Html_link);
html_file = Ctor(2, Root_key_html_file, Xog_menu_mgr_src.Html_file);
tabs_btns = Ctor(3, Root_key_tabs_btns, Xog_menu_mgr_src.Tabs_btns);
prog = Ctor(4, Root_key_prog, Xog_menu_mgr_src.Prog);
info = Ctor(5, Root_key_info, Xog_menu_mgr_src.Info);
}
public Xog_mnu_grp Tabs_btns() {return tabs_btns;} private Xog_mnu_grp tabs_btns;
public Xog_mnu_grp Html_page() {return html_page;} private Xog_mnu_grp html_page;
public Xog_mnu_grp Html_link() {return html_link;} private Xog_mnu_grp html_link;
public Xog_mnu_grp Html_file() {return html_file;} private Xog_mnu_grp html_file;
public Xog_mnu_grp Prog() {return prog;} private Xog_mnu_grp prog;
public Xog_mnu_grp Info() {return info;} private Xog_mnu_grp info;
public void Init_by_kit() {
for (int i = 0; i < mnus.length; i++)
mnus[i].Source_exec(gui_mgr.App().Gfs_mgr()); // NOTE: build menu now; NOTE: do not set default here, or else will override user setting
}
public void Lang_changed(Xol_lang lang) {
for (int i = 0; i < mnus.length; i++)
Xog_mnu_base.Update_grp_by_lang(gui_mgr.Menu_mgr().Menu_bldr(), lang, mnus[i]);
}
public Xog_mnu_grp Get_or_new(String key) {
Xog_mnu_grp rv = (Xog_mnu_grp)hash.Fetch(key);
if (rv == null) {
rv = new Xog_mnu_grp(gui_mgr, true, key);
hash.Add(key, rv);
}
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_new(m.ReadStr("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
public static final String Root_key_tabs_btns = "browser.tabs.btns"
, Root_key_html_page = "html_box", Root_key_html_link = "browser.html.link", Root_key_html_file = "browser.html.file"
, Root_key_prog = "browser.prog", Root_key_info = "browser.info"
;
private Xog_mnu_grp Ctor(int i, String key, String src) {
Xog_mnu_grp rv = Get_or_new(key).Source_default_(src);
mnus[i] = rv;
return rv;
}
}

View File

@@ -0,0 +1,46 @@
/*
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.gui.menus; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.xowa.gui.menus.dom.*;
public class Xog_window_mnu_mgr implements GfoInvkAble {
private OrderedHash hash = OrderedHash_.new_();
public Xog_mnu_grp Browser() {return browser;} private Xog_mnu_grp browser;
public Xog_window_mnu_mgr(Xoa_gui_mgr gui_mgr, Xog_menu_mgr menu_mgr) {
this.gui_mgr = gui_mgr;
browser = Get_or_new(Root_key_browser_win).Source_default_(Xog_menu_mgr_src.Browser_win); // NOTE: set default here (fires before cfg)
} private Xoa_gui_mgr gui_mgr;
public void Init_by_kit() {
browser.Source_exec(gui_mgr.App().Gfs_mgr()); // NOTE: build menu now; NOTE: do not set default here, or else will override user setting
}
public Xog_mnu_grp Get_or_new(String key) {
Xog_mnu_grp rv = (Xog_mnu_grp)hash.Fetch(key);
if (rv == null) {
rv = new Xog_mnu_grp(gui_mgr, false, key);
hash.Add(key, rv);
}
return rv;
}
public void Lang_changed(Xol_lang lang) {
Xog_mnu_base.Update_grp_by_lang(gui_mgr.Menu_mgr().Menu_bldr(), lang, browser);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_new(m.ReadStr("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
public static final String Root_key_browser_win = "main_win";
}

View File

@@ -0,0 +1,117 @@
/*
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.gui.menus.dom; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.menus.*;
import gplx.gfui.*; import gplx.xowa.gui.cmds.*;
public abstract class Xog_mnu_base implements GfoInvkAble {
private ListAdp list = ListAdp_.new_();
public Xog_mnu_base() {evt_mgr = new Xog_mnu_evt_mgr(this);}
public Xog_mnu_evt_mgr Evt_mgr() {return evt_mgr;} private Xog_mnu_evt_mgr evt_mgr;
public void Evt_mgr_(Xog_mnu_evt_mgr v) {this.evt_mgr = v;}
public Xoa_gui_mgr Gui_mgr() {return gui_mgr;} private Xoa_gui_mgr gui_mgr;
public abstract boolean Tid_is_app_menu_grp();
public void Ctor(Xoa_gui_mgr gui_mgr) {this.gui_mgr = gui_mgr;}
public void Clear() {
int len = list.Count();
for (int i = 0; i < len; i++) {
Xog_mnu_itm itm = (Xog_mnu_itm)list.FetchAt(i);
itm.Clear();
}
list.Clear();
}
public int Len() {return list.Count();}
public Xog_mnu_itm Get_at(int i) {return (Xog_mnu_itm)list.FetchAt(i);}
public Xog_mnu_itm Add_btn_default(String key) {return Add_itm_default(Xog_mnu_itm.Tid_btn, key);}
public Xog_mnu_itm Add_chk_default(String key) {return Add_itm_default(Xog_mnu_itm.Tid_chk, key);}
public Xog_mnu_itm Add_rdo_default(String key) {return Add_itm_default(Xog_mnu_itm.Tid_rdo, key);}
public Xog_mnu_itm Add_grp_default(String key) {return Add_itm_default(Xog_mnu_itm.Tid_grp, key);}
private Xog_mnu_itm Add_itm_default(byte tid, String key) {
Xog_mnu_itm itm = gui_mgr.Menu_mgr().Regy().Get_or_make(key);
itm.Tid_(tid);
list.Add(itm);
return itm;
}
public Xog_mnu_itm Add_btn(String key, String text, String shortcut, String img, String cmd) {
Xog_mnu_itm rv = Add_itm(Xog_mnu_itm.Tid_btn, key, text, shortcut, img);
rv.Cmd_(cmd);
return rv;
}
public Xog_mnu_itm Add_chk(String key, String text, String shortcut, String img, String cmd) {
Xog_mnu_itm rv = Add_itm(Xog_mnu_itm.Tid_chk, key, text, shortcut, img);
rv.Cmd_(cmd);
return rv;
}
public Xog_mnu_itm Add_rdo(String key, String text, String shortcut, String img, String cmd) {
Xog_mnu_itm rv = Add_itm(Xog_mnu_itm.Tid_rdo, key, text, shortcut, img);
rv.Cmd_(cmd);
return rv;
}
public Xog_mnu_itm Add_grp(String key, String text, String shortcut, String img) {return Add_itm(Xog_mnu_itm.Tid_grp, key, text, shortcut, img);}
private Xog_mnu_itm Add_itm(byte tid, String key, String text, String shortcut, String img) {
Xog_mnu_itm itm = gui_mgr.Menu_mgr().Regy().Get_or_make(key);
itm.Tid_(tid);
list.Add(itm);
itm.Init_by_custom(text, shortcut, img);
return itm;
}
public Xog_mnu_itm Add_spr() {
String key = "xowa.spr" + Int_.XtoStr(list.Count());
Xog_mnu_itm rv = new Xog_mnu_itm(gui_mgr, key).Tid_(Xog_mnu_itm.Tid_spr);
list.Add(rv);
return rv;
}
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_clear)) this.Clear();
// else if (ctx.Match(k, Invk_add)) return Add_itm_default(Xog_mnu_itm.Tid_nil, m.ReadStr("v"));
else if (ctx.Match(k, Invk_add_spr)) return Add_spr();
else if (ctx.Match(k, Invk_add_grp_default)) return Add_grp_default(m.ReadStr("v"));
else if (ctx.Match(k, Invk_add_grp)) return Add_grp(m.ReadStr("key"), m.ReadStr("text"), m.ReadStr("shortcut"), m.ReadStrOr("img", ""));
else if (ctx.Match(k, Invk_add_btn_default)) return Add_btn_default(m.ReadStr("v"));
else if (ctx.Match(k, Invk_add_btn)) return Add_btn(m.ReadStr("key"), m.ReadStr("text"), m.ReadStr("shortcut"), m.ReadStr("img"), m.ReadStr("cmd"));
else if (ctx.Match(k, Invk_add_chk_default)) return Add_chk_default(m.ReadStr("v"));
else if (ctx.Match(k, Invk_add_chk)) return Add_chk(m.ReadStr("key"), m.ReadStr("text"), m.ReadStr("shortcut"), m.ReadStr("img"), m.ReadStr("cmd"));
else if (ctx.Match(k, Invk_add_rdo_default)) return Add_rdo_default(m.ReadStr("v"));
else if (ctx.Match(k, Invk_add_rdo)) return Add_rdo(m.ReadStr("key"), m.ReadStr("text"), m.ReadStr("shortcut"), m.ReadStr("img"), m.ReadStr("cmd"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_clear = "clear"
, Invk_add_spr = "add_spr"
, Invk_add_grp_default = "add_grp_default", Invk_add_grp = "add_grp"
, Invk_add_btn_default = "add_btn_default", Invk_add_btn = "add_btn"
, Invk_add_chk_default = "add_chk_default", Invk_add_chk = "add_chk"
, Invk_add_rdo_default = "add_rdo_default", Invk_add_rdo = "add_rdo"
;
public static void Update_grp_by_lang(Xog_mnu_bldr bldr, Xol_lang lang, Xog_mnu_base grp) {
int len = grp.Len();
for (int i = 0; i < len; i++) {
Xog_mnu_itm itm = grp.Get_at(i);
itm.Init_by_lang(lang);
if (itm.Under_gui() != null) {
itm.Under_gui().Text_(itm.Gui_text());
ImageAdp img = grp.Tid_is_app_menu_grp()
? ImageAdp_.Null // set image to null if window menu grp
: bldr.Get_img(itm.Img_nest())
;
itm.Under_gui().Img_(img);
}
if (itm.Tid() == Xog_mnu_itm.Tid_grp)
Update_grp_by_lang(bldr, lang, itm);
}
}
}

View File

@@ -0,0 +1,84 @@
/*
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.gui.menus.dom; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.menus.*;
import gplx.gfui.*; import gplx.xowa.gui.cmds.*;
public class Xog_mnu_bldr {
private Xoa_app app; private Gfui_kit kit; private Io_url img_dir;
public void Init_by_kit(Xoa_app app, Gfui_kit kit, Io_url img_dir) {
this.app = app; this.kit = kit; this.img_dir = img_dir;
}
public void Build(Gfui_mnu_grp grp_gui, Xog_mnu_grp grp_dom) {
if (grp_gui == null) return; // NOTE: hackish, ignore call from user.gfs b/c it fires before kit is inited; note that Xog_popup_mnu_mgr will call html_box's context menu explicitly
grp_gui.Itms_clear();
Build_owner(grp_gui, grp_dom);
}
private void Build_owner(Gfui_mnu_grp grp_gui, Xog_mnu_base grp_dom) {
int len = grp_dom.Len();
for (int i = 0; i < len; i++) {
Xog_mnu_itm sub_dom = grp_dom.Get_at(i);
Gfui_mnu_itm sub_gui = null;
String sub_text = sub_dom.Name(), sub_shortcut = sub_dom.Shortcut();
switch (sub_dom.Tid()) {
case Xog_mnu_itm.Tid_spr: sub_gui = grp_gui.Itms_add_separator(); break;
case Xog_mnu_itm.Tid_btn: sub_gui = Add_btn(grp_gui, sub_dom, sub_text, sub_shortcut); break;
case Xog_mnu_itm.Tid_chk: sub_gui = Add_chk(grp_gui, sub_dom, sub_text, sub_shortcut); break;
case Xog_mnu_itm.Tid_rdo: sub_gui = Add_rdo(grp_gui, sub_dom, sub_text, sub_shortcut); break;
case Xog_mnu_itm.Tid_grp: {
Gfui_mnu_grp sub_gui_grp = grp_gui.Itms_add_grp(sub_dom.Gui_text(), Get_img(sub_dom.Img_nest()));
Build_owner(sub_gui_grp, (Xog_mnu_base)sub_dom);
sub_gui = sub_gui_grp;
break;
}
default: throw Err_.unhandled(sub_dom.Tid());
}
sub_dom.Under_gui_(sub_gui);
}
}
public ImageAdp Get_img(String[] img_nest) {
Io_url img_url = img_nest.length == 0 ? Io_url_.Null : img_dir.GenSubFil_nest(img_nest);
return Io_mgr._.ExistsFil(img_url) ? kit.New_img_load(img_url) : ImageAdp_null._; // NOTE: must check if file exists else swt exception; NOTE: must use ImageAdp_null._, not ImageAdp_.Null, else error in non-X11 environments
}
private Gfui_mnu_itm Add_btn(Gfui_mnu_grp owner_gui, Xog_mnu_itm sub, String sub_text, String sub_shortcut) {
String cmd_text = "app.api.exec('" + sub.Key() + "');";
GfoMsg msg = app.Gfs_mgr().Parse_root_msg(cmd_text);
ImageAdp img = Get_img(sub.Img_nest());
return owner_gui.Itms_add_btn_msg(sub.Gui_text(), img, app, app.Gfs_mgr(), msg);
}
private Gfui_mnu_itm Add_chk(Gfui_mnu_grp owner_gui, Xog_mnu_itm sub, String sub_text, String sub_shortcut) {
ImageAdp img = Get_img(sub.Img_nest());
GfoMsg msg_n = app.Gfs_mgr().Parse_root_msg("app.api.exec('" + sub.Key() + "n_');");
GfoMsg msg_y = app.Gfs_mgr().Parse_root_msg("app.api.exec('" + sub.Key() + "y_');");
Gfui_mnu_itm mnu_itm = owner_gui.Itms_add_chk_msg(sub.Gui_text(), img, app, app.Gfs_mgr(), msg_n, msg_y);
sub.Evt_mgr().Sub(mnu_itm);
Xog_cmd_itm cmd = app.Gui_mgr().Cmd_mgr().Get_or_null(sub.Key());
boolean v = Bool_.cast_(app.Gfs_mgr().Run_str_for(app, cmd.Cmd()));
mnu_itm.Selected_(v);
return mnu_itm;
}
// private void Add_chk(String key, String text, String shortcut, String img) {
// Xog_mnu_itm rv = Add_itm(Xog_mnu_itm.Tid_chk, key, text, shortcut, img);
// Xog_cmd_itm cmd = gui_mgr.Cmd_mgr().Regy().Get_or_null(key); if (cmd == null) throw Err_.new_("unknown cmd; key={0}", key);
// GfoEvObj pub = gui_mgr.App().Gfs_mgr().Get_owner_as_event_obj(cmd.Cmd());
// GfoEvMgr_.SubSame(pub, Xog_mnu_evt_mgr.Evt_selected_changed, rv.Evt_mgr());
// }
private Gfui_mnu_itm Add_rdo(Gfui_mnu_grp owner_gui, Xog_mnu_itm sub, String sub_text, String sub_shortcut) {
ImageAdp img = Get_img(sub.Img_nest());
GfoMsg msg = app.Gfs_mgr().Parse_root_msg("app.api.exec('" + sub.Key() + "');");
return owner_gui.Itms_add_rdo_msg(sub.Gui_text(), img, app, app.Gfs_mgr(), msg);
}
}

View File

@@ -0,0 +1,38 @@
/*
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.gui.menus.dom; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.menus.*;
import gplx.gfui.*; import gplx.xowa.gui.cmds.*;
public class Xog_mnu_evt_mgr implements GfoEvObj {
private OrderedHash itms = OrderedHash_.new_();
public Xog_mnu_evt_mgr(Xog_mnu_base owner) {this.ev_mgr = GfoEvMgr.new_(this);}
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
public void Sub(Gfui_mnu_itm mnu_itm) {
itms.Add(mnu_itm.Uid(), mnu_itm);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Evt_selected_changed)) {
int len = itms.Count();
for (int i = 0; i < len; i++) {
Gfui_mnu_itm itm = (Gfui_mnu_itm)itms.FetchAt(i);
itm.Selected_(m.ReadBool("v"));
}
}
return this;
}
public static final String Evt_selected_changed = "selected_changed";
}

View File

@@ -0,0 +1,109 @@
/*
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.gui.menus.dom; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.menus.*;
import gplx.gfui.*;
import gplx.xowa.apps.*; import gplx.xowa.gui.views.*;
public class Xog_mnu_grp extends Xog_mnu_base {
public Xog_mnu_grp(Xoa_gui_mgr gui_mgr, boolean mnu_is_popup, String key) {
this.app = gui_mgr.App(); this.mnu_is_popup = mnu_is_popup; this.key = key;
this.Ctor(gui_mgr);
} private Xoa_app app;
public String Key() {return key;} private String key; private boolean mnu_is_popup;
public Gfui_mnu_grp Under_mnu() {return under_mnu;} private Gfui_mnu_grp under_mnu;
@Override public boolean Tid_is_app_menu_grp() {return !mnu_is_popup;}
public boolean Enabled() {return enabled;} private boolean enabled = true;
public void Enabled_(boolean v) {
this.enabled = v;
if (under_mnu != null) // null when changed by cfg.gfs
under_mnu.Itms_clear();
if (v)
this.Source_exec(app.Gfs_mgr());
else
this.Clear();
if (!mnu_is_popup && app.Gui_mgr().Browser_win().Win_box() != null)
GfoInvkAble_.InvkCmd(app.Gui_mgr().Browser_win(), gplx.gfui.Gfui_html.Evt_win_resized);
}
public String Source() {return source;} private String source;
public String Source_default() {return source_default;} public Xog_mnu_grp Source_default_(String v) {source_default = source = v; return this;} private String source_default;
private Xog_mnu_grp Source_(Xoa_gfs_mgr gfs_mgr, String v) {
Object rslt = Source_exec(gfs_mgr, v);
if (rslt != GfoInvkAble_.Rv_error)
source = v;
return this;
}
public Object Source_exec(Xoa_gfs_mgr gfs_mgr) {return Source_exec(gfs_mgr, source);}
private Object Source_exec(Xoa_gfs_mgr gfs_mgr, String v) {
if (!enabled) return GfoInvkAble_.Rv_handled;
String script = "clear;\n" + v + "build;";
return gfs_mgr.Run_str_for(this, script);
}
public void Build() {
Xoa_gui_mgr gui_mgr = app.Gui_mgr(); Gfui_kit kit = gui_mgr.Kit(); Xog_win_itm win = gui_mgr.Browser_win();
if (!kit.Kit_init_done()) return; // NOTE: .gfs will fire Build before Kit.Init; check that kit is inited
if (under_mnu == null) {
if (mnu_is_popup) {
if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_tabs_btns))
under_mnu = kit.New_mnu_popup(key, win.Tab_mgr().Tab_mgr());
else
under_mnu = kit.New_mnu_popup(key, win.Win_box());
}
else
under_mnu = kit.New_mnu_bar(key, win.Win_box());
}
Xog_mnu_bldr bldr = gui_mgr.Menu_mgr().Menu_bldr();
bldr.Build(under_mnu, this);
Xog_mnu_base.Update_grp_by_lang(bldr, app.User().Lang(), this); // NOTE: always set lang after rebuild; else changes in Help:Options/Menus will show blank captions; DATE:2014-06-05
if (mnu_is_popup) {
boolean rebind_to_win = false;
if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_tabs_btns)) {
kit.Set_mnu_popup(win.Tab_mgr().Tab_mgr(), under_mnu);
rebind_to_win = true;
}
else if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_html_page)) // rebind new popup box; DATE:2014-05-16
Bind_popup_menu(gui_mgr);
else if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_html_link))
rebind_to_win = true;
else if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_prog))
kit.Set_mnu_popup(win.Prog_box(), under_mnu);
else if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_info))
kit.Set_mnu_popup(win.Info_box(), under_mnu);
if (rebind_to_win) { // WORKAROUND: SWT seems to bind popup menus to window; always rebind window to html_page; DATE:2014-05-17
kit.Set_mnu_popup(win.Win_box(), gui_mgr.Menu_mgr().Popup().Html_page().Under_mnu());
}
}
}
private void Bind_popup_menu(Xoa_gui_mgr gui_mgr) {
Gfui_kit kit = gui_mgr.Kit(); Xog_win_itm win = gui_mgr.Browser_win(); Xog_tab_mgr tab_mgr = win.Tab_mgr();
int tabs_len = tab_mgr.Tabs_len();
for (int i = 0; i < tabs_len; i++) {
Xog_tab_itm tab = tab_mgr.Tabs_get_at(i);
kit.Set_mnu_popup(tab.Html_box(), under_mnu);
}
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_build)) this.Build();
else if (ctx.Match(k, Invk_enabled)) return Yn.X_to_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) this.Enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_source)) return source;
else if (ctx.Match(k, Invk_source_)) this.Source_(app.Gfs_mgr(), m.ReadStr("v"));
else if (ctx.Match(k, Invk_source_default)) return source_default;
else if (ctx.Match(k, Invk_source_default_)) source_default = m.ReadStr("v");
else return super.Invk(ctx, ikey, k, m);
return this;
} private static final String Invk_build = "build", Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_source = "source", Invk_source_ = "source_", Invk_source_default = "source_default", Invk_source_default_ = "source_default_";
}

View File

@@ -0,0 +1,87 @@
/*
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.gui.menus.dom; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.menus.*;
import gplx.gfui.*; import gplx.xowa.gui.cmds.*;
public class Xog_mnu_itm extends Xog_mnu_base {
private Xoa_gui_mgr gui_mgr;
public Xog_mnu_itm(Xoa_gui_mgr gui_mgr, String key) {
this.gui_mgr = gui_mgr; this.key = key; this.key_bry = Bry_.new_utf8_(key);
this.Ctor(gui_mgr);
}
public byte Tid() {return tid;} public Xog_mnu_itm Tid_(byte v) {tid = v; return this;} private byte tid;
@Override public boolean Tid_is_app_menu_grp() {return false;}
public String Key() {return key;} private String key; private byte[] key_bry;
public String Name() {return name;} public void Name_(String v) {this.name = v; Gui_text_calc_();} private String name = "";
public String Shortcut() {return shortcut;} public void Shortcut_(String v) {this.shortcut = v; Gui_text_calc_();} private String shortcut;
public String Gui_text() {return gui_text;} public void Gui_text_calc_() {gui_text = Gui_text_calc(name, shortcut);} private String gui_text = "";
public String[] Img_nest() {return img_nest;} private String[] img_nest = String_.Ary_empty;
private String Cmd() {
Xog_cmd_itm cmd_itm = gui_mgr.Cmd_mgr().Get_or_null(key);
return cmd_itm == null ? "" : cmd_itm.Cmd();
}
public Xog_mnu_itm Cmd_(String cmd) {
Xog_cmd_itm cmd_itm = gui_mgr.Cmd_mgr().Get_or_make(key);
cmd_itm.Cmd_(cmd);
return this;
}
public Gfui_mnu_itm Under_gui() {return under_gui;} public void Under_gui_(Gfui_mnu_itm v) {under_gui = v;} private Gfui_mnu_itm under_gui;
private Xog_mnu_itm Init_by_clone(Xog_mnu_itm comp) {
this.tid = comp.tid; this.name = comp.name; this.shortcut = comp.shortcut; this.img_nest = comp.img_nest; this.gui_text = comp.gui_text;
return this;
}
public void Init_by_lang(Xol_lang lang) {
this.name = Pf_msg_mgr.Get_msg_val_gui_or(lang, Xog_cmd_itm_.Msg_pre_api, key_bry, Xog_cmd_itm_.Msg_suf_name, name); // NOTE: custom cmds must use Get_val_or, not Get_val_or_null; DATE:2014-05-30
this.shortcut = Pf_msg_mgr.Get_msg_val_gui_or(lang, Xog_cmd_itm_.Msg_pre_api, key_bry, Xog_cmd_itm_.Msg_suf_letter, shortcut);
this.img_nest = Img_nest_of(Pf_msg_mgr.Get_msg_val_gui_or(lang, Xog_cmd_itm_.Msg_pre_api, key_bry, Xog_cmd_itm_.Msg_suf_image, ""));
this.gui_text = Gui_text_calc(name, shortcut);
}
public void Init_by_custom(String name, String shortcut, String img_nest_str) {
this.name = name;
this.shortcut = shortcut;
this.img_nest = Img_nest_of(img_nest_str);
this.gui_text = Gui_text_calc(name, shortcut);
}
public static String Gui_text_calc(String name, String shortcut) {
if (shortcut == null || String_.Len(shortcut) != 1) return name; // shortcut is null or > 1 char; return name
int pos = String_.FindFwd(String_.Lower(name), String_.Lower(shortcut)); // search for shortcut in name
if (pos == String_.Find_none) return name; // shortcut not found; return name; EX: "x" in "File" returns "File"
return String_.Mid(name, 0, pos) + "&" + String_.Mid(name, pos); // add & before shortcut; EX: "x" in "Exit" -> "E&xit"
}
public Xog_mnu_itm Clone() {
Xog_mnu_itm rv = new Xog_mnu_itm(gui_mgr, key).Init_by_clone(this);
rv.Evt_mgr_(this.Evt_mgr());
return rv;
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_text)) return name;
else if (ctx.Match(k, Invk_text_)) Name_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_shortcut)) return shortcut;
else if (ctx.Match(k, Invk_shortcut_)) Shortcut_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_cmd)) return this.Cmd();
else if (ctx.Match(k, Invk_cmd_)) Cmd_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_img)) return String_.Concat_with_str("/", img_nest);
else if (ctx.Match(k, Invk_img_)) img_nest = Img_nest_of(m.ReadStr("v"));
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk_text = "text", Invk_text_ = "text_", Invk_shortcut = "shortcut", Invk_shortcut_ = "shortcut_", Invk_cmd = "cmd", Invk_cmd_ = "cmd_", Invk_img = "img", Invk_img_ = "img_"
;
public static final byte Tid_nil = 0, Tid_grp = 1, Tid_spr = 2, Tid_btn = 3, Tid_chk = 4, Tid_rdo = 5;
private static String[] Img_nest_of(String img) {return String_.Len_eq_0(img) ? String_.Ary_empty : String_.Split(img, "/");}
public static final Xog_mnu_itm Null = new Xog_mnu_itm(null, "null");
}

View File

@@ -0,0 +1,103 @@
/*
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.gui.menus.dom; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.menus.*;
import gplx.xowa.gui.cmds.*;
public class Xog_mnu_regy {
private OrderedHash hash;
private Xoa_gui_mgr gui_mgr;
public Xog_mnu_regy(Xoa_gui_mgr gui_mgr) {
this.gui_mgr = gui_mgr;
}
public void Init_by_app(Xoa_app app) {
hash = OrderedHash_.new_();
Xog_cmd_mgr cmd_mgr = app.Gui_mgr().Cmd_mgr();
int len = cmd_mgr.Len();
for (int i = 0; i < len; i++) {
Xog_cmd_itm cmd_itm = cmd_mgr.Get_at(i);
String key = cmd_itm.Key();
Xog_mnu_itm rv = new Xog_mnu_itm(gui_mgr, key);
hash.Add(key, rv);
}
Init_obsolete(hash, gui_mgr);
}
public Xog_mnu_itm Get_or_make(String key) {
Xog_mnu_itm rv = (Xog_mnu_itm)hash.Fetch(key);
if (rv == null) {
rv = new Xog_mnu_itm(gui_mgr, key);
hash.Add(key, rv);
}
else
rv = rv.Clone();
return rv;
}
private static void Init_obsolete(OrderedHash hash, Xoa_gui_mgr gui_mgr) {
Init_obsolete_itm(hash, gui_mgr, "xowa.file" , Xog_cmd_itm_.Key_gui_menus_group_file);
Init_obsolete_itm(hash, gui_mgr, "xowa.tabs.new_dflt__at_dflt__focus_y" , Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y);
Init_obsolete_itm(hash, gui_mgr, "xowa.tabs.close_cur" , Xog_cmd_itm_.Key_gui_browser_tabs_close_cur);
Init_obsolete_itm(hash, gui_mgr, "xowa.file.save_as" , Xog_cmd_itm_.Key_gui_page_view_save_as);
Init_obsolete_itm(hash, gui_mgr, "xowa.file.print" , Xog_cmd_itm_.Key_gui_page_view_print);
Init_obsolete_itm(hash, gui_mgr, "xowa.file.exit" , Xog_cmd_itm_.Key_app_exit);
Init_obsolete_itm(hash, gui_mgr, "xowa.edit" , Xog_cmd_itm_.Key_gui_menus_group_edit);
Init_obsolete_itm(hash, gui_mgr, "xowa.edit.select_all" , Xog_cmd_itm_.Key_gui_page_selection_select_all);
Init_obsolete_itm(hash, gui_mgr, "xowa.edit.copy" , Xog_cmd_itm_.Key_gui_page_selection_copy);
Init_obsolete_itm(hash, gui_mgr, "xowa.edit.find" , Xog_cmd_itm_.Key_gui_browser_find_show_by_paste);
Init_obsolete_itm(hash, gui_mgr, "xowa.view" , Xog_cmd_itm_.Key_gui_menus_group_view);
Init_obsolete_itm(hash, gui_mgr, "xowa.view.font.increase" , Xog_cmd_itm_.Key_gui_font_increase);
Init_obsolete_itm(hash, gui_mgr, "xowa.view.font.decrease" , Xog_cmd_itm_.Key_gui_font_decrease);
Init_obsolete_itm(hash, gui_mgr, "xowa.view.page.read" , Xog_cmd_itm_.Key_gui_page_view_mode_read);
Init_obsolete_itm(hash, gui_mgr, "xowa.view.page.edit" , Xog_cmd_itm_.Key_gui_page_view_mode_edit);
Init_obsolete_itm(hash, gui_mgr, "xowa.view.page.html" , Xog_cmd_itm_.Key_gui_page_view_mode_html);
Init_obsolete_itm(hash, gui_mgr, "xowa.view.windows.progress.show" , Xog_cmd_itm_.Key_gui_browser_prog_log_show);
Init_obsolete_itm(hash, gui_mgr, "xowa.history" , Xog_cmd_itm_.Key_gui_menus_group_history);
Init_obsolete_itm(hash, gui_mgr, "xowa.history.go_bwd" , Xog_cmd_itm_.Key_nav_go_bwd);
Init_obsolete_itm(hash, gui_mgr, "xowa.history.go_fwd" , Xog_cmd_itm_.Key_nav_go_fwd);
Init_obsolete_itm(hash, gui_mgr, "xowa.history.show" , Xog_cmd_itm_.Key_usr_history_show);
Init_obsolete_itm(hash, gui_mgr, "xowa.bookmarks" , Xog_cmd_itm_.Key_gui_menus_group_bookmarks);
Init_obsolete_itm(hash, gui_mgr, "xowa.bookmarks.goto_main_page" , Xog_cmd_itm_.Key_nav_wiki_main_page);
Init_obsolete_itm(hash, gui_mgr, "xowa.bookmarks.add" , Xog_cmd_itm_.Key_usr_bookmarks_add);
Init_obsolete_itm(hash, gui_mgr, "xowa.bookmarks.show" , Xog_cmd_itm_.Key_usr_bookmarks_show);
Init_obsolete_itm(hash, gui_mgr, "xowa.tools" , Xog_cmd_itm_.Key_gui_menus_group_tools);
Init_obsolete_itm(hash, gui_mgr, "xowa.tools.options" , Xog_cmd_itm_.Key_nav_cfg_main);
Init_obsolete_itm(hash, gui_mgr, "xowa.tools.wikis.import_from_list" , Xog_cmd_itm_.Key_nav_setup_import_from_list);
Init_obsolete_itm(hash, gui_mgr, "xowa.tools.wikis.import_from_script" , Xog_cmd_itm_.Key_nav_setup_import_from_script);
Init_obsolete_itm(hash, gui_mgr, "xowa.tools.wikis.maintenance" , Xog_cmd_itm_.Key_nav_setup_maintenance);
Init_obsolete_itm(hash, gui_mgr, "xowa.tools.wikis.download" , Xog_cmd_itm_.Key_nav_setup_download);
Init_obsolete_itm(hash, gui_mgr, "xowa.help" , Xog_cmd_itm_.Key_gui_menus_group_help);
Init_obsolete_itm(hash, gui_mgr, "xowa.help.help" , Xog_cmd_itm_.Key_nav_help_help);
Init_obsolete_itm(hash, gui_mgr, "xowa.help.change_log" , Xog_cmd_itm_.Key_nav_help_change_log);
Init_obsolete_itm(hash, gui_mgr, "xowa.help.diagnostics" , Xog_cmd_itm_.Key_nav_help_diagnostics);
Init_obsolete_itm(hash, gui_mgr, "xowa.help.context_menu" , Xog_cmd_itm_.Key_nav_cfg_menu);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data" , Xog_cmd_itm_.Key_gui_menus_group_system_data);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data.log_session" , Xog_cmd_itm_.Key_nav_system_data_log_session);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data.cfg_app" , Xog_cmd_itm_.Key_nav_system_data_cfg_app);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data.cfg_lang" , Xog_cmd_itm_.Key_nav_system_data_cfg_lang);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data.cfg_user" , Xog_cmd_itm_.Key_nav_system_data_cfg_user);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data.cfg_custom" , Xog_cmd_itm_.Key_nav_system_data_cfg_custom);
Init_obsolete_itm(hash, gui_mgr, "xowa.system.data.usr_history" , Xog_cmd_itm_.Key_nav_system_data_usr_history);
Init_obsolete_itm(hash, gui_mgr, "xowa.help.about" , Xog_cmd_itm_.Key_nav_help_about);
Init_obsolete_itm(hash, gui_mgr, "xowa.tabs.new_link__at_dflt__focus_n" , Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_n);
Init_obsolete_itm(hash, gui_mgr, "xowa.tabs.new_link__at_dflt__focus_y" , Xog_cmd_itm_.Key_gui_browser_tabs_new_link__at_dflt__focus_y);
Init_obsolete_itm(hash, gui_mgr, "xowa.widgets.find.show_by_paste" , Xog_cmd_itm_.Key_gui_browser_find_show_by_paste);
Init_obsolete_itm(hash, gui_mgr, "xowa.file.save_file_as" , Xog_cmd_itm_.Key_gui_page_selection_save_file_as);
Init_obsolete_itm(hash, gui_mgr, "xowa.widgets.prog_log.show" , Xog_cmd_itm_.Key_gui_browser_prog_log_show);
}
private static void Init_obsolete_itm(OrderedHash hash, Xoa_gui_mgr gui_mgr, String old, String cur) {
Xog_mnu_itm rv = new Xog_mnu_itm(gui_mgr, cur);
hash.Add(old, rv);
}
}

View File

@@ -0,0 +1,156 @@
/*
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.gui.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.xowa.files.*; import gplx.xowa.gui.views.*;
public class Xog_url_wkr {
private Xoh_href href = new Xoh_href();
private Xoa_app app; private Xog_win_itm win; private Xoa_page page;
public byte Href_tid() {return href.Tid();}
public Xog_url_wkr Parse(Xog_win_itm win, String href_str) {
if (href_str == null) return this; // text is not link; return;
byte[] href_bry = Bry_.new_utf8_(href_str);
this.win = win; this.app = win.App(); this.page = win.Active_page();
app.Href_parser().Parse(href, href_bry, page.Wiki(), page.Ttl().Page_url());
return this;
}
public Xoa_url Exec() {
byte[] href_bry = href.Raw();
switch (href.Tid()) {
case Xoh_href.Tid_null: return Rslt_handled; // url is invalid; return handled (which effectively ignores)
case Xoh_href.Tid_xowa: return Exec_url_xowa(app); // xowa:app.version
case Xoh_href.Tid_http: return Exec_url_http(app); // http://site.org
case Xoh_href.Tid_anchor: return Exec_url_anchor(win); // #anchor
case Xoh_href.Tid_xcmd: return Exec_url_xcmd(win); // /xcmd/app.version
case Xoh_href.Tid_file: return Exec_url_file(app, page, win, href_bry); // file:///xowa/A.png
default: return Exec_url_page(app, page, win, href_bry); // Page /wiki/Page
}
}
private Xoa_url Exec_url_xowa(Xoa_app app) { // EX: xowa:app.version
// NOTE: must catch exception else it will bubble to SWT browser and raise secondary exception of xowa is not a registered protocol
try {app.Gfs_mgr().Run_str(String_.new_utf8_(href.Page()));}
catch (Exception e) {app.Gui_mgr().Kit().Ask_ok("", "", Err_.Message_gplx_brief(e));}
return Rslt_handled;
}
private Xoa_url Exec_url_http(Xoa_app app) { // EX: http:a.org
app.Fsys_mgr().App_mgr().Exec_view_web(href.Raw());
return Rslt_handled;
}
private Xoa_url Exec_url_anchor(Xog_win_itm win) { // EX: #anchor
win.Active_html_itm().Scroll_page_by_id_gui(String_.new_utf8_(href.Anchor())); // NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
return Rslt_handled;
}
private Xoa_url Exec_url_xcmd(Xog_win_itm win) { // EX: /xcmd/
byte[] xowa_href_bry = href.Page();
int xowa_href_bry_len = xowa_href_bry.length;
int slash_pos = Bry_finder.Find_fwd(xowa_href_bry, Byte_ascii.Slash); if (slash_pos == Bry_.NotFound) slash_pos = xowa_href_bry_len;
byte[] xowa_cmd_bry = Bry_.Mid(xowa_href_bry, 0, slash_pos);
String xowa_cmd_str = String_.new_utf8_(xowa_cmd_bry);
GfoMsg m = GfoMsg_.new_cast_(xowa_cmd_str);
if (String_.Eq(xowa_cmd_str, Xog_win_itm.Invk_eval))
m.Add("cmd", String_.new_utf8_(xowa_href_bry, slash_pos + 1, xowa_href_bry_len));
win.Invk(GfsCtx.new_(), 0, xowa_cmd_str, m);
return Rslt_handled;
}
private Xoa_url Exec_url_file(Xoa_app app, Xoa_page page, Xog_win_itm win, byte[] href_bry) { // EX: file:///xowa/A.png
href_bry = app.Url_converter_url().Decode(href_bry);
Io_url href_url = Io_url_.http_any_(String_.new_utf8_(href_bry), Op_sys.Cur().Tid_is_wnt());
gplx.gfui.Gfui_html html_box = win.Active_html_box();
String xowa_ttl = page.Wiki().Gui_mgr().Cfg_browser().Content_editable()
? html_box.Html_active_atr_get_str(gplx.xowa.html.Xoh_html_tag.Nde_xowa_title_str, null)
: Xoh_dom_.Title_by_href(app.Url_converter_comma(), app.Utl_bry_bfr_mkr().Get_b512().Mkr_rls(), href_bry, Bry_.new_utf8_(html_box.Html_doc_html()));
if (!Io_mgr._.ExistsFil(href_url)) {
Xof_xfer_itm xfer_itm = new Xof_xfer_itm();
byte[] title = app.Url_converter_url().Decode(Bry_.new_utf8_(xowa_ttl));
xfer_itm.Atrs_by_lnki(Xop_lnki_type.Id_none, -1, -1, -1, Xof_doc_thumb.Null, Xof_doc_page.Null).Atrs_by_ttl(title, Bry_.Empty);
page.Wiki().File_mgr().Find_meta(xfer_itm);
page.File_queue().Clear();
page.File_queue().Add(xfer_itm); // NOTE: set elem_id to "impossible" number, otherwise it will auto-update an image on the page with a super-large size; [[File:Alfred Sisley 062.jpg]]
page.Wiki().File_mgr().Repo_mgr().Xfer_mgr().Force_orig_y_();
page.File_queue().Exec(Xof_exec_tid.Tid_viewer_app, win.Usr_dlg(), page.Wiki(), page);
page.Wiki().File_mgr().Repo_mgr().Xfer_mgr().Force_orig_n_();
}
if (Io_mgr._.ExistsFil(href_url)) {
ProcessAdp media_player = app.Fsys_mgr().App_mgr().App_by_ext(href_url.Ext());
media_player.Run(href_url);
}
return Rslt_handled;
}
private Xoa_url Exec_url_page(Xoa_app app, Xoa_page page, Xog_win_itm win, byte[] href_bry) { // EX: "Page"; "/wiki/Page"; // rewritten; DATE:2014-01-19
Xoa_url rv = new Xoa_url();
Xow_wiki wiki = page.Wiki();
app.Url_parser().Parse(rv, href_bry); // needed for query_args
byte[] anchor_bry = href.Anchor();
byte[] page_bry = rv.Page_bry();
byte[][] segs_ary = rv.Segs_ary();
int segs_ary_len = segs_ary.length;
boolean use_main_page = false;
if ( segs_ary_len > 0 // handle "Special:Search/Earth" which creates segs[1] {"Special:Search"} and page="Earth"
|| href.Tid() == Xoh_href.Tid_site) { // NOTE: if site, must always (a) zap Segs_ary and (b) force correct page; see tests; DATE:2014-01-21
int segs_bgn = 0;
boolean segs_iterate = true;
if (href.Tid() == Xoh_href.Tid_site) { // site, handle multiple segs; EX: "home/wiki/", "home/wiki/Help:Contents"; DATE:2014-01-21
if (segs_ary_len < 2) { // only 0 or 1 seg; usually occurs for logo and other xwiki links to Main_Page; EX: "/site/en.wikipedia.org/wiki/"; "/site/en.wikipedia.org/"
page_bry = wiki.Init_assert().Props().Main_page(); // use Main_page; DATE:2014-02-16
use_main_page = true;
segs_iterate = false;
}
else
segs_bgn = 2; // start from seg_2; seg_0="/en.wikipedia.org/" and seg_1="/wiki/"; note that > 2 segs possible; EX: "/site/en.wikipedia.org/wiki/A/B/C
}
if (segs_iterate) {
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b128();
for (int i = segs_bgn; i < segs_ary_len; i++) {
tmp_bfr.Add(segs_ary[i]);
tmp_bfr.Add_byte(Byte_ascii.Slash);
}
tmp_bfr.Add(page_bry);
page_bry = tmp_bfr.Mkr_rls().XtoAryAndClear();
}
rv.Segs_ary_(Bry_.Ary_empty);
}
Gfo_url_arg[] qargs = rv.Args();
int qargs_len = qargs.length;
if (qargs_len > 0) { // remove anchors from qargs; EX: "to=B#mw_pages"
for (int i = 0; i < qargs_len; i++) {
Gfo_url_arg arg = qargs[i];
int anchor_pos = Bry_finder.Find_bwd(arg.Val_bry(), Byte_ascii.Hash); // NOTE: must .FindBwd to handle Category args like de.wikipedia.org/wiki/Kategorie:Begriffskl%C3%A4rung?pagefrom=#::12%20PANZERDIVISION#mw-pages; DATE:2013-06-18
if (anchor_pos != Bry_.NotFound)
arg.Val_bry_(Bry_.Mid(arg.Val_bry(), 0, anchor_pos));
}
}
if (!Bry_.Eq(page.Wiki().Domain_bry(), href.Wiki())) {// xwiki; EX: "file:///site/en.wiktionary.org/wiki/a"; EX: (1) goto w:Anything; (2) click on "anything" in wikt; "anything" will be parsed by en.wiki's rules, not en.wikt; DATE:2013-01-30
wiki = app.Wiki_mgr().Get_by_key_or_make(href.Wiki()).Init_assert(); // get xwiki and set to wiki
if (use_main_page)
page_bry = wiki.Props().Main_page(); // get Main_page for new wiki; DATE:2014-02-23
Xoa_ttl tmp_ttl = Xoa_ttl.parse_(wiki, page_bry); // reparse ttl according to xwiki's case_match rules; NOTE: do not use rv.Page_bry() or else will lose sub_pages (A/B/C); DATE:2014-02-21
if (tmp_ttl != null)
page_bry = tmp_ttl.Full_db();
}
rv.Wiki_(wiki);
rv.Wiki_bry_(wiki.Domain_bry()); // needed b/c url_parser.Parse(href) will result in wiki of "wiki" for "/wiki/Page"
rv.Page_bry_(page_bry);
rv.Anchor_bry_(anchor_bry);
return rv;
}
public static Xoa_url Rslt_handled = null;
public static Xoa_url Exec_url(Xog_win_itm win, String href_str) {
Xog_url_wkr url_wkr = new Xog_url_wkr();
url_wkr.Parse(win, href_str);
return url_wkr.Exec();
}
}

View File

@@ -0,0 +1,100 @@
/*
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.gui.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import org.junit.*; import gplx.xowa.gui.views.*;
public class Xog_url_wkr_tst {
@Before public void init() {fxt.Clear();} private Xog_url_wkr_fxt fxt = new Xog_url_wkr_fxt();
@Test public void term() {fxt.Clear();}
@Test public void Basic() {
fxt.Init_exec("file:///wiki/A").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A").Test();
}
@Test public void Basic_question() {
fxt.Init_exec("file:///wiki/A?").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A?").Expd_qargs_("").Test();
}
@Test public void Basic_question_text() {
fxt.Init_exec("file:///wiki/A?B").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A?B").Expd_qargs_("").Test();
}
@Test public void Redirect() {
fxt.Init_exec("file:///wiki/A?redirect=no").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("A").Expd_qargs_("?redirect=no").Test();
}
@Test public void Search() {
fxt.Init_exec("file:///wiki/Special:Search/Moon%3Ffulltext%3Dy%26xowa_page_index%3D1").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("Special:Search/Moon").Expd_qargs_("?fulltext=y&xowa_page_index=1").Test();
}
@Test public void Ctg() {
fxt.Init_exec("file:///wiki/Category:A?pagefrom=A#mw-pages").Expd_tid_(Xoh_href.Tid_wiki).Expd_page_("Category:A").Expd_qargs_("?pagefrom=A").Expd_anchor_("mw-pages").Test();
}
@Test public void Xwiki() {
Xow_ns_mgr ns_mgr = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_ascii_("en.wiktionary.org")).Ns_mgr();
ns_mgr.Ns_main().Case_match_(Xow_ns_case_.Id_all);
fxt.Init_exec("file:///site/en.wiktionary.org/wiki/a").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wiktionary.org").Expd_page_("a").Test();
ns_mgr.Ns_category().Case_match_(Xow_ns_case_.Id_all);
fxt.Init_exec("file:///site/en.wiktionary.org/wiki/Category:a").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wiktionary.org").Expd_page_("Category:a").Test();
fxt.Init_exec("file:///site/en.wiktionary.org/wiki/A/B/C").Expd_tid_(Xoh_href.Tid_site).Expd_page_("A/B/C").Test();
}
@Test public void Xwiki_site_sidebar() {// PURPOSE: make sure sidebar links don't fail; DATE:2014-01-21
fxt.Init_exec("file:///site/en.wikipedia.org/wiki/A").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("A").Test();
}
@Test public void Xwiki_site_logo() { // DATE:2014-01-21
fxt.Init_exec("file:///site/en.wikipedia.org/wiki/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("Main_Page").Test();
fxt.Init_exec("file:///site/en.wikipedia.org/wiki").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("Main_Page").Test();
fxt.Init_exec("file:///site/en.wikipedia.org/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("Main_Page").Test();
}
@Test public void Main_page() {// PURPOSE: Main_page does not update to use Main_page of xwiki; DATE:2014-02-23
fxt.App().User().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
gplx.xowa.wikis.Xoa_wiki_regy.Make_wiki_dir(fxt.App(), "zh.wikipedia.org");
fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_ascii_("zh.wikipedia.org")).Props().Main_page_(Bry_.new_ascii_("Zh_Main_Page"));
fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_ascii_("en.wikipedia.org")).Props().Main_page_(Bry_.new_ascii_("En_Main_Page"));
fxt.Init_exec("file:///site/zh.wikipedia.org/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("zh.wikipedia.org").Expd_page_("Zh_Main_Page").Test();
fxt.Init_exec("file:///site/en.wikipedia.org/").Expd_tid_(Xoh_href.Tid_site).Expd_wiki_("en.wikipedia.org").Expd_page_("En_Main_Page").Test(); // still stuck at Zh
}
}
class Xog_url_wkr_fxt {
private Xoa_app app; private Xow_wiki wiki;
private Xog_win_itm win;
private Xog_url_wkr url_wkr = new Xog_url_wkr();
private String init_raw;
public Xoa_app App() {return app;}
public Xog_url_wkr_fxt Expd_tid_(byte v) {expd_tid = v; return this;} private byte expd_tid;
public Xog_url_wkr_fxt Expd_wiki_(String v) {expd_wiki = v; return this;} private String expd_wiki;
public Xog_url_wkr_fxt Expd_page_(String v) {expd_page = v; return this;} private String expd_page;
public Xog_url_wkr_fxt Expd_anchor_(String v) {expd_anchor = v; return this;} private String expd_anchor;
public Xog_url_wkr_fxt Expd_qargs_(String v) {expd_qargs = v; return this;} private String expd_qargs;
public void Clear() {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
Xoa_app_fxt.Init_gui(app);
win = app.Gui_mgr().Browser_win();
win.Active_page_(Xoa_page.test_(wiki, Xoa_ttl.parse_(wiki, Bry_.new_utf8_("test")))); // TODO: remove unnecessary page init
expd_wiki = expd_page = expd_qargs = expd_anchor = null;
}
public Xog_url_wkr_fxt Init_exec(String raw) {
this.init_raw = raw;
return this;
}
public void Test() {
Xoa_url url = url_wkr.Parse(win, init_raw).Exec();
Tfds.Eq(expd_tid, url_wkr.Href_tid());
Tfds.Eq(expd_page, String_.new_utf8_(url.Page_bry()));
if (expd_wiki != null) Tfds.Eq(expd_wiki , String_.new_utf8_(url.Wiki_bry()));
if (expd_anchor != null) Tfds.Eq(expd_anchor , String_.new_utf8_(url.Anchor_bry()));
if (expd_qargs != null) Tfds.Eq(expd_qargs , String_.new_utf8_(url.Args_all_as_bry()));
}
}

View File

@@ -0,0 +1,43 @@
/*
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.gui.urls.url_macros; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.urls.*;
public class Xog_url_macro_grp implements GfoInvkAble {
public ByteTrieMgr_slim Trie() {return trie;} private ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_();
public void Del(byte[] abrv) {trie.Del(abrv);}
public void Set(String abrv, String fmt) {Set(Bry_.new_utf8_(abrv), Bry_.new_utf8_(fmt));}
public void Set(byte[] abrv, byte[] fmt) {trie.Add(abrv, new Xog_url_macro_itm(abrv, fmt));}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_clear)) trie.Clear();
else if (ctx.Match(k, Invk_set)) Set(m.ReadBry("abrv"), m.ReadBry("fmt"));
else if (ctx.Match(k, Invk_del)) Del(m.ReadBry("abrv"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_clear = "clear", Invk_set = "set", Invk_del = "del";
}
class Xog_url_macro_itm {
private Bry_fmtr fmtr;
public Xog_url_macro_itm(byte[] abrv, byte[] fmt) {this.abrv = abrv; this.fmt = fmt;}
public byte[] Abrv() {return abrv;} private byte[] abrv;
public byte[] Fmt() {return fmt;} private byte[] fmt;
public byte[] Fmtr_exec(Bry_bfr bfr, Object... args) {
if (fmtr == null) fmtr = new Bry_fmtr().Fmt_(fmt).Compile();
fmtr.Bld_bfr_many(bfr, args);
return bfr.XtoAryAndClear();
}
}

View File

@@ -0,0 +1,91 @@
/*
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.gui.urls.url_macros; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.urls.*;
public class Xog_url_macro_mgr {
private Bry_bfr bfr = Bry_bfr.reset_(255);
public Xog_url_macro_mgr() {
this.Init();
}
public void Lang_default_(byte[] v) {lang_default = v;} private byte[] lang_default = Bry_.new_ascii_("en");
public Xog_url_macro_grp Types_mgr() {return types_mgr;} private Xog_url_macro_grp types_mgr = new Xog_url_macro_grp();
public Xog_url_macro_grp Custom_mgr() {return custom_mgr;} private Xog_url_macro_grp custom_mgr = new Xog_url_macro_grp();
public byte[] Fmt_or_null(byte[] raw) {
int raw_len = raw.length;
int dot_pos = -1;
for (int i = 0; i < raw_len; i++) {
byte b = raw[i];
switch (b) {
case Byte_ascii.Dot:
dot_pos = i;
break;
case Byte_ascii.Colon:
return Fmt_or_null__type(raw, raw_len, dot_pos, i);
}
}
return Unhandled;
}
private byte[] Fmt_or_null__type(byte[] raw, int raw_len, int dot_pos, int colon_pos) {
boolean dot_missing = dot_pos == -1;
int type_bgn = dot_pos + 1, type_end = colon_pos; // +1 to start type after dot;
if (dot_missing) type_bgn = 0;
Object custom_obj = custom_mgr.Trie().MatchAtCurExact(raw, 0, type_end); // match entire prefix
if (custom_obj == null) {
Object type_obj = types_mgr.Trie().MatchAtCurExact(raw, type_bgn, type_end);
if (type_obj == null) return Unhandled; // type abrv is not known; exit; EX: "en.unknown:Page"; "Page"
byte[] lang_bry = dot_missing ? lang_default : Bry_.Mid(raw, 0, dot_pos);
Xog_url_macro_itm type_itm = (Xog_url_macro_itm)type_obj;
return type_itm.Fmtr_exec(bfr, lang_bry, Bry_.Mid(raw, colon_pos + 1, raw_len));
}
else {
Xog_url_macro_itm custom_itm = (Xog_url_macro_itm)custom_obj;
return custom_itm.Fmtr_exec(bfr, Bry_.Mid(raw, colon_pos + 1, raw_len));
}
}
private void Init() {
types_mgr.Set("w" , "~{0}.wikipedia.org/wiki/~{1}");
types_mgr.Set("d" , "~{0}.wiktionary.org/wiki/~{1}");
types_mgr.Set("s" , "~{0}.wikisource.org/wiki/~{1}");
types_mgr.Set("v" , "~{0}.wikivoyage.org/wiki/~{1}");
types_mgr.Set("q" , "~{0}.wikiquote.org/wiki/~{1}");
types_mgr.Set("b" , "~{0}.wikibooks.org/wiki/~{1}");
types_mgr.Set("u" , "~{0}.wikiversity.org/wiki/~{1}");
types_mgr.Set("n" , "~{0}.wikinews.org/wiki/~{1}");
types_mgr.Set("a" , "~{0}.wikia.com/wiki/~{1}");
custom_mgr.Set("c" , "commons.wikimedia.org/wiki/~{0}");
custom_mgr.Set("wd" , "www.wikidata.org/wiki/~{0}");
custom_mgr.Set("wd.q" , "www.wikidata.org/wiki/Q~{0}");
custom_mgr.Set("wd.p" , "www.wikidata.org/wiki/Property:P~{0}");
custom_mgr.Set("sp" , "wikispecies.wikimedia.org/wiki/~{0}");
custom_mgr.Set("meta" , "meta.wikimedia.org/wiki/~{0}");
custom_mgr.Set("s.w" , "simple.wikipedia.org/wiki/~{0}");
custom_mgr.Set("s.d" , "simple.wiktionary.org/wiki/~{0}");
custom_mgr.Set("s.b" , "simple.wikibooks.org/wiki/~{0}");
custom_mgr.Set("s.q" , "simple.wikiquote.org/wiki/~{0}");
custom_mgr.Set("?" , "Special:Search/~{0}?fulltext=y");
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lang_default)) return String_.new_utf8_(lang_default);
else if (ctx.Match(k, Invk_lang_default_)) lang_default = m.ReadBry("v");
else if (ctx.Match(k, Invk_types)) return types_mgr;
else if (ctx.Match(k, Invk_custom)) return custom_mgr;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_lang_default = "lang_default", Invk_lang_default_ = "lang_default_", Invk_types = "types", Invk_custom = "custom";
public static final byte[] Unhandled = null;
}

View File

@@ -0,0 +1,56 @@
/*
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.gui.urls.url_macros; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.urls.*;
import org.junit.*;
public class Xog_url_macro_mgr_tst {
@Before public void init() {fxt.Clear();} private Xog_url_macro_mgr_fxt fxt = new Xog_url_macro_mgr_fxt();
@Test public void Custom_basic() {fxt.Test("?:Page" , "Special:Search/Page?fulltext=y");}
@Test public void Type_basic() {fxt.Test("en.w:Page" , "en.wikipedia.org/wiki/Page");}
@Test public void Type_main() {fxt.Test("en.w:" , "en.wikipedia.org/wiki/");}
@Test public void Type_tid() {fxt.Test("w:Page" , "en.wikipedia.org/wiki/Page");}
@Test public void Type_lang() {fxt.Test("fr.w:Page" , "fr.wikipedia.org/wiki/Page");}
@Test public void Type_unhandled() {fxt.Test("x:A" , null);}
@Test public void Type_unhandled_ns() {fxt.Test("Help:A" , null);}
@Test public void Type_custom() {fxt.Test("wd.q:123" , "www.wikidata.org/wiki/Q123");}
@Test public void Type_del() {
fxt.Test("w:A", "en.wikipedia.org/wiki/A");
fxt.Abrv_mgr().Types_mgr().Del(Bry_.new_utf8_("w"));
fxt.Test("w:A", null);
}
@Test public void Type_set() {
fxt.Abrv_mgr().Types_mgr().Set("w", "~{0}.~{1}");
fxt.Test("w.A", null);
}
@Test public void Lang_default() {
fxt.Abrv_mgr().Lang_default_(Bry_.new_ascii_("fr"));
fxt.Test("w:Page", "fr.wikipedia.org/wiki/Page");
}
@Test public void Precedence() { // PURPOSE: Custom should take precedence over type
fxt.Abrv_mgr().Custom_mgr().Set("w", "custom:~{0}");
fxt.Test("w:Page" , "custom:Page");
}
}
class Xog_url_macro_mgr_fxt {
public void Clear() {
abrv_mgr = new Xog_url_macro_mgr();
}
public Xog_url_macro_mgr Abrv_mgr() {return abrv_mgr;} private Xog_url_macro_mgr abrv_mgr;
public void Test(String raw, String expd) {
Tfds.Eq(expd, String_.new_ascii_(abrv_mgr.Fmt_or_null(Bry_.new_ascii_(raw))));
}
}

View File

@@ -0,0 +1,38 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Rect_ref {
public Rect_ref(int x, int y, int w, int h) {this.x = x; this.y = y; this.w = w; this.h = h;}
public int X() {return x;} public Rect_ref X_(int v) {x = v; return this;} private int x;
public int Y() {return y;} public Rect_ref Y_(int v) {y = v; return this;} private int y;
public int W() {return w;} public Rect_ref W_(int v) {w = v; return this;} private int w;
public int H() {return h;} public Rect_ref H_(int v) {h = v; return this;} private int h;
public int X_max() {return x + w;}
public int Y_max() {return y + h;}
public gplx.gfui.RectAdp XtoRectAdp() {return gplx.gfui.RectAdp_.new_(x, y, w, h);}
public gplx.gfui.RectAdp XtoRectAdp_add(Rect_ref v) {return gplx.gfui.RectAdp_.new_(x + v.x, y + v.y, w + v.w, h + v.h);}
@Override public String toString() {return String_.Format("{0},{1},{2},{3}", x, y, w, h);}
public static final Rect_ref Zero = new Rect_ref(0, 0, 0, 0);
public static Rect_ref rectAdp_(gplx.gfui.RectAdp v) {return new Rect_ref(v.X(), v.Y(), v.Width(), v.Height());}
public static Rect_ref parse_(String raw) {
try {
String[] ary = String_.Split(raw, ",");
return new Rect_ref(Int_.parse_(ary[0]), Int_.parse_(ary[1]), Int_.parse_(ary[2]), Int_.parse_(ary[3]));
} catch(Exception exc) {throw Err_.parse_type_exc_(exc, Rect_ref.class, raw);}
}
}

View File

@@ -0,0 +1,213 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*;
public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
private Xoa_app app;
public Xog_html_itm(Xog_tab_itm owner_tab) {
this.owner_tab = owner_tab;
app = owner_tab.Tab_mgr().Win().App();
js_cbk = new Xog_html_js_cbk(this);
Gfui_kit kit = owner_tab.Tab_mgr().Win().Kit();
cmd_sync = kit.New_cmd_sync(this); // NOTE: always use sync; async will cause some images to be "lost" in update;
cmd_async = kit.New_cmd_async(this);
ev_mgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
public Xog_tab_itm Owner_tab() {return owner_tab;} private Xog_tab_itm owner_tab;
public Gfui_html Html_box() {return html_box;} private Gfui_html html_box;
public Xog_html_js_cbk Js_cbk() {return js_cbk;} private Xog_html_js_cbk js_cbk;
public GfoInvkAble Cmd_sync() {return cmd_sync;} private GfoInvkAble cmd_sync;
public GfoInvkAble Cmd_async() {return cmd_async;} private GfoInvkAble cmd_async;
public void Switch_mem(Xog_html_itm comp) {
Xog_tab_itm temp_owner_tab = owner_tab; // NOTE: reparent owner_tab, since owner_tab will be switching its html_itm
this.owner_tab = comp.owner_tab;
comp.owner_tab = temp_owner_tab;
}
public void Html_box_(Gfui_html html_box) {
this.html_box = html_box;
html_box.Html_js_cbks_add("xowa_exec", js_cbk);
}
public String Html_selected_get_src_or_empty() {return html_box.Html_doc_selected_get_src_or_empty();}
public String Html_selected_get_href_or_text() {return Html_extract_text(html_box.Html_doc_selected_get_href_or_text());}
public String Html_selected_get_text_or_href() {return Html_extract_text(html_box.Html_doc_selected_get_text_or_href());}
private String Html_extract_text(String v) {
Xoa_page page = owner_tab.Page();
String site = page.Wiki().Domain_str();
String ttl = String_.new_utf8_(page.Ttl().Full_db());
return Xog_html_itm__href_extractor.Html_extract_text(site, ttl, v);
}
public void Show(Xoa_page page) {
byte view_mode = owner_tab.View_mode();
byte[] html_src = page.Wiki().Html_mgr().Page_wtr_mgr().Gen(page, view_mode);
Html_src_(page, html_src);
if (view_mode == Xog_page_mode.Tid_read){ // used only for Xosrh test; DATE:2014-01-29
html_box.Html_doc_body_focus(); // NOTE: only focus if read so up / down will scroll box; edit / html should focus edit-box; DATE:2014-06-05
page.Root().Data_htm_(html_src);
}
}
private void Html_src_(Xoa_page page, byte[] html_src) {
html_box.Html_doc_html_(String_.new_utf8_(html_src));
}
public void Html_swap(Xog_html_itm trg_itm) {
Xog_html_itm src_itm = this;
Gfui_html src_html = html_box;
Gfui_html trg_html = trg_itm.html_box;
Xog_html_js_cbk src_js_cbk = js_cbk;
Xog_html_js_cbk trg_js_cbk = trg_itm.js_cbk;
src_itm.html_box = trg_html;
trg_itm.html_box = src_html;
src_itm.js_cbk = trg_js_cbk;
trg_itm.js_cbk = src_js_cbk;
}
public byte[] Get_elem_value_for_edit_box_as_bry() {return Bry_.new_utf8_(this.Get_elem_value_for_edit_box());}
public String Get_elem_value_for_edit_box() {return html_box.Html_elem_atr_get_str(Elem_id__xowa_edit_data_box, Gfui_html.Atr_value);}
public String Get_elem_value(String elem_id) {return html_box.Html_elem_atr_get_str(elem_id, Gfui_html.Atr_value);}
public void Html_img_update(String elem_id, String elem_src, int elem_width, int elem_height) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_img_update).Add("elem_id", elem_id).Add("elem_src", elem_src).Add("elem_width", elem_width).Add("elem_height", elem_height);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_img_update, m);
} Object guard = new Object();
public void Html_elem_delete(String elem_id) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_delete).Add("elem_id", elem_id);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_elem_delete, m);
}
public void Html_atr_set(String elem_id, String atr_key, String atr_val) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_atr_set).Add("elem_id", elem_id).Add("atr_key", atr_key).Add("atr_val", atr_val);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_elem_atr_set, m);
}
public void Html_elem_atr_set_append(String elem_id, String atr_key, String atr_val) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_atr_set_append).Add("elem_id", elem_id).Add("atr_key", atr_key).Add("atr_val", atr_val);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_elem_atr_set_append, m);
}
public void Html_elem_replace_html(String id, String html) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_replace_html).Add("id", id).Add("html", html);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_elem_replace_html, m);
}
public void Html_gallery_packed_exec() {
if (!String_.Eq(owner_tab.Tab_key(), owner_tab.Tab_mgr().Active_tab().Tab_key())) return; // do not exec unless active;
GfoMsg m = GfoMsg_.new_cast_(Invk_html_gallery_packed_exec);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_gallery_packed_exec, m);
module_packed_done = true;
}
private boolean module_packed_done = false;
public void Tab_selected(Xoa_page page) {
if ( page.Html_data().Module_mgr().Itm_gallery().Enabled()
&& !module_packed_done
) {
this.Html_gallery_packed_exec();
}
}
public void Scroll_page_by_bmk_gui() {GfoInvkAble_.InvkCmd(cmd_async, Invk_scroll_page_by_bmk);}
private void Scroll_page_by_bmk() {
if (!String_.Eq(owner_tab.Tab_key(), owner_tab.Tab_mgr().Active_tab().Tab_key())) return; // only set html page position on active tab; otherwise, page "scrolls down" mysteriously on unseen tab; DATE:2014-05-02
String html_doc_pos = owner_tab.Page().Html_data().Bmk_pos();
if (html_doc_pos == null) {
String auto_focus_id = app.Gui_mgr().Html_mgr().Auto_focus_id();
if (String_.Len_eq_0(auto_focus_id)) return; // don't focus anything
if (String_.Eq(auto_focus_id, " first_anchor")) // NOTE: HTML 4/5 do not allow space as id; XOWA using space here to create a unique_key that will never collide with any id
html_box.Html_doc_body_focus(); // NOTE: will focus body if content-editable, or first_anchor otherwise
else
html_box.Html_elem_focus(auto_focus_id);
}
else if (String_.Eq(html_doc_pos, gplx.xowa.gui.history.Xog_history_itm.Html_doc_pos_toc)) // NOTE: special case to handle TOC clicks; DATE:2013-07-17
Scroll_page_by_id("toc");
else
html_box.Html_window_vpos_(html_doc_pos);
}
public void Scroll_page_by_id_gui(String id) {GfoInvkAble_.InvkCmd_val(cmd_async, Invk_scroll_page_by_id, id);}
private boolean Scroll_page_by_id(String id) {
return (id == null)
? false
: html_box.Html_elem_scroll_into_view(app.Url_converter_id().Encode_str(id));
}
public void Js_enabled_(boolean v) {
html_box.Html_js_enabled_(v);
}
private void When_menu_detected() {
Xoa_gui_mgr gui_mgr = app.Gui_mgr(); Gfui_kit kit = gui_mgr.Kit();
Xog_popup_mnu_mgr popup_mnu_mgr = gui_mgr.Menu_mgr().Popup();
Xog_mnu_grp popup_mnu = popup_mnu_mgr.Html_page();
if (String_.Len_gt_0(this.Html_selected_get_src_or_empty()))
popup_mnu = popup_mnu_mgr.Html_file();
else if (String_.Len_gt_0(this.Html_selected_get_text_or_href()))
popup_mnu = popup_mnu_mgr.Html_link();
kit.Set_mnu_popup(html_box, popup_mnu.Under_mnu());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_html_img_update)) html_box.Html_elem_img_update(m.ReadStr("elem_id"), m.ReadStr("elem_src"), m.ReadInt("elem_width"), m.ReadInt("elem_height"));
else if (ctx.Match(k, Invk_html_elem_atr_set)) html_box.Html_elem_atr_set(m.ReadStr("elem_id"), m.ReadStr("atr_key"), m.ReadStr("atr_val"));
else if (ctx.Match(k, Invk_html_elem_atr_set_append)) html_box.Html_elem_atr_set_append(m.ReadStr("elem_id"), m.ReadStr("atr_key"), m.ReadStr("atr_val"));
else if (ctx.Match(k, Invk_html_elem_delete)) html_box.Html_elem_delete(m.ReadStr("elem_id"));
else if (ctx.Match(k, Invk_html_elem_replace_html)) html_box.Html_elem_replace_html(m.ReadStr("id"), m.ReadStr("html"));
else if (ctx.Match(k, Invk_html_gallery_packed_exec)) html_box.Html_gallery_packed_exec();
else if (ctx.Match(k, Invk_scroll_page_by_bmk)) Scroll_page_by_bmk();
else if (ctx.Match(k, Invk_scroll_page_by_id)) Scroll_page_by_id(m.ReadStr("v"));
else if (ctx.Match(k, Invk_html_elem_focus)) html_box.Html_elem_focus(m.ReadStr("v"));
else if (ctx.Match(k, GfuiElemKeys.Evt_menu_detected)) When_menu_detected();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_html_gallery_packed_exec = "html_gallery_packed_exec"
, Invk_html_img_update = "html_img_update", Invk_html_elem_atr_set = "html_elem_atr_set"
, Invk_html_elem_atr_set_append = "html_elem_atr_set_append", Invk_html_elem_delete = "html_elem_delete", Invk_html_elem_replace_html = "html_elem_replace_html"
, Invk_scroll_page_by_bmk = "scroll_page_by_bmk", Invk_scroll_page_by_id = "scroll_page_by_id"
;
public static final String
Elem_id__xowa_edit_data_box = "xowa_edit_data_box"
, Elem_id__xowa_edit_rename_box = "xowa_edit_rename_box"
, Elem_id__first_heading = "firstHeading"
, Invk_html_elem_focus = "html_elem_focus"
;
}
class Xog_html_itm__href_extractor {
private static final byte Text_tid_none = 0, Text_tid_text = 1, Text_tid_href = 2;
private static final byte Href_tid_wiki = 1, Href_tid_site = 2, Href_tid_anchor = 3;
private static final byte[] File_protocol_bry = Bry_.new_ascii_("file://");
private static final int File_protocol_len = File_protocol_bry.length;
private static final ByteTrieMgr_slim href_trie = ByteTrieMgr_slim.cs_()
.Add_str_byte("/site/" , Href_tid_site)
.Add_str_byte("/wiki/" , Href_tid_wiki)
.Add_str_byte("#" , Href_tid_anchor)
;
public static String Html_extract_text(String site, String page, String text_str) {
byte[] text_bry = Bry_.new_utf8_(text_str);
int text_tid = Byte_ascii.X_to_digit(text_bry[0]);
int text_len = text_bry.length;
switch (text_tid) {
case Text_tid_none: return "";
case Text_tid_text: return String_.new_utf8_(text_bry, 2, text_len); // 2 to skip "1|"
case Text_tid_href: break; // fall through to below
default: throw Err_.unhandled(text_tid);
}
int href_bgn = 2; // 2 for length of "2|"
if (Bry_.HasAtBgn(text_bry, File_protocol_bry, 2, text_len)) {
href_bgn += File_protocol_len; // skip "file://"
}
Byte_obj_val href_tid = (Byte_obj_val)href_trie.MatchAtCur(text_bry, href_bgn, text_len);
if (href_tid != null) {
switch (href_tid.Val()) {
case Href_tid_wiki: return site + String_.new_utf8_(text_bry, href_bgn, text_len);
case Href_tid_site: return String_.new_utf8_(text_bry, href_bgn + 6, text_len); // +6 to skip "site/"
case Href_tid_anchor: return site + "/wiki/" + page + String_.new_utf8_(text_bry, href_bgn, text_len);
}
}
return String_.new_utf8_(text_bry, 2, text_len); // 2 to skip "2|"; handles "http://" text as well as any fall-thru from above
}
public static final Xog_html_itm__href_extractor _ = new Xog_html_itm__href_extractor(); Xog_html_itm__href_extractor() {}
}

View File

@@ -0,0 +1,48 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import org.junit.*;
public class Xog_html_itm_tst {
@Before public void init() {fxt.Clear();} private Xog_html_itm_fxt fxt = new Xog_html_itm_fxt();
@Test public void Extract_href__text() {
fxt.Test_extract_href("0|" , "");
fxt.Test_extract_href("1|selected_text" , "selected_text");
fxt.Test_extract_href("2|http://a.org" , "http://a.org");
}
@Test public void Extract_href__file() {
fxt.Test_extract_href("2|file:///site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1");
fxt.Test_extract_href("2|file:///wiki/Page_2" , "en.wikipedia.org/wiki/Page_2");
fxt.Test_extract_href("2|file://#anchor" , "en.wikipedia.org/wiki/Page_0#anchor");
}
@Test public void Extract_href__internal() { //
fxt.Test_extract_href("2|/site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1");
fxt.Test_extract_href("2|/wiki/Page_2" , "en.wikipedia.org/wiki/Page_2");
fxt.Test_extract_href("2|#anchor" , "en.wikipedia.org/wiki/Page_0#anchor");
}
}
class Xog_html_itm_fxt {
public void Clear() {
cur_wiki = "en.wikipedia.org";
cur_page = "Page_0";
}
public String Cur_wiki() {return cur_wiki;} public Xog_html_itm_fxt Cur_wiki_(String v) {cur_wiki = v; return this;} private String cur_wiki;
public String Cur_page() {return cur_page;} public Xog_html_itm_fxt Cur_page_(String v) {cur_page = v; return this;} private String cur_page;
public void Test_extract_href(String text_str, String expd) {
Tfds.Eq(expd, Xog_html_itm__href_extractor.Html_extract_text(cur_wiki, cur_page, text_str));
}
}

View File

@@ -0,0 +1,187 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.threads.*; import gplx.xowa.xtns.pfuncs.ifs.*;
public class Xog_html_js_cbk implements GfoInvkAble {
private Xoa_app app;
private Xog_html_itm html_itm;
private Xop_root_tkn root = new Xop_root_tkn();
private Bry_bfr bfr = Bry_bfr.reset_(255);
public Xog_html_js_cbk(Xog_html_itm html_itm) {this.html_itm = html_itm; this.app = html_itm.Owner_tab().Tab_mgr().Win().App();}
private String Xowa_exec_test(GfoMsg m) { // concat args with pipe; EX: xowa_exec('proc', 'arg0', 'arg1'); -> proc|arg0|arg1
bfr.Clear();
bfr.Add_str(m.Key());
int len = m.Args_count();
for (int i = 0; i < len; i++)
bfr.Add_str("|").Add_str(m.Args_getAt(i).Val_to_str_or_empty());
return bfr.XtoStrAndClear();
}
private String[] Xowa_exec_test_as_array(GfoMsg m) {// return args as array; EX: xowa_exec('proc', 'arg0', 'arg1'); -> proc,arg0,arg1
bfr.Clear();
int len = m.Args_count();
String[] rv = new String[len + 1];
rv[0] = Invk_xowa_exec_test_as_array;
for (int i = 0; i < len; i++)
rv[i + 1] = Object_.XtoStr_OrEmpty(m.ReadValAt(i));
return rv;
}
private String Parse_to_html(GfoMsg m) {
Xoa_page page = html_itm.Owner_tab().Page();
Xow_wiki wiki = page.Wiki();
Xop_ctx ctx = wiki.Ctx();
boolean old_para_enabled = ctx.Para().Enabled();
byte[] raw = Bry_.new_utf8_(m.Args_getAt(0).Val_to_str_or_empty());
boolean para_enabled = m.Args_count() < 2 ? false : Bool_.parse_(m.Args_getAt(1).Val_to_str_or_empty());
try {
wiki.Ctx().Para().Enabled_(para_enabled);
wiki.Parser().Parse_text_to_wdom(root, wiki.Ctx(), wiki.Ctx().Tkn_mkr(), raw, 0);
byte[] data = root.Data_mid();
wiki.Html_mgr().Html_wtr().Write_all(bfr, wiki.Ctx(), data, root);
return bfr.XtoStrAndClear();
}
finally {
wiki.Ctx().Para().Enabled_(old_para_enabled);
}
}
private String Get_page(GfoMsg m) {
Xow_wiki wiki = html_itm.Owner_tab().Page().Wiki();
try {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, m.Args_getAt(0).Val_to_bry());
Xoa_page page = wiki.Data_mgr().Get_page(ttl, false);
return String_.new_utf8_(page.Data_raw());
} catch (Exception e) {Err_.Noop(e); return null;}
}
private String Popups_get_async_bgn(GfoMsg m) {
try {
byte[] js_cbk = m.Args_getAt(0).Val_to_bry();
byte[] href_bry = m.Args_getAt(1).Val_to_bry();
return html_itm.Owner_tab().Page().Wiki().Html_mgr().Module_mgr().Popup_mgr().Get_async_bgn(js_cbk, href_bry);
} catch (Exception e) {Err_.Noop(e); return null;}
}
private String Popups_get_html(GfoMsg m) {
try {
int popups_id = Int_.X_by_double_(Double_.cast_(m.Args_getAt(0).Val()));
byte[] href_bry = m.Args_getAt(1).Val_to_bry();
return html_itm.Owner_tab().Page().Wiki().Html_mgr().Module_mgr().Popup_mgr().Show_init(href_bry, popups_id);
} catch (Exception e) {Err_.Noop(e); return null;}
}
private String[] Get_title_meta(Xow_wiki wiki, byte[] ttl) {
Pfunc_ifexist.Exists(tmp_page, wiki.Ctx(), ttl);
return String_.Ary(tmp_page.Exists() ? "1" : "0", Int_.XtoStr(tmp_page.Id()), Int_.XtoStr(tmp_page.Ns_id()), String_.new_utf8_(tmp_page.Ttl_wo_ns()), Bool_.XtoStr_lower(tmp_page.Type_redirect()), tmp_page.Modified_on().XtoStr_fmt("yyyy-MM-dd HH:mm:ss"), Int_.XtoStr(tmp_page.Text_len()));
} private static final Xodb_page tmp_page = Xodb_page.tmp_();
private String[][] Get_titles_meta(GfoMsg m) {
Xow_wiki wiki = html_itm.Owner_tab().Page().Wiki();
try {
byte[][] ttls = Bry_.Split(Bry_.new_utf8_((String)m.ReadValAt(0)), Byte_ascii.NewLine);
int ttls_len = ttls.length;
String[][] rv = new String[ttls_len][];
for (int i = 0; i < ttls_len; i++) {
byte[] ttl = ttls[i];
rv[i] = Get_title_meta(wiki, ttl);
}
return rv;
} catch (Exception e) {Err_.Noop(e); return null;}
}
private boolean Get_title_exists(Xow_wiki wiki, byte[] ttl) {
return Pfunc_ifexist.Exists(tmp_page, wiki.Ctx(), ttl);
}
private String[] Get_titles_exists(GfoMsg m) {
Xow_wiki wiki = html_itm.Owner_tab().Page().Wiki();
try {
byte[][] ttls = Bry_.Ary_obj((Object[])m.ReadValAt(0));
int ttls_len = ttls.length;
String[] rv = new String[ttls_len];
for (int i = 0; i < ttls_len; i++) {
byte[] ttl = ttls[i];
rv[i] = Get_title_exists(wiki, ttl) ? "1" : "0";
}
return rv;
} catch (Exception e) {Err_.Noop(e); return null;}
}
private String Get_search_suggestions(GfoMsg m) {
Xow_wiki wiki = html_itm.Owner_tab().Page().Wiki();
byte[] search_str = Bry_.new_utf8_((String)m.ReadValAt(0));
byte[] cbk_func = Bry_.new_utf8_((String)m.ReadValAt(1));
app.Gui_mgr().Search_suggest_mgr().Search(wiki, search_str, cbk_func);
return "";
}
private String[] Wikidata_get_label(GfoMsg m) {
try {
ThreadAdp_.Sleep(10); // slow down calls to prevent random crashing in XulRunner; DATE:2014-04-23
gplx.xowa.xtns.wdatas.Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr();
wdata_mgr.Wdata_wiki().Init_assert(); // NOTE: must assert else ns_mgr won't load Property
int len = m.Args_count();
if (len < 1) return null;
byte[][] langs = Bry_.Split(m.Args_getAt(0).Val_to_bry(), Byte_ascii.Semic);
int langs_len = langs.length;
String[] rv = new String[len - 1];
for (int i = 1; i < len; i++) {
try {
byte[] ttl_bry = m.Args_getAt(i).Val_to_bry();
gplx.xowa.xtns.wdatas.Wdata_doc page = wdata_mgr.Pages_get(ttl_bry); if (page == null) continue;
for (int j = 0; j < langs_len; j++) {
byte[] lang_key = langs[j];
if (Bry_.Eq(lang_key, Wikidata_get_label_xowa_ui_lang))
lang_key = app.Sys_cfg().Lang();
byte[] val_bry = null;
if (Bry_.Eq(lang_key, Wikidata_get_label_xowa_title))
val_bry = ttl_bry;
else {
val_bry = page.Label_list_get(lang_key);
}
if (val_bry == null) continue;
rv[i - 1] = String_.new_utf8_(val_bry);
break;
}
} catch (Exception e) {Err_.Noop(e); rv[i] = null;}
finally {}
}
return rv;
} catch (Exception e) {Err_.Noop(e); return null;}
}
private String Scripts_exec(GfoMsg m) {
Object rv = null;
try {
rv = app.Gfs_mgr().Run_str(m.Args_getAt(0).Val_to_str_or_empty());
}
catch (Exception e) {Err_.Noop(e); return null;}
return Object_.XtoStr_OrEmpty(rv);
}
private static final byte[] Wikidata_get_label_xowa_ui_lang = Bry_.new_ascii_("xowa_ui_lang"), Wikidata_get_label_xowa_title = Bry_.new_ascii_("xowa_title");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_parse_to_html)) return Parse_to_html(m);
else if (ctx.Match(k, Invk_wikidata_get_label)) return Wikidata_get_label(m);
else if (ctx.Match(k, Invk_get_page)) return Get_page(m);
else if (ctx.Match(k, Invk_popups_get_async_bgn)) return Popups_get_async_bgn(m);
else if (ctx.Match(k, Invk_popups_get_html)) return Popups_get_html(m);
else if (ctx.Match(k, Invk_scripts_exec)) return Scripts_exec(m);
else if (ctx.Match(k, Invk_get_search_suggestions)) return Get_search_suggestions(m);
else if (ctx.Match(k, Invk_get_titles_meta)) return Get_titles_meta(m);
else if (ctx.Match(k, Invk_get_titles_exists)) return Get_titles_exists(m);
else if (ctx.Match(k, Invk_get_current_url)) return String_.new_utf8_(html_itm.Owner_tab().Page().Url().Raw());
else if (ctx.Match(k, Invk_xowa_exec_test)) return Xowa_exec_test(m);
else if (ctx.Match(k, Invk_xowa_exec_test_as_array))return Xowa_exec_test_as_array(m);
else return GfoInvkAble_.Rv_unhandled;
}
public static final String Invk_parse_to_html = "parse_to_html", Invk_wikidata_get_label = "wikidata_get_label", Invk_get_page = "get_page", Invk_scripts_exec = "scripts_exec"
, Invk_get_search_suggestions = "get_search_suggestions", Invk_get_titles_meta = "get_titles_meta", Invk_get_titles_exists = "get_titles_exists", Invk_get_current_url = "get_current_url"
, Invk_xowa_exec_test = "xowa_exec_test", Invk_xowa_exec_test_as_array = "xowa_exec_test_as_array"
, Invk_popups_get_async_bgn = "popups_get_async_bgn"
, Invk_popups_get_html = "popups_get_html"
;
}

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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import org.junit.*; import gplx.xowa.xtns.wdatas.*;
public class Xog_html_js_cbk_tst {
@Before public void init() {fxt.Clear();} private Xog_html_js_cbk_fxt fxt = new Xog_html_js_cbk_fxt();
@Test public void Get_title() {
fxt.Fxt().Init_page_create("exists");
fxt.Test_get_title("exists", "1" , "0" , Int_.XtoStr(Int_.MinValue), "Exists", "false", "0001-01-01 00:00:00", "0");
fxt.Test_get_title("absent", "0", "-1", Int_.XtoStr(Int_.MinValue), null , "false", "0001-01-01 00:00:00", "0");
}
}
class Xog_html_js_cbk_fxt {
public void Clear() {
fxt = new Xop_fxt();
Xoa_app_fxt.Init_gui(fxt.App());
} private Xop_fxt fxt;
public Xop_fxt Fxt() {return fxt;}
public void Test_get_title(String ttl, Object... expd) {
Xoa_app app = fxt.App();
Xow_wiki wiki = fxt.Wiki();
Xoa_page page = Xoa_page.test_(wiki, Xoa_ttl.parse_(wiki, Bry_.new_ascii_("mock_page")));
Xog_tab_itm tab = app.Gui_mgr().Browser_win().Active_tab();
tab.Page_(page);
Xog_html_js_cbk exec = tab.Html_itm().Js_cbk();
GfoMsg msg = GfoMsg_.new_cast_(Xog_html_js_cbk.Invk_get_titles_meta).Add("ttl", ttl);
String[][] actl = (String[][])GfoInvkAble_.InvkCmd_msg(exec, Xog_html_js_cbk.Invk_get_titles_meta, msg);
Tfds.Eq_ary_str(expd, actl[0]);
}
}

View File

@@ -0,0 +1,63 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import org.junit.*; import gplx.xowa.xtns.wdatas.*;
public class Xog_html_js_cbk_wdata_labels_tst {
@Before public void init() {fxt.Init();} Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt();
@Test public void Basic() {
fxt.Init_pages_add(fxt.page_bldr_("q1").Label_add("en", "en_q1").Xto_page_doc());
fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "en_q2").Xto_page_doc());
fxt.Init_pages_add(fxt.page_bldr_("Property:P1").Label_add("en", "en_property_p1").Xto_page_doc());
Tst_wikidata_label_get(String_.Ary("en", "q1", "q2", "Property:P1"), String_.Ary("en_q1", "en_q2", "en_property_p1"));
}
@Test public void Outliers() {
fxt.Init_pages_add(fxt.page_bldr_("q1").Label_add("en", "en_q1").Label_add("de", "de_q1").Xto_page_doc());
Tst_wikidata_label_get(String_.Ary("fr", "q1"), String_.Ary((String)null));
Tst_wikidata_label_get(String_.Ary("de", "q1"), String_.Ary("de_q1"));
Tst_wikidata_label_get(String_.Ary("xowa_title", "q1"), String_.Ary("q1"));
Tst_wikidata_label_get(String_.Ary("xowa_ui_lang", "q1"), String_.Ary("en_q1"));
Tst_wikidata_label_get(String_.Ary("fr;de", "q1"), String_.Ary("de_q1"));
}
@Test public void Escaped() { // PURPOSE: \t should be escaped; EX:wd.q:2; DATE:2014-04-23
Wdata_doc d = doc_("q1", String_.Concat_lines_nl
( "{ 'entity':['item',1]"
, ", 'label':"
, " { 'en':'\\ta'" // NOTE: json literally has "\t", not (char)8
, " }"
, "}"
));
fxt.Init_pages_add(d);
Tst_wikidata_label_get(String_.Ary("en", "q1"), String_.Ary("\ta"));
}
private Wdata_doc doc_(String qid, String src) {
gplx.json.Json_doc doc = gplx.json.Json_doc.new_apos_(src);
Xoa_app app = Xoa_app_fxt.app_();
Wdata_doc rv = new Wdata_doc(Bry_.new_ascii_(qid), app.Wiki_mgr().Wdata_mgr(), doc);
return rv;
}
private void Tst_wikidata_label_get(String[] args, String[] expd) {
Xoa_app_fxt.Init_gui(fxt.App());
Xog_html_js_cbk exec = fxt.App().Gui_mgr().Browser_win().Active_html_itm().Js_cbk();
GfoMsg msg = GfoMsg_.new_cast_(Xog_html_js_cbk.Invk_wikidata_get_label);
int args_len = args.length;
for (int i = 0; i < args_len; i++)
msg.Add("v", args[i]);
String[] actl = (String[])GfoInvkAble_.InvkCmd_msg(exec, Xog_html_js_cbk.Invk_wikidata_get_label, msg);
Tfds.Eq_ary_str(expd, actl);
}
}

View File

@@ -0,0 +1,109 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xog_layout implements GfoInvkAble {
public Xog_layout() {
go_bwd_btn.Owner_(this);
go_fwd_btn.Owner_(this);
url_box.Owner_(this);
url_exec_btn.Owner_(this);
find_close_btn.Owner_(this);
search_box.Owner_(this);
search_exec_btn.Owner_(this);
html_box.Owner_(this);
find_box.Owner_(this);
prog_box.Owner_(this);
note_box.Owner_(this);
main_win.Owner_(this);
}
public Xog_layout_box Go_fwd_btn() {return go_fwd_btn;} private Xog_layout_box go_fwd_btn = new Xog_layout_box();
public Xog_layout_box Go_bwd_btn() {return go_bwd_btn;} private Xog_layout_box go_bwd_btn = new Xog_layout_box();
public Xog_layout_box Url_box() {return url_box;} private Xog_layout_box url_box = new Xog_layout_box();
public Xog_layout_box Url_exec_btn() {return url_exec_btn;} private Xog_layout_box url_exec_btn = new Xog_layout_box();
public Xog_layout_box Find_close_btn() {return find_close_btn;} private Xog_layout_box find_close_btn = new Xog_layout_box();
public Xog_layout_box Search_box() {return search_box;} private Xog_layout_box search_box = new Xog_layout_box();
public Xog_layout_box Search_exec_btn() {return search_exec_btn;} private Xog_layout_box search_exec_btn = new Xog_layout_box();
public Xog_layout_box Html_box() {return html_box;} private Xog_layout_box html_box = new Xog_layout_box();
public Xog_layout_box Find_box() {return find_box;} private Xog_layout_box find_box = new Xog_layout_box();
public Xog_layout_box Find_fwd_btn() {return find_fwd_btn;} private Xog_layout_box find_fwd_btn = new Xog_layout_box();
public Xog_layout_box Find_bwd_btn() {return find_bwd_btn;} private Xog_layout_box find_bwd_btn = new Xog_layout_box();
public Xog_layout_box Prog_box() {return prog_box;} private Xog_layout_box prog_box = new Xog_layout_box();
public Xog_layout_box Note_box() {return note_box;} private Xog_layout_box note_box = new Xog_layout_box();
public Xog_layout_box Browser_win() {return main_win;} private Xog_layout_box main_win = new Xog_layout_box();
public void Find_show() {
Visible_(true, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
GfuiTextBox find_box = win.Find_box();
find_box.Focus();
int text_len = String_.Len(find_box.Text());
if (text_len > 0) { // if text exists, select it; GUI:Firefox
find_box.SelBgn_set(0);
find_box.SelLen_set(text_len);
}
}
public void Find_close() {
Visible_(false, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
win.Active_html_box().Focus();
}
private void Visible_(boolean v, GfuiElem... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++)
ary[i].Visible_set(v);
}
public void Init(Xog_win_itm win) {
this.win = win;
go_bwd_btn.Adj_text(win.Go_bwd_btn());
go_fwd_btn.Adj_text(win.Go_fwd_btn());
url_box.Adj_text(win.Url_box());
url_exec_btn.Adj_text(win.Url_exec_btn());
find_close_btn.Adj_text(win.Find_close_btn());
search_box.Adj_text(win.Search_box());
search_exec_btn.Adj_text(win.Search_exec_btn());
find_box.Adj_text(win.Find_box());
find_fwd_btn.Adj_text(win.Find_fwd_btn());
find_bwd_btn.Adj_text(win.Find_bwd_btn());
prog_box.Adj_text(win.Prog_box());
note_box.Adj_text(win.Info_box());
Visible_(false, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
} private Xog_win_itm win;
public int Box_height_calc(Gfui_kit kit, GfuiElem url_box) {
if (box_height > 0) return box_height;
float font_height = kit.Calc_font_height(url_box, "I");
box_height = (int)(font_height * 2);
return box_height;
} private int box_height = 0;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_go_fwd_btn)) return go_fwd_btn;
else if (ctx.Match(k, Invk_go_bwd_btn)) return go_bwd_btn;
else if (ctx.Match(k, Invk_url_box)) return url_box;
else if (ctx.Match(k, Invk_url_exec_btn)) return url_exec_btn;
else if (ctx.Match(k, Invk_find_close_btn)) return find_close_btn;
else if (ctx.Match(k, Invk_search_box)) return search_box;
else if (ctx.Match(k, Invk_search_exec_btn)) return search_exec_btn;
else if (ctx.Match(k, Invk_html_box)) return html_box;
else if (ctx.Match(k, Invk_find_box)) return find_box;
else if (ctx.Match(k, Invk_find_fwd_btn)) return find_fwd_btn;
else if (ctx.Match(k, Invk_find_bwd_btn)) return find_bwd_btn;
else if (ctx.Match(k, Invk_prog_box)) return prog_box;
else if (ctx.Match(k, Invk_note_box)) return note_box;
else if (ctx.Match(k, Invk_main_win)) return main_win;
else return GfoInvkAble_.Rv_unhandled;
}
static final String Invk_coord_mode_ = "coord_mode_", Invk_go_fwd_btn = "go_fwd_btn", Invk_go_bwd_btn = "go_bwd_btn", Invk_url_box = "url_box", Invk_search_box = "search_box", Invk_html_box = "html_box", Invk_find_box = "find_box", Invk_prog_box = "prog_box", Invk_note_box = "note_box"
, Invk_main_win = "main_win", Invk_find_fwd_btn = "find_fwd_btn", Invk_find_bwd_btn = "find_bwd_btn", Invk_url_exec_btn = "url_exec_btn", Invk_search_exec_btn = "search_exec_btn", Invk_find_close_btn = "find_close_btn";
}

View File

@@ -0,0 +1,83 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*;
public class Xog_layout_box implements GfoInvkAble {
public GfoInvkAble Owner() {return owner;} public Xog_layout_box Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
public int X_abs() {return x_abs;} public Xog_layout_box X_abs_(int v) {x_abs = v; return this;} private int x_abs = Int_.MinValue;
public int Y_abs() {return y_abs;} public Xog_layout_box Y_abs_(int v) {y_abs = v; return this;} private int y_abs = Int_.MinValue;
public int W_abs() {return w_abs;} public Xog_layout_box W_abs_(int v) {w_abs = v; return this;} private int w_abs = Int_.MinValue;
public int H_abs() {return h_abs;} public Xog_layout_box H_abs_(int v) {h_abs = v; return this;} private int h_abs = Int_.MinValue;
public int X_rel() {return x_rel;} public Xog_layout_box X_rel_(int v) {x_rel = v; return this;} private int x_rel = Int_.MinValue;
public int Y_rel() {return y_rel;} public Xog_layout_box Y_rel_(int v) {y_rel = v; return this;} private int y_rel = Int_.MinValue;
public int W_rel() {return w_rel;} public Xog_layout_box W_rel_(int v) {w_rel = v; return this;} private int w_rel = Int_.MinValue;
public int H_rel() {return h_rel;} public Xog_layout_box H_rel_(int v) {h_rel = v; return this;} private int h_rel = Int_.MinValue;
public String Text() {return text;} public Xog_layout_box Text_(String v) {text = v; return this;} private String text;
public String Font_name() {return font_name;} public Xog_layout_box Font_name_(String v) {font_name = v; return this;} private String font_name;
public float Font_size() {return font_size;} public Xog_layout_box Font_size_(float v) {font_size = v; return this;} float font_size = Float_.NaN;
public FontStyleAdp Font_style() {return font_style;} public Xog_layout_box Font_style_(FontStyleAdp v) {font_style = v; return this;} FontStyleAdp font_style;
public byte Mode() {return mode;} public Xog_layout_box Mode_(byte v) {mode = v; return this;} private byte mode = Mode_rel;
public void Adj_size(Rect_ref rect) {
if (w_abs > -1) rect.W_(w_abs); if (w_rel != Int_.MinValue) rect.W_(w_rel + rect.W());
if (h_abs > -1) rect.H_(h_abs); if (h_rel != Int_.MinValue) rect.H_(h_rel + rect.H());
}
public void Adj_pos(Rect_ref rect) {
if (x_abs > -1) rect.X_(x_abs); if (x_rel != Int_.MinValue) rect.X_(x_rel + rect.X());
if (y_abs > -1) rect.Y_(y_abs); if (y_rel != Int_.MinValue) rect.Y_(y_rel + rect.Y());
}
public void Adj_text(GfuiElem elem) {
if (text != null) elem.Text_(text);
if (font_name != null || !Float_.IsNaN(font_size) || font_style != null)
elem.TextMgr().Font_(Font_make(font_name, font_size, font_style));
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_x_abs_)) x_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_y_abs_)) y_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_w_abs_)) w_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_h_abs_)) h_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_x_rel_)) x_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_y_rel_)) y_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_w_rel_)) w_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_h_rel_)) h_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_size_abs_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {w_abs = ary[0]; h_abs = ary[1];}}
else if (ctx.Match(k, Invk_size_rel_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {w_rel = ary[0]; h_rel = ary[1];}}
else if (ctx.Match(k, Invk_pos_abs_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {x_abs = ary[0]; y_abs = ary[1];}}
else if (ctx.Match(k, Invk_pos_rel_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {x_rel = ary[0]; y_rel = ary[1];}}
else if (ctx.Match(k, Invk_rect_abs_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 4, null); if (ary != null) {w_abs = ary[0]; h_abs = ary[1]; x_abs = ary[2]; y_abs = ary[3];}}
else if (ctx.Match(k, Invk_rect_rel_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 4, null); if (ary != null) {w_rel = ary[0]; h_rel = ary[1]; x_rel = ary[2]; y_rel = ary[3];}}
else if (ctx.Match(k, Invk_text_)) text = m.ReadStr("v");
else if (ctx.Match(k, Invk_font_name_)) font_name = m.ReadStr("v");
else if (ctx.Match(k, Invk_font_size_)) font_size = m.ReadFloat("v");
else if (ctx.Match(k, Invk_font_style_)) font_style = FontStyleAdp_.parse_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_mode_)) mode = String_.Eq(m.ReadStr("v"), "abs") ? Mode_abs : Mode_rel;
else if (ctx.Match(k, Invk_owner)) return owner;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final byte Mode_abs = 0, Mode_rel = 1;
static final String Invk_x_abs_ = "x_abs_", Invk_y_abs_ = "y_abs_", Invk_w_abs_ = "w_abs_", Invk_h_abs_ = "h_abs_", Invk_x_rel_ = "x_rel_", Invk_y_rel_ = "y_rel_", Invk_w_rel_ = "w_rel_", Invk_h_rel_ = "h_rel_"
, Invk_size_abs_ = "size_abs_", Invk_pos_abs_ = "pos_abs_", Invk_rect_abs_ = "rect_abs_", Invk_size_rel_ = "size_rel_", Invk_pos_rel_ = "pos_rel_", Invk_rect_rel_ = "rect_rel_"
, Invk_text_ = "text_"
, Invk_font_name_ = "font_name_", Invk_font_size_ = "font_size_", Invk_font_style_ = "font_style_", Invk_mode_ = "mode_", Invk_owner = "owner";
FontAdp Font_make(String font_name, float font_size, FontStyleAdp font_style) {
String new_font_name = font_name == null ? "Arial" : font_name;
float new_font_size = Float_.IsNaN(font_size) ? 8 : font_size;
FontStyleAdp new_font_style = font_style == null ? FontStyleAdp_.Plain : font_style;
return FontAdp.new_(new_font_name, new_font_size, new_font_style);
}
}

View File

@@ -0,0 +1,254 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.threads.*; import gplx.gfui.*; import gplx.xowa.gui.history.*; import gplx.xowa.gui.bnds.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.cfgs2.*;
public class Xog_tab_itm implements GfoInvkAble {
private Xog_win_itm win; private Xocfg_tab_mgr cfg_tab_mgr;
public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data) {
this.tab_mgr = tab_mgr; this.tab_data = tab_data;
this.win = tab_mgr.Win(); this.cfg_tab_mgr = win.App().Cfg_regy ().App().Gui_mgr().Tab_mgr();
html_itm = new Xog_html_itm(this);
cmd_sync = win.Kit().New_cmd_sync(this);
}
public GfoInvkAble Cmd_sync() {return cmd_sync;} private GfoInvkAble cmd_sync;
public void Make_html_box(int uid, Gfui_tab_itm tab_box, Xog_win_itm win, GfuiElem owner) {
this.tab_box = tab_box;
Xoa_app app = win.App(); Xoa_gui_mgr gui_mgr = win.Gui_mgr(); Gfui_kit kit = win.Kit();
Gfui_html html_box = kit.New_html("html_box" + Int_.XtoStr(uid), owner);
html_box.Html_js_enabled_(gui_mgr.Html_mgr().Javascript_enabled());
html_box.Html_invk_src_(win);
html_itm.Html_box_(html_box);
if (app.Mode() == Xoa_app_.Mode_gui) { // NOTE: only run for gui; will cause firefox addon to fail; DATE:2014-05-03
html_box.Html_doc_html_(""); // NOTE: must set source, else control will be empty, and key events will not be raised; DATE:2014-04-30
IptBnd_.ipt_to_(IptCfg_.Null, html_box, this, "popup", IptEventType_.MouseDown, IptMouseBtn_.Right);
GfoEvMgr_.SubSame(html_box, GfuiElemKeys.Evt_menu_detected, html_itm);
gui_mgr.Bnd_mgr().Bind(Xog_bnd_box_.Tid_browser_html, html_box);
if (!Env_.Mode_testing())
kit.Set_mnu_popup(html_box, gui_mgr.Menu_mgr().Popup().Html_page().Under_mnu());
}
}
public void Switch_mem(Xog_tab_itm comp) {
html_itm.Switch_mem(comp.html_itm); // switch html_itm.owner_tab reference only
Xog_html_itm temp_html_itm = html_itm; // switch .html_itm, since the underlying CTabFolder has reparented the control
this.html_itm = comp.html_itm;
comp.html_itm = temp_html_itm;
Xoa_page temp_page = page; // switch .page, since its underlying html_box has changed and .page must reflect html_box
this.page = comp.page;
comp.page = temp_page;
page.Tab_(this); comp.Page().Tab_(comp);
byte temp_view_mode = view_mode; // switch .view_mode to match .page
this.view_mode = comp.view_mode;
comp.view_mode = temp_view_mode;
Xog_history_mgr temp_history_mgr = history_mgr; // switch .history_mgr along with .page
this.history_mgr = comp.history_mgr;
comp.history_mgr = temp_history_mgr;
}
public Gfui_tab_itm_data Tab_data() {return tab_data;} private Gfui_tab_itm_data tab_data;
public String Tab_key() {return tab_data.Key();}
public int Tab_idx() {return tab_data.Idx();} public void Tab_idx_(int v) {tab_data.Idx_(v);}
public Xog_tab_mgr Tab_mgr() {return tab_mgr;} private Xog_tab_mgr tab_mgr;
public Gfui_tab_itm Tab_box() {return tab_box;} private Gfui_tab_itm tab_box;
public boolean Tab_is_loading() {return tab_is_loading;} private boolean tab_is_loading;
public Xog_html_itm Html_itm() {return html_itm;} private Xog_html_itm html_itm;
public Gfui_html Html_box() {return html_itm.Html_box();}
public Xoa_page Page() {return page;}
public void Page_(Xoa_page page) {Page_(true, page);}
public void Page_(boolean update_ui, Xoa_page page) {
this.page = page;
if (update_ui) {
this.Tab_name_();
tab_box.Tab_tip_text_(String_.new_utf8_(page.Url().X_to_full()));
}
} private Xoa_page page;
public void Tab_name_() {
byte[] tab_name = page.Html_data().Custom_name();
if (tab_name == null) tab_name = page.Ttl().Full_txt();
Tab_name_(String_.new_utf8_(tab_name));
}
public void Tab_name_(String tab_name) {
Xocfg_tab_btn_mgr cfg_tab_btn_mgr = cfg_tab_mgr.Btn_mgr();
tab_name = Xog_tab_itm_.Tab_name_min(tab_name, cfg_tab_btn_mgr.Text_min_chars());
tab_name = Xog_tab_itm_.Tab_name_max(tab_name, cfg_tab_btn_mgr.Text_max_chars());
tab_box.Tab_name_(tab_name);
}
public Xog_history_mgr History_mgr() {return history_mgr;} private Xog_history_mgr history_mgr = new Xog_history_mgr();
public byte View_mode() {return view_mode;} public Xog_tab_itm View_mode_(byte v) {view_mode = v; return this;} private byte view_mode = Xog_page_mode.Tid_read;
public void Pin_toggle() {
}
public void Show_url_bgn(Xoa_url url) {
this.tab_is_loading = true;
Xoa_app app = win.App(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
Xoa_page page = Xoa_page.Empty;
if ( url.Anchor_str() != null // url has anchor
&& url.Eq_page(page.Url()) // url has same page_name as existing page
&& url.Args().length == 0) { // url has no args; needed for Category:A?from=b#mw-pages
html_itm.Scroll_page_by_id_gui(url.Anchor_str()); // skip page_load and jump to anchor
return;
}
if (win.Page__async__working(url)) return;
app.Gui_mgr().Search_suggest_mgr().Cancel(); // cancel pending search_suggest calls
app.Log_wtr().Queue_enabled_(true);
usr_dlg.Clear();
Xow_wiki wiki = url.Wiki();
wiki.Init_assert(); // NOTE: assert wiki.Init before parsing; needed b/c lang (with lang-specific ns) is only loaded on init, and parse Xoa_ttl.parse_ will fail below; EX:pt.wikipedia.org/wiki/Wikipedia:P<>gina principal
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, url.Page_bry());
if (ttl == null) {usr_dlg.Prog_one("", "", "title is invalid: ~{0}", String_.new_utf8_(url.Raw())); return;}
usr_dlg.Prog_one("", "", "loading: ~{0}", String_.new_utf8_(ttl.Raw()));
this.Html_box().Html_js_eval_script("xowa_popups_hide_all();");
app.Thread_mgr().Page_load_mgr().Add_at_end(new Load_page_wkr(this, wiki, url, ttl)).Run();
}
public void Show_url_loaded(Xoa_page page) {
Xow_wiki wiki = page.Wiki(); Xoa_url url = page.Url(); Xoa_ttl ttl = page.Ttl();
Xoa_app app = wiki.App(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
try {
wiki.Ctx().Cur_page_(page);
if (page.Missing()) {
if (wiki.Db_mgr().Save_mgr().Create_enabled()) {
page = Xoa_page.create_(wiki, ttl);
view_mode = Xog_page_mode.Tid_edit;
history_mgr.Add(page); // NOTE: must put new_page on stack so that pressing back will pop new_page, not previous page
Xog_tab_itm_read_mgr.Show_page(this, page, false);
}
else {
if (page.Redirect_list().Count() > 0)
usr_dlg.Prog_many("", "", "could not find: ~{0} (redirected from ~{1})", String_.new_utf8_(page.Url().Page_bry()), String_.new_utf8_((byte[])page.Redirect_list().FetchAt(0)));
else {
if (ttl.Ns().Id_file())
usr_dlg.Prog_one("", "", "commons.wikimedia.org must be installed in order to view the file. See [[Help:Wikis/Commons]]: ~{0}", String_.new_utf8_(url.Raw()));
else
usr_dlg.Prog_one("", "", "could not find: ~{0}", String_.new_utf8_(url.Raw()));
}
}
app.Log_wtr().Queue_enabled_(false);
return;
}
if (!page.Redirected()) page.Url_(url); // NOTE: handle redirect from commons
if (page.Ttl().Anch_bgn() != Bry_.NotFound) page.Url().Anchor_bry_(page.Ttl().Anch_txt()); // NOTE: occurs when page is a redirect to an anchor; EX: w:Duck race -> Rubber duck#Races
history_mgr.Add(page);
Xog_tab_itm_read_mgr.Show_page(this, page, true);
if (app.Api_root().Usr().History().Enabled()) app.User().History_mgr().Add(page);
usr_dlg.Prog_none("", "", "rendering html");
// win.Page__async__bgn(this);
app.Thread_mgr().File_load_mgr().Add_at_end(new Load_files_wkr(this)).Run();
}
finally {
app.Thread_mgr().Page_load_mgr().Resume();
this.tab_is_loading = false;
}
}
@gplx.Internal protected void Show_url_failed(Load_page_wkr wkr) {
try {
Xog_tab_itm_read_mgr.Show_page_err(win, this, wkr.Wiki(), wkr.Url(), wkr.Ttl(), wkr.Exc());
} finally {
wkr.Wiki().App().Thread_mgr().Page_load_mgr().Resume();
}
}
public void Async() {
if (page == null) return; // TEST: occurs during Xog_win_mgr_tst
Xow_wiki wiki = page.Wiki(); Xoa_app app = wiki.App(); Xog_win_itm win_itm = tab_mgr.Win(); Gfo_usr_dlg usr_dlg = win_itm.Usr_dlg();
app.Usr_dlg().Log_many("", "", "page.async: url=~{0}", page.Url().X_to_full_str_safe());
if (page.Url().Anchor_str() != null) html_itm.Scroll_page_by_id_gui(page.Url().Anchor_str());
if (usr_dlg.Canceled()) {usr_dlg.Prog_none("", "", ""); app.Log_wtr().Queue_enabled_(false); return;}
int xfer_len = 0;
xfer_len = page.File_queue().Count();
String page_ttl_str = String_.new_utf8_(page.Ttl().Raw());
if (xfer_len > 0){
usr_dlg.Prog_one("", "", "downloading images: ~{0}", xfer_len);
try {page.File_queue().Exec(gplx.xowa.files.Xof_exec_tid.Tid_wiki_page, usr_dlg, wiki, page);}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.image: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
}
xfer_len = page.File_math().Count();
if (xfer_len > 0){
try {
usr_dlg.Prog_one("", "", "generating math: ~{0}", xfer_len);
for (int i = 0; i < xfer_len; i++) {
if (usr_dlg.Canceled()) {usr_dlg.Prog_none("", "", ""); app.Log_wtr().Queue_enabled_(false); return;}
gplx.xowa.xtns.math.Xof_math_itm itm = (gplx.xowa.xtns.math.Xof_math_itm)page.File_math().FetchAt(i);
String queue_msg = usr_dlg.Prog_many("", "", "generating math ~{0} of ~{1}: ~{2}", i + ListAdp_.Base1, xfer_len, String_.new_utf8_(itm.Math()));
app.File_mgr().Math_mgr().MakePng(itm.Math(), itm.Hash(), itm.Png_url(), queue_msg);
gplx.gfui.SizeAdp size = app.File_mgr().Img_mgr().Wkr_query_img_size().Exec(itm.Png_url());
html_itm.Html_img_update("xowa_math_img_" + itm.Id(), itm.Png_url().To_http_file_str(), size.Width(), size.Height());
html_itm.Html_elem_delete("xowa_math_txt_" + itm.Id());
}
page.File_math().Clear();
}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.math: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
}
if (page.Html_cmd_mgr().Count() > 0) {
try {page.Html_cmd_mgr().Exec(app, page);}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.cmds: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
}
try {
Xop_lnki_logger_redlinks_wkr redlinks_wkr = new Xop_lnki_logger_redlinks_wkr(win_itm, page);
ThreadAdp_.invk_(redlinks_wkr, gplx.xowa.parsers.lnkis.redlinks.Xop_lnki_logger_redlinks_wkr.Invk_run).Start();
usr_dlg.Prog_none("", "imgs.done", "");
} catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.redlinks: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
try {app.File_mgr().Cache_mgr().Compress_check();}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.cache: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
app.Log_wtr().Queue_enabled_(false);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_show_url_loaded_swt)) this.Show_url_loaded((Xoa_page)m.ReadObj("v"));
else if (ctx.Match(k, Invk_show_url_failed_swt)) this.Show_url_failed((Load_page_wkr)m.ReadObj("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_show_url_loaded_swt = "show_url_loaded_swt", Invk_show_url_failed_swt = "show_url_failed_swt";
}
class Load_page_wkr implements Gfo_thread_wkr {
private Xog_tab_itm tab;
public Load_page_wkr(Xog_tab_itm tab, Xow_wiki wiki, Xoa_url url, Xoa_ttl ttl) {this.tab = tab; this.wiki = wiki; this.url = url; this.ttl = ttl;}
public String Name() {return "xowa.load_page_wkr";}
public boolean Resume() {return false;}
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Xoa_url Url() {return url;} private Xoa_url url;
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
public Exception Exc() {return exc;} private Exception exc;
public void Exec() {
try {
Xoa_app app = wiki.App();
app.Usr_dlg().Log_many("", "", "page.load: url=~{0}", url.X_to_full_str_safe());
if (Env_.System_memory_free() < app.Sys_cfg().Free_mem_when()) // check if low in memory
app.Free_mem(false); // clear caches (which will clear bry_bfr_mk)
else // not low in memory
app.Utl_bry_bfr_mkr().Clear(); // clear bry_bfr_mk only; NOTE: call before page parse, not when page is first added, else threading errors; DATE:2014-05-30
Xoa_page page = wiki.GetPageByTtl(url, ttl, tab);
GfoInvkAble_.InvkCmd_val(tab.Cmd_sync(), Xog_tab_itm.Invk_show_url_loaded_swt, page);
}
catch (Exception e) {
this.exc = e;
GfoInvkAble_.InvkCmd_val(tab.Cmd_sync(), Xog_tab_itm.Invk_show_url_failed_swt, this);
}
}
}
class Load_files_wkr implements Gfo_thread_wkr {
private Xog_tab_itm tab;
public Load_files_wkr(Xog_tab_itm tab) {this.tab = tab;}
public String Name() {return "xowa.load_files_wkr";}
public boolean Resume() {return true;}
public void Exec() {
try {tab.Async();}
catch (Exception e) {
tab.Tab_mgr().Win().App().Usr_dlg().Warn_many("error while running file wkr; page=~{0} err=~{1}", tab.Page().Url().X_to_full_str(), Err_.Message_gplx_brief(e));
}
}
}

View File

@@ -0,0 +1,30 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
public class Xog_tab_itm_ {
public static String Tab_name_min(String name, int min) {
int name_len = String_.Len(name);
return min == Tab_name_min_disabled || name_len > min ? name : name + String_.Repeat(" ", min - name_len);
}
public static String Tab_name_max(String name, int max) {
int name_len = String_.Len(name);
return max == Tab_name_max_disabled || name_len <= max ? name : String_.Mid(name, 0, max) + "...";
}
public static final int Tab_name_min_disabled = -1, Tab_name_max_disabled = -1;
public static final Xog_tab_itm Null = null;
}

View File

@@ -0,0 +1,123 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.html.*;
public class Xog_tab_itm_edit_mgr {
public static void Save(Xog_tab_itm tab, boolean quick_save) {
if (tab.View_mode() != Xog_page_mode.Tid_edit) return; // exit if not edit; handles ctrl+s being pressed on read/html modes
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
byte[] new_text = Get_new_text(tab);
if (page.Edit_mode() == Xoa_page_.Edit_mode_create) {
wiki.Db_mgr().Save_mgr().Data_create(page.Ttl(), new_text);
page.Edit_mode_update_(); // set to update so that next save does not try to create
}
else
wiki.Db_mgr().Save_mgr().Data_update(page, new_text);
Invalidate(wiki);
page.Data_raw_(new_text);
wiki.ParsePage_root(page, true); // refresh html
win_itm.Usr_dlg().Prog_one("", "", "saved page ~{0}", String_.new_utf8_(page.Ttl().Full_txt_raw())); // NOTE: show message after ParsePage_root, b/c ParsePage_root will flash "Loading page"; DATE:2014-05-17
if (!quick_save) { // full_save; save page and go to read mode
page.Html_data().Edit_preview_(Bry_.Empty);
Xoa_page stack_page = tab.History_mgr().Cur_page(wiki); // NOTE: must be to CurPage() else changes will be lost when going Bwd,Fwd
stack_page.Data_raw_(page.Data_raw()); // NOTE: overwrite with "saved" changes
stack_page.Wiki().ParsePage_root(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
win_itm.Page__mode_(Xog_page_mode.Tid_read);
win_itm.Page__async__bgn(tab);
}
}
public static void Preview(Xog_tab_itm tab) {
if (tab.View_mode() != Xog_page_mode.Tid_edit) return; // exit if not edit; handles preview somehow being called?
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
Xog_html_itm html_itm = tab.Html_itm();
byte[] new_text = Get_new_text(tab);
Xoa_page new_page = Xoa_page.new_(wiki, page.Ttl());
new_page.Revision_data().Id_(page.Revision_data().Id()); // NOTE: page_id needed for sqlite (was not needed for xdat)
new_page.Data_raw_(new_text);
wiki.ParsePage_root(new_page, true); // refresh html
tab.Page_(new_page);
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xog_page_mode.Tid_read);
wkr.Page_(new_page);
wkr.XferAry(tmp_bfr, 0);
byte[] new_html = tmp_bfr.Mkr_rls().XtoAryAndClear();
new_page.Html_data().Edit_preview_(new_html);
Invalidate(wiki);
win_itm.Page__mode_(Xog_page_mode.Tid_edit);
html_itm.Scroll_page_by_id_gui(Xog_html_itm.Elem_id__first_heading);// NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
win_itm.Page__async__bgn(tab); // NOTE: needed to show images during preview; DATE:2014-06-21
}
public static void Rename(Xog_tab_itm tab) {
if (tab.View_mode() != Xog_page_mode.Tid_edit) return; // exit if not edit; handles ctrl+r being pressed
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
if (Bry_.Eq(page.Ttl().Page_db(), wiki.Props().Main_page())) {
win_itm.Usr_dlg().Warn_many("", "", "The Main Page cannot be renamed");
return;
}
byte[] new_text = Bry_.new_utf8_(tab.Html_itm().Get_elem_value(Xog_html_itm.Elem_id__xowa_edit_rename_box));
if (Bry_.Len_eq_0(new_text)) return; // no ttl given; exit
new_text = Xoa_ttl.Replace_spaces(new_text); // ttls cannot have spaces; only underscores
Xoa_ttl new_ttl = Xoa_ttl.parse_(wiki, new_text);
int new_ns_id = new_ttl.Ns().Id();
if (new_ns_id != Xow_ns_.Id_main) {
win_itm.Usr_dlg().Warn_many("", "", "The new page name must remain in the same namespace");
return;
}
wiki.Db_mgr().Save_mgr().Data_rename(page, new_ns_id, new_text);
page.Ttl_(Xoa_ttl.parse_(wiki, Bry_.Add(page.Ttl().Ns().Name_db_w_colon(), new_text)));
win_itm.Page__mode_(Xog_page_mode.Tid_read);
win_itm.Usr_dlg().Prog_one("", "", "renamed page to {0}", String_.new_utf8_(page.Ttl().Full_txt_raw()));
}
public static void Focus(Xog_win_itm win, String elem_focus_id) {
Gfui_html html_box = win.Active_html_box();
html_box.Focus();
html_box.Html_elem_focus(elem_focus_id);
}
public static void Debug(Xog_win_itm win, byte view_tid) {
Xog_tab_itm tab = win.Tab_mgr().Active_tab(); Xoa_page page = tab.Page();
Xow_wiki wiki = page.Wiki(); Xop_ctx ctx = wiki.Ctx();
ctx.Defn_trace().Clear(); // TODO: move_me
ctx.Defn_trace_(Xot_defn_trace_dbg._);
Xoa_ttl ttl = page.Ttl();
Xoa_page new_page = Xoa_page.new_(page.Wiki(), ttl);
byte[] data = tab.Html_itm().Get_elem_value_for_edit_box_as_bry();
new_page.Data_raw_(data);
wiki.ParsePage_root(new_page, true);
Bry_bfr bfr = win.App().Utl_bry_bfr_mkr().Get_m001();
bfr.Add(new_page.Root().Root_src());
wiki.Ctx().Defn_trace().Print(data, bfr);
new_page.Data_raw_(bfr.Mkr_rls().XtoAryAndClear());
byte old = tab.View_mode();
tab.View_mode_(view_tid);
Xog_tab_itm_read_mgr.Show_page(tab, new_page, false);
tab.History_mgr().Add(new_page);
tab.View_mode_(old);
}
private static void Invalidate(Xow_wiki wiki) {// invalidate everything on updates; especially needed for page transclusion; {{/my_subpage}} DATE:2014-04-10
gplx.xowa.xtns.scribunto.Scrib_core.Core_invalidate();
wiki.Cache_mgr().Free_mem_all();
}
private static byte[] Get_new_text(Xog_tab_itm tab) {
byte[] rv = tab.Html_itm().Get_elem_value_for_edit_box_as_bry();
rv = Bry_.Trim(rv, 0, rv.length, false, true, Bry_.Trim_ary_ws); // MW: trim all trailing ws; REF:EditPage.php!safeUnicodeInput; DATE:2014-04-25
return rv;
}
}

View File

@@ -0,0 +1,111 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.threads.*;
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.gui.history.*;
public class Xog_tab_itm_read_mgr {
public static void Async(Xog_tab_itm tab) {tab.Async();}
public static void Show_page(Xog_tab_itm tab, Xoa_page new_page, boolean reset_to_read) {Show_page(tab, new_page, reset_to_read, false, false, Xog_history_stack.Nav_fwd);}
public static void Show_page(Xog_tab_itm tab, Xoa_page new_page, boolean reset_to_read, boolean new_page_is_same, boolean show_is_err, byte history_nav_type) {
if (reset_to_read) tab.View_mode_(Xog_page_mode.Tid_read);
if (new_page.Url().Action_is_edit()) tab.View_mode_(Xog_page_mode.Tid_edit);
Xoa_page cur_page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm(); Gfui_html html_box = html_itm.Html_box();
Xoa_app app = cur_page.App(); Xog_win_itm win = tab.Tab_mgr().Win();
if (cur_page != null && !new_page_is_same) { // if new_page_is_same, don't update DocPos; will "lose" current position
cur_page.Html_data().Bmk_pos_(html_box.Html_window_vpos());
tab.History_mgr().Update_html_doc_pos(cur_page, history_nav_type); // HACK: old_page is already in stack, but need to update its hdoc_pos
}
win.Usr_dlg().Prog_none("", "", "locating images");
try {tab.Html_itm().Show(new_page);}
catch (Exception e) {
if (show_is_err) { // trying to show error page, but failed; don't show again, else recursion until out of memory; TODO:always load error page; no reason it should fail; WHEN:html_skin; DATE:2014-06-08
String new_page_url = new_page.Url().X_to_full_str_safe();
String err_msg = "fatal error trying to load error page; page=" + new_page_url;
app.Usr_dlg().Warn_many("", "", err_msg);
app.Gui_mgr().Kit().Ask_ok("", "", err_msg);
return;
}
else
Show_page_err(win, tab, new_page.Wiki(), new_page.Url(), new_page.Ttl(), e);
return;
}
tab.Page_(new_page);
if (tab == tab.Tab_mgr().Active_tab())
Update_selected_tab(app, win, new_page.Url(), new_page.Ttl());
Xol_font_info lang_font = new_page.Wiki().Lang().Gui_font();
if (lang_font.Name() == null) lang_font = app.Gui_mgr().Win_cfg().Font();
Xog_win_itm_.Font_update(tab.Tab_mgr().Win(), lang_font);
tab.Tab_mgr().Tab_mgr().Focus();
html_box.Focus();
win.Usr_dlg().Prog_none("", "", ""); // blank out status bar
if (tab.View_mode() == Xog_page_mode.Tid_read)
html_itm.Scroll_page_by_bmk_gui();
else
GfoInvkAble_.InvkCmd_val(tab.Html_itm().Cmd_async(), Xog_html_itm.Invk_html_elem_focus, Xog_html_itm.Elem_id__xowa_edit_data_box); // NOTE: must be async, else won't work; DATE:2014-06-05
}
public static void Update_selected_tab_blank(Xoa_app app, Xog_win_itm win) {Update_selected_tab(app, win, null, null);} // called when all tabs are null
public static void Update_selected_tab(Xoa_app app, Xog_win_itm win, Xoa_url url, Xoa_ttl ttl) {
String url_str = "", win_str = Win_text_blank;
if (url != null && ttl != null) {
try {url_str = app.Url_parser().Build_str(url);}
catch (Exception e) { // HACK: failed pages will have a null wiki; for now, catch and ignore; DATE:2014-06-22
app.Usr_dlg().Warn_many("", "", "failed to build url: url=~{0}, err=~{1}", String_.new_utf8_(url.Raw()), Err_.Message_gplx(e));
url_str = String_.new_utf8_(ttl.Full_txt());
}
win_str = String_.new_utf8_(Bry_.Add(ttl.Full_txt(), Win_text_suffix_page));
}
win.Url_box().Text_(url_str);
win.Win_box().Text_(win_str);
}
private static final byte[] Win_text_suffix_page = Bry_.new_ascii_(" - XOWA"); private static final String Win_text_blank = "XOWA";
public static void Show_page_err(Xog_win_itm win, Xog_tab_itm tab, Xow_wiki wiki, Xoa_url url, Xoa_ttl ttl, Exception e) {
String err_msg = String_.Format("page_load fail: page={0} err={1}", String_.new_utf8_(url.Raw()), Err_.Message_gplx(e));
win.Usr_dlg().Warn_many("", "", err_msg);
win.App().Log_wtr().Queue_enabled_(false);
Xoa_page fail_page = wiki.Data_mgr().Get_page(ttl, false);
tab.View_mode_(Xog_page_mode.Tid_edit);
Update_selected_tab(win.App(), win, url, ttl);
Show_page(tab, fail_page, false, false, true, Xog_history_stack.Nav_fwd);
win.Win_box().Text_(err_msg);
}
public static void Launch(Xog_win_itm win) {
Xoa_app app = win.App();
Gfo_log_bfr log_bfr = app.Log_bfr();
log_bfr.Add("app.launch.page.bgn");
Xow_wiki home_wiki = app.User().Wiki();
Xoa_page launch_page = Xog_tab_itm_read_mgr.Launch_page(win, home_wiki, app.Sys_cfg().Launch_url());
if (launch_page.Missing())
launch_page = Xog_tab_itm_read_mgr.Launch_page(win, home_wiki, Xoa_sys_cfg.Launch_url_dflt);
log_bfr.Add("app.launch.page.show");
Xog_tab_itm tab = win.Active_tab();
Xog_tab_itm_read_mgr.Show_page(tab, launch_page, false);
tab.History_mgr().Add(launch_page);
tab.Html_itm().Html_box().Focus(); //this.Html_box().Html_doc_body_focus(); // focus the html_box so wheel scroll works; DATE:2013-02-08
app.Gui_wtr().Prog_none("", "", "");
log_bfr.Add("app.launch.page.end");
app.Gui_wtr().Log_wtr().Log_msg_to_session_direct(log_bfr.Xto_str());
}
private static Xoa_page Launch_page(Xog_win_itm win, Xow_wiki home_wiki, String launch_str) {
Xoa_url launch_url = Xoa_url_parser.Parse_url(win.App(), home_wiki, launch_str);
Xow_wiki launch_wiki = launch_url.Wiki();
Xoa_ttl launch_ttl = Xoa_ttl.parse_(launch_wiki, launch_url.Page_bry());
Xoa_page rv = launch_wiki.GetPageByTtl(launch_url, launch_ttl).Url_(launch_url); // FUTURE: .Url_() should not be called (needed for anchor); EX: en.wikipedia.org/Earth#Biosphere
win.Active_page_(rv); // set to blank page
return rv;
}
}

View File

@@ -0,0 +1,247 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.cfgs2.*;
public class Xog_tab_mgr implements GfoEvObj {
private OrderedHash tab_regy = OrderedHash_.new_(); private int tab_uid = 0;
public Xog_tab_mgr(Xog_win_itm win) {
this.win = win;
ev_mgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
public Xog_win_itm Win() {return win;} private Xog_win_itm win;
public Gfui_tab_mgr Tab_mgr() {return tab_mgr;} private Gfui_tab_mgr tab_mgr;
public void Init_by_kit(Gfui_kit kit) {
tab_mgr = kit.New_tab_mgr("xowa.tab_mgr", win.Win_box());
active_tab = Xog_tab_itm_.Null;
tab_mgr.Btns_selected_color_(ColorAdp_.White);
tab_mgr.Btns_unselected_color_(ColorAdp_.LightGray);
GfoEvMgr_.SubSame_many(tab_mgr, this, Gfui_tab_mgr.Evt_tab_selected, Gfui_tab_mgr.Evt_tab_closed, Gfui_tab_mgr.Evt_tab_switched);
Xocfg_tab_btn_mgr btn_mgr = win.App().Cfg_regy().App().Gui_mgr().Tab_mgr().Btn_mgr();
Btns_place_on_top_(btn_mgr.Place_on_top());
Btns_curved_(btn_mgr.Curved());
Btns_close_visible_(btn_mgr.Close_visible());
Btns_unselected_close_visible_(btn_mgr.Unselected_close_visible());
Btns_height_(btn_mgr.Height());
GfoEvMgr_.SubSame_many(btn_mgr, this
, Xocfg_tab_btn_mgr.Evt_place_on_top_changed, Xocfg_tab_btn_mgr.Evt_height_changed, Xocfg_tab_btn_mgr.Evt_curved_changed
, Xocfg_tab_btn_mgr.Evt_close_visible_changed, Xocfg_tab_btn_mgr.Evt_unselected_close_visible_changed
, Xocfg_tab_btn_mgr.Evt_text_min_chars_changed, Xocfg_tab_btn_mgr.Evt_text_max_chars_changed
, Xocfg_tab_btn_mgr.Evt_hide_if_one_changed
);
}
public Xog_tab_itm Active_tab() {return active_tab;} private Xog_tab_itm active_tab;
public Xog_tab_itm Active_tab_assert() {
if (active_tab == Xog_tab_itm_.Null) this.Tabs_new_dflt(false, true); // update_ui=false; create dflt tab, but do not update name; will be updated later by whatever loads page
return active_tab;
}
public boolean Active_tab_is_null() {return active_tab == Xog_tab_itm_.Null;}
private void Btns_place_on_top_(boolean v) {tab_mgr.Btns_place_on_top_(v);}
private void Btns_curved_(boolean v) {tab_mgr.Btns_curved_(v);}
private void Btns_height_(int v) {tab_mgr.Btns_height_(v);}
private void Btns_close_visible_(boolean v) {tab_mgr.Btns_close_visible_(v);}
private void Btns_unselected_close_visible_(boolean v) {tab_mgr.Btns_unselected_close_visible_(v);}
private void Btns_text_recalc() {
int len = this.Tabs_len();
for (int i = 0; i < len; i++) {
Xog_tab_itm tab_itm = this.Tabs_get_at(i);
tab_itm.Tab_name_();
}
}
public int Tabs_len() {return tab_regy.Count();}
public void Tabs_new_init() {
this.Tabs_new(true, true);
}
public Xog_tab_itm Tabs_get_at(int i) {return (Xog_tab_itm)tab_regy.FetchAt(i);}
public Xog_tab_itm Tabs_new_dflt() {return Tabs_new_dflt(false);}
public Xog_tab_itm Tabs_new_dflt(boolean focus) {return Tabs_new_dflt(false, focus);}
public Xog_tab_itm Tabs_new_dflt(boolean update_ui, boolean focus) {
boolean active_tab_is_null = this.Active_tab_is_null();
Xow_wiki cur_wiki = active_tab_is_null ? win.App().User().Wiki() : active_tab.Page().Wiki();
Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null);
Xoa_ttl ttl = Xoa_ttl.parse_(cur_wiki, gplx.xowa.specials.xowa.default_tab.Default_tab_page.Ttl_full_bry);
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(win.App(), cur_wiki, ttl.Full_db_as_str());
rv.Page_(update_ui, Xoa_page.new_(cur_wiki, ttl));
rv.Show_url_bgn(url);
return rv;
}
private Xog_tab_itm Tabs_new(boolean focus, boolean active_tab_is_null) {
String tab_key = "tab_" + Int_.XtoStr(tab_uid++); int tab_idx = tab_regy.Count();
Gfui_tab_itm_data tab_data = new Gfui_tab_itm_data(tab_key, tab_idx);
Xog_tab_itm rv = new Xog_tab_itm(this, tab_data);
Gfui_tab_itm tab_box = tab_mgr.Tabs_add(tab_data);
rv.Make_html_box(tab_uid, tab_box, win, tab_mgr);
tab_box.Subs_add(rv.Html_itm().Html_box());
tab_regy.Add(tab_key, rv);
if ( focus
|| active_tab_is_null // NOTE: must select 1st tab, else nothing will show in tab box
) {
tab_mgr.Tabs_select_by_idx(rv.Tab_idx());
active_tab = rv;
}
Tabs_hide_if_one_chk();
return rv;
}
public void Tabs_new_dupe(boolean focus) {
if (this.Active_tab_is_null()) return;
String url = active_tab.Page().Url().X_to_full_str();
Tabs_new_dflt(focus);
win.Page__navigate_by_url_bar(url);
}
public void Tabs_javascript_enabled_(boolean v) {
int len = tab_regy.Count();
for (int i = 0; i < len; i++) {
Xog_tab_itm tab = Tabs_get_by_idx_or_warn(i);
tab.Html_itm().Js_enabled_(v);
}
}
private void Tabs_selected(String key) {
Xog_tab_itm tab = Tabs_get_by_key_or_warn(key); if (tab == null) return;
active_tab = tab;
Xoa_page page = tab.Page();
Xog_tab_itm_read_mgr.Update_selected_tab(win.App(), win, page.Url(), page.Ttl());
tab.Html_itm().Tab_selected(page);
}
public void Tabs_close_cur() {
if (this.Active_tab_is_null()) return;
tab_mgr.Tabs_close_by_idx(active_tab.Tab_idx());
}
public void Tabs_close_others() {this.Tabs_close_to_bgn(); this.Tabs_close_to_end();}
public void Tabs_close_to_bgn() {if (Active_tab_is_null()) return; Tabs_close_rng(0 , active_tab.Tab_idx());}
public void Tabs_close_to_end() {if (Active_tab_is_null()) return; Tabs_close_rng(active_tab.Tab_idx() + 1 , tab_regy.Count());}
public void Tabs_close_rng(int bgn, int end) {
for (int i = bgn; i < end; i++)
tab_mgr.Tabs_close_by_idx(bgn);
}
public void Tabs_close_undo() {
if (closed_undo_list.Count() == 0) return;
String url = (String)ListAdp_.Pop(closed_undo_list);
Tabs_new_dflt(true);
win.Page__navigate_by_url_bar(url);
}
private ListAdp closed_undo_list = ListAdp_.new_();
private void Tabs_closed(String key) {
Xog_tab_itm itm = Tabs_get_by_key_or_warn(key); if (itm == null) return;
closed_undo_list.Add(itm.Page().Url().X_to_full_str());
tab_regy.Del(key);
if (tab_regy.Count() == 0) {
active_tab = Xog_tab_itm_.Null;
Xog_tab_itm_read_mgr.Update_selected_tab_blank(win.App(), win);
}
else
Tabs_recalc_idx();
Tabs_hide_if_one_chk();
}
private Xog_tab_itm Tabs_get_by_key_or_warn(String key) {
Xog_tab_itm rv = (Xog_tab_itm)tab_regy.Fetch(key); if (rv == null) win.App().Usr_dlg().Warn_many("", "", "tab.selected could not find tab; key={0}", key);
return rv;
}
private Xog_tab_itm Tabs_get_by_idx_or_warn(int idx) {
Xog_tab_itm rv = (Xog_tab_itm)tab_regy.FetchAt(idx); if (rv == null) win.App().Usr_dlg().Warn_many("", "", "tab.selected could not find tab; idx={0}", idx);
return rv;
}
private void Tabs_recalc_idx() {
int len = tab_regy.Count();
for (int i = 0; i < len; i++) {
Xog_tab_itm itm = Tabs_get_by_idx_or_warn(i);
itm.Tab_idx_(i);
}
}
public void Tabs_select(boolean fwd) {
if (this.Active_tab_is_null()) return;
int new_idx = TabBox_.Cycle(fwd, active_tab.Tab_idx(), tab_regy.Count());
tab_mgr.Tabs_select_by_idx(new_idx);
}
public void Tabs_select_by_idx(int v) {
if (v >= tab_regy.Count()) return;
tab_mgr.Tabs_select_by_idx(v);
}
public void Tabs_move(boolean fwd) {
if (this.Active_tab_is_null()) return;
int src_idx = active_tab.Tab_idx();
int trg_idx = TabBox_.Cycle(fwd, src_idx, tab_regy.Count());
tab_mgr.Tabs_switch(src_idx, trg_idx);
}
private void Tabs_switched(String src_key, String trg_key) {
Xog_tab_itm src_itm = Tabs_get_by_key_or_warn(src_key);
Xog_tab_itm trg_itm = Tabs_get_by_key_or_warn(trg_key);
src_itm.Switch_mem(trg_itm);
active_tab = trg_itm; // NOTE: src_itm initiated switch, but trg_itm is now active b/c everything in src_itm has now been reparented to trg_itm; DATE:2014-05-12
}
public void Tabs_new_link(boolean focus, String link) {
if (String_.Len_eq_0(link)) {
if (this.Active_tab_is_null()) return;
link = active_tab.Html_itm().Html_selected_get_text_or_href();
}
if (String_.Len_eq_0(link)) {win.App().Usr_dlg().Prog_many("", "", "no link or text selected"); return;}
Tabs_new_link(link, focus);
}
public void Tabs_new_link(String link, boolean focus) {
Xow_wiki wiki = active_tab.Page().Wiki();
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(win.App(), wiki, link); // NOTE: link must be of form domain/wiki/page; DATE:2014-05-27
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, url.Page_bry());
Xog_tab_itm new_tab = Tabs_new(focus, false);
new_tab.Page_(false, Xoa_page.new_(wiki, ttl));
new_tab.Tab_name_(String_.new_utf8_(Xoa_ttl.Replace_unders(url.Page_bry())));
new_tab.Show_url_bgn(url);
if (focus)
tab_mgr.Tabs_select_by_idx(new_tab.Tab_idx());
}
private void Tabs_hide_if_one_chk() {
gplx.xowa.cfgs2.Xocfg_tab_btn_mgr btn_mgr = win.App().Cfg_regy().App().Gui_mgr().Tab_mgr().Btn_mgr();
if (!btn_mgr.Hide_if_one()) return;
if (tab_regy.Count() > 1) {
if (tab_mgr.Btns_height() != btn_mgr.Height())
Btns_height_(btn_mgr.Height());
}
else {
if (tab_mgr.Btns_height() != 0)
Btns_height_(0);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tabs_new_dflt__at_dflt__focus_y)) Tabs_new_dflt(Bool_.Y);
else if (ctx.Match(k, Invk_tabs_new_link__at_dflt__focus_n)) Tabs_new_link(Bool_.N, m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_tabs_new_link__at_dflt__focus_y)) Tabs_new_link(Bool_.Y, m.ReadStrOr("v", null));
else if (ctx.Match(k, Gfui_tab_mgr.Evt_tab_selected)) Tabs_selected(m.ReadStr("key"));
else if (ctx.Match(k, Gfui_tab_mgr.Evt_tab_closed)) Tabs_closed(m.ReadStr("key"));
else if (ctx.Match(k, Gfui_tab_mgr.Evt_tab_switched)) Tabs_switched(m.ReadStr("src"), m.ReadStr("trg"));
else if (ctx.Match(k, Invk_tabs_close_cur)) Tabs_close_cur();
else if (ctx.Match(k, Invk_tabs_select_bwd)) Tabs_select(Bool_.N);
else if (ctx.Match(k, Invk_tabs_select_fwd)) Tabs_select(Bool_.Y);
else if (ctx.Match(k, Invk_tabs_switch_cur_bwd)) Tabs_move(Bool_.N);
else if (ctx.Match(k, Invk_tabs_switch_cur_fwd)) Tabs_move(Bool_.Y);
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_place_on_top_changed)) Btns_place_on_top_(m.ReadBool("v"));
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_curved_changed)) Btns_curved_(m.ReadBool("v"));
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_height_changed)) Btns_height_(m.ReadInt("v"));
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_close_visible_changed)) Btns_close_visible_(m.ReadBool("v"));
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_unselected_close_visible_changed)) Btns_unselected_close_visible_(m.ReadBool("v"));
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_text_min_chars_changed)) Btns_text_recalc();
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_text_max_chars_changed)) Btns_text_recalc();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String
Invk_tabs_select_fwd = "tabs_select_fwd" , Invk_tabs_select_bwd = "tabs_select_bwd"
, Invk_tabs_switch_cur_fwd = "tabs_switch_cur_fwd" , Invk_tabs_switch_cur_bwd = "tabs_switch_cur_bwd"
, Invk_tabs_new_dflt__at_dflt__focus_y = "tabs_new_dflt__at_dflt__focus_y"
, Invk_tabs_new_link__at_dflt__focus_n = "tabs_new_link__at_dflt__focus_n"
, Invk_tabs_new_link__at_dflt__focus_y = "tabs_new_link__at_dflt__focus_y"
, Invk_tabs_close_cur = "tabs_close_cur"
;
}

View File

@@ -0,0 +1,306 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.threads.*; import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.history.*; import gplx.xowa.xtns.math.*; import gplx.xowa.files.*;
import gplx.xowa.gui.urls.*; import gplx.xowa.gui.views.*;
import gplx.xowa.parsers.lnkis.redlinks.*;
public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
private GfoInvkAble sync_cmd;
public Xog_win_itm(Xoa_app app, Xoa_gui_mgr gui_mgr) {
this.app = app; this.gui_mgr = gui_mgr;
this.tab_mgr = new Xog_tab_mgr(this);
}
public Gfui_kit Kit() {return kit;} private Gfui_kit kit;
public Xoa_gui_mgr Gui_mgr() {return gui_mgr;} private Xoa_gui_mgr gui_mgr;
public GfuiWin Win_box() {return win_box;} private GfuiWin win_box;
public GfuiBtn Go_bwd_btn() {return go_bwd_btn;} private GfuiBtn go_bwd_btn;
public GfuiBtn Go_fwd_btn() {return go_fwd_btn;} private GfuiBtn go_fwd_btn;
public GfuiTextBox Url_box() {return url_box;} private GfuiTextBox url_box;
public GfuiBtn Url_exec_btn() {return url_exec_btn;} private GfuiBtn url_exec_btn;
public GfuiTextBox Search_box() {return search_box;} private GfuiTextBox search_box;
public GfuiBtn Search_exec_btn() {return search_exec_btn;} private GfuiBtn search_exec_btn;
public GfuiTextBox Find_box() {return find_box;} private GfuiTextBox find_box;
public GfuiBtn Find_close_btn() {return find_close_btn;} private GfuiBtn find_close_btn;
public GfuiBtn Find_fwd_btn() {return find_fwd_btn;} private GfuiBtn find_fwd_btn;
public GfuiBtn Find_bwd_btn() {return find_bwd_btn;} private GfuiBtn find_bwd_btn;
public GfuiTextBox Prog_box() {return prog_box;} private GfuiTextBox prog_box;
public GfuiTextBox Info_box() {return info_box;} private GfuiTextBox info_box;
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} private GfoEvMgr evMgr;
public Xoa_app App() {return app;} private Xoa_app app;
public Xog_tab_mgr Tab_mgr() {return tab_mgr;} private Xog_tab_mgr tab_mgr;
public Xog_tab_itm Active_tab() {return tab_mgr.Active_tab();}
public Xoa_page Active_page() {return tab_mgr.Active_tab().Page();} public void Active_page_(Xoa_page v) {tab_mgr.Active_tab().Page_(v);}
public Xog_html_itm Active_html_itm() {return tab_mgr.Active_tab().Html_itm();}
public Gfui_html Active_html_box() {return tab_mgr.Active_tab().Html_itm().Html_box();}
public Xog_resizer Resizer() {return resizer;} private Xog_resizer resizer = new Xog_resizer();
public Gfo_usr_dlg Usr_dlg() {return app.Usr_dlg();}
public void Refresh_win_size() {
if (win_box != null) // NOTE: will be null when html box adjustment pref is set and application is starting
resizer.Exec_win_resize(app, win_box.Width(), win_box.Height());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_link_click)) Win__link_click();
else if (ctx.Match(k, Invk_link_print)) Xog_win_itm__prog_href_mgr.Print(this);
else if (ctx.Match(k, Gfui_html.Evt_link_hover)) Xog_win_itm__prog_href_mgr.Hover(app, this.Active_page(), m.ReadStr("v"));
else if (ctx.Match(k, Gfui_html.Evt_location_changed)) Win__link_clicked(m.ReadStr("v"));
else if (ctx.Match(k, Gfui_html.Evt_location_changing)) Page__navigate_by_internal_href(m.ReadStr("v"), tab_mgr.Active_tab());
else if (ctx.Match(k, Gfui_html.Evt_win_resized)) Refresh_win_size();
else if (ctx.Match(k, Invk_page_refresh)) Page__refresh();
else if (ctx.Match(k, Invk_page_async_exec)) Xog_tab_itm_read_mgr.Async((Xog_tab_itm)m.ReadObj("v"));
else if (ctx.Match(k, Invk_page_view_read)) Page__mode_(Xog_page_mode.Tid_read);
else if (ctx.Match(k, Invk_page_view_edit)) Page__mode_(Xog_page_mode.Tid_edit);
else if (ctx.Match(k, Invk_page_view_html)) Page__mode_(Xog_page_mode.Tid_html);
else if (ctx.Match(k, Invk_page_edit_save)) Xog_tab_itm_edit_mgr.Save(tab_mgr.Active_tab(), Bool_.N);
else if (ctx.Match(k, Invk_page_edit_save_draft)) Xog_tab_itm_edit_mgr.Save(tab_mgr.Active_tab(), Bool_.Y);
else if (ctx.Match(k, Invk_page_edit_preview)) Xog_tab_itm_edit_mgr.Preview(tab_mgr.Active_tab());
else if (ctx.Match(k, Invk_page_edit_rename)) Xog_tab_itm_edit_mgr.Rename(tab_mgr.Active_tab());
else if (ctx.Match(k, Invk_page_edit_focus_box)) Xog_tab_itm_edit_mgr.Focus(this, Xog_html_itm.Elem_id__xowa_edit_data_box);
else if (ctx.Match(k, Invk_page_edit_focus_first)) Xog_tab_itm_edit_mgr.Focus(this, Xog_html_itm.Elem_id__first_heading);
else if (ctx.Match(k, Invk_page_dbg_html)) Xog_tab_itm_edit_mgr.Debug(this, Xog_page_mode.Tid_html);
else if (ctx.Match(k, Invk_page_dbg_wiki)) Xog_tab_itm_edit_mgr.Debug(this, Xog_page_mode.Tid_edit);
else if (ctx.Match(k, Invk_page_goto)) Page__navigate_by_url_bar(m.ReadStr("v"));
else if (ctx.Match(k, Invk_page_goto_recent)) Page__navigate_by_url_bar(app.User().History_mgr().Get_at_last(app));
else if (ctx.Match(k, Invk_history_bwd)) {Page__navigate_by_history(Bool_.N);}
else if (ctx.Match(k, Invk_history_fwd)) {Page__navigate_by_history(Bool_.Y);}
else if (ctx.Match(k, Invk_app_exit)) App__exit();
else if (ctx.Match(k, Invk_eval)) App__eval(m.ReadStr("cmd"));
else if (ctx.Match(k, Invk_page_async_cancel_wait)) Page__async__cancel__wait();
else if (ctx.Match(k, Invk_page_async_restart)) Page__async__restart();
else if (ctx.Match(k, Invk_search)) Page__navigate_by_search();
else if (ctx.Match(k, Invk_window_font_changed)) Xog_win_itm_.Font_update(this, (Xol_font_info)m.CastObj("font"));
else if (ctx.Match(k, Invk_app)) return app;
else if (ctx.Match(k, Invk_page)) return this.Active_page();
else if (ctx.Match(k, Invk_wiki)) return this.Active_page().Wiki();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_page_async_exec = "page_async_exec"
, Invk_page_async_cancel_wait = "page_async_cancel_wait", Invk_page_async_restart = "page_async_restart"
;
public static final String
Invk_app = "app", Invk_wiki = "wiki", Invk_page = "page", Invk_shortcuts = "shortcuts"
, Invk_link_click = "link_click", Invk_link_print = "link_print"
, Invk_window_font_changed = "winow_font_changed"
, Invk_search = "search"
, Invk_page_view_edit = "page_view_edit", Invk_page_view_read = "page_view_read", Invk_page_view_html = "page_view_html"
, Invk_history_fwd = "history_fwd", Invk_history_bwd = "history_bwd"
, Invk_page_refresh = "page_refresh"
, Invk_page_edit_focus_box = "page_edit_focus_box", Invk_page_edit_focus_first = "page_edit_focus_first"
, Invk_page_edit_save = "page_edit_save", Invk_page_edit_save_draft = "page_edit_save_draft", Invk_page_edit_preview = "page_edit_preview", Invk_page_edit_rename = "page_edit_rename"
, Invk_page_dbg_wiki = "page_dbg_wiki", Invk_page_dbg_html = "page_dbg_html"
, Invk_app_exit = "app_exit"
, Invk_eval = "eval"
// xowa.gfs: shortcuts
, Invk_page_goto = "page_goto", Invk_page_goto_recent = "page_goto_recent"
;
private void Win__link_click() { // NOTE: only applies when content_editable=y; if n, then link_click will be handled by SwtBrowser location changed (Win__link_clicked)
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoa_page page = tab.Page();
if (page.Wiki().Gui_mgr().Cfg_browser().Content_editable()) {
String href = tab.Html_itm().Html_box().Html_active_atr_get_str(Gfui_html.Atr_href, null);
if (String_.Len_eq_0(href)) return; // NOTE: href can be null for images; EX: [[File:Loudspeaker.svg|11px|link=|alt=play]]; link= basically means don't link to image
Page__navigate_by_internal_href(href, tab);
}
}
private void Win__link_clicked(String anchor_raw) {
String url = url_box.Text();
int pos = String_.FindFwd(url, gplx.xowa.html.Xoh_html_tag.Const_anchor);
if (pos != Bry_.NotFound) url = String_.Mid(url, 0, pos);
String anchor_str = Parse_evt_location_changing(anchor_raw);
byte[] anchor_bry = Bry_.new_utf8_(anchor_str);
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoa_page page = tab.Page();
if (anchor_str != null) { // link has anchor
url_box.Text_(url + "#" + anchor_str); // update url box
page.Html_data().Bmk_pos_(Xog_history_itm.Html_doc_pos_toc); // HACK: anchor clicked; set docPos of curentPage to TOC (so back will go back to TOC)
tab.History_mgr().Update_html_doc_pos(page, Xog_history_stack.Nav_by_anchor); // HACK: update history_mgr; note that this must occur before setting Anchor (since Anchor will generate a new history itm)
page.Url().Anchor_bry_(anchor_bry); // update url
}
tab.History_mgr().Add(page);
app.User().History_mgr().Add(page.Url(), page.Ttl(), Bry_.Add_w_dlm(Byte_ascii.Hash, page.Url().Page_bry(), anchor_bry));
}
public void App__exit() {
if (!app.Term_cbk()) return; // NOTE: exit called by keyboard shortcut, or exit link; must call Term_cbk manually; Alt-F4/X button will call Term_cbk in closing event
app.Gui_mgr().Kit().Kit_term();
}
private void App__eval(String s) {
String snippet = this.Active_html_box().Html_elem_atr_get_str(s, Gfui_html.Atr_innerHTML);
app.Gfs_mgr().Run_str(snippet);
}
private static String Parse_evt_location_changing(String v) { // EX: about:blank#anchor -> anchor
int pos = String_.FindFwd(v, gplx.xowa.html.Xoh_html_tag.Const_anchor);
return pos == Bry_.NotFound
? null
: String_.Mid(v, pos + 1);
}
public void Page__mode_(byte new_mode_tid) {
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoa_page page = tab.Page();
if ( new_mode_tid == Xog_page_mode.Tid_read // used to be && cur_view_tid == Edit; removed clause else redlinks wouldn't show when going form html to read (or clicking read multiple times) DATE: 2013-11-26;
&& !page.Missing() // if new page, don't try to reload
) {
// NOTE: if moving from "Edit" to "Read", reload page (else Preview changes will still show); NOTE: do not call Exec_page_reload / Exec_page_refresh, which will fire redlinks code
page = tab_mgr.Active_tab().History_mgr().Cur_page(page.Wiki()); // NOTE: must set to CurPage() else changes will be lost when going Bwd,Fwd
tab.Page_(page);
page.Wiki().ParsePage_root(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
Xoa_url url = page.Url();
if (url.Args_exists(Xoa_url_parser.Bry_arg_action, Xoa_url_parser.Bry_arg_action_edit)) // url has ?action=edit
app.Url_parser().Parse(url, url.X_to_full()); // remove all query args; handle (1) s.w:Earth?action=edit; (2) click on Read; DATE:2014-03-06
}
tab.View_mode_(new_mode_tid);
if (page.Missing()) return;
Xog_tab_itm_read_mgr.Show_page(tab, page, false);
// Exec_page_refresh(); // commented out; causes lnke to show as [2] instead of [1] when saving page; EX: [http://a.org b] DATE:2014-04-24
}
public void Page__navigate_by_search() {Page__navigate_by_url_bar(app.Gui_mgr().Win_cfg().Search_box_fmtr().Bld_str_many(search_box.Text()));}
public void Page__navigate_by_url_bar(String href) {
Xog_tab_itm tab = tab_mgr.Active_tab_assert();
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(app, tab.Page().Wiki(), href);
tab.Show_url_bgn(url);
}
private void Page__navigate_by_internal_href(String href, Xog_tab_itm tab) { // NOTE: different from Navigate_by_url_bar in that it handles "file:///" and other @gplx.Internal protected formats; EX: "/site/", "about:blank"; etc..
Xoa_url url = Xog_url_wkr.Exec_url(this, href);
if (url != Xog_url_wkr.Rslt_handled)
tab.Show_url_bgn(url);
}
public void Page__navigate_by_history(boolean fwd) {
Xog_tab_itm tab = tab_mgr.Active_tab();
if (tab == Xog_tab_itm_.Null) return;
Xoa_page cur_page = tab.Page();
Xoa_page new_page = tab.History_mgr().Go_by_dir(cur_page.Wiki(), fwd);
if (new_page.Missing()) return;
byte history_nav_type = fwd ? Xog_history_stack.Nav_fwd : Xog_history_stack.Nav_bwd;
boolean new_page_is_same = Bry_.Eq(cur_page.Ttl().Full_txt(), new_page.Ttl().Full_txt());
Xog_tab_itm_read_mgr.Show_page(tab, new_page, true, new_page_is_same, false, history_nav_type);
Page__async__bgn(tab);
}
public void Page__reload() {
Xog_tab_itm tab = tab_mgr.Active_tab();
Xoa_page page = tab.History_mgr().Cur_page(tab.Page().Wiki()); // NOTE: must set to CurPage() else changes will be lost when going Bwd,Fwd
tab.Page_(page);
page.Wiki().ParsePage_root(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
Page__refresh();
}
public void Page__refresh() {
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoa_page page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm();
page.Html_data().Bmk_pos_(html_itm.Html_box().Html_window_vpos());
html_itm.Show(page);
if (page.Url().Anchor_str() == null)
html_itm.Scroll_page_by_bmk_gui();
else
html_itm.Scroll_page_by_id_gui(page.Url().Anchor_str());
Page__async__bgn(tab);
}
public void Page__async__bgn(Xog_tab_itm tab) {
page__async__thread = ThreadAdp_.invk_msg_(this, GfoMsg_.new_cast_(Invk_page_async_exec).Add("v", tab)).Start();
} private ThreadAdp page__async__thread = ThreadAdp.Null;
public boolean Page__async__working(Xoa_url url) {
if (page__async__thread.IsAlive()) { // cancel pending image downloads
page__async__restart_url = url;
this.Usr_dlg().Canceled_y_();
app.File_mgr().Download_mgr().Download_wkr().Download_xrg().Prog_cancel_y_();
ThreadAdp_.invk_(this, Invk_page_async_cancel_wait).Start();
return true;
}
return false;
}
private void Page__async__cancel__wait() {
while (page__async__thread.IsAlive()) {
ThreadAdp_.Sleep(10);
}
this.Active_page().File_queue().Clear();
this.Usr_dlg().Canceled_n_(); // NOTE: must mark "uncanceled", else one cancelation will stop all future downloads; DATE:2014-05-04
GfoInvkAble_.InvkCmd(sync_cmd, Invk_page_async_restart);
}
private void Page__async__restart() {
tab_mgr.Active_tab().Show_url_bgn(page__async__restart_url);
} private Xoa_url page__async__restart_url;
public void Lang_changed(Xol_lang lang) {
Xoa_app app = gui_mgr.App();
Xog_win_itm_.Update_tiptext(app, go_bwd_btn , Xol_msg_itm_.Id_xowa_window_go_bwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, go_fwd_btn , Xol_msg_itm_.Id_xowa_window_go_fwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, url_box , Xol_msg_itm_.Id_xowa_window_url_box_tooltip);
Xog_win_itm_.Update_tiptext(app, url_exec_btn , Xol_msg_itm_.Id_xowa_window_url_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, search_box , Xol_msg_itm_.Id_xowa_window_search_box_tooltip);
Xog_win_itm_.Update_tiptext(app, search_exec_btn , Xol_msg_itm_.Id_xowa_window_search_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, find_close_btn , Xol_msg_itm_.Id_xowa_window_find_close_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, find_box , Xol_msg_itm_.Id_xowa_window_find_box_tooltip);
Xog_win_itm_.Update_tiptext(app, find_bwd_btn , Xol_msg_itm_.Id_xowa_window_find_bwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, find_fwd_btn , Xol_msg_itm_.Id_xowa_window_find_fwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, prog_box , Xol_msg_itm_.Id_xowa_window_prog_box_tooltip);
Xog_win_itm_.Update_tiptext(app, info_box , Xol_msg_itm_.Id_xowa_window_info_box_tooltip);
}
public byte[] App__retrieve_by_url(String url_str, String output_str) {
synchronized (App__retrieve__lock) {
boolean output_html = String_.Eq(output_str, "html");
Xoa_url url = new Xoa_url();
byte[] url_bry = Bry_.new_utf8_(url_str);
Xow_wiki home_wiki = app.User().Wiki();
Xoa_ttl ttl = Xoa_ttl.parse_(home_wiki, Xoa_page_.Main_page_bry); // NOTE: must be Main_Page, not "" else Firefox Addon will fail; DATE:2014-03-13
Xoa_page new_page = Xoa_page.new_(home_wiki, ttl);
this.Active_page_(new_page);
url = Xoa_url_parser.Parse_url(url, app, new_page.Wiki(), url_bry, 0, url_bry.length, true);
new_page.Url_(url);
return App__retrieve_by_href(url, output_html);
}
} private Object App__retrieve__lock = new Object();
public byte[] App__retrieve_by_href(String href, boolean output_html) {return App__retrieve_by_href(Xog_url_wkr.Exec_url(this, href), output_html);} // NOTE: used by drd
private byte[] App__retrieve_by_href(Xoa_url url, boolean output_html) {
if (url == null) return Bry_.new_ascii_("missing");
Xoa_ttl ttl = Xoa_ttl.parse_(url.Wiki(), url.Page_bry());
Xoa_page new_page = url.Wiki().GetPageByTtl(url, ttl);
if (new_page.Missing()) {return Bry_.Empty;}
Xog_tab_itm tab = tab_mgr.Active_tab();
tab.Page_(new_page);
tab.History_mgr().Add(new_page);
byte[] rv = output_html
? url.Wiki().Html_mgr().Page_wtr_mgr().Gen(new_page, tab.View_mode())
: new_page.Data_raw()
;
if (app.Shell().Fetch_page_exec_async())
app.Gui_mgr().Browser_win().Page__async__bgn(tab);
return rv;
}
public void Init_by_kit(Gfui_kit kit) {
this.kit = kit;
win_box = kit.New_win_app("win");
sync_cmd = win_box.Kit().New_cmd_sync(this);
Io_url img_dir = app.User().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "chrome");
FontAdp ui_font = app.Gui_mgr().Win_cfg().Font().XtoFontAdp();
go_bwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "go_bwd_btn", "go_bwd.png" );
go_fwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "go_fwd_btn", "go_fwd.png" );
url_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "url_box" , true);
url_exec_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "url_exec_btn", "url_exec.png" );
search_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "search_box" , true);
search_exec_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "search_exec_btn", "search_exec.png" );
find_close_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "find_close_btn", "find_close.png" );
find_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "find_box" , true);
find_fwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "find_fwd_btn", "find_fwd.png" );
find_bwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "find_bwd_btn", "find_bwd.png" );
prog_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "prog_box" , false);
info_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "note_box" , false);
tab_mgr.Init_by_kit(kit);
this.Lang_changed(app.User().Lang());
GfoEvMgr_.SubSame_many(this, this, Gfui_html.Evt_location_changed, Gfui_html.Evt_location_changing, Gfui_html.Evt_link_hover);
GfoEvMgr_.SubSame(win_box, Gfui_html.Evt_win_resized, this);
GfoEvMgr_.Sub(app.Gui_mgr().Win_cfg().Font(), Xol_font_info.Font_changed, this, Invk_window_font_changed);
if ( !Env_.Mode_testing()
&& app.Mode() == Xoa_app_.Mode_gui) // only run for gui; do not run for tcp/http server; DATE:2014-05-03
app.Usr_dlg().Ui_wkr_(new Gfo_usr_dlg_ui_swt(kit, prog_box, info_box, info_box, app.Gui_mgr().Win_cfg()));
}
}

View File

@@ -0,0 +1,58 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.bnds.*; import gplx.xowa.gui.cmds.*;
public class Xog_win_itm_ {
public static void Show_win(Xog_win_itm win) {
Xoa_app app = win.App(); GfuiWin win_box = win.Win_box();
win_box.Focus_able_(false);
win_box.BackColor_(ColorAdp_.White);
win.Tab_mgr().Tab_mgr().BackColor_(ColorAdp_.White);
app.User().Cfg_mgr().Startup_mgr().Window_mgr().Init_window(win_box);
win.Resizer().Exec_win_resize(app, win_box.Width(), win_box.Height());
IconAdp.regy_loadDir_shallow(app.User().Fsys_mgr().Root_dir().GenSubDir_nest("app", "img", "win"));
win_box.Icon_(IconAdp.regy_("xowa.app"));
}
public static GfuiBtn new_btn(Xoa_app app, Gfui_kit kit, GfuiWin win, Io_url img_dir, String id, String file) {
GfuiBtn rv = kit.New_btn(id, win);
rv.Btn_img_(kit.New_img_load(img_dir.GenSubFil(file)));
return rv;
}
public static GfuiTextBox new_txt(Xoa_app app, Gfui_kit kit, GfuiWin win, FontAdp ui_font, String id, boolean border_on) {
GfuiTextBox rv = kit.New_text_box(id, win, KeyVal_.new_(GfuiTextBox.CFG_border_on_, border_on));
rv.TextMgr().Font_(ui_font);
return rv;
}
public static void Update_tiptext(Xoa_app app, GfuiElem elem, int tiptext_id) {
elem.TipText_(Xog_win_itm_.new_tiptext(app, tiptext_id));
}
public static void Font_update(Xog_win_itm win, Xol_font_info itm_font) {
FontAdp gui_font = win.Url_box().TextMgr().Font();
if (!itm_font.Eq(gui_font)) {
FontAdp new_font = itm_font.XtoFontAdp();
win.Url_box().TextMgr().Font_(new_font);
win.Find_box().TextMgr().Font_(new_font);
win.Prog_box().TextMgr().Font_(new_font);
win.Tab_mgr().Tab_mgr().TextMgr().Font_(new_font);
}
}
public static String new_tiptext(Xoa_app app, int id) {return String_.new_utf8_(app.User().Lang().Msg_mgr().Val_by_id(app.User().Wiki(), id));}
}

View File

@@ -0,0 +1,41 @@
/*
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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*;
public class Xog_win_itm__prog_href_mgr {
private static Xoh_href tmp_href = new Xoh_href();
private static Bry_bfr tmp_bfr = Bry_bfr.reset_(512);
public static void Print(Xog_win_itm win) { // PURPOSE: print href in prog box when in content editable mode
String href = win.Active_html_box().Html_active_atr_get_str(Gfui_html.Atr_href, "");// get selected href from html_box
href = win.App().Url_converter_href().Decode_str(href); // remove url encodings
if (!String_.Eq(href, win.Prog_box().Text()))
win.Usr_dlg().Prog_direct(href);
}
public static void Hover(Xoa_app app, Xoa_page page, String href) {
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
if ( String_.Len_eq_0(href) // href is null / empty; occurs when hovering over empty space
|| String_.Eq(href, "file:///")) {
usr_dlg.Prog_direct(""); // clear out previous entry
return;
}
Xow_wiki wiki = page.Wiki();
app.Href_parser().Parse(tmp_href, href, wiki, page.Ttl().Page_url());
tmp_href.Print_to_bfr(tmp_bfr, wiki.Gui_mgr().Cfg_browser().Link_hover_full());
usr_dlg.Prog_direct(tmp_bfr.XtoStrAndClear());
}
}