mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-02 07:24:19 +00:00
Gui: Add option to display actual HTML in SWT browser
This commit is contained in:
parent
a9afa7a827
commit
4360e42e95
@ -20,6 +20,7 @@ public class Xofulltext_args_wiki {
|
||||
public Hash_adp ns_hash = Hash_adp_.New();
|
||||
public int bgn;
|
||||
public int len;
|
||||
public int end() {return bgn + len;}
|
||||
|
||||
public Xofulltext_args_wiki(byte[] wiki) {
|
||||
this.wiki = wiki;
|
||||
|
@ -25,9 +25,11 @@ public class Xofulltext_searcher_ui {
|
||||
this.cbk_mgr = cbk_mgr;
|
||||
this.cbk_trg = cbk_trg;
|
||||
}
|
||||
public void Send_wiki_add(byte[] wiki) {
|
||||
public void Send_wiki_add(byte[] wiki, int rng_bgn, int rng_end) {
|
||||
cbk_mgr.Send_json(cbk_trg, "xo.fulltext_searcher.results__wiki__add__recv", gplx.core.gfobjs.Gfobj_nde.New()
|
||||
.Add_bry("wiki", wiki)
|
||||
.Add_int("rng_bgn", rng_bgn + List_adp_.Base1)
|
||||
.Add_int("rng_end", rng_end)
|
||||
);
|
||||
}
|
||||
public void Send_wiki_update(byte[] wiki, int found, int searched) {
|
||||
@ -66,4 +68,7 @@ public class Xofulltext_searcher_ui {
|
||||
.Add_bool("show_all_matches", show_all_matches)
|
||||
);
|
||||
}
|
||||
public void Send_done() {
|
||||
cbk_mgr.Send_json(cbk_trg, "xo.fulltext_searcher.results__done__recv", gplx.core.gfobjs.Gfobj_nde.New());
|
||||
}
|
||||
}
|
||||
|
@ -29,13 +29,13 @@ import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.gflucenes.*;
|
||||
import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.*;
|
||||
class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
private final Xoa_app app;
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
private final Hash_adp wkr_hash = Hash_adp_.New();
|
||||
public Xofulltext_searcher_svc(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Cancel(Json_nde args) {this.Cancel(args.Get_as_str("page_guid"));}
|
||||
private void Cancel(String page_guid) {
|
||||
Xofulltext_args_qry prv_args = (Xofulltext_args_qry)hash.Get_by(page_guid);
|
||||
Xofulltext_args_qry prv_args = (Xofulltext_args_qry)wkr_hash.Get_by(page_guid);
|
||||
if (prv_args != null) {
|
||||
prv_args.Cancel();
|
||||
}
|
||||
@ -45,7 +45,9 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
Xofulltext_args_qry search_args = Xofulltext_args_qry.New_by_json(args);
|
||||
search_args.cache_mgr = this.Cache_mgr();
|
||||
|
||||
// cancel any existing searches
|
||||
this.Cancel(search_args.page_guid);
|
||||
wkr_hash.Add(search_args.page_guid, search_args);
|
||||
|
||||
// autosave any changes if enabled
|
||||
Xocfg_mgr cfg_mgr = app.Cfg();
|
||||
@ -59,8 +61,6 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
// cfg_mgr.Set_bry_app ("xowa.addon.search.fulltext.special.namespaces", search_args.namespaces);
|
||||
}
|
||||
|
||||
hash.Add(search_args.page_guid, search_args);
|
||||
|
||||
// launch thread
|
||||
gplx.core.threads.Thread_adp_.Start_by_val("search", Cancelable_.Never, this, Invk__search, search_args);
|
||||
}
|
||||
@ -84,7 +84,7 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
// get wiki and notify
|
||||
byte[] wiki_domain = wiki_args.wiki;
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_make_init_y(wiki_domain);
|
||||
ui.Send_wiki_add(wiki_domain);
|
||||
ui.Send_wiki_add(wiki_domain, wiki_args.bgn, wiki_args.end());
|
||||
|
||||
// try to get from cache
|
||||
byte[] qry_key = args.Qry_key(wiki_domain, wiki_args.ns_ids);
|
||||
@ -99,8 +99,10 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
qry = cache_mgr.Get_or_null(qry_id);
|
||||
if (qry != null) {
|
||||
boolean all_shown = Display_cached_qry(args, ui, wiki, qry, qry_id, wiki_args);
|
||||
if (all_shown || qry.done)
|
||||
if (all_shown || qry.done) {
|
||||
ui.Send_done();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
args.qry_id = qry_id;
|
||||
@ -108,6 +110,7 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
// do search
|
||||
Xofulltext_searcher searcher = Get_searcher(wiki);
|
||||
searcher.Search(ui, wiki, qry, args, wiki_args);
|
||||
ui.Send_done();
|
||||
}
|
||||
catch (Exception exc) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to search_wiki; err=~{0}", Err_.Message_gplx_log(exc));
|
||||
|
@ -18,7 +18,8 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
|
||||
import gplx.xowa.guis.menus.*; import gplx.xowa.guis.menus.dom.*; import gplx.xowa.guis.cbks.js.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.js.*; import gplx.xowa.htmls.heads.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
|
||||
import gplx.xowa.htmls.*;
|
||||
public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm, Xoh_page_html_source {
|
||||
private Xoae_app app; private final Object thread_lock = new Object();
|
||||
private final String_obj_ref scroll_top = String_obj_ref.null_(), node_path = String_obj_ref.null_();
|
||||
protected Xog_html_itm() {} // TEST: for prefs_mgr
|
||||
@ -47,6 +48,9 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
|
||||
html_box.Html_js_cbks_add("xowa_exec", js_cbk);
|
||||
Gfo_evt_mgr_.Sub_same(html_box, Gfui_html.Evt_zoom_changed, this);
|
||||
}
|
||||
public byte[] Get_page_html() {
|
||||
return Bry_.new_u8(html_box.Text());
|
||||
}
|
||||
public String Html_selected_get_src_or_empty() {return html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_src_or_empty);}
|
||||
public String Html_selected_get_href_or_text() {return Html_extract_text(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_href_or_text));}
|
||||
public String Html_selected_get_text_or_href() {return Html_extract_text(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_text_or_href));}
|
||||
@ -60,7 +64,7 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
|
||||
}
|
||||
public void Show(Xoae_page page) {
|
||||
byte view_mode = owner_tab.View_mode();
|
||||
byte[] html_src = page.Wikie().Html_mgr().Page_wtr_mgr().Gen(page, view_mode); // NOTE: must use wiki of page, not of owner tab; DATE:2015-03-05
|
||||
byte[] html_src = page.Wikie().Html_mgr().Page_wtr_mgr().Gen(page, this, view_mode); // NOTE: must use wiki of page, not of owner tab; DATE:2015-03-05
|
||||
Html_src_(page, html_src);
|
||||
if (view_mode == Xopg_page_.Tid_read){ // used only for Xosrh test; DATE:2014-01-29
|
||||
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Win__focus_body); // NOTE: only focus if read so up / down will scroll box; edit / html should focus edit-box; DATE:2014-06-05
|
||||
|
19
400_xowa/src/gplx/xowa/htmls/Xoh_page_html_source.java
Normal file
19
400_xowa/src/gplx/xowa/htmls/Xoh_page_html_source.java
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoh_page_html_source {
|
||||
byte[] Get_page_html();
|
||||
}
|
28
400_xowa/src/gplx/xowa/htmls/Xoh_page_html_source_.java
Normal file
28
400_xowa/src/gplx/xowa/htmls/Xoh_page_html_source_.java
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_page_html_source_ {
|
||||
public static Xoh_page_html_source
|
||||
Wtr = new Xoh_page_html_source__wtr()
|
||||
, Noop = new Xoh_page_html_source__noop()
|
||||
;
|
||||
}
|
||||
class Xoh_page_html_source__wtr implements Xoh_page_html_source {
|
||||
public byte[] Get_page_html() {return null;}
|
||||
}
|
||||
class Xoh_page_html_source__noop implements Xoh_page_html_source {
|
||||
public byte[] Get_page_html() {return null;}
|
||||
}
|
@ -53,7 +53,8 @@ public class Xoh_page_wtr_mgr implements Gfo_invk {
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
wiki.App().Cfg().Bind_many_wiki(this, wiki, Cfg__scripting_enabled);
|
||||
}
|
||||
public byte[] Gen(Xoae_page page, byte output_tid) {
|
||||
public byte[] Gen(Xoae_page page, byte output_tid) {return Gen(page, Xoh_page_html_source_.Noop, output_tid);}
|
||||
public byte[] Gen(Xoae_page page, Xoh_page_html_source page_html_source, byte output_tid) {
|
||||
Xoh_page_wtr_wkr wtr = Wkr(output_tid);
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
if (init) {
|
||||
@ -62,7 +63,7 @@ public class Xoh_page_wtr_mgr implements Gfo_invk {
|
||||
page_edit_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
page_html_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
}
|
||||
wtr.Write_page(html_bfr, page, wiki.Parser_mgr().Ctx());
|
||||
wtr.Write_page(html_bfr, page, wiki.Parser_mgr().Ctx(), page_html_source);
|
||||
return html_bfr.To_bry_and_clear_and_rls();
|
||||
}
|
||||
public Xoh_page_wtr_wkr Wkr(byte output_tid) {
|
||||
|
@ -21,6 +21,7 @@ import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.d
|
||||
import gplx.xowa.xtns.pagebanners.*;
|
||||
import gplx.xowa.apps.gfs.*; import gplx.xowa.htmls.portal.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.xowa.htmls.core.*;
|
||||
public class Xoh_page_wtr_wkr {
|
||||
private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
@ -30,7 +31,7 @@ public class Xoh_page_wtr_wkr {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page; private byte[] root_dir_bry;
|
||||
public Xoh_page_wtr_wkr(Xoh_page_wtr_mgr mgr, byte page_mode) {this.mgr = mgr; this.page_mode = page_mode;}
|
||||
public Xoh_page_wtr_wkr Ctgs_enabled_(boolean v) {ctgs_enabled = v; return this;} private boolean ctgs_enabled = true;
|
||||
public void Write_page(Bry_bfr rv, Xoae_page page, Xop_ctx ctx) {
|
||||
public void Write_page(Bry_bfr rv, Xoae_page page, Xop_ctx ctx, Xoh_page_html_source page_html_source) {
|
||||
synchronized (thread_lock_1) {
|
||||
this.page = page; this.wiki = page.Wikie(); this.app = wiki.Appe();
|
||||
ctx.Page_(page); // HACK: must update page for toc_mgr; WHEN: Xoae_page rewrite
|
||||
@ -47,10 +48,20 @@ public class Xoh_page_wtr_wkr {
|
||||
}
|
||||
Bry_bfr page_bfr = wiki.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page rv to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
|
||||
Xoh_wtr_ctx hctx = null;
|
||||
if (page_mode == Xopg_page_.Tid_html && wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid_is_hdump_save()) {
|
||||
hctx = Xoh_wtr_ctx.Hdump;
|
||||
Write_body(page_bfr, ctx, hctx, page);
|
||||
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
|
||||
if (page_mode == Xopg_page_.Tid_html && wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid_is_custom()) {
|
||||
byte[] html_bry = null;
|
||||
|
||||
// get html from html dump
|
||||
if (wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid() == Xow_hdump_mode.Hdump_save.Tid()) {
|
||||
hctx = Xoh_wtr_ctx.Hdump;
|
||||
Write_body(page_bfr, ctx, hctx, page);
|
||||
html_bry = page_bfr.To_bry_and_clear();
|
||||
}
|
||||
// get from swt browser
|
||||
else {
|
||||
html_bry = page_html_source.Get_page_html();
|
||||
}
|
||||
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(html_bry));
|
||||
}
|
||||
else {
|
||||
hctx = Xoh_wtr_ctx.Basic;
|
||||
|
@ -22,20 +22,25 @@ public class Xow_hdump_mode {
|
||||
public Xow_hdump_mode(int tid, String key, String gui) {
|
||||
this.tid = tid; this.key = key; this.gui = gui;
|
||||
}
|
||||
public boolean Tid_is_hdump_save() {return tid == Hdump_save.tid;}
|
||||
public int Tid() {return tid;}
|
||||
// boolean Tid_is_hdump_save() {return tid == Hdump_save.tid;}
|
||||
public boolean Tid_is_custom() {return tid < Shown.tid;}
|
||||
|
||||
public static final Xow_hdump_mode
|
||||
Shown = new Xow_hdump_mode(0, "shown" , "Shown")
|
||||
, Hdump_save = new Xow_hdump_mode(1, "hdump_save" , "Saved for HTML DB")
|
||||
, Hdump_load = new Xow_hdump_mode(2, "hdump_load" , "Loaded by HTML DB");
|
||||
Swt_browser = new Xow_hdump_mode(0, "swt_browser" , "SWT Browser")
|
||||
, Hdump_save = new Xow_hdump_mode(1, "hdump_save" , "Saved for HTML DB")
|
||||
, Shown = new Xow_hdump_mode(2, "shown" , "Shown")
|
||||
, Hdump_load = new Xow_hdump_mode(3, "hdump_load" , "Loaded by HTML DB")
|
||||
;
|
||||
public static void Cfg__reg_type(gplx.xowa.addons.apps.cfgs.mgrs.types.Xocfg_type_mgr type_mgr) {
|
||||
type_mgr.Lists__add("list:xowa.wiki.hdumps.html_mode", To_kv(Shown), To_kv(Hdump_save), To_kv(Hdump_load));
|
||||
type_mgr.Lists__add("list:xowa.wiki.hdumps.html_mode", To_kv(Shown), To_kv(Swt_browser), To_kv(Hdump_save), To_kv(Hdump_load));
|
||||
}
|
||||
private static Keyval To_kv(Xow_hdump_mode mode) {return Keyval_.new_(mode.key, mode.gui);}
|
||||
public static Xow_hdump_mode Parse(String v) {
|
||||
if (String_.Eq(v, Shown.key)) return Shown;
|
||||
else if (String_.Eq(v, Hdump_save.key)) return Hdump_save;
|
||||
else if (String_.Eq(v, Hdump_load.key)) return Hdump_load;
|
||||
else if (String_.Eq(v, Swt_browser.key)) return Swt_browser;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class Xox_xowa_html_cmd_fxt {
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(raw_bry);
|
||||
fxt.Page().Root_(root);
|
||||
html_mgr.Html_wtr().Write_doc(bfr, fxt.Ctx(), raw_bry, root);
|
||||
html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, fxt.Page(), fxt.Ctx());
|
||||
html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, fxt.Page(), fxt.Ctx(), Xoh_page_html_source_.Wtr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user