mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Wiki: Support renamed folders (fix)
This commit is contained in:
@@ -1,32 +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.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public class Xog_cbk_mgr { // INSTANCE:app
|
||||
private Xog_cbk_wkr[] wkrs = Xog_cbk_wkr_.Ary_empty; private int wkrs_len = 0;
|
||||
public void Reg(Xog_cbk_wkr wkr) {
|
||||
this.wkrs = (Xog_cbk_wkr[])Array_.Resize_add_one(wkrs, wkrs_len, wkr);
|
||||
++wkrs_len;
|
||||
}
|
||||
public void Send_json(Xog_cbk_trg trg, String func, Gfobj_nde data) {
|
||||
for (int i = 0; i < wkrs_len; ++i) {
|
||||
Xog_cbk_wkr wkr = wkrs[i];
|
||||
wkr.Send_json(trg, func, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
public class Xog_cbk_trg {
|
||||
Xog_cbk_trg(byte tid, byte[] page_ttl) {this.tid = tid; this.page_ttl = page_ttl;}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public byte[] Page_ttl() {return page_ttl;} private final byte[] page_ttl; // same as ttl.Full_db(); EX: Special:XowaDownloadCentral
|
||||
|
||||
public static final byte Tid__cbk_enabled = 0, Tid__specific_page = 1;
|
||||
public static final Xog_cbk_trg Any = new Xog_cbk_trg(Tid__cbk_enabled, null);
|
||||
public static Xog_cbk_trg New(byte[] page_ttl) {return new Xog_cbk_trg(Tid__specific_page, page_ttl);}
|
||||
}
|
||||
@@ -1,25 +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.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public interface Xog_cbk_wkr {
|
||||
Object Send_json(Xog_cbk_trg trg, String func, Gfobj_nde data);
|
||||
}
|
||||
class Xog_cbk_wkr_ {
|
||||
public static final Xog_cbk_wkr[] Ary_empty = new Xog_cbk_wkr[0];
|
||||
}
|
||||
@@ -1,22 +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.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public interface Xog_json_wkr {
|
||||
void Send_json(String func, Gfobj_nde data);
|
||||
}
|
||||
@@ -1,59 +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.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.xowa.guis.views.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Js_img_mgr {
|
||||
public static void Update_link_missing(Xog_js_wkr html_itm, String html_id) {
|
||||
html_itm.Html_redlink(html_id);
|
||||
}
|
||||
public static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Xof_file_itm itm) {
|
||||
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_view_url()
|
||||
, itm.Orig_w(), itm.Orig_h(), itm.Orig_ext(), itm.Html_orig_url(), itm.Orig_ttl(), itm.Html_gallery_mgr_h());
|
||||
}
|
||||
private static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Js_img_wkr img_wkr, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, Io_url html_view_url
|
||||
, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl, int gallery_mgr_h) {
|
||||
if (!page.Wiki().App().Mode().Tid_supports_js()) return; // do not update html widget unless app is gui; null ref on http server; DATE:2014-09-17
|
||||
switch (elem_tid) {
|
||||
case Xof_html_elem.Tid_gallery_v2:
|
||||
img_wkr.Js_wkr__update_hdoc(page, js_wkr, uid, html_w, html_h, html_view_url, orig_w, orig_h, orig_ext, html_orig_url, lnki_ttl);
|
||||
return;
|
||||
}
|
||||
String html_id = To_doc_uid(uid);
|
||||
js_wkr.Html_img_update(html_id, html_view_url.To_http_file_str(), html_w, html_h);
|
||||
if (Xop_lnki_type.Id_is_thumbable(lnki_type)) { // thumb needs to set cls and width
|
||||
js_wkr.Html_atr_set(html_id, "class", gplx.xowa.htmls.core.wkrs.imgs.atrs.Xoh_img_cls_.Str__thumbimage);
|
||||
js_wkr.Html_atr_set("xowa_file_div_" + uid, "style", "width:" + html_w + "px;");
|
||||
}
|
||||
switch (elem_tid) {
|
||||
case Xof_html_elem.Tid_gallery:
|
||||
js_wkr.Html_atr_set("xowa_gallery_div3_" + uid, "style", "margin:" + Gallery_mgr_wtr_.Calc_vpad(gallery_mgr_h, html_h) + "px auto;");
|
||||
break;
|
||||
case Xof_html_elem.Tid_imap:
|
||||
img_wkr.Js_wkr__update_hdoc(page, js_wkr, uid, html_w, html_h, html_view_url, orig_w, orig_h, orig_ext, html_orig_url, lnki_ttl);
|
||||
break;
|
||||
case Xof_html_elem.Tid_vid:
|
||||
String html_id_vid = "xowa_file_play_" + uid;
|
||||
js_wkr.Html_atr_set(html_id_vid, "style", "width:" + html_w + "px;max-width:" + (html_w - 2) + "px;");
|
||||
js_wkr.Html_atr_set(html_id_vid, "href", html_orig_url.To_http_file_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static String To_doc_uid(int html_uid) {return gplx.xowa.htmls.Xoh_img_mgr.Str__html_uid + Int_.To_str(html_uid);}
|
||||
}
|
||||
@@ -1,23 +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.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.xowa.files.*;
|
||||
public interface Js_img_wkr {
|
||||
void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url
|
||||
, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl);
|
||||
}
|
||||
@@ -1,29 +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.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
public interface Xog_js_wkr {
|
||||
void Html_img_update (String uid, String src, int w, int h);
|
||||
void Html_redlink (String html_uid);
|
||||
|
||||
void Html_atr_set (String uid, String key, String val);
|
||||
void Html_elem_replace_html (String uid, String html);
|
||||
void Html_elem_append_above (String uid, String html);
|
||||
void Html_elem_delete (String elem_id);
|
||||
void Html_gallery_packed_exec ();
|
||||
void Html_popups_bind_hover_to_doc ();
|
||||
}
|
||||
@@ -1,31 +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.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
public class Xog_js_wkr_ {
|
||||
public static final Xog_js_wkr Noop = new Xog_js_wkr__noop();
|
||||
}
|
||||
class Xog_js_wkr__noop implements Xog_js_wkr {
|
||||
public void Html_img_update (String uid, String src, int w, int h) {}
|
||||
public void Html_atr_set (String uid, String key, String val) {}
|
||||
public void Html_elem_replace_html (String uid, String html) {}
|
||||
public void Html_elem_append_above (String uid, String html) {}
|
||||
public void Html_redlink (String html_uid) {}
|
||||
public void Html_elem_delete (String elem_id) {}
|
||||
public void Html_gallery_packed_exec() {}
|
||||
public void Html_popups_bind_hover_to_doc() {}
|
||||
}
|
||||
@@ -1,38 +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.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
public class Xog_js_wkr__log implements Xog_js_wkr {
|
||||
private final List_adp log_list = List_adp_.New();
|
||||
public void Html_img_update (String uid, String src, int w, int h) {log_list.Add(Object_.Ary(Proc_img_update, uid, src, w, h));}
|
||||
public void Html_atr_set (String uid, String key, String val) {log_list.Add(Object_.Ary(Proc_atr_set, uid, key, val));}
|
||||
public void Html_redlink (String uid) {log_list.Add(Object_.Ary(Proc_redlink, uid));}
|
||||
public void Html_elem_replace_html (String uid, String html) {log_list.Add(Object_.Ary(Proc_replace_html, uid, html));}
|
||||
public void Html_elem_append_above (String uid, String html) {log_list.Add(Object_.Ary(Proc_append_above, uid, html));}
|
||||
public void Html_elem_delete (String elem_id) {log_list.Add(Object_.Ary(Proc_delete, elem_id));}
|
||||
public void Html_gallery_packed_exec() {log_list.Add(Object_.Ary(Proc_gallery_packed_exec));}
|
||||
public void Html_popups_bind_hover_to_doc() {log_list.Add(Object_.Ary(Proc_popups_bind_hover_to_doc));}
|
||||
|
||||
public void Log__clear() {log_list.Clear();}
|
||||
public int Log__len() {return log_list.Count();}
|
||||
public Object[] Log__get_at(int i) {return (Object[])log_list.Get_at(i);}
|
||||
|
||||
public static final String
|
||||
Proc_img_update = "img_update", Proc_atr_set = "atr_set", Proc_redlink = "redlink", Proc_replace_html = "replace_html"
|
||||
, Proc_append_above = "append_above", Proc_delete = "delete", Proc_gallery_packed_exec = "gallery_packed_exec", Proc_popups_bind_hover_to_doc = "popups_bind_hover_to_doc"
|
||||
;
|
||||
}
|
||||
@@ -1,34 +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.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.core.logs.*; import gplx.core.gfobjs.*; import gplx.xowa.guis.cbks.*;
|
||||
public class Gfo_log__swt extends Gfo_log__file { private final Xog_cbk_mgr cbk_mgr;
|
||||
public Gfo_log__swt(Xog_cbk_mgr cbk_mgr, Io_url url, Gfo_log_itm_wtr fmtr) {super(url, fmtr);this.cbk_mgr = cbk_mgr;}
|
||||
@Override public void Exec(byte type, long time, long elapsed, String msg, Object[] args) {
|
||||
if (type == Gfo_log_itm.Type__prog) return;
|
||||
super.Exec(type, time, elapsed, msg, args);
|
||||
Gfobj_nde nde = Gfobj_nde.New().Add_str("msg", msg);
|
||||
int args_len = args.length;
|
||||
for (int i = 0; i < args_len; i += 2) {
|
||||
String key = Object_.Xto_str_strict_or_null_mark(args[i]);
|
||||
Object val = i + 1 < args_len ? args[i + 1] : "<<NULL>>";
|
||||
nde.Add_str(key, Object_.Xto_str_strict_or_null_mark(val));
|
||||
}
|
||||
cbk_mgr.Send_json(Xog_cbk_trg.Any, "xo.log.add__recv", nde);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +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.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public class Gfobj_wtr__json__browser extends Gfobj_wtr__json { private final Bry_bfr bfr;
|
||||
public Gfobj_wtr__json__browser() {
|
||||
this.Opt_ws_(Bool_.N).Opt_backslash_2x_(Bool_.Y);
|
||||
this.bfr = this.Bfr();
|
||||
}
|
||||
public String Write_as_func__swt(String func_name, Gfobj_grp root) {return Write_as_func(Bool_.Y, func_name, root);}
|
||||
public String Write_as_func__drd(String func_name, Gfobj_grp root) {return Write_as_func(Bool_.N, func_name, root);}
|
||||
private String Write_as_func(boolean write_return, String func_name, Gfobj_grp root) {
|
||||
if (write_return) bfr.Add(Bry__func_bgn); // NOTE: Android WebView fails if return is passed; EX: "return 'true'" works on SWT.Browser, but not WebView
|
||||
bfr.Add_str_u8(func_name);
|
||||
bfr.Add(Bry__args_bgn);
|
||||
this.Write(root);
|
||||
bfr.Add(Bry__args_end);
|
||||
return this.To_str();
|
||||
}
|
||||
private static final byte[]
|
||||
Bry__func_bgn = Bry_.new_a7("return ")
|
||||
, Bry__args_bgn = Bry_.new_a7("('")
|
||||
, Bry__args_end = Bry_.new_a7("');")
|
||||
;
|
||||
}
|
||||
@@ -1,41 +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.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public class Gfobj_wtr__json__browser__tst {
|
||||
private final Gfobj_wtr__json__browser__fxt fxt = new Gfobj_wtr__json__browser__fxt();
|
||||
@Test public void Json_proc() {
|
||||
fxt.Test__json_proc
|
||||
( "proc_name"
|
||||
, fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_long ("k2", 2)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "return proc_name('{\"k1\":\"v1\",\"k2\":2,\"k3\":3}');"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Gfobj_wtr__json__browser__fxt extends Gfobj_wtr__json_fxt { public Gfobj_wtr__json__browser__fxt Test__json_proc() {return this;}
|
||||
public void Test__json_proc(String proc_name, Gfobj_nde root, String expd) {
|
||||
Gfobj_wtr__json__browser wtr = new Gfobj_wtr__json__browser();
|
||||
String actl = wtr.Write_as_func__swt(proc_name, root);
|
||||
Gftest.Eq__str(expd, actl, "json_write");
|
||||
}
|
||||
}
|
||||
@@ -1,64 +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.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
|
||||
public class Xog_cbk_wkr__swt implements Xog_cbk_wkr {
|
||||
private final Xoa_gui_mgr gui_mgr;
|
||||
private final Xog_browser_func browser_func;
|
||||
private final Gfobj_wtr__json__browser json_wtr = new Gfobj_wtr__json__browser();
|
||||
public Xog_cbk_wkr__swt(Xoa_gui_mgr gui_mgr) {
|
||||
this.gui_mgr = gui_mgr;
|
||||
this.browser_func = new Xog_browser_func();
|
||||
}
|
||||
public Object Send_json(Xog_cbk_trg trg, String func, Gfobj_nde data) {
|
||||
if (gui_mgr.Kit().Tid() != Gfui_kit_.Swt_tid) return null; // guard against calling when HTTP_server
|
||||
String script = json_wtr.Write_as_func__swt(func, data);
|
||||
GfuiInvkCmd swt_cmd = gui_mgr.Kit().New_cmd_sync(browser_func.Script_(script));
|
||||
Xog_tab_mgr tab_mgr = gui_mgr.Browser_win().Tab_mgr();
|
||||
int tabs_len = tab_mgr.Tabs_len();
|
||||
Object rv = null;
|
||||
for (int i = 0; i < tabs_len; ++i) {
|
||||
Xog_tab_itm tab = tab_mgr.Tabs_get_at(i);
|
||||
Xoa_page page = tab.Page();
|
||||
boolean match = false;
|
||||
switch (trg.Tid()) {
|
||||
case Xog_cbk_trg.Tid__cbk_enabled:
|
||||
match = page.Html_data().Cbk_enabled();
|
||||
break;
|
||||
case Xog_cbk_trg.Tid__specific_page:
|
||||
match = Bry_.Eq(trg.Page_ttl(), page.Ttl().Full_db_wo_qarg()); // NOTE: ignore qargs to handle Special:XowaCfg?grp=some_grp; DATE:2016-12-28
|
||||
break;
|
||||
}
|
||||
if (match) {
|
||||
browser_func.Tab_(tab);
|
||||
rv = Gfo_invk_.Invk_no_key(swt_cmd);
|
||||
if (rv == null && !String_.Eq(func, "xo.log.add__recv")) throw Err_.new_("gplx.swt", "send_json was not acknowledged", "func", func, "script", script);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xog_browser_func implements Gfo_invk {
|
||||
private String script;
|
||||
public Xog_browser_func Script_(String v) {this.script = v; return this;}
|
||||
public void Tab_(Xog_tab_itm v) {this.tab = v;} private Xog_tab_itm tab;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return tab.Html_box().Html_js_eval_script_as_obj(script);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user