1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-05-31 22:44:34 +00:00

Cfg: Convert Gui - Tabs

This commit is contained in:
gnosygnu 2016-12-13 10:26:56 -05:00
parent 317880d083
commit 22a173ae0b
19 changed files with 97 additions and 237 deletions

View File

@ -33,21 +33,35 @@ public class Xocfg_mgr {
public void Clear() {
cache_mgr.Clear();
}
public boolean Bind_bool(Xow_wiki wiki, String key, Gfo_invk sub) {return Yn.parse_or(Bind_str(wiki, key, sub), false);}
public String Bind_str(Xow_wiki wiki, String key, Gfo_invk sub) {
String ctx = wiki.Domain_itm().Abrv_xo_str();
public void Bind_many_app(Gfo_invk sub, String... keys) {Bind_many(sub, Xocfg_mgr.Ctx__app, keys);}
public void Bind_many(Gfo_invk sub, String ctx, String... keys) {
try {
for (String key : keys) {
String val = Bind_str(ctx, key, sub);
cache_mgr.Pub(ctx, key, val);
}
}
catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "bind failed: ctx=~{0} keys=~{1} err=~{2}", ctx, String_.AryXtoStr(keys), Err_.Message_gplx_log(e));
}
}
public boolean Bind_bool_app(String key, Gfo_invk sub) {return Yn.parse_or(Bind_str(Xocfg_mgr.Ctx__app, key, sub), false);}
public boolean Bind_bool(Xow_wiki wiki, String key, Gfo_invk sub) {return Yn.parse_or(Bind_str(wiki, key, sub), false);}
public String Bind_str(Xow_wiki wiki, String key, Gfo_invk sub) {return Bind_str(wiki.Domain_itm().Abrv_xo_str(), key, sub);}
public String Bind_str(String ctx, String key, Gfo_invk sub) {
cache_mgr.Sub(sub, ctx, key, key);
return cache_mgr.Get(ctx, key);
}
public String Get_str_app(String key) {return Get_str(gplx.xowa.addons.apps.cfgs.specials.edits.objs.Xoedit_itm.Ctx__app, key);}
public String Get_str_app(String key) {return Get_str(Xocfg_mgr.Ctx__app, key);}
public String Get_str(String ctx, String key) {
return cache_mgr.Get(ctx, key);
}
public void Set_str_app(String key, String val) {Set_str(gplx.xowa.addons.apps.cfgs.specials.edits.objs.Xoedit_itm.Ctx__app, key, val);}
public void Set_str_app(String key, String val) {Set_str(Xocfg_mgr.Ctx__app, key, val);}
public void Set_str(String ctx, String key, String val) {
cache_mgr.Set(ctx, key, val);
}
public void Del(String ctx, String key) {
cache_mgr.Del(ctx, key);
}
public static String Ctx__app = "app";
}

View File

