mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
25
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_db.java
Normal file
25
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_db.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public interface Xoa_cfg_db {
|
||||
void Cfg_reset_all(Xoa_cfg_mgr cfg_mgr);
|
||||
void Cfg_save_bgn(Xoa_cfg_mgr cfg_mgr);
|
||||
void Cfg_save_end(Xoa_cfg_mgr cfg_mgr);
|
||||
void Cfg_save_run(Xoa_cfg_mgr cfg_mgr, Xoa_cfg_grp cfg_grp, Xoa_cfg_itm cfg_itm);
|
||||
void Cfg_load_run(Xoa_cfg_mgr cfg_mgr);
|
||||
}
|
||||
45
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_db_txt.java
Normal file
45
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_db_txt.java
Normal 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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
public class Xoa_cfg_db_txt implements Xoa_cfg_db {
|
||||
private Bry_fmtr fmtr = Bry_fmtr.new_("app.cfgs.get('~{msg}', '~{wiki}').val = '~{val}';\n", "msg", "wiki", "val");
|
||||
public void Cfg_reset_all(Xoa_cfg_mgr cfg_mgr) {
|
||||
Io_url src_url = this.Cfg_url(cfg_mgr);
|
||||
Io_url trg_url = src_url.GenNewNameAndExt("xowa_user_cfg." + DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss() + ".gfs");
|
||||
Io_mgr.Instance.MoveFil_args(src_url, trg_url, true).Exec();
|
||||
if (cfg_mgr.App().Tid_is_edit())
|
||||
((Xoae_app)cfg_mgr.App()).Gui_mgr().Kit().Ask_ok("", "", "Options cleared. Please restart XOWA.");
|
||||
}
|
||||
public void Cfg_load_run(Xoa_cfg_mgr cfg_mgr) {
|
||||
String load = Io_mgr.Instance.LoadFilStr(Cfg_url(cfg_mgr));
|
||||
cfg_mgr.App().Gfs_mgr().Run_str(load);
|
||||
}
|
||||
public void Cfg_save_bgn(Xoa_cfg_mgr cfg_mgr) {
|
||||
bfr.ClearAndReset();
|
||||
} private Bry_bfr bfr = Bry_bfr.new_();
|
||||
public void Cfg_save_end(Xoa_cfg_mgr cfg_mgr) {
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "shutting down app; saving cfg: len=~{0}", bfr.Len());
|
||||
Io_mgr.Instance.SaveFilBfr(Cfg_url(cfg_mgr), bfr);
|
||||
}
|
||||
public void Cfg_save_run(Xoa_cfg_mgr cfg_mgr, Xoa_cfg_grp cfg_grp, Xoa_cfg_itm cfg_itm) {
|
||||
fmtr.Bld_bfr_many(bfr, Xoa_gfs_wtr_.Escape(cfg_grp.Key_bry()), Xoa_gfs_wtr_.Escape(cfg_itm.Key()), Xoa_gfs_wtr_.Escape(cfg_itm.Val()));
|
||||
}
|
||||
public Io_url Cfg_url(Xoa_cfg_mgr cfg_mgr) {return ((Xoae_app)cfg_mgr.App()).Usere().Fsys_mgr().App_data_cfg_dir().GenSubFil(File_name);}
|
||||
public static final String File_name = "xowa_user_cfg.gfs";
|
||||
}
|
||||
64
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_grp.java
Normal file
64
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_grp.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoa_cfg_grp {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry(); private final Xoa_cfg_mgr mgr;
|
||||
public Xoa_cfg_grp(Xoa_cfg_mgr mgr, Xoa_cfg_grp_tid tid, byte[] key_bry) {
|
||||
this.mgr = mgr; this.tid = tid; this.key_bry = key_bry; this.key_str = String_.new_u8(key_bry);
|
||||
}
|
||||
public Xoa_cfg_grp_tid Tid() {return tid;} private final Xoa_cfg_grp_tid tid;
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
|
||||
public String Key_str() {return key_str;} private final String key_str;
|
||||
public boolean Notify(Xoa_cfg_itm itm) {return mgr.Notify(this, itm);}
|
||||
public Xoa_cfg_itm Get_by_or_null(byte[] key) {return (Xoa_cfg_itm)hash.Get_by(key);}
|
||||
public Xoa_cfg_itm Get_by_or_make(byte[] key) {
|
||||
Xoa_cfg_itm rv = (Xoa_cfg_itm)hash.Get_by(key);
|
||||
if (rv == null) {
|
||||
rv = new Xoa_cfg_itm(this, key);
|
||||
hash.Add(key, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xoa_cfg_itm Get_by_wiki(byte[] domain_bry, int domain_tid) {
|
||||
Xoa_cfg_itm rv = (Xoa_cfg_itm)hash.Get_by(domain_bry);
|
||||
if (rv == null) { // match by domain_bry failed; try tid
|
||||
rv = (Xoa_cfg_itm)hash.Get_by(Xow_domain_tid_.Get_type_as_bry(domain_tid));
|
||||
if (rv == null) // match by type failed; try all
|
||||
rv = (Xoa_cfg_itm)hash.Get_by(Xoa_cfg_grp_tid.Key_all_bry);
|
||||
if (rv == null) // match by all failed; try app
|
||||
rv = (Xoa_cfg_itm)hash.Get_by(Xoa_cfg_grp_tid.Key_app_bry);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Db_load_end() {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoa_cfg_itm itm = (Xoa_cfg_itm)hash.Get_at(i);
|
||||
itm.Val_load_done();
|
||||
}
|
||||
}
|
||||
public void Db_save(Xoa_cfg_db db) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoa_cfg_itm itm = (Xoa_cfg_itm)hash.Get_at(i);
|
||||
if (!itm.Val_is_customized() && !itm.Val_is_dirty()) continue; // system default and unchanged; no need to save
|
||||
db.Cfg_save_run(mgr, this, itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_grp_tid.java
Normal file
47
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_grp_tid.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoa_cfg_grp_tid {
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public int Wiki_tid() {return wiki_tid;} private int wiki_tid;
|
||||
public static final byte Tid_null = 0, Tid_all = 1, Tid_type = 2, Tid_wiki = 3, Tid_app = 4;
|
||||
public static final String Key_app_str = "app";
|
||||
public static final byte[] Key_all_bry = Bry_.new_a7("*"), Key_app_bry = Bry_.new_a7(Key_app_str);
|
||||
public static Xoa_cfg_grp_tid parse(byte[] key) {
|
||||
Xoa_cfg_grp_tid rv = (Xoa_cfg_grp_tid)factory.Get_by_bry(key);
|
||||
if (rv == null) {
|
||||
rv = new Xoa_cfg_grp_tid();
|
||||
if (Bry_.Eq(key, Key_all_bry)) rv.tid = Tid_all;
|
||||
else if (Bry_.Eq(key, Key_app_bry)) rv.tid = Tid_app;
|
||||
else {
|
||||
Xow_domain_itm wiki_type = Xow_domain_itm_.parse(key);
|
||||
if (wiki_type.Domain_type_id() == Xow_domain_tid_.Int__other)
|
||||
rv.tid = Tid_wiki;
|
||||
else {
|
||||
rv.tid = Tid_type;
|
||||
rv.wiki_tid = wiki_type.Domain_type_id();
|
||||
}
|
||||
}
|
||||
rv.key = key;
|
||||
factory.Add(key, rv);
|
||||
}
|
||||
return rv;
|
||||
} static Hash_adp_bry factory = Hash_adp_bry.cs();
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_itm.java
Normal file
43
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_itm.java
Normal 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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_cfg_itm implements GfoInvkAble {
|
||||
public Xoa_cfg_itm(Xoa_cfg_grp grp, byte[] key) {this.grp = grp; this.key = key;}
|
||||
public Xoa_cfg_grp Grp() {return grp;} private final Xoa_cfg_grp grp;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public String Val() {return val;} private String val;
|
||||
public boolean Val_is_dirty() {return val_is_dirty;} private boolean val_is_dirty;
|
||||
public boolean Val_is_customized() {return val_is_customized;} private boolean val_is_customized; // false if value is system default; true if changed by user
|
||||
public void Val_(String v) {
|
||||
this.val = v;
|
||||
if (grp.Notify(this)) {
|
||||
val_is_customized = true;
|
||||
val_is_dirty = true;
|
||||
}
|
||||
}
|
||||
public void Val_load_done() {
|
||||
val_is_dirty = false;
|
||||
val_is_customized = true;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_val)) return val;
|
||||
else if (ctx.Match(k, Invk_val_)) Val_(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_val = "val", Invk_val_ = "val_";
|
||||
}
|
||||
123
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_mgr.java
Normal file
123
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_mgr.java
Normal 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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoa_cfg_mgr implements GfoInvkAble {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public Xoa_cfg_mgr(Xoa_app app) {this.app = app;}
|
||||
public Xoa_app App() {return app;} private final Xoa_app app;
|
||||
public Xoa_cfg_itm Get_itm_or_null(byte[] grp_key, byte[] itm_key) {
|
||||
Xoa_cfg_grp grp = (Xoa_cfg_grp)hash.Get_by(grp_key);
|
||||
return grp == null ? null : grp.Get_by_or_null(itm_key);
|
||||
}
|
||||
public Xoa_cfg_itm Get_itm_or_make(byte[] grp_key, byte[] itm_key) {
|
||||
Xoa_cfg_grp grp = null;
|
||||
Object grp_obj = hash.Get_by(grp_key);
|
||||
if (grp_obj == null) {
|
||||
Xoa_cfg_grp_tid tid = Xoa_cfg_grp_tid.parse(itm_key);
|
||||
grp = new Xoa_cfg_grp(this, tid, grp_key);
|
||||
hash.Add(grp_key, grp);
|
||||
}
|
||||
else
|
||||
grp = (Xoa_cfg_grp)grp_obj;
|
||||
return grp.Get_by_or_make(itm_key);
|
||||
}
|
||||
public void Set_by_app(String grp_key, String val) {Set(Bry_.new_u8(grp_key), Xoa_cfg_grp_tid.Key_app_bry, val);}
|
||||
public void Set_by_all(String grp_key, String val) {Set(Bry_.new_u8(grp_key), Xoa_cfg_grp_tid.Key_all_bry, val);}
|
||||
public void Set_by_type(String grp_key, byte tid, String val) {Set(Bry_.new_u8(grp_key), Xow_domain_tid_.Get_type_as_bry(tid), val);}
|
||||
private void Set(byte[] grp_key, byte[] tid_key, String val) {Get_itm_or_make(grp_key, tid_key).Val_(val);}
|
||||
public void Init(Xow_wiki wiki) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_cfg_grp grp = (Xoa_cfg_grp)hash.Get_at(i);
|
||||
Xoa_cfg_itm itm = grp.Get_by_wiki(wiki.Domain_bry(), wiki.Domain_tid());
|
||||
if (itm == null) continue; // grp exists, but not for wiki; EX: rule exists for download.enabled and enwiki, but frwiki loaded
|
||||
if (itm.Grp().Tid().Tid() == Xoa_cfg_grp_tid.Tid_app) continue; // rule is for app; don't run for wiki init
|
||||
Eval_set(wiki, grp.Key_str(), itm.Val());
|
||||
}
|
||||
}
|
||||
public boolean Notify(Xoa_cfg_grp grp, Xoa_cfg_itm itm) {
|
||||
Xoa_cfg_grp_tid grp_tid = grp.Tid();
|
||||
byte tid_byte = grp_tid.Tid();
|
||||
switch (tid_byte) {
|
||||
case Xoa_cfg_grp_tid.Tid_app:
|
||||
return Eval_set(app, grp.Key_str(), itm.Val());
|
||||
case Xoa_cfg_grp_tid.Tid_all:
|
||||
case Xoa_cfg_grp_tid.Tid_type:
|
||||
boolean all = tid_byte == Xoa_cfg_grp_tid.Tid_all;
|
||||
int wiki_count = app.Wiki_mgri().Count();
|
||||
boolean rv = true;
|
||||
for (int i = 0; i < wiki_count; i++) {
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_at_i(i);
|
||||
if (all || wiki.Domain_tid() == grp_tid.Wiki_tid()) {
|
||||
if (!Eval_set(wiki, grp.Key_str(), itm.Val()))
|
||||
rv = false;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
case Xoa_cfg_grp_tid.Tid_wiki: {
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_by_key_or_null_i(itm.Key());
|
||||
if (wiki == null) return true; // wiki not installed; return true (no error)
|
||||
return Eval_set(wiki, grp.Key_str(), itm.Val());
|
||||
}
|
||||
default:
|
||||
throw Err_.new_unhandled(tid_byte);
|
||||
}
|
||||
}
|
||||
public void Reset_all() {
|
||||
hash.Clear();
|
||||
db_txt.Cfg_reset_all(this);
|
||||
}
|
||||
public void Db_load_txt() {Db_load(db_txt);}
|
||||
public void Db_load(Xoa_cfg_db db) {
|
||||
db.Cfg_load_run(this);
|
||||
this.Db_load_end();
|
||||
}
|
||||
private void Db_load_end() {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_cfg_grp grp = (Xoa_cfg_grp)hash.Get_at(i);
|
||||
grp.Db_load_end();
|
||||
}
|
||||
}
|
||||
public void Db_save_txt() {Db_save(db_txt);} private final Xoa_cfg_db_txt db_txt = new Xoa_cfg_db_txt();
|
||||
public void Db_save(Xoa_cfg_db db) {
|
||||
int len = hash.Count();
|
||||
db.Cfg_save_bgn(this);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_cfg_grp grp = (Xoa_cfg_grp)hash.Get_at(i);
|
||||
grp.Db_save(db);
|
||||
}
|
||||
db.Cfg_save_end(this);
|
||||
}
|
||||
private boolean Eval_set(GfoInvkAble invk, String key, String val) {
|
||||
String msg_str = key + "_(<:['\n" + val + "\n']:>);";
|
||||
Object rslt = app.Gfs_mgr().Run_str_for(invk, msg_str);
|
||||
return rslt != GfoInvkAble_.Rv_error;
|
||||
}
|
||||
public Object Eval_get(GfoInvkAble invk, String key) {
|
||||
String msg_str = key + ";";
|
||||
return app.Gfs_mgr().Run_str_for(invk, msg_str);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get_itm_or_make(m.ReadBry("itm_key"), m.ReadBry("grp_key"));
|
||||
else if (ctx.Match(k, Invk_reset_all)) Reset_all();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_get = "get", Invk_reset_all = "reset_all";
|
||||
}
|
||||
86
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_mgr_tst.java
Normal file
86
400_xowa/src/gplx/xowa/apps/cfgs/Xoa_cfg_mgr_tst.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
public class Xoa_cfg_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_cfg_mgr_fxt fxt = new Xoa_cfg_mgr_fxt();
|
||||
@Test public void Init() {
|
||||
fxt.Init_cfg_all("import.db_text_max", "1000");
|
||||
fxt.Test_init_wiki("simple.wikipedia.org", "import.db_text_max", "1000");
|
||||
fxt.Test_cfg_itm("simple.wikipedia.org", "import.db_text_max", false, false);
|
||||
}
|
||||
@Test public void Notify() {
|
||||
fxt.Exec_make_wiki("simple.wikipedia.org");
|
||||
fxt.Test_cfg_set("app.cfgs.get('import.db_text_max', 'simple.wikipedia.org').val = '2000';", "simple.wikipedia.org", "import.db_text_max", "2000");
|
||||
fxt.Test_cfg_itm("simple.wikipedia.org", "import.db_text_max", true, true);
|
||||
fxt.Test_save("app.cfgs.get('import.db_text_max', 'simple.wikipedia.org').val = '2000';\n");
|
||||
}
|
||||
@Test public void Notify_quote() {
|
||||
fxt.Test_cfg_set("app.cfgs.get('app.gui.html.css_xtn', 'app').val = 'a''b';", "*", "app.gui.html.css_xtn", "a'b");
|
||||
fxt.Test_cfg_itm("app", "app.gui.html.css_xtn", true, true);
|
||||
fxt.Test_save("app.cfgs.get('app.gui.html.css_xtn', 'app').val = 'a''b';\n");
|
||||
}
|
||||
@Test public void Init_should_not_notify_if_app() {
|
||||
fxt.Init_cfg_app("import.db_text_max", "1000");
|
||||
fxt.Test_init_wiki("simple.wikipedia.org", "import.db_text_max", "3000"); // 3000 is default; itm shouldn't change b/c cfg is app level; DATE:2013-07-14
|
||||
}
|
||||
}
|
||||
class Xoa_cfg_mgr_fxt {
|
||||
public void Clear() {
|
||||
// if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
cfg_mgr = app.Cfg_mgr();
|
||||
// }
|
||||
} private Xoae_app app; Xoa_cfg_mgr cfg_mgr;
|
||||
public void Init_cfg_all(String key, String val) {Init_cfg(key, val, Xoa_cfg_grp_tid.Key_all_bry);}
|
||||
public void Init_cfg_app(String key, String val) {Init_cfg(key, val, Xoa_cfg_grp_tid.Key_app_bry);}
|
||||
private void Init_cfg(String key, String val, byte[] tid) {
|
||||
Xoa_cfg_itm itm = app.Cfg_mgr().Get_itm_or_make(Bry_.new_a7(key), tid);
|
||||
itm.Val_(val);
|
||||
}
|
||||
public Xowe_wiki Exec_make_wiki(String wiki_key_str) {return Exec_make_wiki(Bry_.new_a7(wiki_key_str));}
|
||||
public Xowe_wiki Exec_make_wiki(byte[] wiki_key_bry) {return app.Wiki_mgr().Get_by_key_or_make(wiki_key_bry);}
|
||||
public void Test_init_wiki(String wiki_key_str, String itm_key_str, String expd_val) {
|
||||
byte[] wiki_key_bry = Bry_.new_a7(wiki_key_str);
|
||||
Xowe_wiki wiki = Exec_make_wiki(wiki_key_bry);
|
||||
wiki.Init_assert();
|
||||
Test_cfg_get(wiki, itm_key_str, expd_val);
|
||||
}
|
||||
public void Test_cfg_set(String cfg_msg, String wiki_key_str, String prop_key, String expd_val) {
|
||||
byte[] wiki_key_bry = Bry_.new_a7(wiki_key_str);
|
||||
app.Gfs_mgr().Run_str_for(app, cfg_msg);
|
||||
Xowe_wiki wiki = Exec_make_wiki(wiki_key_bry);
|
||||
Test_cfg_get(wiki, prop_key, expd_val);
|
||||
}
|
||||
private void Test_cfg_get(GfoInvkAble invk, String prop, String expd) {
|
||||
Tfds.Eq(expd, Object_.Xto_str_strict_or_null_mark(app.Cfg_mgr().Eval_get(invk, prop)));
|
||||
}
|
||||
public void Test_cfg_itm(String wiki, String prop, boolean expd_customized, boolean expd_dirty) {
|
||||
Test_cfg_itm(Bry_.new_a7(wiki), Bry_.new_a7(prop), expd_customized, expd_dirty);
|
||||
}
|
||||
public void Test_cfg_itm(byte[] wiki, byte[] prop, boolean expd_customized, boolean expd_dirty) {
|
||||
Xoa_cfg_itm itm = cfg_mgr.Get_itm_or_make(prop, wiki);
|
||||
Tfds.Eq(itm.Val_is_customized(), expd_customized);
|
||||
Tfds.Eq(itm.Val_is_dirty(), expd_dirty);
|
||||
}
|
||||
public void Test_save(String expd) {
|
||||
Xoa_cfg_db_txt db = new Xoa_cfg_db_txt();
|
||||
cfg_mgr.Db_save(db);
|
||||
Tfds.Eq(expd, Io_mgr.Instance.LoadFilStr(db.Cfg_url(cfg_mgr)));
|
||||
}
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_parser.java
Normal file
36
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_parser.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.parsers.lnkis.cfgs.*;
|
||||
public class Xowc_parser implements GfoInvkAble {
|
||||
public Xowc_parser(Xowe_wiki wiki) {
|
||||
lnki_cfg = new Xoc_lnki_cfg(wiki);
|
||||
}
|
||||
public Xoc_lnki_cfg Lnki_cfg() {return lnki_cfg;} private Xoc_lnki_cfg lnki_cfg;
|
||||
public Xowc_xtns Xtns() {return xtns;} private Xowc_xtns xtns = new Xowc_xtns();
|
||||
public boolean Display_title_restrict() {return display_title_restrict;} public void Display_title_restrict_(boolean v) {display_title_restrict = v;} private boolean display_title_restrict = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_xtns)) return xtns;
|
||||
else if (ctx.Match(k, Invk_lnki)) return lnki_cfg;
|
||||
else if (ctx.Match(k, Invk_display_title_restrict)) return display_title_restrict;
|
||||
else if (ctx.Match(k, Invk_display_title_restrict_)) display_title_restrict = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_xtns = "xtns", Invk_lnki = "lnki", Invk_display_title_restrict = "display_title_restrict", Invk_display_title_restrict_ = "display_title_restrict_";
|
||||
}
|
||||
81
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages.java
Normal file
81
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowc_xtn_pages implements GfoInvkAble {
|
||||
public boolean Init_needed() {return init_needed;} private boolean init_needed = true;
|
||||
public int Ns_page_id() {return ns_page_id;} private int ns_page_id = Int_.Min_value;
|
||||
public int Ns_page_talk_id() {return ns_page_talk_id;} private int ns_page_talk_id = Int_.Min_value;
|
||||
public int Ns_index_id() {return ns_index_id;} private int ns_index_id = Int_.Min_value;
|
||||
public int Ns_index_talk_id() {return ns_index_talk_id;} private int ns_index_talk_id = Int_.Min_value;
|
||||
public void Ns_names_(byte[] page_name, byte[] page_talk_name, byte[] index_name, byte[] index_talk_name) {
|
||||
this.page_name = page_name; this.page_talk_name = page_talk_name; this.index_name = index_name; this.index_talk_name = index_talk_name;
|
||||
}
|
||||
private byte[]
|
||||
page_name = Default_ns_page_name
|
||||
, page_talk_name = Default_ns_page_talk_name
|
||||
, index_name = Default_ns_index_name
|
||||
, index_talk_name = Default_ns_index_talk_name;
|
||||
public void Reset() {
|
||||
ns_page_id = ns_page_talk_id = ns_index_id = ns_index_talk_id = Int_.Min_value;
|
||||
init_needed = true;
|
||||
}
|
||||
public void Init(Xow_ns_mgr ns_mgr) {
|
||||
init_needed = false;
|
||||
int len = ns_mgr.Ords_len();
|
||||
for (int i = 0; i < len; i++) { // Page / Index ns_ids are variable per wiki; iterate over ns, and set ns_id
|
||||
Xow_ns ns = ns_mgr.Ords_get_at(i); if (ns == null) continue;
|
||||
byte[] ns_name = ns.Name_enc();
|
||||
if (Bry_.Eq(ns_name, page_name)) {ns_page_id = ns.Id(); ns_mgr.Ns_page_id_(ns_page_id);}
|
||||
else if (Bry_.Eq(ns_name, page_talk_name)) ns_page_talk_id = ns.Id();
|
||||
else if (Bry_.Eq(ns_name, index_name)) ns_index_id = ns.Id();
|
||||
else if (Bry_.Eq(ns_name, index_talk_name)) ns_index_talk_id = ns.Id();
|
||||
}
|
||||
int aliases_added = 0;
|
||||
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_page_id , Default_ns_page_name);
|
||||
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_page_talk_id , Default_ns_page_talk_name);
|
||||
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_index_id , Default_ns_index_name);
|
||||
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_index_talk_id , Default_ns_index_talk_name);
|
||||
if (aliases_added > 0) // NOTE: will probably only be 0 for English Wikisource
|
||||
ns_mgr.Init_w_defaults();
|
||||
}
|
||||
private int Set_canonical(Xow_ns_mgr ns_mgr, int aliases_added, int id, byte[] name) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(id);
|
||||
if ( ns == null // ns doesn't exist; should throw error;
|
||||
|| !Bry_.Eq(ns.Name_bry(), name) // ns exists, but name doesn't match canonical
|
||||
) {
|
||||
ns_mgr.Aliases_add(id, String_.new_a7(name));
|
||||
++aliases_added;
|
||||
}
|
||||
return aliases_added;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_ns_names_)) Ns_names_(m.ReadBry("page"), m.ReadBry("page_talk"), m.ReadBry("index"), m.ReadBry("index_talk"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_ns_names_ = "ns_names_";
|
||||
public static final byte[] Xtn_key = Bry_.new_a7("pages");
|
||||
public static final int Ns_index_id_default = 102, Ns_page_id_default = 104;
|
||||
|
||||
private static final byte[]
|
||||
Default_ns_page_name = Bry_.new_a7("Page")
|
||||
, Default_ns_page_talk_name = Bry_.new_a7("Page_talk")
|
||||
, Default_ns_index_name = Bry_.new_a7("Index")
|
||||
, Default_ns_index_talk_name = Bry_.new_a7("Index_talk")
|
||||
;
|
||||
}
|
||||
65
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java
Normal file
65
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xowc_xtn_pages_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xowc_xtn_pages_fxt fxt = new Xowc_xtn_pages_fxt();
|
||||
@Test public void Init() {
|
||||
fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by <siteinfo>
|
||||
fxt.Init_names("Foreign_page", "Foreign_page_talk", "Foreign_index", "Foreign_index_talk"); // ns set by .gfs files in /user/wiki/#cfg
|
||||
fxt.Exec_init();
|
||||
fxt.Test_ns_ids(200, 201, 202, 203);
|
||||
fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk");
|
||||
}
|
||||
}
|
||||
class Xowc_xtn_pages_fxt {
|
||||
private Xow_ns_mgr ns_mgr;
|
||||
private Xowc_xtn_pages cfg_pages;
|
||||
public void Clear() {
|
||||
ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
|
||||
cfg_pages = new Xowc_xtn_pages();
|
||||
}
|
||||
public Xowc_xtn_pages_fxt Init_ns(int id, String name) {
|
||||
ns_mgr.Add_new(id, name);
|
||||
return this;
|
||||
}
|
||||
public void Init_names(String page_name, String page_talk_name, String index_name, String index_talk_name) {
|
||||
cfg_pages.Ns_names_(Bry_.new_a7(page_name), Bry_.new_a7(page_talk_name), Bry_.new_a7(index_name), Bry_.new_a7(index_talk_name));
|
||||
}
|
||||
public void Exec_init() {
|
||||
ns_mgr.Init_w_defaults(); // init ns_msg
|
||||
cfg_pages.Init(ns_mgr); // init cfg
|
||||
}
|
||||
public void Test_ns_ids(int page_id, int page_talk_id, int index_id, int index_talk_id) {
|
||||
Tfds.Eq(page_id , cfg_pages.Ns_page_id());
|
||||
Tfds.Eq(page_talk_id , cfg_pages.Ns_page_talk_id());
|
||||
Tfds.Eq(index_id , cfg_pages.Ns_index_id());
|
||||
Tfds.Eq(index_talk_id , cfg_pages.Ns_index_talk_id());
|
||||
}
|
||||
public void Test_ns_canonical(String page_name, String page_talk_name, String index_name, String index_talk_name) {
|
||||
Test_ns_canonical_itm(page_name , cfg_pages.Ns_page_id());
|
||||
Test_ns_canonical_itm(page_talk_name , cfg_pages.Ns_page_talk_id());
|
||||
Test_ns_canonical_itm(index_name , cfg_pages.Ns_index_id());
|
||||
Test_ns_canonical_itm(index_talk_name , cfg_pages.Ns_index_talk_id());
|
||||
}
|
||||
private void Test_ns_canonical_itm(String name, int expd_ns_id) {
|
||||
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_a7(name));
|
||||
int actl_ns_id = ns == null ? Int_.Min_value : ns.Id();
|
||||
Tfds.Eq(expd_ns_id, actl_ns_id);
|
||||
}
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtns.java
Normal file
28
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtns.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xowc_xtns implements GfoInvkAble {
|
||||
private Hash_adp_bry hash = Hash_adp_bry.ci_a7();
|
||||
public Xowc_xtns() {hash.Add(Xowc_xtn_pages.Xtn_key, itm_pages);}
|
||||
public Xowc_xtn_pages Itm_pages() {return itm_pages;} private Xowc_xtn_pages itm_pages = new Xowc_xtn_pages();
|
||||
public Object Get_by_key(byte[] key) {return hash.Get_by_bry(key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return (GfoInvkAble)hash.Get_by_bry(m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_get = "get";
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_gui_mgr.java
Normal file
31
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_gui_mgr.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
public class Xocfg_gui_mgr implements GfoInvkAble {
|
||||
public Xocfg_gui_mgr(Xoae_app app) {
|
||||
win_cfg = new Xocfg_win(app);
|
||||
}
|
||||
public Xocfg_win Win() {return win_cfg;} private Xocfg_win win_cfg;
|
||||
public Xocfg_html Html() {return html_cfg;} private Xocfg_html html_cfg = new Xocfg_html();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_win)) return win_cfg;
|
||||
else if (ctx.Match(k, Invk_html)) return html_cfg;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_win = "win", Invk_html = "html";
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_html.java
Normal file
31
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_html.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
public class Xocfg_html implements GfoInvkAble {
|
||||
public Xocfg_html() {
|
||||
this.content_editable = false; // CFG: default to false for general user
|
||||
}
|
||||
public boolean Content_editable() {return content_editable;} public Xocfg_html Content_editable_(boolean v) {content_editable = v; return this;} private boolean content_editable;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_content_editable)) return Yn.To_str(content_editable);
|
||||
else if (ctx.Match(k, Invk_content_editable_)) content_editable = m.ReadYn_toggle("v", content_editable);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_content_editable = "content_editable", Invk_content_editable_ = "content_editable_";
|
||||
}
|
||||
106
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_pref_mgr.java
Normal file
106
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_pref_mgr.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
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.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
class Test_api implements GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_meta)) return meta_mgr.Get_or_null(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
// return this;
|
||||
} private static final String Invk_meta = "meta";
|
||||
private static final String Invk_prop_1 = "prop_1", Invk_prop_2 = "prop_2", Invk_prop_3 = "prop_3", Invk_prop_bry = "bry", Invk_prop_enm = "enm";
|
||||
private static final boolean Dflt_prop_1 = false;
|
||||
private static final int Dflt_prop_2 = 2;
|
||||
private static final String Dflt_prop_3 = "3";
|
||||
private static final byte[] Dflt_prop_bry = Bry_.new_a7("bry");
|
||||
private static final int Dflt_prop_enm = 5;
|
||||
private static final Xocfg_meta_mgr meta_mgr = new Xocfg_meta_mgr().Add
|
||||
( Xocfg_meta_itm_.bool_ (Invk_prop_1, Dflt_prop_1)
|
||||
, Xocfg_meta_itm_.int_ (Invk_prop_2, Dflt_prop_2).Rng_bgn_(-1)
|
||||
, Xocfg_meta_itm_.str_ (Invk_prop_3, Dflt_prop_3)
|
||||
, Xocfg_meta_itm_.bry_ (Invk_prop_bry, Dflt_prop_bry)
|
||||
, Xocfg_meta_itm_.enm_ (Invk_prop_enm, Dflt_prop_enm).Itms_list_("a", "b", "c")
|
||||
, Xocfg_meta_itm_.str_ (Invk_prop_3, Dflt_prop_3).Gui_itm_(Xocfg_gui_itm_.memo_(40, 60))
|
||||
// , Xocfg_meta_itm_.enum_ (Invk_prop_3, Dflt_prop_3).Add("a", "b").Add("b", "c").Data(Xocfg_gui.list("a"))
|
||||
)
|
||||
;
|
||||
}
|
||||
interface Xocfg_gui_itm {
|
||||
}
|
||||
class Xocfg_gui_itm_ {
|
||||
public static Xocfg_gui_itm_memo memo_(int box_w, int box_h) {return new Xocfg_gui_itm_memo(box_w, box_h);}
|
||||
}
|
||||
class Xocfg_gui_itm_fld {
|
||||
}
|
||||
class Xocfg_gui_itm_memo implements Xocfg_gui_itm {
|
||||
public Xocfg_gui_itm_memo(int box_w, int box_h) {this.box_w = box_w; this.box_h = box_h;}
|
||||
public int Box_w() {return box_w;} private int box_w;
|
||||
public int Box_h() {return box_h;} private int box_h;
|
||||
}
|
||||
class Xocfg_meta_mgr {
|
||||
private Hash_adp hash = Hash_adp_.new_();
|
||||
public Xocfg_meta_mgr Add(Xocfg_meta_itm_base... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xocfg_meta_itm_base itm = (Xocfg_meta_itm_base)ary[i];
|
||||
hash.Add(itm.Prop_key(), itm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Xocfg_meta_itm_base Get_or_null(String key) {return (Xocfg_meta_itm_base)hash.Get_by(key);}
|
||||
}
|
||||
abstract class Xocfg_meta_itm_base {
|
||||
public void Set(int prop_type, String prop_key, Object prop_dflt) {
|
||||
this.prop_key = prop_key; this.prop_type = prop_type; this.prop_dflt = prop_dflt;
|
||||
}
|
||||
public String Prop_key() {return prop_key;} private String prop_key;
|
||||
public Object Prop_dflt() {return prop_dflt;} private Object prop_dflt;
|
||||
public int Prop_type() {return prop_type;} private int prop_type;
|
||||
}
|
||||
class Xocfg_meta_itm_ {
|
||||
public static Xocfg_meta_itm_bool bool_(String key, boolean dflt) {return new Xocfg_meta_itm_bool(key, dflt);}
|
||||
public static Xocfg_meta_itm_int int_(String key, int dflt) {return new Xocfg_meta_itm_int(key, dflt);}
|
||||
public static Xocfg_meta_itm_str str_(String key, String dflt) {return new Xocfg_meta_itm_str(key, dflt);}
|
||||
public static Xocfg_meta_itm_bry bry_(String key, byte[] dflt) {return new Xocfg_meta_itm_bry(key, dflt);}
|
||||
public static Xocfg_meta_itm_enm enm_(String key, int dflt) {return new Xocfg_meta_itm_enm(key, dflt);}
|
||||
}
|
||||
class Xodfg_pref_itm_type_ {
|
||||
public static final int Tid_bool = 1, Tid_int = 2, Tid_str = 3, Tid_bry = 4, Tid_enm = 5;
|
||||
}
|
||||
class Xocfg_meta_itm_bool extends Xocfg_meta_itm_base {
|
||||
public Xocfg_meta_itm_bool(String prop_key, boolean prop_dflt) {this.Set(Xodfg_pref_itm_type_.Tid_bool, prop_key, prop_dflt);}
|
||||
}
|
||||
class Xocfg_meta_itm_int extends Xocfg_meta_itm_base {
|
||||
public Xocfg_meta_itm_int(String prop_key, int prop_dflt) {this.Set(Xodfg_pref_itm_type_.Tid_int, prop_key, prop_dflt);}
|
||||
public Xocfg_meta_itm_int Rng_bgn_(int bgn) {return Rng_(bgn, Int_.Max_value);}
|
||||
public Xocfg_meta_itm_int Rng_(int bgn, int end) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Xocfg_meta_itm_str extends Xocfg_meta_itm_base {
|
||||
public Xocfg_meta_itm_str(String prop_key, String prop_dflt) {this.Set(Xodfg_pref_itm_type_.Tid_str, prop_key, prop_dflt);}
|
||||
public Xocfg_gui_itm Gui_itm() {return gui_itm;} public Xocfg_meta_itm_base Gui_itm_(Xocfg_gui_itm v) {gui_itm = v; return this;} private Xocfg_gui_itm gui_itm;
|
||||
}
|
||||
class Xocfg_meta_itm_bry extends Xocfg_meta_itm_base {
|
||||
public Xocfg_meta_itm_bry(String prop_key, byte[] prop_dflt) {this.Set(Xodfg_pref_itm_type_.Tid_bry, prop_key, prop_dflt);}
|
||||
}
|
||||
class Xocfg_meta_itm_enm extends Xocfg_meta_itm_base {
|
||||
public Xocfg_meta_itm_enm(String prop_key, int prop_dflt) {this.Set(Xodfg_pref_itm_type_.Tid_enm, prop_key, prop_dflt);}
|
||||
public Xocfg_meta_itm_enm Itms_list_(String... ary) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_win.java
Normal file
32
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xocfg_win.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
import gplx.xowa.guis.langs.*;
|
||||
public class Xocfg_win implements GfoInvkAble {
|
||||
public Xocfg_win(Xoae_app app) {}
|
||||
public Xol_font_info Font() {return font;} private Xol_font_info font = new Xol_font_info("Arial", 8, gplx.gfui.FontStyleAdp_.Plain);
|
||||
public Bry_fmtr Search_box_fmtr() {return search_box_fmtr;} private Bry_fmtr search_box_fmtr = Bry_fmtr.new_("Special:Allpages?from=", "search");
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_font)) return font;
|
||||
else if (ctx.Match(k, Invk_search_box_fmt_)) search_box_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_search_box_fmt_ = "search_box_fmt_", Invk_font = "font";
|
||||
public static final float Font_size_default = 8;
|
||||
}
|
||||
25
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xow_gui_mgr.java
Normal file
25
400_xowa/src/gplx/xowa/apps/cfgs/gui/Xow_gui_mgr.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
public class Xow_gui_mgr implements GfoInvkAble {
|
||||
public Xocfg_html Cfg_browser() {return cfg_browser;} private Xocfg_html cfg_browser = new Xocfg_html();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_cfg_browser)) return cfg_browser;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_cfg_browser = "cfg_browser";
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_bnd_itm.java
Normal file
59
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_bnd_itm.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.gfui.*; import gplx.xowa.guis.bnds.*; import gplx.xowa.guis.cmds.*;
|
||||
import gplx.langs.gfs.*; import gplx.xowa.apps.*;
|
||||
public class Xocfg_bnd_itm implements GfoInvkAble {
|
||||
private Xocfg_bnd_mgr mgr;
|
||||
public Xocfg_bnd_itm(Xocfg_bnd_mgr mgr, Xog_cmd_itm cmd, Xog_bnd_itm bnd) {
|
||||
this.mgr = mgr; this.cmd = cmd; this.bnd = bnd;
|
||||
}
|
||||
public Xog_bnd_itm Bnd() {return bnd;} private Xog_bnd_itm bnd;
|
||||
public Xog_cmd_itm Cmd() {return cmd;} private Xog_cmd_itm cmd;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_cmd_name)) return cmd.Name_or_missing();
|
||||
else if (ctx.Match(k, Invk_cmd_tip)) return cmd.Tip_or_missing();
|
||||
else if (ctx.Match(k, Invk_cmd_uid)) return cmd.Uid();
|
||||
else if (ctx.Match(k, Invk_cmd_ctg_name)) return cmd.Ctg().Name();
|
||||
else if (ctx.Match(k, Invk_cmd_ctg_sort)) return cmd.Ctg().Tid();
|
||||
else if (ctx.Match(k, Invk_bnd_key)) return bnd.Key();
|
||||
else if (ctx.Match(k, Invk_bnd_uid)) return bnd.Uid();
|
||||
else if (ctx.Match(k, Invk_bnd_sys)) return Yn.To_str(bnd.Sys());
|
||||
else if (ctx.Match(k, Invk_bnd_cmd)) return bnd.Cmd();
|
||||
else if (ctx.Match(k, Invk_bnd_cmd_)) bnd.Cmd_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_bnd_box)) return Xog_bnd_box_.Xto_gui_str(bnd.Box());
|
||||
else if (ctx.Match(k, Invk_bnd_box_idx)) return bnd.Box();
|
||||
else if (ctx.Match(k, Invk_bnd_ipt)) return mgr.Bnd_mgr().Bnd_parser().Xto_norm(bnd.Ipt().Key());
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String
|
||||
Invk_cmd_uid = "cmd_uid"
|
||||
, Invk_cmd_name = "cmd_name"
|
||||
, Invk_cmd_tip = "cmd_tip"
|
||||
, Invk_cmd_ctg_name = "cmd_ctg_name"
|
||||
, Invk_cmd_ctg_sort = "cmd_ctg_sort"
|
||||
, Invk_bnd_key = "bnd_key"
|
||||
, Invk_bnd_uid = "bnd_uid"
|
||||
, Invk_bnd_sys = "bnd_sys"
|
||||
, Invk_bnd_box = "bnd_box"
|
||||
, Invk_bnd_box_idx = "bnd_box_idx"
|
||||
, Invk_bnd_ipt = "bnd_ipt"
|
||||
, Invk_bnd_cmd = "bnd_cmd", Invk_bnd_cmd_ = "bnd_cmd_"
|
||||
;
|
||||
}
|
||||
51
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_bnd_itm_srl.java
Normal file
51
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_bnd_itm_srl.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.gfui.*; import gplx.xowa.guis.bnds.*;
|
||||
import gplx.langs.gfs.*; import gplx.xowa.apps.gfs.*;
|
||||
public class Xocfg_bnd_itm_srl implements GfoInvkAble {
|
||||
private Xoae_app app;
|
||||
public Xocfg_bnd_itm_srl(Xoae_app app, String key) {
|
||||
this.app = app;
|
||||
this.key = key;
|
||||
}
|
||||
public String Key() {return key;} private String key;
|
||||
public int Box() {return box;} private int box;
|
||||
public IptArg Ipt() {return ipt;} private IptArg ipt;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_src_)) Src_(app, this, m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_box_)) box = Xog_bnd_box_.Xto_sys_int(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_ipt_)) ipt = IptArg_.parse(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_src_ = "src_", Invk_box_ = "box_", Invk_ipt_ = "ipt_";
|
||||
public static String Src(Xoae_app app, int box, IptArg ipt) { // box_('browser').ipt_('mod.c+key.q');
|
||||
Gfs_wtr wtr = app.Gfs_mgr().Wtr();
|
||||
wtr.Add_set_eq(Key_box, Bry_.new_a7(Xog_bnd_box_.Xto_sys_str(box)));
|
||||
wtr.Add_set_eq(Key_ipt, Bry_.new_a7(ipt.Key()));
|
||||
return wtr.Bfr().To_str_and_clear();
|
||||
} private static final byte[] Key_box = Bry_.new_a7("box"), Key_ipt = Bry_.new_a7("ipt");
|
||||
public static void Src_(Xoae_app app, Xocfg_bnd_itm_srl itm, String v) {
|
||||
Xoa_gfs_mgr gfs_mgr = app.Gfs_mgr();
|
||||
gfs_mgr.Run_str_for(itm, v);
|
||||
Xog_bnd_itm bnd = app.Gui_mgr().Bnd_mgr().Get_or_null(itm.Key());
|
||||
if (bnd != null) // should not happen, but guard against backward compatibility issues (deprecating old bindings)
|
||||
app.Gui_mgr().Bnd_mgr().Set(bnd, itm.Box(), itm.Ipt());
|
||||
}
|
||||
}
|
||||
69
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_bnd_mgr.java
Normal file
69
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_bnd_mgr.java
Normal 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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
import gplx.gfui.*; import gplx.xowa.guis.bnds.*; import gplx.xowa.guis.cmds.*;
|
||||
import gplx.xowa.apps.fmtrs.*;
|
||||
public class Xocfg_bnd_mgr implements GfoInvkAble, Gfo_sort_able {
|
||||
private Xog_bnd_mgr_srl bnd_mgr_srl; private Xog_cmd_mgr cmd_mgr;
|
||||
private Xoa_fmtr_sort_mgr sorter;
|
||||
public Xocfg_bnd_mgr(Xoae_app app) {
|
||||
this.app = app; this.bnd_mgr = app.Gui_mgr().Bnd_mgr(); this.cmd_mgr = app.Gui_mgr().Cmd_mgr();
|
||||
bnd_mgr_srl = new Xog_bnd_mgr_srl(app, bnd_mgr);
|
||||
sorter = new Xoa_fmtr_sort_mgr(this);
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xog_bnd_mgr Bnd_mgr() {return bnd_mgr;} private Xog_bnd_mgr bnd_mgr;
|
||||
private Ordered_hash regy;
|
||||
public void Init() {
|
||||
regy = Ordered_hash_.New();
|
||||
int len = bnd_mgr.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xog_bnd_itm bnd = bnd_mgr.Get_at(i);
|
||||
Xog_cmd_itm cmd = cmd_mgr.Get_or_null(bnd.Cmd()); if (cmd == null) throw Err_.new_unhandled(bnd.Cmd());
|
||||
Xocfg_bnd_itm cfg_itm = new Xocfg_bnd_itm(this, cmd, bnd);
|
||||
regy.Add(bnd.Key(), cfg_itm);
|
||||
}
|
||||
}
|
||||
private Xocfg_bnd_itm_srl Init(String key) {return new Xocfg_bnd_itm_srl(app, key);}
|
||||
public Xocfg_bnd_itm Get_at(int i) {return (Xocfg_bnd_itm)regy.Get_at(i);}
|
||||
public int Len() {return regy.Count();}
|
||||
public void Sort(gplx.lists.ComparerAble comparer) {regy.Sort_by(comparer);}
|
||||
private void Set_bulk(byte[] src) {
|
||||
try {
|
||||
bnd_mgr_srl.Load_by_bry(src);
|
||||
}
|
||||
catch (Exception e) { // catch errors, so that next cmd (which is page.reload) can still execute
|
||||
app.Usr_dlg().Warn_many("", "", "failed to set bnds; src=~{0} err=~{1}", String_.new_u8(src), Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
private void Show_shortcut_win(String uid, String name, String binding) {
|
||||
Xog_bnd_win win = new Xog_bnd_win();
|
||||
win.Show(app.Gui_mgr().Kit(), app.Gui_mgr().Browser_win().Win_box(), bnd_mgr.Bnd_parser(), name, binding);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Xoa_fmtr_itm.Invk_get_at)) return this.Get_at(m.ReadInt("v"));
|
||||
else if (ctx.Match(k, Xoa_fmtr_itm.Invk_len)) return this.Len();
|
||||
else if (ctx.Match(k, Xoa_fmtr_itm.Invk_sorter)) return sorter;
|
||||
else if (ctx.Match(k, Invk_set_bulk)) Set_bulk(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_init)) return Init(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_show_shortcut_win)) Show_shortcut_win(m.ReadStr("uid"), m.ReadStr("name"), m.ReadStr("binding"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_set_bulk = "set_bulk", Invk_init = "init", Invk_show_shortcut_win = "show_shortcut_win";
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_gui_mgr.java
Normal file
29
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_gui_mgr.java
Normal 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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
public class Xocfg_gui_mgr implements GfoInvkAble {
|
||||
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;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_tabs = "tabs", Invk_bnds = "bnds";
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_regy.java
Normal file
34
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_regy.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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_regy implements GfoInvkAble {
|
||||
public Xocfg_regy(Xoae_app app) {
|
||||
app_cfg = new Xocfg_root(app, Xocfg_root_.Tid_app);
|
||||
}
|
||||
public Xocfg_root App() {return app_cfg;} private Xocfg_root app_cfg;
|
||||
public Xocfg_root Get_or_null(String key) {
|
||||
if (String_.Eq(key, Key_app)) return app_cfg;
|
||||
else throw Err_.new_unhandled(key);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get_or_null(m.ReadStrOr("v", Key_app));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_get = "get";
|
||||
public static final String Key_app = null;
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_root.java
Normal file
31
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_root.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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 implements GfoInvkAble {
|
||||
public Xocfg_root(Xoae_app app, byte tid) {
|
||||
this.tid = tid;
|
||||
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;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_gui = "gui";
|
||||
}
|
||||
21
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_root_.java
Normal file
21
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_root_.java
Normal 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.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;
|
||||
}
|
||||
69
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_tab_btn_mgr.java
Normal file
69
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_tab_btn_mgr.java
Normal 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.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 GfoInvkAble, GfoEvMgrOwner {
|
||||
public Xocfg_tab_btn_mgr() {
|
||||
evMgr = GfoEvMgr.new_(this);
|
||||
}
|
||||
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
|
||||
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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(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"); GfoEvMgr_.PubVal(this, Evt_hide_if_one_changed, hide_if_one);}
|
||||
else return GfoInvkAble_.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"
|
||||
;
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_tab_mgr.java
Normal file
27
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_tab_mgr.java
Normal 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.apps.cfgs.old; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.cfgs.*;
|
||||
public class Xocfg_tab_mgr implements GfoInvkAble {
|
||||
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 GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_new = "new", Invk_btns = "btns";
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_tab_new_mgr.java
Normal file
50
400_xowa/src/gplx/xowa/apps/cfgs/old/Xocfg_tab_new_mgr.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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 GfoInvkAble {
|
||||
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 GfoInvkAble_.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));
|
||||
}
|
||||
Reference in New Issue
Block a user