mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Cfg: Remove old prefs system
This commit is contained in:
parent
b876e4a680
commit
1ea75765d7
@ -172,7 +172,6 @@ public class Xoae_app implements Xoa_app, Gfo_invk {
|
|||||||
xwiki_mgr__sitelink_mgr.Init_by_app();
|
xwiki_mgr__sitelink_mgr.Init_by_app();
|
||||||
stage = Xoa_stage_.Tid_launch;
|
stage = Xoa_stage_.Tid_launch;
|
||||||
user.Cfg_mgr().Setup_mgr().Setup_run_check(this); log_bfr.Add("app.upgrade.done");
|
user.Cfg_mgr().Setup_mgr().Setup_run_check(this); log_bfr.Add("app.upgrade.done");
|
||||||
gplx.xowa.users.prefs.Prefs_converter.Instance.Check(this);
|
|
||||||
user.Wiki().Init_assert(); // NOTE: must assert wiki and load langs first, else will be asserted during Portal_mgr().Init(), which will cause IndexOutOfBounds; DATE:2014-10-04
|
user.Wiki().Init_assert(); // NOTE: must assert wiki and load langs first, else will be asserted during Portal_mgr().Init(), which will cause IndexOutOfBounds; DATE:2014-10-04
|
||||||
gplx.xowa.addons.users.wikis.regys.Xou_regy_addon.Init(this);
|
gplx.xowa.addons.users.wikis.regys.Xou_regy_addon.Init(this);
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,7 @@ public class Xoa_boot_mgr {
|
|||||||
catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0}", Err_.Message_gplx_full(e));}
|
catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0}", Err_.Message_gplx_full(e));}
|
||||||
app.Usr_dlg().Log_wkr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
|
app.Usr_dlg().Log_wkr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
|
||||||
|
|
||||||
// run gfs
|
// run gfs; prefs.gfs and app.gfs
|
||||||
gplx.xowa.users.prefs.Prefs_rename_mgr.Instance.Check(app.Usere().Fsys_mgr().App_data_cfg_user_fil());
|
|
||||||
Io_url cmd_file = arg_mgr.Cmd__file();
|
Io_url cmd_file = arg_mgr.Cmd__file();
|
||||||
try {app.Gfs_mgr().Run_url(cmd_file);}
|
try {app.Gfs_mgr().Run_url(cmd_file);}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -30,7 +30,6 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
|||||||
this.user_db_mgr = new Xou_db_mgr(app);
|
this.user_db_mgr = new Xou_db_mgr(app);
|
||||||
this.cfg_mgr = new Xou_cfg(this);
|
this.cfg_mgr = new Xou_cfg(this);
|
||||||
this.history_mgr = new Xou_history_mgr(fsys_mgr.App_data_history_fil());
|
this.history_mgr = new Xou_history_mgr(fsys_mgr.App_data_history_fil());
|
||||||
this.prefs_mgr = new gplx.xowa.users.prefs.Prefs_mgr(app);
|
|
||||||
}
|
}
|
||||||
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private final Gfo_evt_mgr ev_mgr;
|
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private final Gfo_evt_mgr ev_mgr;
|
||||||
public String Key() {return key;} private String key;
|
public String Key() {return key;} private String key;
|
||||||
@ -49,7 +48,6 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
|||||||
public Xowe_wiki Wiki() {if (wiki == null) wiki = Xou_user_.new_or_create_(this, app); return wiki;} private Xowe_wiki wiki;
|
public Xowe_wiki Wiki() {if (wiki == null) wiki = Xou_user_.new_or_create_(this, app); return wiki;} private Xowe_wiki wiki;
|
||||||
public Xou_history_mgr History_mgr() {return history_mgr;} private Xou_history_mgr history_mgr;
|
public Xou_history_mgr History_mgr() {return history_mgr;} private Xou_history_mgr history_mgr;
|
||||||
public Xou_cfg Cfg_mgr() {return cfg_mgr;} private Xou_cfg cfg_mgr;
|
public Xou_cfg Cfg_mgr() {return cfg_mgr;} private Xou_cfg cfg_mgr;
|
||||||
public gplx.xowa.users.prefs.Prefs_mgr Prefs_mgr() {return prefs_mgr;} gplx.xowa.users.prefs.Prefs_mgr prefs_mgr;
|
|
||||||
public Xow_msg_mgr Msg_mgr() {
|
public Xow_msg_mgr Msg_mgr() {
|
||||||
if (msg_mgr == null)
|
if (msg_mgr == null)
|
||||||
msg_mgr = new Xow_msg_mgr(this.Wiki(), this.Lang()); // NOTE: must call this.Lang() not this.lang, else nullRef exception when using "app.shell.fetch_page"; DATE:2013-04-12
|
msg_mgr = new Xow_msg_mgr(this.Wiki(), this.Lang()); // NOTE: must call this.Lang() not this.lang, else nullRef exception when using "app.shell.fetch_page"; DATE:2013-04-12
|
||||||
@ -89,14 +87,13 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
|||||||
else if (ctx.Match(k, Invk_wiki)) return this.Wiki(); // NOTE: mass parse relies on this being this.Wiki(), not wiki
|
else if (ctx.Match(k, Invk_wiki)) return this.Wiki(); // NOTE: mass parse relies on this being this.Wiki(), not wiki
|
||||||
else if (ctx.Match(k, Invk_history)) return history_mgr;
|
else if (ctx.Match(k, Invk_history)) return history_mgr;
|
||||||
else if (ctx.Match(k, Invk_fsys)) return fsys_mgr;
|
else if (ctx.Match(k, Invk_fsys)) return fsys_mgr;
|
||||||
else if (ctx.Match(k, Invk_prefs)) return prefs_mgr;
|
|
||||||
else if (ctx.Match(k, Invk_cfg)) return cfg_mgr;
|
else if (ctx.Match(k, Invk_cfg)) return cfg_mgr;
|
||||||
else if (ctx.Match(k, "name")) return key; //throw Err_.new_unhandled(k); // OBSOLETE: used to return key
|
else if (ctx.Match(k, "name")) return key; //throw Err_.new_unhandled(k); // OBSOLETE: used to return key
|
||||||
else return Gfo_invk_.Rv_unhandled;
|
else return Gfo_invk_.Rv_unhandled;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public static final String Invk_available_from_fsys = "available_from_fsys", Invk_available_from_bulk = "available_from_bulk", Invk_bookmarks_add_fmt_ = "bookmarks_add_fmt_"
|
public static final String Invk_available_from_fsys = "available_from_fsys", Invk_available_from_bulk = "available_from_bulk", Invk_bookmarks_add_fmt_ = "bookmarks_add_fmt_"
|
||||||
, Invk_wiki = "wiki", Invk_history = "history", Invk_fsys = "fsys", Invk_lang = "lang", Invk_msgs = "msgs", Invk_prefs = "prefs", Invk_cfg = "cfg";
|
, Invk_wiki = "wiki", Invk_history = "history", Invk_fsys = "fsys", Invk_lang = "lang", Invk_msgs = "msgs", Invk_cfg = "cfg";
|
||||||
public static final String Key_xowa_user = "anonymous";
|
public static final String Key_xowa_user = "anonymous";
|
||||||
public static final String Evt_lang_changed = "lang_changed";
|
public static final String Evt_lang_changed = "lang_changed";
|
||||||
public void Available_from_fsys() {
|
public void Available_from_fsys() {
|
||||||
|
@ -1,113 +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.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
|
||||||
import gplx.xowa.apps.cfgs.*;
|
|
||||||
public class Prefs_converter {
|
|
||||||
private Bry_bfr bfr = Bry_bfr_.New();
|
|
||||||
private List_adp list = List_adp_.New();
|
|
||||||
public void Check(Xoae_app app) {
|
|
||||||
int options_version = app.Sys_cfg().Options_version();
|
|
||||||
if (options_version == 1) {
|
|
||||||
Io_url cfg_dir = app.Usere().Fsys_mgr().App_data_cfg_dir();
|
|
||||||
Io_url cfg_fil = cfg_dir.GenSubFil("user_system_cfg.gfs");
|
|
||||||
Io_url trg_fil = cfg_fil.GenNewNameAndExt(gplx.xowa.apps.cfgs.Xoa_cfg_db_txt.File_name);
|
|
||||||
if (!Io_mgr.Instance.ExistsFil(trg_fil)) { // do not overwrite file if it is there (i.e.: it's already converted); needed when running in app_mode = cmd (see HACK in Xob_bldr.Run)
|
|
||||||
String old_str = Io_mgr.Instance.LoadFilStr_args(cfg_fil).MissingIgnored_(true).Exec();
|
|
||||||
String new_str = Convert(old_str);
|
|
||||||
Io_mgr.Instance.SaveFilStr(trg_fil, new_str);
|
|
||||||
app.Cfg_mgr().Db_load_txt();
|
|
||||||
app.Cfg_mgr().Set_by_app("app.setup.dumps.wiki_storage_type", "sqlite");
|
|
||||||
app.Log_wtr().Log_to_session_fmt("converted options to v2");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public String Convert(String raw) {
|
|
||||||
list.Clear();
|
|
||||||
GfoMsg root_msg = gplx.langs.gfs.Gfs_msg_bldr.Instance.ParseToMsg(raw);
|
|
||||||
int len = root_msg.Subs_count();
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
GfoMsg msg = root_msg.Subs_getAt(i);
|
|
||||||
Convert_msg(msg, 0);
|
|
||||||
}
|
|
||||||
return Convert_to_stage2(list);
|
|
||||||
}
|
|
||||||
public String Convert_to_stage2(List_adp list) {
|
|
||||||
bfr.Add_str_a7("app.cfgs.get('app.sys_cfg.options_version', 'app').val = '2';").Add_byte_nl();
|
|
||||||
int len = list.Count();
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
Prefs_converter_itm itm = (Prefs_converter_itm)list.Get_at(i);
|
|
||||||
bfr.Add_str_a7("app.cfgs.get('");
|
|
||||||
Write_escaped_str(bfr, itm.Key());
|
|
||||||
bfr.Add_str_a7("', '" + Xoa_cfg_grp_tid.Key_app_str + "'");
|
|
||||||
bfr.Add_str_a7(").val = '");
|
|
||||||
Write_escaped_str(bfr, itm.Val());
|
|
||||||
bfr.Add_str_a7("';\n");
|
|
||||||
}
|
|
||||||
return bfr.To_str_and_clear();
|
|
||||||
}
|
|
||||||
private void Write_escaped_str(Bry_bfr bfr, String str) {
|
|
||||||
byte[] bry = Bry_.new_u8(str);
|
|
||||||
int len = bry.length;
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
byte b = bry[i];
|
|
||||||
if (b == Byte_ascii.Apos)
|
|
||||||
bfr.Add_byte_repeat(Byte_ascii.Apos, 2);
|
|
||||||
else
|
|
||||||
bfr.Add_byte(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void Convert_msg(GfoMsg m, int depth) {
|
|
||||||
int subs_len = m.Subs_count();
|
|
||||||
if (subs_len == 0) {
|
|
||||||
bfr.Add_byte(Byte_ascii.Dot);
|
|
||||||
byte[] prop_set_key = Bry_.new_u8(m.Key());
|
|
||||||
int prop_set_key_len = prop_set_key.length;
|
|
||||||
if (prop_set_key_len == 0) return; // empty key; return now, else error
|
|
||||||
if (prop_set_key[prop_set_key_len - 1] != Byte_ascii.Underline) return; // doesn't end with _
|
|
||||||
bfr.Add_mid(prop_set_key, 0, prop_set_key_len - 1);
|
|
||||||
Prefs_converter_itm itm = new Prefs_converter_itm();
|
|
||||||
itm.Key_(bfr.To_str_and_clear());
|
|
||||||
String prop_val = m.Args_getAt(0).Val_to_str_or_empty();
|
|
||||||
itm.Val_(prop_val);
|
|
||||||
list.Add(itm);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (depth != 0) bfr.Add_byte(Byte_ascii.Dot);
|
|
||||||
if (String_.Eq(m.Key(), "scripts")) {bfr.Clear(); return;}
|
|
||||||
bfr.Add_str_u8(m.Key());
|
|
||||||
int args_count = m.Args_count();
|
|
||||||
if (args_count > 0) {
|
|
||||||
bfr.Add_byte(Byte_ascii.Paren_bgn);
|
|
||||||
for (int i = 0; i < args_count; i++) {
|
|
||||||
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
|
|
||||||
Keyval kv = m.Args_getAt(i);
|
|
||||||
bfr.Add_byte(Byte_ascii.Quote);
|
|
||||||
bfr.Add_str_u8(kv.Val_to_str_or_empty());
|
|
||||||
bfr.Add_byte(Byte_ascii.Quote);
|
|
||||||
}
|
|
||||||
bfr.Add_byte(Byte_ascii.Paren_end);
|
|
||||||
}
|
|
||||||
Convert_msg(m.Subs_getAt(0), depth + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static final Prefs_converter Instance = new Prefs_converter(); Prefs_converter() {}
|
|
||||||
}
|
|
||||||
class Prefs_converter_itm {
|
|
||||||
public String Key() {return key;} public void Key_(String v) {this.key = v;} private String key;
|
|
||||||
public String Val() {return val;} public void Val_(String v) {this.val = v;} private String val;
|
|
||||||
}
|
|
@ -1,62 +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.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
|
||||||
import org.junit.*;
|
|
||||||
public class Prefs_converter_tst {
|
|
||||||
@Before public void init() {} Prefs_converter_fxt fxt = new Prefs_converter_fxt();
|
|
||||||
@Test public void Basic() {
|
|
||||||
fxt.Test_convert(String_.Concat_lines_nl
|
|
||||||
( "app.scripts.txns.get('user.prefs.general').version_('0.7.2.0').bgn();"
|
|
||||||
, "a.b.c_('d');"
|
|
||||||
, "e.f.g_h_(1);"
|
|
||||||
, "i.j('k').l_(2);"
|
|
||||||
), String_.Concat_lines_nl
|
|
||||||
( "app.cfgs.get('app.sys_cfg.options_version', 'app').val = '2';"
|
|
||||||
, "app.cfgs.get('a.b.c', 'app').val = 'd';"
|
|
||||||
, "app.cfgs.get('e.f.g_h', 'app').val = '1';"
|
|
||||||
, "app.cfgs.get('i.j(\"k\").l', 'app').val = '2';"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class Prefs_converter_fxt {
|
|
||||||
Prefs_converter converter = Prefs_converter.Instance;
|
|
||||||
public void Test_convert(String raw, String expd) {
|
|
||||||
String actl = converter.Convert(raw);
|
|
||||||
Tfds.Eq_str_lines(expd, actl);
|
|
||||||
}
|
|
||||||
public void Parse(String raw_str) {
|
|
||||||
byte[] raw_bry = Bry_.new_u8(raw_str);
|
|
||||||
int bgn_pos = Bry_find_.Find_fwd(raw_bry, Byte_ascii.Paren_bgn);
|
|
||||||
if (bgn_pos == Bry_find_.Not_found) throw Err_.new_wo_type("unable to find paren_bgn", "raw", raw_str);
|
|
||||||
int end_pos = Bry_find_.Find_fwd(raw_bry, Byte_ascii.Paren_end, bgn_pos);
|
|
||||||
if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("unable to find paren_end", "raw", raw_str);
|
|
||||||
raw_bry = Bry_.Mid(raw_bry, bgn_pos, end_pos);
|
|
||||||
int len = raw_bry.length;
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
byte[] c = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(raw_bry, i);
|
|
||||||
if (c.length == 1) {
|
|
||||||
switch (c[0]) {
|
|
||||||
case Byte_ascii.Dash:
|
|
||||||
break;
|
|
||||||
case Byte_ascii.Pipe:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,124 +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.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
|
||||||
import gplx.langs.htmls.*;
|
|
||||||
class Prefs_html_wtr {
|
|
||||||
public Prefs_html_wtr(Prefs_mgr prefs_mgr) {this.prefs_mgr = prefs_mgr;} Prefs_mgr prefs_mgr; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
|
||||||
public void Write(Bry_bfr bfr, byte[] src, Gfh_nde hnde, int prop_idx, byte[] trg_type, byte[] trg_val) {
|
|
||||||
Object prop_val = Eval_prop_get(hnde);
|
|
||||||
byte elem_type = Prefs_mgr.Elem_tid_tid_of(hnde);
|
|
||||||
bfr.Add_mid(src, hnde.Tag_lhs_bgn(), hnde.Tag_lhs_end() - 1);
|
|
||||||
switch (elem_type) {
|
|
||||||
case Prefs_mgr.Elem_tid_input_text: this.Write_input(bfr, hnde, prop_idx, prop_val); break;
|
|
||||||
case Prefs_mgr.Elem_tid_select: this.Write_select(bfr, hnde, prop_idx, prop_val); break;
|
|
||||||
case Prefs_mgr.Elem_tid_input_xowa_io: this.Write_io(bfr, hnde, prop_idx, prop_val); return;
|
|
||||||
case Prefs_mgr.Elem_tid_input_checkbox: this.Write_checkbox(bfr, hnde, prop_idx, prop_val); break;
|
|
||||||
case Prefs_mgr.Elem_tid_textarea: this.Write_textarea(bfr, hnde, prop_idx, prop_val); break;
|
|
||||||
}
|
|
||||||
bfr.Add_mid(src, hnde.Tag_rhs_bgn(), hnde.Tag_rhs_end());
|
|
||||||
}
|
|
||||||
private void Write_input(Bry_bfr bfr, Gfh_nde hnde, int prop_idx, Object prop_val) {
|
|
||||||
Write__id(bfr, prop_idx); // " id='xowa_prop_123'"
|
|
||||||
Write__value_atr(bfr, prop_val); // " value='abc'"
|
|
||||||
Write__nde_end(bfr); // ">"
|
|
||||||
}
|
|
||||||
private void Write_textarea(Bry_bfr bfr, Gfh_nde hnde, int prop_idx, Object prop_val) {
|
|
||||||
Write__id(bfr, prop_idx); // " id='xowa_prop_123'"
|
|
||||||
Write__nde_end(bfr); // ">"
|
|
||||||
bfr.Add(Gfh_utl.Escape_html_as_bry(Bry_.new_u8(Object_.Xto_str_strict_or_empty(prop_val))));
|
|
||||||
// "abcde"
|
|
||||||
}
|
|
||||||
private void Write_checkbox(Bry_bfr bfr, Gfh_nde hnde, int prop_idx, Object prop_val) {
|
|
||||||
Write__id(bfr, prop_idx); // " id='xowa_prop_123'"
|
|
||||||
boolean prop_val_is_true = String_.Eq((String)prop_val, "y");
|
|
||||||
if (prop_val_is_true)
|
|
||||||
bfr.Add(Atr_stub_checked); // " checked='checked'"
|
|
||||||
Write__nde_end(bfr); // ">"
|
|
||||||
}
|
|
||||||
private void Write_select(Bry_bfr bfr, Gfh_nde hnde, int prop_idx, Object prop_val) {
|
|
||||||
Keyval[] options_list = Get_select_options(hnde);
|
|
||||||
Write__id(bfr, prop_idx); // " id='xowa_prop_123'"
|
|
||||||
Write__nde_end(bfr); // ">"
|
|
||||||
bfr.Add_byte_nl(); // "\n"
|
|
||||||
int len = options_list.length;
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
Keyval option = options_list[i];
|
|
||||||
bfr.Add(Nde_stub_option_bgn); // " <option value='"
|
|
||||||
bfr.Add_str_u8(option.Key()); // "option_key"
|
|
||||||
bfr.Add_byte(Byte_ascii.Apos); // "'"
|
|
||||||
if (String_.Eq(Object_.Xto_str_strict_or_empty(prop_val), option.Key()))
|
|
||||||
bfr.Add_str_a7(" selected='selected'"); // " selected='selected'"
|
|
||||||
bfr.Add_byte(Byte_ascii.Gt); // ">"
|
|
||||||
bfr.Add_str_u8(option.Val_to_str_or_empty());// "option_text"
|
|
||||||
bfr.Add(Nde_stub_option_end); // "</option>\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void Write_io(Bry_bfr bfr, Gfh_nde hnde, int prop_idx, Object prop_val) {
|
|
||||||
Write__id(bfr, prop_idx); // " id='xowa_prop_123'"
|
|
||||||
Write__value_atr(bfr, prop_val); // " value='abc'"
|
|
||||||
Write__nde_end(bfr); // ">"
|
|
||||||
Write__tag_end(bfr, hnde); // "</input>"
|
|
||||||
Write_io_btn(bfr, hnde, prop_idx);
|
|
||||||
}
|
|
||||||
private void Write_io_btn(Bry_bfr bfr, Gfh_nde hnde, int prop_idx) {
|
|
||||||
bfr.Add_str_a7("<button id='xowa_prop_").Add_int_variable(prop_idx).Add_str_a7("_io").Add_byte(Byte_ascii.Apos);
|
|
||||||
bfr.Add_str_a7(" class='options_button' onclick='xowa_io_select(\"file\", \"");
|
|
||||||
bfr.Add_str_a7("xowa_prop_").Add_int_variable(prop_idx);
|
|
||||||
byte[] xowa_io_msg = hnde.Atrs_val_by_key_bry(Bry_.new_a7("xowa_io_msg"));
|
|
||||||
if (xowa_io_msg == null) xowa_io_msg = Bry_.new_a7("Please select a file.");
|
|
||||||
bfr.Add_str_a7("\", \"").Add(xowa_io_msg).Add_str_a7("\");'>");
|
|
||||||
bfr.Add_str_a7("...</button>").Add_byte_nl();
|
|
||||||
}
|
|
||||||
private static final byte[] Atr_key_xowa_prop_list = Bry_.new_a7("xowa_prop_list")
|
|
||||||
, Atr_stub_id = Bry_.new_a7(" id='xowa_prop_")
|
|
||||||
, Atr_stub_value = Bry_.new_a7(" value='")
|
|
||||||
, Atr_stub_checked = Bry_.new_a7(" checked='checked'")
|
|
||||||
, Nde_stub_option_bgn = Bry_.new_a7(" <option value='")
|
|
||||||
, Nde_stub_option_end = Bry_.new_a7("</option>\n")
|
|
||||||
;
|
|
||||||
Object Eval_prop_get(Gfh_nde hnde) {
|
|
||||||
byte[] cmd = hnde.Atrs_val_by_key_bry(Prefs_mgr.Bry_prop);
|
|
||||||
if (cmd == null)
|
|
||||||
cmd = hnde.Atrs_val_by_key_bry(Prefs_mgr.Bry_prop_get);
|
|
||||||
tmp_bfr.Add(cmd).Add_byte(Byte_ascii.Semic);
|
|
||||||
try {return prefs_mgr.Eval(tmp_bfr.To_bry_and_clear());}
|
|
||||||
catch (Exception e) {return Err_.Message_gplx_full(e);}
|
|
||||||
}
|
|
||||||
Keyval[] Get_select_options(Gfh_nde hnde) {
|
|
||||||
byte[] options_list_key = hnde.Atrs_val_by_key_bry(Atr_key_xowa_prop_list);
|
|
||||||
tmp_bfr.Add(options_list_key).Add_byte(Byte_ascii.Semic);
|
|
||||||
try {return (Keyval[])prefs_mgr.Eval(tmp_bfr.To_bry_and_clear());}
|
|
||||||
catch (Exception e) {Err_.Noop(e); return Keyval_.Ary_empty;}
|
|
||||||
}
|
|
||||||
private void Write__nde_end(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Gt);}
|
|
||||||
private void Write__id(Bry_bfr bfr, int prop_idx) {
|
|
||||||
bfr.Add(Atr_stub_id); // " id='xowa_prop_"
|
|
||||||
bfr.Add_int_variable(prop_idx); // "123"
|
|
||||||
bfr.Add_byte(Byte_ascii.Apos); // "'"
|
|
||||||
}
|
|
||||||
private void Write__value_atr(Bry_bfr bfr, Object prop_val) {
|
|
||||||
bfr.Add(Atr_stub_value); // " value='"
|
|
||||||
bfr.Add(Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, Object_.Xto_str_strict_or_empty(prop_val)));
|
|
||||||
// "abcde"
|
|
||||||
bfr.Add_byte(Byte_ascii.Apos); // "'"
|
|
||||||
}
|
|
||||||
private void Write__tag_end(Bry_bfr bfr, Gfh_nde hnde) {
|
|
||||||
bfr.Add_mid(hnde.Src(), hnde.Tag_rhs_bgn(), hnde.Tag_rhs_end()); // "</input>"
|
|
||||||
// bfr.Add_byte_nl(); // "\n"; NOTE: do not write \n; will move to next line; DATE:2013-10-16
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,158 +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.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
|
||||||
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.langs.htmls.*;
|
|
||||||
import gplx.gfui.*; import gplx.gfui.controls.standards.*;
|
|
||||||
import gplx.xowa.guis.views.*;
|
|
||||||
import gplx.xowa.apps.urls.*;
|
|
||||||
import gplx.xowa.parsers.*;
|
|
||||||
public class Prefs_mgr implements Gfo_invk {
|
|
||||||
public Prefs_mgr(Xoae_app app) {
|
|
||||||
this.app = app;
|
|
||||||
atrs_hash = Hash_adp_bry.cs();
|
|
||||||
atrs_hash.Add(Bry_prop, Byte_obj_val.new_(Tid_prop));
|
|
||||||
atrs_hash.Add(Bry_prop_get, Byte_obj_val.new_(Tid_prop_get));
|
|
||||||
atrs_hash.Add(Bry_prop_set, Byte_obj_val.new_(Tid_prop_set));
|
|
||||||
html_wtr = new Prefs_html_wtr(this);
|
|
||||||
} private Xoae_app app; private Hash_adp_bry atrs_hash; private Gfh_parser html_rdr = new Gfh_parser(); private Prefs_html_wtr html_wtr;
|
|
||||||
private Prefs_trg_mgr option_trgs_mgr = new Prefs_trg_mgr();
|
|
||||||
public void Html_box_mok_(Xog_html_itm v) {this.html_box_mok = v;} private Xog_html_itm html_box_mok;
|
|
||||||
public byte[] Props_get(byte[] src) {
|
|
||||||
// option_trgs_mgr.Init(app.Gui_mgr().Browser_win().Active_page().Url());
|
|
||||||
if (props_get_fmtr == null) props_get_fmtr = Bry_fmtr.keys_().Eval_mgr_(app.Gfs_mgr().Eval_mgr());
|
|
||||||
src = this.Parse_wikitext_to_html(src);
|
|
||||||
props_get_fmtr.Fmt_(src);
|
|
||||||
Bry_bfr bfr = Bry_bfr_.New();
|
|
||||||
try {src = props_get_fmtr.Fmt_(src).Bld_bry_none(bfr);}
|
|
||||||
catch (Exception e) {src = Bry_.Add(src, Bry_.new_u8(Err_.Message_gplx_full(e)));}
|
|
||||||
Gfh_nde[] hndes = html_rdr.Parse_as_ary(src);
|
|
||||||
hndes = Gfh_selecter.Select(src, hndes, atrs_hash);
|
|
||||||
int pos = 0;
|
|
||||||
int len = hndes.length;
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
Gfh_nde hnde = hndes[i];
|
|
||||||
bfr.Add_mid(src, pos, hnde.Tag_lhs_bgn());
|
|
||||||
html_wtr.Write(bfr, src, hnde, i, option_trgs_mgr.Trg_type(), option_trgs_mgr.Trg_val());
|
|
||||||
pos = hnde.Tag_rhs_end();
|
|
||||||
}
|
|
||||||
bfr.Add_mid(src, pos, src.length);
|
|
||||||
return bfr.To_bry_and_clear();
|
|
||||||
} private Bry_fmtr props_get_fmtr;
|
|
||||||
private void Props_set_and_reload() {
|
|
||||||
Xoae_page page = app.Gui_mgr().Browser_win().Active_page();
|
|
||||||
Props_set(page.Db().Text().Text_bry());
|
|
||||||
page.Wikie().Parser_mgr().Parse(page, true); // reparse in order to save new values to root; needed for history and going back / fwd; DATE:2014-02-07
|
|
||||||
// app.Api_root().Gui().Page().View().Reload(); // force reload to update page; needed for language; DATE:2014-05-26; NOTE: deactivate on 2015-08-13; refreshing page causes options to not show
|
|
||||||
Xog_tab_itm tab = app.Gui_mgr().Browser_win().Active_tab(); if (tab != null) tab.Exec_notify(Bool_.Y, "options saved");
|
|
||||||
}
|
|
||||||
public void Props_set(byte[] src) {
|
|
||||||
src = Bry_.Replace(src, Bry_.new_a7("<xowa_cmd>"), Bry_.new_a7("<xowa_cmd>"));
|
|
||||||
src = Bry_.Replace(src, Bry_.new_a7("</xowa_cmd>"), Bry_.new_a7("</xowa_cmd>"));
|
|
||||||
src = this.Parse_wikitext_to_html(src);
|
|
||||||
Gfh_nde[] hndes = html_rdr.Parse_as_ary(src);
|
|
||||||
hndes = Gfh_selecter.Select(src, hndes, atrs_hash);
|
|
||||||
int len = hndes.length;
|
|
||||||
boolean tidy_enabled = true; // app.Html_mgr().Tidy_mgr().Enabled();
|
|
||||||
Bry_bfr cmd_bfr = Bry_bfr_.Reset(255);
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
Gfh_nde hnde = hndes[i];
|
|
||||||
Props_set_by_hnde(cmd_bfr, src, hnde, i, tidy_enabled);
|
|
||||||
}
|
|
||||||
app.Cfg_mgr().Db_save_txt();
|
|
||||||
}
|
|
||||||
private void Props_set_by_hnde(Bry_bfr cmd_bfr, byte[] src, Gfh_nde hnde, int i, boolean tidy_enabled) {
|
|
||||||
byte[] eval_code = hnde.Atrs_val_by_key_bry(Bry_prop);
|
|
||||||
if (eval_code == null) eval_code = hnde.Atrs_val_by_key_bry(Bry_prop_set);
|
|
||||||
String hnde_val = null;
|
|
||||||
String hnde_key = "xowa_prop_" + Int_.To_str(i);
|
|
||||||
Xog_html_itm html_itm = html_box_mok == null ? app.Gui_mgr().Browser_win().Active_tab().Html_itm() : html_box_mok; // TEST:
|
|
||||||
byte elem_tid = Prefs_mgr.Elem_tid_tid_of(hnde);
|
|
||||||
switch (elem_tid) {
|
|
||||||
case Elem_tid_input_text:
|
|
||||||
case Elem_tid_input_xowa_io:
|
|
||||||
case Elem_tid_select: hnde_val = html_itm.Html_elem_atr_get_str(hnde_key, Gfui_html.Atr_value); break;
|
|
||||||
case Elem_tid_textarea: hnde_val = Gfh_utl.Unescape_as_str(html_itm.Html_elem_atr_get_str(hnde_key, Gfui_html.Atr_value)); break;
|
|
||||||
case Elem_tid_input_checkbox: hnde_val = html_itm.Html_elem_atr_get_bool(hnde_key, "checked") ? "y" : "n"; break;
|
|
||||||
}
|
|
||||||
byte[] get_cmd = Props_get(eval_code);
|
|
||||||
Object get_val = Eval_run(Bry_.Add(get_cmd, Byte_ascii.Semic));
|
|
||||||
String get_str = Object_.Xto_str_strict_or_null_mark(get_val);
|
|
||||||
hnde_val = Scrub_tidy_trailing_nl_in_textarea(tidy_enabled, elem_tid, hnde_val);
|
|
||||||
get_str = Scrub_tidy_trailing_nl_in_textarea(tidy_enabled, elem_tid, get_str);
|
|
||||||
if (String_.Eq(get_str, hnde_val)) return;
|
|
||||||
try {app.Cfg_mgr().Set_by_app(String_.new_u8(get_cmd), hnde_val);}
|
|
||||||
catch (Exception e) {app.Usr_dlg().Warn_many("", "", "pref update failed: code=~{0} err=~{1}", eval_code, Err_.Message_gplx_full(e));}
|
|
||||||
}
|
|
||||||
private Object Eval_run(byte[] cmd) {
|
|
||||||
try {return Eval(cmd);}
|
|
||||||
catch (Exception e) {Err_.Noop(e); return null;}
|
|
||||||
}
|
|
||||||
private byte[] Parse_wikitext_to_html(byte[] src) {
|
|
||||||
Xowe_wiki wiki = app.Usere().Wiki(); // NOTE: this limits prefs to home_wiki only
|
|
||||||
Xop_root_tkn root = new Xop_root_tkn();
|
|
||||||
Xop_ctx ctx = Xop_ctx.New__top(wiki); // NOTE: always create new ctx; do not reuse existing, else popup will clear out existing page's prefs; DATE:2015-04-29
|
|
||||||
wiki.Parser_mgr().Main().Parse_text_to_wdom(root, ctx, ctx.Tkn_mkr(), src, 0);
|
|
||||||
return root.Data_mid();
|
|
||||||
}
|
|
||||||
public Object Eval(byte[] code) {return app.Gfs_mgr().Run_str(String_.new_a7(code));}
|
|
||||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
|
||||||
if (ctx.Match(k, Invk_exec_get)) return Props_get(m.ReadBry("v"));
|
|
||||||
else if (ctx.Match(k, Invk_save)) Props_set_and_reload();
|
|
||||||
else return Gfo_invk_.Rv_unhandled;
|
|
||||||
return this;
|
|
||||||
} private static final String Invk_exec_get = "exec_get", Invk_save = "save";
|
|
||||||
private static final byte Tid_prop = 0, Tid_prop_get = 1, Tid_prop_set = 2;
|
|
||||||
public static final byte[] Bry_prop = Bry_.new_a7("xowa_prop"), Bry_prop_get = Bry_.new_a7("xowa_prop_get"), Bry_prop_set = Bry_.new_a7("xowa_prop_set"), Bry_id = Bry_.new_a7("id");
|
|
||||||
public static byte Elem_tid_tid_of(Gfh_nde hnde) {
|
|
||||||
byte[] elem_name = Bry_.Mid(hnde.Src(), hnde.Name_bgn(), hnde.Name_end());
|
|
||||||
if (Bry_.Eq(elem_name, Nde_textarea)) return Elem_tid_textarea;
|
|
||||||
else if (Bry_.Eq(elem_name, Nde_select)) return Elem_tid_select;
|
|
||||||
else if (Bry_.Eq(elem_name, Nde_input)) {
|
|
||||||
byte[] input_type = hnde.Atrs_val_by_key_bry(Input_type);
|
|
||||||
if (input_type == null) return Elem_tid_input_text;// treat <input /> as <input type='text'/>
|
|
||||||
if (Bry_.Eq(input_type, Type_text)) return Elem_tid_input_text;
|
|
||||||
else if (Bry_.Eq(input_type, Type_checkbox)) return Elem_tid_input_checkbox;
|
|
||||||
else if (Bry_.Eq(input_type, Type_combo)) return Elem_tid_input_combo;
|
|
||||||
else if (Bry_.Eq(input_type, Type_xowa_io)) return Elem_tid_input_xowa_io;
|
|
||||||
else return Elem_tid_null;
|
|
||||||
}
|
|
||||||
else return Elem_tid_null;
|
|
||||||
} private static final byte[] Input_type = Bry_.new_a7("type"), Nde_input = Bry_.new_a7("input"), Nde_textarea = Bry_.new_a7("textarea"), Nde_select = Bry_.new_a7("select"), Type_text = Bry_.new_a7("text"), Type_checkbox = Bry_.new_a7("checkbox"), Type_combo = Bry_.new_a7("xowa_combo"), Type_xowa_io = Bry_.new_a7("xowa_io");
|
|
||||||
public static String Scrub_tidy_trailing_nl_in_textarea(boolean tidy_enabled, byte elem_tid, String val) {
|
|
||||||
return // if tidy_enabled and text_area and ends with \n, then remove \n; DATE:2014-06-21
|
|
||||||
( tidy_enabled
|
|
||||||
&& elem_tid == Elem_tid_textarea
|
|
||||||
&& String_.Has_at_end(val, "\n")
|
|
||||||
)
|
|
||||||
? String_.MidByLen(val, 0, String_.Len(val) - 1)
|
|
||||||
: val
|
|
||||||
;
|
|
||||||
}
|
|
||||||
public static final byte Elem_tid_null = 0, Elem_tid_input_text = 1, Elem_tid_textarea = 2, Elem_tid_input_checkbox = 3, Elem_tid_select = 4, Elem_tid_input_combo = 5, Elem_tid_input_xowa_io = 6;
|
|
||||||
}
|
|
||||||
class Prefs_trg_mgr {
|
|
||||||
private Gfo_qarg_mgr_old arg_hash = new Gfo_qarg_mgr_old();
|
|
||||||
public byte[] Trg_type() {return trg_type;} private byte[] trg_type;
|
|
||||||
public byte[] Trg_val() {return trg_val;} private byte[] trg_val;
|
|
||||||
public void Init(Xoa_url url) {
|
|
||||||
arg_hash.Load(url.Qargs_ary());
|
|
||||||
trg_type = arg_hash.Get_val_bry_or(Prefs_trg_mgr.Arg_option_trg_type_bry, null);
|
|
||||||
trg_val = arg_hash.Get_val_bry_or(Prefs_trg_mgr.Arg_option_trg_val_bry, null);
|
|
||||||
}
|
|
||||||
public static final byte[] Arg_option_trg_type_bry = Bry_.new_a7("option_trg_type"), Arg_option_trg_val_bry = Bry_.new_a7("option_trg_val");
|
|
||||||
}
|
|
@ -1,184 +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.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
|
||||||
import org.junit.*;
|
|
||||||
import gplx.gfui.*; import gplx.gfui.controls.standards.*; import gplx.xowa.apps.gfs.*; import gplx.langs.gfs.*;
|
|
||||||
import gplx.xowa.guis.views.*;
|
|
||||||
public class Prefs_mgr_tst {
|
|
||||||
private Prefs_mgr_fxt fxt = new Prefs_mgr_fxt();
|
|
||||||
@Before public void init() {fxt.Clear();}
|
|
||||||
@Test public void Get_basic_pass() {
|
|
||||||
fxt.Exec_get("<input xowa_prop='app.user.name'></input> text", "<input xowa_prop='app.user.name' id='xowa_prop_0' value='test_user'></input> text");
|
|
||||||
}
|
|
||||||
@Test public void Get_basic_fail() {
|
|
||||||
fxt.Exec_get("<input xowa_prop='fail.prop'></input>", "<input xowa_prop='fail.prop' id='xowa_prop_0' value='Error'></input>");
|
|
||||||
}
|
|
||||||
@Test public void Get_eval_pass() {
|
|
||||||
fxt.Exec_get("~{<>app.user.name;<>}", "test_user");
|
|
||||||
}
|
|
||||||
@Test public void Get_eval_fail() {
|
|
||||||
fxt.Exec_get_has("~{<>fail.prop;<>}", "~{<>fail.prop;<>}[err 0] <gplx> key not found: key=fail");
|
|
||||||
}
|
|
||||||
@Test public void Set() {
|
|
||||||
fxt.Init_elem_atr_val("xowa_prop_0", "abc");
|
|
||||||
fxt.Test_set("<input xowa_prop='app.gui.html.auto_focus_id' id='xowa_prop_0'>abc</input>");
|
|
||||||
Tfds.Eq("abc", fxt.App().Gui_mgr().Html_mgr().Auto_focus_id());
|
|
||||||
}
|
|
||||||
// @Test public void Get_checkbox() {
|
|
||||||
// fxt.App().File_mgr().Wmf_mgr().Enabled_(true);
|
|
||||||
// fxt.Exec_get("a <input type='checkbox' xowa_prop='app.files.download.enabled'></input> b", "a <input type='checkbox' xowa_prop='app.files.download.enabled' id='xowa_prop_0' checked='checked'></input> b");
|
|
||||||
// fxt.App().File_mgr().Wmf_mgr().Enabled_(false);
|
|
||||||
// fxt.Exec_get("a <input type='checkbox' xowa_prop='app.files.download.enabled'></input> b", "a <input type='checkbox' xowa_prop='app.files.download.enabled' id='xowa_prop_0'></input> b");
|
|
||||||
// }
|
|
||||||
// @Test public void Set_checkbox() {
|
|
||||||
// fxt.Init_elem_atr_checked("xowa_prop_0", "true");
|
|
||||||
// fxt.App().File_mgr().Wmf_mgr().Enabled_(false);
|
|
||||||
// fxt.Test_set("<input type='checkbox' xowa_prop='app.files.download.enabled' checked='checked' id='xowa_prop_0'></input>");
|
|
||||||
// Tfds.Eq(true, fxt.App().File_mgr().Wmf_mgr().Enabled());
|
|
||||||
// fxt.Init_elem_atr_checked("xowa_prop_0", "false");
|
|
||||||
// fxt.Test_set("<input type='checkbox' xowa_prop='app.files.download.enabled' id='xowa_prop_0'></input>");
|
|
||||||
// Tfds.Eq(false, fxt.App().File_mgr().Wmf_mgr().Enabled());
|
|
||||||
// }
|
|
||||||
@Test public void Get_textarea() {
|
|
||||||
fxt.Exec_get("<textarea xowa_prop='app.user.name'></textarea>", "<textarea xowa_prop='app.user.name' id='xowa_prop_0'>test_user</textarea>");
|
|
||||||
}
|
|
||||||
@Test public void Get_textarea_escaped() {
|
|
||||||
fxt.App().Api_root().Test_str_("<b>a</b>");
|
|
||||||
fxt.Exec_get("<textarea xowa_prop='app.api.test_str'></textarea>", "<textarea xowa_prop='app.api.test_str' id='xowa_prop_0'><b>a</b></textarea>");
|
|
||||||
}
|
|
||||||
@Test public void Set_textarea() {
|
|
||||||
fxt.Init_elem_atr_val("xowa_prop_0", "abc");
|
|
||||||
fxt.Test_set("<textarea xowa_prop='app.gui.html.auto_focus_id' id='xowa_prop_0'>abc</textarea>");
|
|
||||||
Tfds.Eq("abc", fxt.App().Gui_mgr().Html_mgr().Auto_focus_id());
|
|
||||||
}
|
|
||||||
@Test public void Set_textarea_escaped() {
|
|
||||||
fxt.Init_elem_atr_val("xowa_prop_0", "<b>a</b>");
|
|
||||||
fxt.Test_set("<textarea xowa_prop='app.gui.html.auto_focus_id' id='xowa_prop_0'><b>a</b></textarea>");
|
|
||||||
Tfds.Eq("<b>a</b>", fxt.App().Gui_mgr().Html_mgr().Auto_focus_id());
|
|
||||||
}
|
|
||||||
// @Test public void Get_select() {
|
|
||||||
// fxt.Exec_get
|
|
||||||
// ( "<select xowa_prop='app.files.math.renderer' xowa_prop_list='app.files.math.renderer_list'></select>", String_.Concat_lines_nl
|
|
||||||
// ( "<select xowa_prop='app.files.math.renderer' xowa_prop_list='app.files.math.renderer_list' id='xowa_prop_0'>"
|
|
||||||
// , " <option value='mathjax' selected='selected'>MathJax</option>"
|
|
||||||
// , " <option value='latex'>LaTeX</option>"
|
|
||||||
// , "</select>"
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
// @Test public void Set_select() {
|
|
||||||
// fxt.Init_elem_atr_val("xowa_prop_0", "mathjax");
|
|
||||||
// fxt.Test_set("<select xowa_prop='app.files.math.renderer' xowa_prop_list='app.files.math.renderer_list'></select>");
|
|
||||||
// Tfds.Eq(true, fxt.App().File_mgr().Math_mgr().Renderer_is_mathjax());
|
|
||||||
// fxt.Init_elem_atr_val("xowa_prop_0", "latex");
|
|
||||||
// fxt.Test_set("<select xowa_prop='app.files.math.renderer' xowa_prop_list='app.files.math.renderer_list'></select>");
|
|
||||||
// Tfds.Eq(false, fxt.App().File_mgr().Math_mgr().Renderer_is_mathjax());
|
|
||||||
// }
|
|
||||||
// @Test public void Get_io_file() {
|
|
||||||
// fxt.Exec_get
|
|
||||||
// ( "<input type='xowa_io' xowa_prop='app.fsys.apps.media' xowa_io_msg='Select program for Web Browser'></input>", String_.Concat
|
|
||||||
// ( "<input type='xowa_io' xowa_prop='app.fsys.apps.media' xowa_io_msg='Select program for Web Browser' id='xowa_prop_0' value='gplx.Gfo_invk__noop'></input>"
|
|
||||||
// , "<button id='xowa_prop_0_io' class='options_button' onclick='xowa_io_select(\"file\", \"xowa_prop_0\", \"Select program for Web Browser\");'>...</button>"
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
@Test public void Scrub_tidy_trailing_nl_in_textarea() {
|
|
||||||
fxt.Test_Scrub_tidy_trailing_nl_in_textarea(Bool_.Y, Bool_.Y, "a\n", "a");
|
|
||||||
fxt.Test_Scrub_tidy_trailing_nl_in_textarea(Bool_.Y, Bool_.Y, "a\n\n", "a\n");
|
|
||||||
fxt.Test_Scrub_tidy_trailing_nl_in_textarea(Bool_.Y, Bool_.Y, "", "");
|
|
||||||
fxt.Test_Scrub_tidy_trailing_nl_in_textarea(Bool_.N, Bool_.N, "a\n", "a\n");
|
|
||||||
fxt.Test_Scrub_tidy_trailing_nl_in_textarea(Bool_.N, Bool_.Y, "a\n", "a\n");
|
|
||||||
fxt.Test_Scrub_tidy_trailing_nl_in_textarea(Bool_.Y, Bool_.N, "a\n", "a\n");
|
|
||||||
}
|
|
||||||
@Test public void Ref() {// PURPOSE: references were duplicating; DATE:2015-05-16
|
|
||||||
fxt.Parser_fxt().Test_html_full_str
|
|
||||||
( String_.Concat_lines_nl_skip_last
|
|
||||||
( "<xowa_cmd>"
|
|
||||||
, "app.user.prefs.exec_get("
|
|
||||||
, "<:['"
|
|
||||||
, "<ref name='a'/>"
|
|
||||||
, "<references>"
|
|
||||||
, "<ref name='a'>b</ref>"
|
|
||||||
, "']:>"
|
|
||||||
, ");"
|
|
||||||
, "</xowa_cmd>"
|
|
||||||
), String_.Concat_lines_nl_skip_last
|
|
||||||
( "<sup id=\"cite_ref-a_0-0\" class=\"reference\"><a href=\"#cite_note-a-0\">[1]</a></sup>"
|
|
||||||
, "<ol class=\"references\">"
|
|
||||||
, "<li id=\"cite_note-a-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-a_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
|
||||||
, "</ol>"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// ( "<ref name='a'><references><ref name='a'>a1</ref></references>", String_.Concat
|
|
||||||
// ( "<input type='xowa_io' xowa_prop='app.fsys.apps.media' xowa_io_msg='Select program for Web Browser' id='xowa_prop_0' value=''></input>"
|
|
||||||
// , "<button id='xowa_prop_0_io' class='options_button' onclick='xowa_io_select(\"file\", \"xowa_prop_0\", \"Select program for Web Browser\");'>...</button>"
|
|
||||||
// ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class Prefs_mgr_fxt {
|
|
||||||
public Xoae_app App() {return app;} private Xoae_app app;
|
|
||||||
private Prefs_mgr prefs_mgr; private Gfui_html_mok html_box;
|
|
||||||
public void Clear() {
|
|
||||||
if (app == null) {
|
|
||||||
GfsCore.Instance.Clear(); // NOTE: clear GfsCore, else Props test will fail for mass run
|
|
||||||
Xoa_gfs_mgr.Msg_parser_init();
|
|
||||||
app = Xoa_app_fxt.Make__app__edit();
|
|
||||||
prefs_mgr = new Prefs_mgr(app);
|
|
||||||
html_box = new Gfui_html_mok();
|
|
||||||
prefs_mgr.Html_box_mok_(html_box);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Xop_fxt Parser_fxt() {return new Xop_fxt(app, app.Usere().Wiki());}
|
|
||||||
public Prefs_mgr_fxt Init_elem_atr_val(String elem_id, String atr_val) {
|
|
||||||
html_box.Html_elem_atr_add(elem_id, Gfui_html.Atr_value, atr_val);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Prefs_mgr_fxt Init_elem_atr_checked(String elem_id, String v) {
|
|
||||||
html_box.Html_elem_atr_add(elem_id, "checked", v);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Prefs_mgr_fxt Init_elem_atr_innerHtml(String elem_id, String v) {
|
|
||||||
html_box.Html_elem_atr_add(elem_id, Gfui_html.Atr_innerHTML, v);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Prefs_mgr_fxt Exec_get(String src_str, String expd) {
|
|
||||||
String actl = String_.new_u8(prefs_mgr.Props_get(Bry_.new_u8(src_str)));
|
|
||||||
Tfds.Eq_str_lines(expd, actl);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Prefs_mgr_fxt Exec_get_has(String src_str, String expd) {
|
|
||||||
String actl = String_.new_u8(prefs_mgr.Props_get(Bry_.new_u8(src_str)));
|
|
||||||
Tfds.Eq_true(String_.Has(actl, expd));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Prefs_mgr_fxt Test_set(String src_str) {
|
|
||||||
prefs_mgr.Props_set(Bry_.new_u8(src_str));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public void Test_Scrub_tidy_trailing_nl_in_textarea(boolean tidy_enabled, boolean elem_is_textarea, String val, String expd) {
|
|
||||||
String actl = Prefs_mgr.Scrub_tidy_trailing_nl_in_textarea(tidy_enabled, elem_is_textarea ? Prefs_mgr.Elem_tid_textarea : Prefs_mgr.Elem_tid_input_text, val);
|
|
||||||
Tfds.Eq(expd, actl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class Gfui_html_mok extends Xog_html_itm { private Hash_adp elem_atrs = Hash_adp_.New();
|
|
||||||
public void Html_elem_atr_add(String elem_id, String atr_key, Object atr_val) {elem_atrs.Add_if_dupe_use_nth(elem_id + "." + atr_key, atr_val);}
|
|
||||||
@Override public String Html_elem_atr_get_str(String id, String atr_key) {
|
|
||||||
return (String)elem_atrs.Get_by(id + "." + atr_key);
|
|
||||||
}
|
|
||||||
@Override public boolean Html_elem_atr_get_bool(String id, String atr_key) {
|
|
||||||
return Bool_.Parse((String)elem_atrs.Get_by(id + "." + atr_key));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +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.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
|
||||||
public class Prefs_rename_mgr {
|
|
||||||
private List_adp list = List_adp_.New();
|
|
||||||
public Prefs_rename_mgr() {
|
|
||||||
List_add(list, "app.cfgs.get('app.gui.html.portal.wikis.visible', 'app').val", "app.cfgs.get('xowa.api.html.page.toggles.get(''offline-wikis'').visible', 'app').val");
|
|
||||||
}
|
|
||||||
public boolean Check(Io_url url) {
|
|
||||||
String cur_str = Io_mgr.Instance.LoadFilStr_args(url).MissingIgnored_().Exec();
|
|
||||||
boolean cur_str_changed = false;
|
|
||||||
int list_len = list.Count();
|
|
||||||
for (int i = 0; i < list_len; ++i) {
|
|
||||||
Prefs_rename_itm itm = (Prefs_rename_itm)list.Get_at(i);
|
|
||||||
if (String_.Has(cur_str, itm.Src())) {
|
|
||||||
cur_str_changed = true;
|
|
||||||
cur_str = String_.Replace(cur_str, itm.Src(), itm.Trg());
|
|
||||||
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.replace: src=~{src} trg = ~{trg}", itm.Src(), itm.Trg());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cur_str_changed)
|
|
||||||
Io_mgr.Instance.SaveFilStr(url, cur_str);
|
|
||||||
return cur_str_changed;
|
|
||||||
}
|
|
||||||
private static void List_add(List_adp list, String src, String trg) {list.Add(new Prefs_rename_itm(src, trg));}
|
|
||||||
public static final Prefs_rename_mgr Instance = new Prefs_rename_mgr();
|
|
||||||
}
|
|
||||||
class Prefs_rename_itm {
|
|
||||||
public Prefs_rename_itm(String src, String trg) {this.src = src; this.trg = trg;}
|
|
||||||
public String Src() {return src;} private String src;
|
|
||||||
public String Trg() {return trg;} private String trg;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user