@ -47,6 +47,8 @@ public class Xoitm_gui_tid { // SERIALIZED
public static String Infer_gui_type(String db_type) {
if (String_.Eq(db_type, "bool"))
return Xoitm_gui_tid.Str__checkbox;
else if (String_.Eq(db_type, "int"))
return Xoitm_gui_tid.Str__numeric;
else if (String_.Eq(db_type, "memo"))
return Xoitm_gui_tid.Str__memo;
else if (String_.Eq(db_type, "io.process"))

View File

@ -32,7 +32,7 @@ class Xocfg_cache_grp {
if (rv != null) return rv.Val();
// global match; EX: "app|key_1"
rv = (Xocfg_cache_itm)vals.Get_by(gplx.xowa.addons.apps.cfgs.specials.edits.objs.Xoedit_itm.Ctx__app);
rv = (Xocfg_cache_itm)vals.Get_by(Xocfg_mgr.Ctx__app);
if (rv != null) return rv.Val();
// dflt

View File

@ -51,6 +51,10 @@ public class Xocfg_cache_mgr {
Xocfg_cache_grp grp = Grps__get_or_load(key);
grp.Sub(sub, ctx, evt);
}
public void Pub(String ctx, String key, String val) {
Xocfg_cache_grp grp = Grps__get_or_load(key);
grp.Pub(ctx, val);
}
public void Dflt(String key, String val) {
Xocfg_cache_grp grp = Grps__get_or_load(key);
grp.Dflt_(val);

View File

@ -27,14 +27,14 @@ public class Xocfg_cache_mgr__tst {
fxt.Test__get("en.d", "key_1", "dflt");
}
@Test public void Get__app() {
String ctx = gplx.xowa.addons.apps.cfgs.specials.edits.objs.Xoedit_itm.Ctx__app;
String ctx = Xocfg_mgr.Ctx__app;
fxt.Init__db_add(ctx, "key_1", "val_1");
fxt.Test__get(ctx, "key_1", "val_1");
fxt.Test__get("en.w", "key_1", "val_1");
fxt.Test__get("en.d", "key_1", "val_1");
}
@Test public void Set__app() {
String ctx = gplx.xowa.addons.apps.cfgs.specials.edits.objs.Xoedit_itm.Ctx__app;
String ctx = Xocfg_mgr.Ctx__app;
fxt.Init__db_add(ctx, "key_1", "123");
fxt.Init__sub(ctx, "key_1", "key_1");
fxt.Exec__set(ctx, "key_1", "234");

View File

@ -21,10 +21,17 @@ public class Xocfg_type_mgr {
public Xocfg_type_mgr() {
this.Lists__add("list:xowa.app.security.privacy.load_mode", "mem", "url");
this.Lists__add("list:xowa.app.startup.window.mode", "previous", "maximized", "absolute", "relative", "default");
this.Lists__add("list:xowa.app.startup.pages.type", "blank", "xowa", "absolute", "previous", "custom");
this.Lists__add("list:xowa.gui.window.html_box.adj_type", "none", "absolute", "relative");
this.Lists__add("list:xowa.app.startup.pages.type", "blank", "xowa", "previous", "custom");
this.Lists__add("list:xowa.gui.window.html_box.adj_type", "none", "relative", "absolute");
this.Lists__add("list:xowa.wiki.dbs.html.basic.html_mode", Keyval_.new_("shown", "Shown"), Keyval_.new_("hdump_save", "Saved for HTML DB"), Keyval_.new_("hdump_load", "Loaded by HTML DB"));
this.Lists__add("list:xowa.wiki.database.general.zip_mode", "text", "gzip", "bz2", "xz");
this.Lists__add("list:xowa.wiki.database.general.zip_mode", "text", "gzip", "bzip2", "xz");
this.Lists__add("list:xowa.html.wiki.portal.missing_class", Keyval_.new_("", "Show as blue link"), Keyval_.new_("new", "Show as red link"), Keyval_.new_("xowa_display_none", "Hide"));
this.Lists__add("list:xowa.html.category.basic.missing_class", "normal", "hide", "red_link");
this.Lists__add("list:xowa.html.tidy.general.engine", "tidy", "jtidy");
this.Lists__add("list:xowa.addon.http_server.general.file_retrieve_mode", Keyval_.new_("wait"), Keyval_.new_("skip"), Keyval_.new_("async_server", "async server"));
this.Lists__add("list:xowa.addon.search_suggest.html_bar.search_mode", "Search", "AllPages", "AllPages_(v2)");
this.Lists__add("list:xowa.addon.math.general.renderer", "MathJax", "LaTeX");
this.Lists__add("list:xowa.addon.scribunto.general.engine", "luaj", "lua");
}
public void Lists__add(String key, String... vals) {
int len = vals.length;

View File

@ -51,7 +51,7 @@ public class Xoedit_itm implements Xoedit_nde, Mustache_doc_itm {
this.edited = true;
}
public void Set_data_by_dflt() {
this.ctx = Ctx__app;
this.ctx = Xocfg_mgr.Ctx__app;
this.val = dflt;
this.date = String_.Empty;
this.edited = false;
@ -89,7 +89,6 @@ public class Xoedit_itm implements Xoedit_nde, Mustache_doc_itm {
else if (String_.Eq(k, "html")) To_html(bfr.Bfr(), type_mgr);
return true;
}
public static String Ctx__app = "app";
public Mustache_doc_itm[] Mustache__subs(String k) {
if (String_.Eq(k, "edited")) return Mustache_doc_itm_.Ary__bool(edited);
return Mustache_doc_itm_.Ary__empty;

View File

@ -31,7 +31,7 @@ public class Xoedit_itm_html {
bfr.Add_str_u8_fmt("<input id=\"{0}\" data-xocfg=\"0\" type=\"text\" accesskey=\"d\" class=\"xocfg_textbox\" value=\"{1}\"></input>", key, data);
break;
case Xoitm_gui_tid.Tid__memo:
bfr.Add_str_u8_fmt("<textarea id=\"{0}\" data-xocfg=\"0\" type=\"text\" accesskey=\"d\" class=\"xocfg_memo\" rows=\"4\">{1}</textarea>", key, data);
bfr.Add_str_u8_fmt("<textarea id=\"{0}\" data-xocfg=\"0\" type=\"text\" accesskey=\"d\" class=\"xocfg_memo\" rows=\"4\">{1}</textarea>", key, String_.Replace(data, "<", "&lt;"));
break;
case Xoitm_gui_tid.Tid__select:
Keyval[] kvs_ary = type_mgr.Lists__get(data_type);

View File

@ -35,6 +35,7 @@ public class Xocfg_maint_svc {
// exec
Xocfg_db_app db_app = Xocfg_db_app.New(app);
db_app.Conn().Txn_bgn("xo__cfg_maint__upsert");
byte[] anch_find_bry = Bry_.new_a7("<a "), anch_repl_bry = Bry_.new_a7("<a tabindex=\"-1\" ");
for (Xocfg_maint_nde nde : ndes) {
if (nde.Type_is_grp()) {
Xocfg_maint_svc.Create_grp(db_app, nde.Key(), nde.Owner(), nde.Name(), nde.Help());
@ -42,6 +43,7 @@ public class Xocfg_maint_svc {
else {
Xocfg_maint_itm itm = (Xocfg_maint_itm)nde;
byte[] help = parser_mgr.Main().Parse_text_to_html(parser_mgr.Ctx(), Bry_.new_u8(itm.Help()));
help = Bry_.Replace(help, anch_find_bry, anch_repl_bry); // replace "<a " with "<a tabindex=-1 " else tabbing will go to hidden anchors in help text
Xocfg_maint_svc.Create_itm(db_app, nde.Key(), nde.Owner(), nde.Name(), String_.new_u8(help), itm.Scope(), itm.Db_type(), itm.Dflt(), itm.Gui_type(), itm.Gui_args());
}
}

View File

@ -18,12 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
public class Xocfg_gui_mgr implements Gfo_invk {
public Xocfg_gui_mgr(Xoae_app app) {bnd_mgr = new Xocfg_bnd_mgr(app);}
public Xocfg_tab_mgr Tab_mgr() {return tab_mgr;} private Xocfg_tab_mgr tab_mgr = new Xocfg_tab_mgr();
public Xocfg_bnd_mgr Bnd_mgr() {return bnd_mgr;} private Xocfg_bnd_mgr bnd_mgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tabs)) return tab_mgr;
else if (ctx.Match(k, Invk_bnds)) return bnd_mgr;
if (ctx.Match(k, Invk_bnds)) return bnd_mgr;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_tabs = "tabs", Invk_bnds = "bnds";
private static final String Invk_bnds = "bnds";
}

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
public class Xocfg_regy implements Gfo_invk {
public Xocfg_regy(Xoae_app app) {
app_cfg = new Xocfg_root(app, Xocfg_root_.Tid_app);
app_cfg = new Xocfg_root(app);
}
public Xocfg_root App() {return app_cfg;} private Xocfg_root app_cfg;
public Xocfg_root Get_or_null(String key) {

View File

@ -17,11 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
public class Xocfg_root implements Gfo_invk {
public Xocfg_root(Xoae_app app, byte tid) {
this.tid = tid;
public Xocfg_root(Xoae_app app) {
this.gui_mgr = new Xocfg_gui_mgr(app);
}
public byte Tid() {return tid;} private byte tid;
public Xocfg_gui_mgr Gui_mgr() {return gui_mgr;} private Xocfg_gui_mgr gui_mgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_gui)) return gui_mgr;

View File

@ -1,21 +0,0 @@
/*
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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
public class Xocfg_root_ {
public static final byte Tid_app = 0, Tid_wiki = 1, Tid_ns = 2;
}

View File

@ -1,69 +0,0 @@
/*
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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
import gplx.xowa.guis.views.*;
public class Xocfg_tab_btn_mgr implements Gfo_invk, Gfo_evt_mgr_owner {
public Xocfg_tab_btn_mgr() {
evt_mgr = new Gfo_evt_mgr(this);
}
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private Gfo_evt_mgr evt_mgr;
public int Height() {return height;} private int height = 20;
public boolean Place_on_top() {return place_on_top;} private boolean place_on_top = true;
public boolean Curved() {return curved;} private boolean curved = false;
public boolean Close_visible() {return close_visible;} private boolean close_visible = true;
public boolean Unselected_close_visible() {return unselected_close_visible;} private boolean unselected_close_visible = true;
public int Text_min_chars() {return text_min_chars;} public Xocfg_tab_btn_mgr Text_min_chars_(int v) {text_min_chars = v; return this;} private int text_min_chars = -1;
public int Text_max_chars() {return text_max_chars;} public Xocfg_tab_btn_mgr Text_max_chars_(int v) {text_max_chars = v; return this;} private int text_max_chars = 40;
public boolean Hide_if_one() {return hide_if_one;} public Xocfg_tab_btn_mgr Hide_if_one_(boolean v) {hide_if_one = v; return this;} private boolean hide_if_one;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_place_on_top)) return Yn.To_str(place_on_top);
else if (ctx.Match(k, Invk_place_on_top_)) {place_on_top = m.ReadYn("v"); Gfo_evt_mgr_.Pub_val(this, Evt_place_on_top_changed, place_on_top);}
else if (ctx.Match(k, Invk_curved)) return Yn.To_str(curved);
else if (ctx.Match(k, Invk_curved_)) {curved = m.ReadYn("v"); Gfo_evt_mgr_.Pub_val(this, Evt_curved_changed, curved);}
else if (ctx.Match(k, Invk_height)) return height;
else if (ctx.Match(k, Invk_height_)) {height = m.ReadInt("v"); Gfo_evt_mgr_.Pub_val(this, Evt_height_changed, height);}
else if (ctx.Match(k, Invk_close_visible)) return Yn.To_str(close_visible);
else if (ctx.Match(k, Invk_close_visible_)) {close_visible = m.ReadYn("v"); Gfo_evt_mgr_.Pub_val(this, Evt_close_visible_changed, close_visible);}
else if (ctx.Match(k, Invk_unselected_close_visible)) return Yn.To_str(unselected_close_visible);
else if (ctx.Match(k, Invk_unselected_close_visible_)) {unselected_close_visible = m.ReadYn("v"); Gfo_evt_mgr_.Pub_val(this, Evt_unselected_close_visible_changed, unselected_close_visible);}
else if (ctx.Match(k, Invk_text_min_chars)) return text_min_chars;
else if (ctx.Match(k, Invk_text_min_chars_)) {text_min_chars = m.ReadInt("v"); Gfo_evt_mgr_.Pub_val(this, Evt_text_min_chars_changed, text_min_chars);}
else if (ctx.Match(k, Invk_text_max_chars)) return text_max_chars;
else if (ctx.Match(k, Invk_text_max_chars_)) {text_max_chars = m.ReadInt("v"); Gfo_evt_mgr_.Pub_val(this, Evt_text_max_chars_changed, text_max_chars);}
else if (ctx.Match(k, Invk_hide_if_one)) return Yn.To_str(hide_if_one);
else if (ctx.Match(k, Invk_hide_if_one_)) {hide_if_one = m.ReadYn("v"); Gfo_evt_mgr_.Pub_val(this, Evt_hide_if_one_changed, hide_if_one);}
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_place_on_top = "place_on_top", Invk_place_on_top_ = "place_on_top_"
, Invk_curved = "curved", Invk_curved_ = "curved_"
, Invk_height = "height", Invk_height_ = "height_"
, Invk_close_visible = "close_visible", Invk_close_visible_ = "close_visible_"
, Invk_unselected_close_visible = "unselected_close_visible", Invk_unselected_close_visible_ = "unselected_close_visible_"
, Invk_text_min_chars = "text_min_chars", Invk_text_min_chars_ = "text_min_chars_"
, Invk_text_max_chars = "text_max_chars", Invk_text_max_chars_ = "text_max_chars_"
, Invk_hide_if_one = "hide_if_one", Invk_hide_if_one_ = "hide_if_one_"
;
public static final String
Evt_place_on_top_changed = "place_on_top_changed", Evt_curved_changed = "curved_changed", Evt_height_changed = "height_changed"
, Evt_close_visible_changed = "close_visible_changed", Evt_unselected_close_visible_changed = "unselected_close_visible_changed"
, Evt_text_min_chars_changed = "text_min_chars_changed", Evt_text_max_chars_changed = "text_max_chars_changed"
, Evt_hide_if_one_changed = "hide_if_one_changed"
;
}

View File

@ -1,27 +0,0 @@
/*
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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
public class Xocfg_tab_mgr implements Gfo_invk {
public Xocfg_tab_new_mgr New_mgr() {return new_mgr;} private Xocfg_tab_new_mgr new_mgr = new Xocfg_tab_new_mgr();
public Xocfg_tab_btn_mgr Btn_mgr() {return btn_mgr;} private Xocfg_tab_btn_mgr btn_mgr = new Xocfg_tab_btn_mgr();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_new)) return new_mgr;
else if (ctx.Match(k, Invk_btns)) return btn_mgr;
else return Gfo_invk_.Rv_unhandled;
} private static final String Invk_new = "new", Invk_btns = "btns";
}

View File

@ -1,50 +0,0 @@
/*
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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
public class Xocfg_tab_new_mgr implements Gfo_invk {
public byte Insert_pos() {return insert_pos;} private byte insert_pos = Xocfg_new_tab_pos.Tid_cur_nxt;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_insert_pos)) return Xocfg_new_tab_pos.Xto_str(insert_pos);
else if (ctx.Match(k, Invk_insert_pos_)) insert_pos = Xocfg_new_tab_pos.Xto_tid(m.ReadStr("v"));
else if (ctx.Match(k, Invk_insert_pos_list)) return Xocfg_new_tab_pos.Options__all;
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_insert_pos = "insert_pos", Invk_insert_pos_ = "insert_pos_", Invk_insert_pos_list = "insert_pos_list";
}
class Xocfg_new_tab_pos {
public static final byte Tid_all_bgn = 0, Tid_all_end = 1, Tid_cur_prv = 2, Tid_cur_nxt = 3;
public static final String Key_all_bgn = "first", Key_all_end = "last", Key_cur_prv = "before", Key_cur_nxt = "after";
public static byte Xto_tid(String v) {
if (String_.Eq(v, Key_all_bgn)) return Tid_all_bgn;
else if (String_.Eq(v, Key_all_end)) return Tid_all_end;
else if (String_.Eq(v, Key_cur_prv)) return Tid_all_end;
else if (String_.Eq(v, Key_cur_nxt)) return Tid_all_end;
else throw Err_.new_unhandled(v);
}
public static String Xto_str(byte v) {
switch (v) {
case Tid_all_bgn: return Key_all_bgn;
case Tid_all_end: return Key_all_end;
case Tid_cur_prv: return Key_cur_prv;
case Tid_cur_nxt: return Key_cur_nxt;
default: throw Err_.new_unhandled(v);
}
}
public static Keyval[] Options__all = Keyval_.Ary(Keyval_.new_(Key_all_bgn), Keyval_.new_(Key_all_end), Keyval_.new_(Key_cur_prv), Keyval_.new_(Key_cur_nxt));
}

View File

@ -21,13 +21,13 @@ import gplx.gfui.*; import gplx.gfui.ipts.*; import gplx.gfui.kits.core.*; impor
import gplx.xowa.guis.history.*; import gplx.xowa.guis.bnds.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.langs.vnts.*;
import gplx.xowa.parsers.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.apps.cfgs.old.*;
import gplx.xowa.parsers.*; import gplx.xowa.wikis.pages.lnkis.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
public class Xog_tab_itm implements Gfo_invk {
private Xog_win_itm win; private Xocfg_tab_mgr cfg_tab_mgr;
private Xog_win_itm win;
public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data, Xowe_wiki wiki, Xoae_page page) {
this.tab_mgr = tab_mgr; this.tab_data = tab_data; this.wiki = wiki; this.page = page;
this.win = tab_mgr.Win(); this.cfg_tab_mgr = win.App().Cfg_regy().App().Gui_mgr().Tab_mgr();
this.win = tab_mgr.Win();
this.html_itm = new Xog_html_itm(this);
cmd_sync = win.Kit().New_cmd_sync(this);
}
@ -96,9 +96,8 @@ public class Xog_tab_itm implements Gfo_invk {
Tab_name_(String_.new_u8(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_name = Xog_tab_itm_.Tab_name_min(tab_name, tab_mgr.Btns__min_chars());
tab_name = Xog_tab_itm_.Tab_name_max(tab_name, tab_mgr.Btns__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();

View File

@ -17,10 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.guis.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.gfui.draws.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.tabs.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.apps.cfgs.old.*; import gplx.xowa.apps.apis.xowa.gui.browsers.*; import gplx.xowa.specials.*;
import gplx.xowa.apps.apis.xowa.gui.browsers.*; import gplx.xowa.specials.*;
import gplx.xowa.apps.urls.*;
public class Xog_tab_mgr implements Gfo_evt_itm {
private Ordered_hash tab_regy = Ordered_hash_.New(); private int tab_uid = 0;
private boolean btns__hide_if_one; private int btns__height;
public Xog_tab_mgr(Xog_win_itm win) {
this.win = win;
ev_mgr = new Gfo_evt_mgr(this);
@ -28,6 +29,8 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr 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 int Btns__min_chars() {return btns__min_chars;} private int btns__min_chars;
public int Btns__max_chars() {return btns__max_chars;} private int btns__max_chars;
public byte Html_load_tid() {return html_load_tid;} private byte html_load_tid;
public boolean Html_load_tid__url() {return html_load_tid == Gxw_html_load_tid_.Tid_url;}
public void Init_by_kit(Gfui_kit kit) {
@ -35,19 +38,8 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
active_tab = Xog_tab_itm_.Null;
tab_mgr.Btns_selected_color_(ColorAdp_.White);
tab_mgr.Btns_unselected_color_(ColorAdp_.LightGray);
Gfo_evt_mgr_.Sub_same_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());
Gfo_evt_mgr_.Sub_same_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
);
Gfo_evt_mgr_.Sub_same_many(tab_mgr, this, Gfui_tab_mgr.Evt_tab_selected, Gfui_tab_mgr.Evt_tab_closed, Gfui_tab_mgr.Evt_tab_switched);
win.App().Cfg().Bind_many_app(this, Cfg__place_on_top, Cfg__height, Cfg__hide_if_one, Cfg__curved, Cfg__close_btn_visible, Cfg__unselected_close_btn_visible, Cfg__max_chars, Cfg__min_chars);
html_load_tid = win.App().Api_root().Gui().Browser().Html().Load_tid();
Gfo_evt_mgr_.Sub_same_many(win.App().Api_root().Gui().Browser().Html(), this
, Xoapi_html_box.Evt_load_tid_changed
@ -59,11 +51,6 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
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++) {
@ -99,7 +86,7 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
tab_mgr.Tabs_select_by_idx(rv.Tab_idx());
active_tab = rv;
}
Tabs_hide_if_one_chk();
Tabs_hide_if_one_chk(false);
return rv;
}
public void Tabs_new_dupe(boolean focus) {
@ -171,7 +158,7 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
}
else
Tabs_recalc_idx();
Tabs_hide_if_one_chk();
Tabs_hide_if_one_chk(false);
}
private Xog_tab_itm Tabs_get_by_key_or_warn(String key) {
Xog_tab_itm rv = (Xog_tab_itm)tab_regy.Get_by(key); if (rv == null) win.App().Usr_dlg().Warn_many("", "", "tab.selected could not find tab; key={0}", key);
@ -225,16 +212,17 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
if (focus)
tab_mgr.Tabs_select_by_idx(new_tab.Tab_idx());
}
private void Tabs_hide_if_one_chk() {
gplx.xowa.apps.cfgs.old.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);
private void Tabs_hide_if_one_chk(boolean force) {
if (btns__hide_if_one || force) {// run code only if enabled or forced
if (tab_regy.Count() == 1) {
int desired_height = btns__hide_if_one ? 0 : btns__height;
if (tab_mgr.Btns_height() != desired_height)
tab_mgr.Btns_height_(desired_height);
}
else {
if (tab_mgr.Btns_height() != btns__height)
tab_mgr.Btns_height_(btns__height);
}
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
@ -249,17 +237,20 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
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 if (ctx.Match(k, Xoapi_html_box.Evt_load_tid_changed)) html_load_tid = m.ReadByte("v");
else if (ctx.Match(k, Cfg__place_on_top)) tab_mgr.Btns_place_on_top_(m.ReadBool("v"));
else if (ctx.Match(k, Cfg__height)) {btns__height = m.ReadInt("v"); tab_mgr.Btns_height_(btns__height);}
else if (ctx.Match(k, Cfg__hide_if_one)) {btns__hide_if_one = m.ReadBool("v"); Tabs_hide_if_one_chk(true);}
else if (ctx.Match(k, Cfg__curved)) tab_mgr.Btns_curved_(m.ReadBool("v"));
else if (ctx.Match(k, Cfg__close_btn_visible)) tab_mgr.Btns_close_visible_(m.ReadBool("v"));
else if (ctx.Match(k, Cfg__unselected_close_btn_visible)) tab_mgr.Btns_unselected_close_visible_(m.ReadBool("v"));
else if (ctx.Match(k, Cfg__max_chars)) {btns__max_chars = m.ReadInt("v"); Btns_text_recalc();}
else if (ctx.Match(k, Cfg__min_chars)) {btns__min_chars = m.ReadInt("v"); Btns_text_recalc();}
else return Gfo_invk_.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"
@ -268,4 +259,15 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
, Invk_tabs_new_link__at_dflt__focus_y = "tabs_new_link__at_dflt__focus_y"
, Invk_tabs_close_cur = "tabs_close_cur"
;
private static final String
Cfg__place_on_top = "xowa.gui.tabs.place_on_top"
, Cfg__height = "xowa.gui.tabs.height"
, Cfg__hide_if_one = "xowa.gui.tabs.hide_if_one"
, Cfg__curved = "xowa.gui.tabs.curved"
, Cfg__close_btn_visible = "xowa.gui.tabs.close_btn_visible"
, Cfg__unselected_close_btn_visible = "xowa.gui.tabs.unselected_close_btn_visible"
, Cfg__max_chars = "xowa.gui.tabs.max_chars"
, Cfg__min_chars = "xowa.gui.tabs.min_chars"
;
}

View File

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_page_cache {
private final Object thread_lock = new Object();
private final Xowe_wiki wiki;
private final Ordered_hash cache = Ordered_hash_.New_bry(); // NOTE: wiki titles are not case-sensitive when ns is "1st-letter" (EX: w:earth an w:Earth); in these cases, two entries will be stored
private final List_adp deleted = List_adp_.New();
@ -32,7 +33,7 @@ public class Xow_page_cache {
cache.Add(ttl_full_db, itm);
}
private void Add_safe(byte[] ttl_full_db, Xow_page_cache_itm itm) {
synchronized (cache) { // LOCK:high-usage;DATE:2016-07-14
synchronized (thread_lock) { // LOCK:high-usage;DATE:2016-07-14
if (!cache.Has(ttl_full_db)) { // check again that itm is not in cache; note that this is necessary as cache.Get is not in "synchronized" block (for performance reasons); DATE:2016-12-12
cache.Add(ttl_full_db, itm);
}
@ -95,7 +96,7 @@ public class Xow_page_cache {
return rv;
}
public void Free_mem(boolean clear_permanent_itms) {
synchronized (cache) { // LOCK:app-level; DATE:2016-07-06
synchronized (thread_lock) { // LOCK:app-level; DATE:2016-07-06
if (clear_permanent_itms)
cache.Clear();
else {
@ -107,8 +108,9 @@ public class Xow_page_cache {
}
len = deleted.Len();
for (int i = 0; i < len; i++) {
Xow_page_cache_itm itm = (Xow_page_cache_itm)cache.Get_at(i);
cache.Del(itm.Ttl().Full_db());
Xow_page_cache_itm itm = (Xow_page_cache_itm)deleted.Get_at(i);
if (itm.Ttl() != null) // missing is null
cache.Del(itm.Ttl().Full_db());
}
deleted.Clear();
}