1
0
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:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,56 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.lists.rings.*;
import gplx.gfui.*; import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.standards.*;
public class Gfo_usr_dlg__gui__swt implements Gfo_usr_dlg__gui, Gfo_invk {
private final GfuiInvkCmd cmd_sync; private final GfuiTextBox prog_box, info_box;
private boolean show_warn, show_note;
public Gfo_usr_dlg__gui__swt(Xoa_app app, Gfui_kit kit, GfuiTextBox prog_box, GfuiTextBox info_box, GfuiTextBox warn_box) {
this.cmd_sync = kit.New_cmd_sync(this); // NOTE: cmd_sync needed else progress messages may be sent out of order
this.prog_box = prog_box; this.info_box = info_box;
app.Cfg().Bind_many_app(this, Cfg__show_warn, Cfg__show_note);
}
public void Clear() {Write(Invk_write_prog, ""); info_box.Text_(""); info_box.ForeColor_(ColorAdp_.Black); info_box.BackColor_(ColorAdp_.White); info_box.Redraw(); info_box_is_warn = false;}
public Ring__string Prog_msgs() {return prog_msgs;} Ring__string prog_msgs = new Ring__string().Max_(128);
public void Write_prog(String text) {Write(Invk_write_prog, text);}
public void Write_note(String text) {if (show_note) Write(Invk_write_note, text);}
public void Write_warn(String text) {if (show_warn) Write(Invk_write_warn, text);}
public void Write_stop(String text) {Write(Invk_write_stop, text);}
private void Write(String invk, String text) {
GfoMsg m = GfoMsg_.new_cast_(invk).Add("v", text);
Gfo_invk_.Invk_by_msg(cmd_sync, invk, m);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_write_prog)) {String v = m.ReadStr("v"); prog_box.Text_(v); prog_box.Redraw(); if (!String_.Eq(v, "")) prog_msgs.Push(v);}
else if (ctx.Match(k, Invk_write_note)) {Info_box_write(m.ReadStr("v"), false); info_box.Redraw();}
else if (ctx.Match(k, Invk_write_warn)) {Info_box_write(m.ReadStr("v"), true); info_box.ForeColor_(ColorAdp_.White); info_box.BackColor_(ColorAdp_.Red); info_box.Redraw();}
else if (ctx.Match(k, Cfg__show_warn)) show_warn = m.ReadYn("v");
else if (ctx.Match(k, Cfg__show_note)) show_note = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private void Info_box_write(String v, boolean warn) {
if (info_box_is_warn) return;
info_box.Text_(v);
info_box_is_warn = warn;
} boolean info_box_is_warn;
private static final String Invk_write_prog = "write_prog", Invk_write_note = "write_note", Invk_write_warn = "write_warn", Invk_write_stop = "write_stop";
private static final String Cfg__show_warn = "xowa.app.debug.show_warn", Cfg__show_note = "xowa.app.debug.show_note";
}

View File

@@ -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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Gfo_usr_dlg_fmt {
public boolean Write_prog_cur(int cur, Gfo_usr_dlg usr_dlg) {
if (cur < prog_prv + prog_interval) return usr_dlg.Canceled();
prog_prv = cur;
String pct = Decimal_adp_.CalcPctStr(cur + List_adp_.Base1, end, "00.00");
usr_dlg.Prog_many(grp_key, msg_key, fmt, Int_.To_str_pad_bgn_zero(cur + List_adp_.Base1, endLen), end, pct);
return usr_dlg.Canceled();
} String fmt; int end, endLen;
public static Gfo_usr_dlg_fmt fmt_(String grp_key, String msg_key, String fmt, int end, float pct) {
Gfo_usr_dlg_fmt rv = new Gfo_usr_dlg_fmt();
rv.grp_key = grp_key; rv.msg_key = msg_key;
rv.fmt = fmt; rv.end = end; rv.endLen = Int_.DigitCount(end); rv.prog_interval = (int)((float)end * (float)(pct / (float)100));;
return rv;
} String grp_key, msg_key;
int prog_interval; int prog_prv = Int_.Min_value;
}

View File

@@ -1,61 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.threads.*; import gplx.core.envs.*;
public class Load_page_wkr implements Gfo_thread_wkr {
private final Xog_tab_itm tab;
public Load_page_wkr(Xog_tab_itm tab, Xowe_wiki wiki, Xoa_url url, Xoa_ttl ttl) {this.tab = tab; this.wiki = wiki; this.url = url; this.ttl = ttl;}
public String Thread__name() {return "xowa.load_page_wkr";}
public boolean Thread__resume() {return false;}
public Xowe_wiki Wiki() {return wiki;} private final Xowe_wiki wiki;
public Xoa_url Url() {return url;} private final Xoa_url url;
public Xoa_ttl Ttl() {return ttl;} private final Xoa_ttl ttl;
public Xoae_page Page() {return page;} private Xoae_page page;
public Exception Exec_err() {return exec_err;} private Exception exec_err;
public void Thread__exec() {
try {
Running_(true);
// wait_for_popups; free mem check;
this.page = wiki.Page_mgr().Load_page(url, ttl, tab);
// launch thread to show page
Gfo_invk_.Invk_by_val(tab.Cmd_sync(), Xog_tab_itm.Invk_show_url_loaded_swt, this);
}
catch (Exception e) {
this.exec_err = e;
Gfo_invk_.Invk_by_val(tab.Cmd_sync(), Xog_tab_itm.Invk_show_url_failed_swt, this);
}
finally {
Running_(false);
}
}
private static final Object thread_lock = new Object(); private static boolean running = false;
public static boolean Running() {
boolean rv = false;
synchronized (thread_lock) {
rv = running;
}
return rv;
}
private static void Running_(boolean v) {
synchronized (thread_lock) {
running = v;
}
}
}

View File

@@ -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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Rect_ref {
public Rect_ref(int x, int y, int w, int h) {this.x = x; this.y = y; this.w = w; this.h = h;}
public int X() {return x;} public Rect_ref X_(int v) {x = v; return this;} private int x;
public int Y() {return y;} public Rect_ref Y_(int v) {y = v; return this;} private int y;
public int W() {return w;} public Rect_ref W_(int v) {w = v; return this;} private int w;
public int H() {return h;} public Rect_ref H_(int v) {h = v; return this;} private int h;
public int X_max() {return x + w;}
public int Y_max() {return y + h;}
public gplx.gfui.RectAdp XtoRectAdp() {return gplx.gfui.RectAdp_.new_(x, y, w, h);}
public gplx.gfui.RectAdp XtoRectAdp_add(Rect_ref v) {return gplx.gfui.RectAdp_.new_(x + v.x, y + v.y, w + v.w, h + v.h);}
@Override public String toString() {return String_.Format("{0},{1},{2},{3}", x, y, w, h);}
public static final Rect_ref Zero = new Rect_ref(0, 0, 0, 0);
public static Rect_ref rectAdp_(gplx.gfui.RectAdp v) {return new Rect_ref(v.X(), v.Y(), v.Width(), v.Height());}
public static Rect_ref parse(String raw) {
try {
String[] ary = String_.Split(raw, ",");
return new Rect_ref(Int_.parse(ary[0]), Int_.parse(ary[1]), Int_.parse(ary[2]), Int_.parse(ary[3]));
} catch(Exception exc) {throw Err_.new_parse_exc(exc, Rect_ref.class, raw);}
}
}

View File

@@ -1,80 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.threads.*;
import gplx.xowa.wikis.pages.lnkis.*;
import gplx.xowa.guis.cbks.js.*;
public class Xog_async_wkr {
public static void Async(Xog_tab_itm tab) {Xog_async_wkr.Async(tab.Page(), tab.Html_itm());}
public static void Async(Xoae_page page, Xog_html_itm js_wkr) {
if (page == null) return; // TEST: occurs during Xog_win_mgr_tst
// get wiki
Xowe_wiki wiki = page.Wikie(); Xoae_app app = wiki.Appe(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
app.Usr_dlg().Log_many("", "", "page.async: url=~{0}", page.Url().To_str());
if (page.Url().Anch_str() != null)
js_wkr.Scroll_page_by_id_gui(page.Url().Anch_str());
if (usr_dlg.Canceled()) {
usr_dlg.Prog_none("", "", "");
app.Log_wtr().Queue_enabled_(false);
return;
}
Async_imgs(usr_dlg, app, wiki, page, js_wkr);
gplx.xowa.xtns.math.Xomath_latex_bldr.Async(app, page, js_wkr);
Async_score(usr_dlg, app, page);
Async_redlinks(usr_dlg, app, page, js_wkr);
// cache maintenance
usr_dlg.Prog_none("", "imgs.done", "");
try {app.File_mgr().Cache_mgr().Compress_check();}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.cache: page=~{0} err=~{1}", page.Ttl().Raw(), Err_.Message_gplx_full(e));}
app.Usere().User_db_mgr().Cache_mgr().Page_end(app.Wiki_mgr());
app.Log_wtr().Queue_enabled_(false); // flush queue
}
private static void Async_imgs(Gfo_usr_dlg usr_dlg, Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xog_js_wkr js_wkr) {
// get images
int len = page.File_queue().Count();
if (len > 0) {
usr_dlg.Prog_one("", "", "downloading images: ~{0}", len);
try {page.File_queue().Exec(wiki, page);}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.image: page=~{0} err=~{1}", page.Ttl().Raw(), Err_.Message_gplx_full(e));}
}
// if gallery.packed exists, call pack; NOTE:must fire even when there are 0 items in queue b/c hdump will restore images without placing in queue; PAGE:en.w:Mexico DATE:2016-08-14
if (page.Html_data().Xtn_gallery_packed_exists()) // packed_gallery exists; fire js once; PAGE:en.w:National_Sculpture_Museum_(Valladolid); DATE:2014-07-21
js_wkr.Html_gallery_packed_exec();
// call imap
if ( page.Html_data().Xtn_imap_exists() // imap exists; DATE:2014-08-07
&& page.Html_data().Head_mgr().Itm__popups().Enabled()
)
js_wkr.Html_popups_bind_hover_to_doc(); // rebind all elements to popup
}
private static void Async_score(Gfo_usr_dlg usr_dlg, Xoae_app app, Xoae_page page) {
// run other cmds
if (page.Html_cmd_mgr().Count() > 0) {
try {page.Html_cmd_mgr().Exec(app, page);}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.cmds: page=~{0} err=~{1}", page.Ttl().Raw(), Err_.Message_gplx_full(e));}
}
}
private static void Async_redlinks(Gfo_usr_dlg usr_dlg, Xoae_app app, Xoae_page page, Xog_js_wkr js_wkr) {
if (page.Tab_data().Tab() == null) return; // needed b/c Preview has page.Tab of null which causes null_ref error in redlinks
Xopg_redlink_mgr.Run_async(page, js_wkr);
}
}

View File

@@ -1,231 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
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 {
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
public Xog_html_itm(Xog_tab_itm owner_tab) {
this.owner_tab = owner_tab;
app = owner_tab.Tab_mgr().Win().App();
js_cbk = new Xoh_js_cbk(this);
Gfui_kit kit = owner_tab.Tab_mgr().Win().Kit();
cmd_sync = kit.New_cmd_sync(this); // NOTE: always use sync; async will cause some images to be "lost" in update;
cmd_async = kit.New_cmd_async(this);
ev_mgr = new Gfo_evt_mgr(this);
}
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr;
public Xog_tab_itm Owner_tab() {return owner_tab;} private Xog_tab_itm owner_tab;
public Gfui_html Html_box() {return html_box;} private Gfui_html html_box;
public Xoh_js_cbk Js_cbk() {return js_cbk;} private Xoh_js_cbk js_cbk;
public Gfo_invk Cmd_sync() {return cmd_sync;} private Gfo_invk cmd_sync;
public Gfo_invk Cmd_async() {return cmd_async;} private Gfo_invk cmd_async;
public void Switch_mem(Xog_html_itm comp) {
Xog_tab_itm temp_owner_tab = owner_tab; // NOTE: reparent owner_tab, since owner_tab will be switching its html_itm
this.owner_tab = comp.owner_tab;
comp.owner_tab = temp_owner_tab;
}
public void Html_box_(Gfui_html html_box) {
this.html_box = html_box;
html_box.Html_js_cbks_add("xowa_exec", js_cbk);
Gfo_evt_mgr_.Sub_same(html_box, Gfui_html.Evt_zoom_changed, this);
}
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));}
public String Html_selected_get_active_or_selection() {return Html_extract_text(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_active_or_selection));}
private String Html_extract_text(String v) {
if (v == null) return ""; // NOTE: Selection__get_text_or_href never gets called on blank hdoc, which is what happens for Special:XowaDefaultTab; DATE:2015-07-09
Xoae_page page = owner_tab.Page();
String site = owner_tab.Wiki().Domain_str();
String ttl = String_.new_u8(page.Ttl().Full_db());
return Xoh_href_gui_utl.Html_extract_text(site, ttl, v);
}
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
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
page.Root().Data_htm_(html_src);
}
}
private void Html_src_(Xoae_page page, byte[] html_bry) {
String html_str = String_.new_u8(html_bry);
if (owner_tab.Tab_mgr().Page_load_mode_is_url()) {
Io_url html_url = app.Usere().Fsys_mgr().App_temp_html_dir().GenSubFil_ary(owner_tab.Tab_key(), ".html");
try {html_box.Html_doc_html_load_by_url(html_url, html_str);}
catch (Exception e) {
app.Usr_dlg().Warn_many("", "", "failed to write html to file; writing directly by memory: page=~{0} file=~{1} err=~{2}", page.Url().To_str(), html_url.Raw(), Err_.Message_gplx_full(e));
html_box.Html_doc_html_load_by_mem(html_str);
}
}
else
html_box.Html_doc_html_load_by_mem(html_str);
}
public void Html_swap(Xog_html_itm trg_itm) {
Xog_html_itm src_itm = this;
Gfui_html src_html = html_box;
Gfui_html trg_html = trg_itm.html_box;
Xoh_js_cbk src_js_cbk = js_cbk;
Xoh_js_cbk trg_js_cbk = trg_itm.js_cbk;
src_itm.html_box = trg_html;
trg_itm.html_box = src_html;
src_itm.js_cbk = trg_js_cbk;
trg_itm.js_cbk = src_js_cbk;
}
public byte[] Get_elem_value_for_edit_box_as_bry() {return Bry_.new_u8(this.Get_elem_value_for_edit_box());}
public String Get_elem_value_for_edit_box() {return Html_elem_atr_get_str(Elem_id__xowa_edit_data_box, Gfui_html.Atr_value);}
public String Get_elem_value(String elem_id) {return Html_elem_atr_get_str(elem_id, Gfui_html.Atr_value);}
public void Html_img_update(String elem_id, String elem_src, int elem_width, int elem_height) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_img_update).Add("elem_id", elem_id).Add("elem_src", elem_src).Add("elem_width", elem_width).Add("elem_height", elem_height);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_img_update, m);
}
public void Html_elem_delete(String elem_id) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_delete).Add("elem_id", elem_id);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_elem_delete, m);
}
@gplx.Virtual public String Html_elem_atr_get_str(String id, String atr_key) {return html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__atr_get_as_obj, id, atr_key);}
@gplx.Virtual public boolean Html_elem_atr_get_bool(String id, String atr_key) {return Bool_.Parse(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__atr_get_to_str, id, atr_key));}
public void Html_atr_set(String elem_id, String atr_key, String atr_val) {
synchronized (thread_lock) { // needed for Special:Search and async cancel; DATE:2015-05-02
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_atr_set).Add("elem_id", elem_id).Add("atr_key", atr_key).Add("atr_val", atr_val);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_elem_atr_set, m);
}
}
public void Html_redlink(String html_uid) {Html_doc_atr_append_or_set(html_uid, "class", gplx.xowa.wikis.pages.lnkis.Xoh_redlink_utl.New_str);}
private void Html_doc_atr_append_or_set(String elem_id, String atr_key, String atr_val) {
GfoMsg m = GfoMsg_.new_cast_(Invk_html_doc_atr_append_or_set).Add("elem_id", elem_id).Add("atr_key", atr_key).Add("atr_val", atr_val);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_doc_atr_append_or_set, m);
}
public void Html_elem_replace_html(String id, String html) {
synchronized (thread_lock) { // needed for Special:Search and async; DATE:2015-04-23
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_replace_html).Add("id", id).Add("html", html);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_elem_replace_html, m);
}
}
public void Html_elem_append_above(String id, String html) {
synchronized (thread_lock) { // needed for Special:Search and async; DATE:2015-04-23
GfoMsg m = GfoMsg_.new_cast_(Invk_html_elem_append_above).Add("id", id).Add("html", html);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_elem_append_above, m);
}
}
public void Html_gallery_packed_exec() {
if (!String_.Eq(owner_tab.Tab_key(), owner_tab.Tab_mgr().Active_tab().Tab_key())) return; // do not exec unless active;
GfoMsg m = GfoMsg_.new_cast_(Invk_html_gallery_packed_exec);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_gallery_packed_exec, m);
module_packed_done = true;
}
public void Html_popups_bind_hover_to_doc() {
if (!String_.Eq(owner_tab.Tab_key(), owner_tab.Tab_mgr().Active_tab().Tab_key())) return; // do not exec unless active;
GfoMsg m = GfoMsg_.new_cast_(Invk_html_popups_bind_hover_to_doc);
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_popups_bind_hover_to_doc, m);
module_popups_done = true;
}
private boolean module_packed_done = false, module_popups_done = false;
public void Tab_selected(Xoae_page page) {
Xoh_head_mgr module_mgr = page.Html_data().Head_mgr();
if (module_mgr.Itm__gallery().Enabled() && !module_packed_done)
this.Html_gallery_packed_exec();
if (module_mgr.Itm__popups().Enabled() && !module_popups_done)
this.Html_popups_bind_hover_to_doc();
}
public void Scroll_page_by_bmk_gui() {Gfo_invk_.Invk_by_key(cmd_async, Invk_scroll_page_by_bmk);}
private void Scroll_page_by_bmk() {
if (!String_.Eq(owner_tab.Tab_key(), owner_tab.Tab_mgr().Active_tab().Tab_key())) return; // only set html page position on active tab; otherwise, page "scrolls down" mysteriously on unseen tab; DATE:2014-05-02
String html_doc_pos = owner_tab.Page().Html_data().Bmk_pos();
if (html_doc_pos == null) {
String auto_focus_id = app.Gui_mgr().Html_mgr().Auto_focus_id();
if (String_.Len_eq_0(auto_focus_id)) return; // don't focus anything
if (String_.Eq(auto_focus_id, " first_anchor")) // NOTE: HTML 4/5 do not allow space as id; XOWA using space here to create a unique_key that will never collide with any id
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Win__focus_body); // NOTE: will focus body if content-editable, else first_anchor
else
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__elem_focus, auto_focus_id);
}
else if (String_.Eq(html_doc_pos, gplx.xowa.guis.history.Xog_history_itm.Html_doc_pos_toc)) // NOTE: special case to handle TOC clicks; DATE:2013-07-17
Scroll_page_by_id("toc");
else {
Html_window_vpos_parse(html_doc_pos, scroll_top, node_path);
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Win__vpos_set, node_path.Val(), scroll_top.Val());
}
}
public void Scroll_page_by_id_gui(String id) {Gfo_invk_.Invk_by_val(cmd_async, Invk_scroll_page_by_id, id);}
private boolean Scroll_page_by_id(String id) {
return (id == null)
? false
: html_box.Html_js_eval_proc_as_bool(Xog_js_procs.Win__scroll_elem_into_view, gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode_str(id));
}
public void Js_enabled_(boolean v) {
html_box.Html_js_enabled_(v);
}
private void When_menu_detected() {
Xoa_gui_mgr gui_mgr = app.Gui_mgr(); Gfui_kit kit = gui_mgr.Kit();
Xog_popup_mnu_mgr popup_mnu_mgr = gui_mgr.Menu_mgr().Popup();
Xog_mnu_grp popup_mnu = popup_mnu_mgr.Html_page();
if (String_.Len_gt_0(this.Html_selected_get_src_or_empty()))
popup_mnu = popup_mnu_mgr.Html_file();
else if (String_.Len_gt_0(this.Html_selected_get_text_or_href()))
popup_mnu = popup_mnu_mgr.Html_link();
kit.Set_mnu_popup(html_box, popup_mnu.Under_mnu());
}
private void When_zoom_changed(boolean clicks_is_positive) {
app.Api_root().Gui().Font().Adj(clicks_is_positive ? 1 : -1);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_html_img_update)) html_box.Html_js_eval_proc_as_bool (Xog_js_procs.Doc__elem_img_update , m.ReadStr("elem_id"), m.ReadStr("elem_src"), m.ReadInt("elem_width"), m.ReadInt("elem_height"));
else if (ctx.Match(k, Invk_html_elem_atr_set)) html_box.Html_js_eval_proc_as_str (Xog_js_procs.Doc__atr_set , m.ReadStr("elem_id"), m.ReadStr("atr_key"), m.ReadStr("atr_val"));
else if (ctx.Match(k, Invk_html_doc_atr_append_or_set)) html_box.Html_js_eval_proc_as_str (Xog_js_procs.Doc__atr_append_or_set , m.ReadStr("elem_id"), m.ReadStr("atr_key"), m.ReadStr("atr_val"));
else if (ctx.Match(k, Invk_html_elem_delete)) html_box.Html_js_eval_proc_as_bool (Xog_js_procs.Doc__elem_delete , m.ReadStr("elem_id"));
else if (ctx.Match(k, Invk_html_elem_replace_html)) html_box.Html_js_eval_proc_as_str (Xog_js_procs.Doc__elem_replace_html , m.ReadStr("id"), m.ReadStr("html"));
else if (ctx.Match(k, Invk_html_elem_append_above)) html_box.Html_js_eval_proc_as_str (Xog_js_procs.Doc__elem_append_above , m.ReadStr("id"), m.ReadStr("html"));
else if (ctx.Match(k, Invk_html_gallery_packed_exec)) html_box.Html_js_eval_proc_as_str (Xog_js_procs.Xtn__gallery_packed_exec);
else if (ctx.Match(k, Invk_html_popups_bind_hover_to_doc)) html_box.Html_js_eval_script("xowa_popups_bind_doc();");
else if (ctx.Match(k, Invk_scroll_page_by_bmk)) Scroll_page_by_bmk();
else if (ctx.Match(k, Invk_scroll_page_by_id)) Scroll_page_by_id(m.ReadStr("v"));
else if (ctx.Match(k, Invk_html_elem_focus)) html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__elem_focus, m.ReadStr("v"));
else if (ctx.Match(k, GfuiElemKeys.Evt_menu_detected)) When_menu_detected();
else if (ctx.Match(k, Gfui_html.Evt_zoom_changed)) When_zoom_changed(m.ReadBool("clicks_is_positive"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_html_gallery_packed_exec = "html_gallery_packed_exec", Invk_html_popups_bind_hover_to_doc = "html_popups_bind_hover_to_doc"
, Invk_html_img_update = "html_img_update", Invk_html_elem_atr_set = "html_elem_atr_set"
, Invk_html_doc_atr_append_or_set = "html_doc_atr_append_or_set", Invk_html_elem_delete = "html_elem_delete", Invk_html_elem_replace_html = "html_elem_replace_html", Invk_html_elem_append_above = "html_elem_append_above"
, Invk_scroll_page_by_bmk = "scroll_page_by_bmk", Invk_scroll_page_by_id = "scroll_page_by_id"
;
public static final String
Elem_id__xowa_edit_data_box = "xowa_edit_data_box"
, Elem_id__xowa_edit_rename_box = "xowa_edit_rename_box"
, Elem_id__first_heading = "firstHeading"
, Invk_html_elem_focus = "html_elem_focus"
;
public static void Html_window_vpos_parse(String v, String_obj_ref scroll_top, String_obj_ref node_path) {
int pipe_pos = String_.FindFwd(v, "|"); if (pipe_pos == String_.Find_none) return; // if elem_get_path returns invalid value, don't fail; DATE:2014-04-05
scroll_top.Val_(String_.Mid(v, 0, pipe_pos));
String node_path_val = String_.Mid(v, pipe_pos + 1, String_.Len(v));
node_path_val = "'" + String_.Replace(node_path_val, ",", "','") + "'";
node_path.Val_(node_path_val);
}
}

View File

@@ -1,46 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Xog_js_procs {
public static final String
Win__focus_body = "xowa.js.win.focus_body"
, Win__vpos_get = "xowa.js.win.vpos_get"
, Win__vpos_set = "xowa.js.win.vpos_set"
, Win__find_in_hdoc = "xowa.js.win.find_in_hdoc"
, Win__find_in_textarea = "xowa.js.win.find_in_textarea"
, Win__scroll_elem_into_view = "xowa.js.win.scroll_elem_into_view"
, Win__print_preview = "xowa.js.win.print_preview"
, Doc__root_html_get = "xowa.js.doc.root_html_get"
, Doc__atr_get_as_obj = "xowa.js.doc.atr_get_as_obj"
, Doc__atr_get_to_str = "xowa.js.doc.atr_get_to_str"
, Doc__atr_set = "xowa.js.doc.atr_set"
, Doc__atr_append_or_set = "xowa.js.doc.atr_append_or_set"
, Doc__elem_focus = "xowa.js.doc.elem_focus"
, Doc__elem_delete = "xowa.js.doc.elem_delete"
, Doc__elem_append_above = "xowa.js.doc.elem_append_above"
, Doc__elem_replace_html = "xowa.js.doc.elem_replace_html"
, Doc__elem_img_update = "xowa.js.doc.elem_img_update"
, Selection__get_text_or_href = "xowa.js.selection.get_text_or_href"
, Selection__get_href_or_text = "xowa.js.selection.get_href_or_text"
, Selection__get_active_or_selection = "xowa.js.selection.get_active_or_selection"
, Selection__get_src_or_empty = "xowa.js.selection.get_src_or_empty"
, Selection__get_active_for_editable_mode = "xowa.js.selection.get_active_for_editable_mode"
, Selection__toggle_focus_for_anchor = "xowa.js.selection.toggle_focus_for_anchor"
, Xtn__gallery_packed_exec = "xowa.js.xtn.gallery_packed_exec"
;
}

View File

@@ -1,102 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.xowa.apps.urls.*;
class Xog_launcher_tabs {
public void Launch(Xog_win_itm win) {
Xoae_app app = win.App(); Gfo_log_bfr log_bfr = app.Log_bfr();
log_bfr.Add("app.launch.page.bgn");
Io_fil_marker fil_marker = new Io_fil_marker().Usr_dlg_(app.Usr_dlg()).Url_(app.Usere().Fsys_mgr().App_temp_dir().GenSubFil_nest("session", "launch.tabs.marker"));
boolean tabs_restored = false;
Xowe_wiki home_wiki = app.Usere().Wiki();
if (fil_marker.Bgn())
tabs_restored = Restore_tabs(app, home_wiki, win, fil_marker);
if (!tabs_restored)
Restore_tab_failover(app, home_wiki, win);
// tab.Html_itm().Html_box().Focus(); // focus the html_box so wheel scroll works; DATE:2013-02-08
app.Usr_dlg().Prog_none("", "", "");
log_bfr.Add("app.launch.page.end");
app.Usr_dlg().Log_wkr().Log_to_session_direct(log_bfr.Xto_str());
}
private boolean Restore_tabs(Xoae_app app, Xowe_wiki home_wiki, Xog_win_itm win, Io_fil_marker fil_marker) {
Xog_startup_tabs startup_tabs = new Xog_startup_tabs().Init_by_app(app).Calc();
String[] launch_urls = startup_tabs.Startup_urls();
try {
int launch_urls_len = launch_urls.length;
for (int i = 0; i < launch_urls_len; ++i) {
String launch_url = launch_urls[i];
Launch_tab(win, home_wiki, launch_url);
}
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_select_by_idx(startup_tabs.Startup_idx());
fil_marker.End();
return true;
}
catch (Exception e) {
app.Usr_dlg().Warn_many("", "", "failed to launch urls: urls=~{0} err=~{1}", String_.AryXtoStr(launch_urls), Err_.Message_gplx_full(e));
Restore_tab_failover(app, home_wiki, win);
return false;
}
}
private void Restore_tab_failover(Xoae_app app, Xowe_wiki home_wiki, Xog_win_itm win) {
try {Launch_tab(win, home_wiki, Xog_startup_tabs.Url__home_main);}
catch (Exception e) {app.Usr_dlg().Warn_many("", "", "failed to launch failover tab: err=~{0}", Err_.Message_gplx_full(e));}
}
private void Launch_tab(Xog_win_itm win, Xowe_wiki home_wiki, String launch_str) {
Xoae_app app = win.App();
Xoa_url launch_url = home_wiki.Utl__url_parser().Parse_by_urlbar_or_null(launch_str); if (launch_url == null) return;
Xowe_wiki launch_wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_or_make_init_y(launch_url.Wiki_bry());
Xoa_ttl launch_ttl = Xoa_ttl.Parse(launch_wiki, launch_url.Page_bry());
Xog_tab_itm tab = win.Tab_mgr().Tabs_new_init(launch_wiki, Xoae_page.New(launch_wiki, launch_ttl)); // WORKAROUND: set the tab to an empty page, else null ref later; DATE:2014-07-23
tab.Show_url_bgn(launch_url);
}
public static final Xog_launcher_tabs Instance = new Xog_launcher_tabs(); Xog_launcher_tabs() {}
}
class Io_fil_marker {
private Io_url url;
private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
public Io_fil_marker Usr_dlg_(Gfo_usr_dlg v) {this.usr_dlg = v; return this;}
public Io_fil_marker Url_(Io_url url) {this.url = url; return this;}
public boolean Bgn() {
boolean rv = false;
synchronized (this) {
try {
rv = !Io_mgr.Instance.ExistsFil(url); // exists = fail; !exists = pass;
if (rv) // pass: file does not exist;
Io_mgr.Instance.SaveFilStr(url, ""); // create
else // file exists from previous run
Io_mgr.Instance.DeleteFil(url); // delete
}
catch (Exception exc) { // something unexpected happened
usr_dlg.Warn_many("", "", "marker.bgn failed: url=~{0} err=~{1}", url.Raw(), Err_.Message_gplx_full(exc));
Io_mgr.Instance.DeleteFil(url); // try to delete it again
}
}
return rv;
}
public void End() {
synchronized (this) {
try {
Io_mgr.Instance.DeleteFil(url); // delete
}
catch (Exception exc) {
usr_dlg.Warn_many("", "", "marker.end failed: url=~{0} err=~{1}", url.Raw(), Err_.Message_gplx_full(exc));
Io_mgr.Instance.DeleteFil(url); // try to delete it again
}
}
}
}

View File

@@ -1,110 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; import gplx.xowa.guis.views.*;
public class Xog_layout implements Gfo_invk {
public Xog_layout() {
go_bwd_btn.Owner_(this);
go_fwd_btn.Owner_(this);
url_box.Owner_(this);
url_exec_btn.Owner_(this);
find_close_btn.Owner_(this);
search_box.Owner_(this);
search_exec_btn.Owner_(this);
html_box.Owner_(this);
find_box.Owner_(this);
prog_box.Owner_(this);
note_box.Owner_(this);
main_win.Owner_(this);
}
public Xog_layout_box Go_fwd_btn() {return go_fwd_btn;} private Xog_layout_box go_fwd_btn = new Xog_layout_box();
public Xog_layout_box Go_bwd_btn() {return go_bwd_btn;} private Xog_layout_box go_bwd_btn = new Xog_layout_box();
public Xog_layout_box Url_box() {return url_box;} private Xog_layout_box url_box = new Xog_layout_box();
public Xog_layout_box Url_exec_btn() {return url_exec_btn;} private Xog_layout_box url_exec_btn = new Xog_layout_box();
public Xog_layout_box Find_close_btn() {return find_close_btn;} private Xog_layout_box find_close_btn = new Xog_layout_box();
public Xog_layout_box Search_box() {return search_box;} private Xog_layout_box search_box = new Xog_layout_box();
public Xog_layout_box Search_exec_btn() {return search_exec_btn;} private Xog_layout_box search_exec_btn = new Xog_layout_box();
public Xog_layout_box Html_box() {return html_box;} private Xog_layout_box html_box = new Xog_layout_box();
public Xog_layout_box Find_box() {return find_box;} private Xog_layout_box find_box = new Xog_layout_box();
public Xog_layout_box Find_fwd_btn() {return find_fwd_btn;} private Xog_layout_box find_fwd_btn = new Xog_layout_box();
public Xog_layout_box Find_bwd_btn() {return find_bwd_btn;} private Xog_layout_box find_bwd_btn = new Xog_layout_box();
public Xog_layout_box Prog_box() {return prog_box;} private Xog_layout_box prog_box = new Xog_layout_box();
public Xog_layout_box Note_box() {return note_box;} private Xog_layout_box note_box = new Xog_layout_box();
public Xog_layout_box Browser_win() {return main_win;} private Xog_layout_box main_win = new Xog_layout_box();
public void Find_show() {
Visible_(true, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
GfuiTextBox find_box = win.Find_box();
find_box.Focus();
int text_len = String_.Len(find_box.Text());
if (text_len > 0) { // if text exists, select it; GUI:Firefox
find_box.SelBgn_set(0);
find_box.SelLen_set(text_len);
}
}
public void Find_close() {
Visible_(false, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
win.Active_html_box().Focus();
}
private void Visible_(boolean v, GfuiElem... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++)
ary[i].Visible_set(v);
}
public void Init(Xog_win_itm win) {
this.win = win;
go_bwd_btn.Adj_text(win.Go_bwd_btn());
go_fwd_btn.Adj_text(win.Go_fwd_btn());
url_box.Adj_text(win.Url_box());
url_exec_btn.Adj_text(win.Url_exec_btn());
find_close_btn.Adj_text(win.Find_close_btn());
search_box.Adj_text(win.Search_box());
search_exec_btn.Adj_text(win.Search_exec_btn());
find_box.Adj_text(win.Find_box());
find_fwd_btn.Adj_text(win.Find_fwd_btn());
find_bwd_btn.Adj_text(win.Find_bwd_btn());
prog_box.Adj_text(win.Prog_box());
note_box.Adj_text(win.Info_box());
win.Tab_mgr().Tab_mgr().TextMgr().Font_(win.Url_box().TextMgr().Font());
Visible_(false, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
} private Xog_win_itm win;
public int Box_height_calc(Gfui_kit kit, GfuiElem url_box) {
if (box_height > 0) return box_height;
float font_height = kit.Calc_font_height(url_box, "I");
box_height = (int)(font_height * 2);
return box_height;
} private int box_height = 0;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_go_fwd_btn)) return go_fwd_btn;
else if (ctx.Match(k, Invk_go_bwd_btn)) return go_bwd_btn;
else if (ctx.Match(k, Invk_url_box)) return url_box;
else if (ctx.Match(k, Invk_url_exec_btn)) return url_exec_btn;
else if (ctx.Match(k, Invk_find_close_btn)) return find_close_btn;
else if (ctx.Match(k, Invk_search_box)) return search_box;
else if (ctx.Match(k, Invk_search_exec_btn)) return search_exec_btn;
else if (ctx.Match(k, Invk_html_box)) return html_box;
else if (ctx.Match(k, Invk_find_box)) return find_box;
else if (ctx.Match(k, Invk_find_fwd_btn)) return find_fwd_btn;
else if (ctx.Match(k, Invk_find_bwd_btn)) return find_bwd_btn;
else if (ctx.Match(k, Invk_prog_box)) return prog_box;
else if (ctx.Match(k, Invk_note_box)) return note_box;
else if (ctx.Match(k, Invk_main_win)) return main_win;
else return Gfo_invk_.Rv_unhandled;
}
static final String Invk_coord_mode_ = "coord_mode_", Invk_go_fwd_btn = "go_fwd_btn", Invk_go_bwd_btn = "go_bwd_btn", Invk_url_box = "url_box", Invk_search_box = "search_box", Invk_html_box = "html_box", Invk_find_box = "find_box", Invk_prog_box = "prog_box", Invk_note_box = "note_box"
, Invk_main_win = "main_win", Invk_find_fwd_btn = "find_fwd_btn", Invk_find_bwd_btn = "find_bwd_btn", Invk_url_exec_btn = "url_exec_btn", Invk_search_exec_btn = "search_exec_btn", Invk_find_close_btn = "find_close_btn";
}

View File

@@ -1,83 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.draws.*; import gplx.gfui.controls.elems.*;
public class Xog_layout_box implements Gfo_invk {
public Gfo_invk Owner() {return owner;} public Xog_layout_box Owner_(Gfo_invk v) {owner = v; return this;} Gfo_invk owner;
public int X_abs() {return x_abs;} private int x_abs = Int_.Min_value;
public int Y_abs() {return y_abs;} private int y_abs = Int_.Min_value;
public int W_abs() {return w_abs;} private int w_abs = Int_.Min_value;
public int H_abs() {return h_abs;} private int h_abs = Int_.Min_value;
private int x_rel = Int_.Min_value;
private int y_rel = Int_.Min_value;
public Xog_layout_box W_rel_(int v) {w_rel = v; return this;} private int w_rel = Int_.Min_value;
public Xog_layout_box H_rel_(int v) {h_rel = v; return this;} private int h_rel = Int_.Min_value;
private String text;
private String font_name;
private float font_size = Float_.NaN;
private FontStyleAdp font_style;
public byte Mode() {return mode;} private byte mode = Mode_rel;
public void Adj_size(Rect_ref rect) {
if (w_abs > -1) rect.W_(w_abs); if (w_rel != Int_.Min_value) rect.W_(w_rel + rect.W());
if (h_abs > -1) rect.H_(h_abs); if (h_rel != Int_.Min_value) rect.H_(h_rel + rect.H());
}
public void Adj_pos(Rect_ref rect) {
if (x_abs > -1) rect.X_(x_abs); if (x_rel != Int_.Min_value) rect.X_(x_rel + rect.X());
if (y_abs > -1) rect.Y_(y_abs); if (y_rel != Int_.Min_value) rect.Y_(y_rel + rect.Y());
}
public void Adj_text(GfuiElem elem) {
if (text != null) elem.Text_(text);
if (font_name != null || !Float_.IsNaN(font_size) || font_style != null)
elem.TextMgr().Font_(Font_make(font_name, font_size, font_style));
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_x_abs_)) x_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_y_abs_)) y_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_w_abs_)) w_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_h_abs_)) h_abs = m.ReadInt("v");
else if (ctx.Match(k, Invk_x_rel_)) x_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_y_rel_)) y_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_w_rel_)) w_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_h_rel_)) h_rel = m.ReadInt("v");
else if (ctx.Match(k, Invk_size_abs_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {w_abs = ary[0]; h_abs = ary[1];}}
else if (ctx.Match(k, Invk_size_rel_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {w_rel = ary[0]; h_rel = ary[1];}}
else if (ctx.Match(k, Invk_pos_abs_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {x_abs = ary[0]; y_abs = ary[1];}}
else if (ctx.Match(k, Invk_pos_rel_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 2, null); if (ary != null) {x_rel = ary[0]; y_rel = ary[1];}}
else if (ctx.Match(k, Invk_rect_abs_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 4, null); if (ary != null) {w_abs = ary[0]; h_abs = ary[1]; x_abs = ary[2]; y_abs = ary[3];}}
else if (ctx.Match(k, Invk_rect_rel_)) {int[] ary = Int_.Ary_parse(m.ReadStr("v"), 4, null); if (ary != null) {w_rel = ary[0]; h_rel = ary[1]; x_rel = ary[2]; y_rel = ary[3];}}
else if (ctx.Match(k, Invk_text_)) text = m.ReadStr("v");
else if (ctx.Match(k, Invk_font_name_)) font_name = m.ReadStr("v");
else if (ctx.Match(k, Invk_font_size_)) font_size = m.ReadFloat("v");
else if (ctx.Match(k, Invk_font_style_)) font_style = FontStyleAdp_.parse(m.ReadStr("v"));
else if (ctx.Match(k, Invk_mode_)) mode = String_.Eq(m.ReadStr("v"), "abs") ? Mode_abs : Mode_rel;
else if (ctx.Match(k, Invk_owner)) return owner;
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final byte Mode_abs = 0, Mode_rel = 1;
private static final String Invk_x_abs_ = "x_abs_", Invk_y_abs_ = "y_abs_", Invk_w_abs_ = "w_abs_", Invk_h_abs_ = "h_abs_", Invk_x_rel_ = "x_rel_", Invk_y_rel_ = "y_rel_", Invk_w_rel_ = "w_rel_", Invk_h_rel_ = "h_rel_"
, Invk_size_abs_ = "size_abs_", Invk_pos_abs_ = "pos_abs_", Invk_rect_abs_ = "rect_abs_", Invk_size_rel_ = "size_rel_", Invk_pos_rel_ = "pos_rel_", Invk_rect_rel_ = "rect_rel_"
, Invk_text_ = "text_"
, Invk_font_name_ = "font_name_", Invk_font_size_ = "font_size_", Invk_font_style_ = "font_style_", Invk_mode_ = "mode_", Invk_owner = "owner";
private static FontAdp Font_make(String font_name, float font_size, FontStyleAdp font_style) {
String new_font_name = font_name == null ? "Arial" : font_name;
float new_font_size = Float_.IsNaN(font_size) ? 8 : font_size;
FontStyleAdp new_font_style = font_style == null ? FontStyleAdp_.Plain : font_style;
return FontAdp.new_(new_font_name, new_font_size, new_font_style);
}
}

View File

@@ -1,123 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.updates.specials.*;
public class Xog_startup_tabs {
private String type, custom_list, prev_list, prev_version, curr_version;
private boolean show_app_update;
public int Startup_idx() {return startup_idx;} private int startup_idx;
public String[] Startup_urls() {return startup_urls;} private String[] startup_urls = String_.Ary_empty;
public Xog_startup_tabs Init_by_app(Xoae_app app) {
Xocfg_mgr cfg = app.Cfg();
this.type = cfg.Get_str_app_or(Cfg__startup_type, Opt__startup_type__previous);
this.custom_list = cfg.Get_str_app_or(Cfg__custom_list, "");
this.prev_list = cfg.Get_str_app_or(Cfg__prev_list, "");
this.prev_version = cfg.Get_str_app_or(Cfg__prev_version, "");
this.curr_version = Xoa_app_.Version;
this.startup_idx = cfg.Get_int_app_or(Cfg__prev_selected, -1);
this.show_app_update = gplx.xowa.addons.apps.updates.Xoa_update_startup.Show_at_startup(app);
return this;
}
public Xog_startup_tabs Calc() {
List_adp list = List_adp_.New(); // NOTE: do not change to hash; duplicate urls are possible
// process main types
if (Manual == null) {
if (String_.Eq(type, "blank")) list.Add(gplx.xowa.specials.Xow_special_meta_.Itm__default_tab.Ttl_str());
else if (String_.Eq(type, "xowa")) list.Add(Url__home_main);
else if (String_.Eq(type, "custom")) Parse_ary(list, custom_list);
else if (String_.Eq(type, Opt__startup_type__previous)) Parse_ary(list, prev_list);
else throw Err_.new_unhandled(type);
}
else
list.Add(Manual);
// if new version, add home/wiki/Main_Page
if (gplx.xowa.apps.versions.Xoa_version_.Compare(prev_version, curr_version) == CompareAble_.Less) {
startup_idx = Add_if_absent(list, Url__home_main);
}
// if show_app_update, add page
if (show_app_update) {
startup_idx = Add_if_absent(list, Xoa_update_special.Prototype.Special__meta().Url__home());
}
// generate urls
startup_urls = (String[])list.To_ary_and_clear(String.class);
// do bounds check
if (startup_idx < 0 || startup_idx >= startup_urls.length)
startup_idx = startup_urls.length - 1;
return this;
}
private static int Add_if_absent(List_adp list, String page) {
// check list for page
int len = list.Len();
for (int i = 0; i < len; i++) {
String itm = (String)list.Get_at(i);
// page found; return its index
if (String_.Eq(itm, page)) {
return i;
}
}
// add if not found
list.Add(page);
return list.Len();
}
private static void Parse_ary(List_adp list, String s) {
if (String_.Len_eq_0(s)) return;
String[] ary = String_.SplitLines_nl(String_.Trim(s));
int len = ary.length;
for (int i = 0; i < len; i++) {
String itm = ary[i];
if (String_.Len_eq_0(itm)) continue;
list.Add(itm);
}
}
public static String Version_previous(Xoa_app app) {return app.Cfg().Get_str_app_or(Cfg__prev_version, "");}
public static void Shutdown(Xoae_app app) {
app.Cfg().Set_str_app(Cfg__prev_version, Xoa_app_.Version);
if (String_.Eq(app.Cfg().Get_str_app_or(Cfg__startup_type, Opt__startup_type__previous), Opt__startup_type__previous)) {
app.Cfg().Set_str_app(Cfg__prev_list , Calc_previous_tabs(app.Gui_mgr().Browser_win().Tab_mgr()));
app.Cfg().Set_int_app(Cfg__prev_selected, app.Gui_mgr().Browser_win().Tab_mgr().Active_tab().Tab_idx());
}
}
private static String Calc_previous_tabs(gplx.xowa.guis.views.Xog_tab_mgr tab_mgr) {
Bry_bfr bfr = Bry_bfr_.New();
int len = tab_mgr.Tabs_len();
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte_nl();
gplx.xowa.guis.views.Xog_tab_itm tab = tab_mgr.Tabs_get_at(i);
bfr.Add_str_u8(tab.Page().Url().To_str());
}
return bfr.To_str_and_clear();
}
public static String Manual = null; // note set by command-line at startup;
private static final String
Cfg__startup_type = "xowa.app.startup.tabs.type"
, Cfg__custom_list = "xowa.app.startup.tabs.custom"
, Cfg__prev_list = "xowa.app.startup.tabs.previous_list"
, Cfg__prev_selected = "xowa.app.startup.tabs.previous_selected"
, Cfg__prev_version = "xowa.app.setup.previous_version"
, Opt__startup_type__previous = "previous";
public static final String
Url__home_main = "home/wiki/Main_Page"
;
}

View File

@@ -1,109 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.envs.*;
import gplx.gfui.*; import gplx.gfui.envs.*; import gplx.gfui.controls.windows.*;
public class Xog_startup_win_ {
public static void Startup(Xoa_app app, GfuiWin win) {
gplx.xowa.addons.apps.cfgs.Xocfg_mgr cfg_mgr = app.Cfg();
String window_mode = cfg_mgr.Get_str_app_or(Cfg__window_mode, "previous");
Rect_ref manual_rect = Rect_ref.parse(cfg_mgr.Get_str_app_or(Cfg__manual_rect, "0,0,800,640"));
// change win_rect per mode: previous; absolute; etc.
boolean init_is_maximized = false;
if (String_.Eq(window_mode, "previous")) {
if (cfg_mgr.Get_bool_app_or(Cfg__prev_maximized, false)) {
win.Maximized_(true);
init_is_maximized = true;
}
else {
Rect_ref previous_rect = null;
String s = cfg_mgr.Get_str_app_or(Cfg__prev_rect, "");
if (String_.Eq(s, "")) {
SizeAdp size = Screen_maximized_calc();
previous_rect = new Rect_ref(0, 0, size.Width(), size.Height());
}
else
previous_rect = Rect_ref.parse(s);
win.Rect_set(previous_rect.XtoRectAdp());
}
}
else if (String_.Eq(window_mode, "absolute")) {
win.Rect_set(manual_rect.XtoRectAdp());
}
else if (String_.Eq(window_mode, "maximized")) {
win.Maximized_(true);
init_is_maximized = true;
}
else if (String_.Eq(window_mode, "default")) {} // noop
else if (String_.Eq(window_mode, "relative")) {
SizeAdp screen_maximized = Screen_maximized_calc();
Rect_ref win_rect = new Rect_ref(0, 0, screen_maximized.Width(), screen_maximized.Height());
win.Rect_set(win_rect.XtoRectAdp_add(manual_rect));
}
// make sure win_rect is safe
boolean safe_mode = cfg_mgr.Get_bool_app_or(Cfg__manual_safe, true);
if (safe_mode && !init_is_maximized) {
RectAdp rect = win.Rect();
boolean force = false; int x = rect.X(), y = rect.Y(), w = rect.Width(), h = rect.Height();
SizeAdp screen_size = Screen_maximized_calc();
int max_w = screen_size.Width(), max_h = screen_size.Height();
int Safe_mode_buffer = 20; // allow minor negative positioning (x=-5), off-screen positioning (w=1605)
if (x < -Safe_mode_buffer || x > max_w + Safe_mode_buffer) {force = true; x = 0;}
if (y < -Safe_mode_buffer || y > max_h + Safe_mode_buffer) {force = true; y = 0;}
if (w < Safe_mode_buffer || x + w > max_w + Safe_mode_buffer) {force = true; w = max_w - x;}
if (h < Safe_mode_buffer || y + h > max_h + Safe_mode_buffer) {force = true; h = max_h - y;}
if (force)
win.Rect_set(RectAdp_.new_(x, y, w, h));
}
}
public static void Shutdown(Xoae_app app, GfuiWin win) {
gplx.xowa.addons.apps.cfgs.Xocfg_mgr cfg_mgr = app.Cfg();
if (String_.Eq(cfg_mgr.Get_str_app_or(Cfg__window_mode, "previous"), "previous")) {
cfg_mgr.Set_str_app(Cfg__prev_rect , win.Rect().Xto_str());
cfg_mgr.Set_str_app(Cfg__prev_maximized , Yn.To_str(win.Maximized()));
}
Xog_startup_tabs.Shutdown(app);
}
public static SizeAdp Screen_maximized_calc() {
Op_sys os = Op_sys.Cur();
SizeAdp screen = ScreenAdp_.screen_(0).Size();
int w = screen.Width();
int h = screen.Height() - 30; // -20=application menu bar; -10 for start bar padding
switch (os.Tid()) {
case Op_sys.Tid_wnt:
switch (os.Sub_tid()) {
case Op_sys.Sub_tid_win_xp: h += -4; break; // NOOP; will keep values as above
default: break; // for all else, use Windows 7 border (which is thicker); note that Windows 8 is being detected as "Windows NT (unknown)", so need to use default; this may not work with Windows 2000
}
break;
default:
h += -4; // default adjustments since version 0.0.0.0; seems to work on XP and LNX
break;
}
return SizeAdp_.new_(w, h);
}
private static final String
Cfg__window_mode = "xowa.app.startup.window.mode"
, Cfg__manual_rect = "xowa.app.startup.window.manual_rect"
, Cfg__manual_safe = "xowa.app.startup.window.manual_safe"
, Cfg__prev_rect = "xowa.app.startup.window.previous_rect"
, Cfg__prev_maximized = "xowa.app.startup.window.previous_maximized"
;
}

View File

@@ -1,21 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.guis.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public interface Xog_tab_close_lnr {
boolean When_close(Xog_tab_itm tab, Xoa_url url);
}

View File

@@ -1,33 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Xog_tab_close_mgr {
private List_adp list = List_adp_.New();
public void Clear() {list.Clear();}
public void Add(Xog_tab_close_lnr lnr) {list.Add(lnr);}
public int Len() {return list.Count();}
public Xog_tab_close_lnr Get_at(int i) {return (Xog_tab_close_lnr)list.Get_at(i);}
public boolean When_close(Xog_tab_itm tab, Xoa_url url) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Xog_tab_close_lnr lnr = Get_at(i);
if (!lnr.When_close(tab, url)) return false;
}
return true;
}
}

View File

@@ -1,245 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.threads.*; import gplx.core.envs.*;
import gplx.gfui.*; import gplx.gfui.ipts.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.guis.history.*; import gplx.xowa.guis.bnds.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.langs.vnts.*;
import gplx.xowa.parsers.*; import gplx.xowa.wikis.pages.lnkis.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
public class Xog_tab_itm implements Gfo_invk {
private Xog_win_itm win;
public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data, Xowe_wiki wiki, Xoae_page page) {
this.tab_mgr = tab_mgr; this.tab_data = tab_data; this.wiki = wiki; this.page = page;
this.win = tab_mgr.Win();
this.html_itm = new Xog_html_itm(this);
cmd_sync = win.Kit().New_cmd_sync(this);
}
public Xowe_wiki Wiki() {return wiki;} public void Wiki_(Xowe_wiki v) {this.wiki = v;} private Xowe_wiki wiki;
public Gfo_invk Cmd_sync() {return cmd_sync;} private Gfo_invk cmd_sync;
public void Make_html_box(int uid, Gfui_tab_itm tab_box, Xog_win_itm win, GfuiElem owner) {
this.tab_box = tab_box;
Xoae_app app = win.App(); Xoa_gui_mgr gui_mgr = win.Gui_mgr(); Gfui_kit kit = win.Kit();
Gfui_html html_box = kit.New_html("html_box" + Int_.To_str(uid), owner);
html_box.Html_js_enabled_(tab_mgr.Javascript_enabled());
html_box.Html_invk_src_(win);
html_itm.Html_box_(html_box);
if (app.Mode().Tid_is_gui()) { // NOTE: only run for gui; will cause firefox_addon to fail; DATE:2014-05-03
html_box.Html_doc_html_load_by_mem(""); // NOTE: must set source, else control will be empty, and key events will not be raised; DATE:2014-04-30
IptBnd_.ipt_to_(IptCfg_.Null, html_box, this, "popup", IptEventType_.MouseDown, IptMouseBtn_.Right);
IptBnd_.cmd_to_(IptCfg_.Null, html_box, win, Xog_win_itm.Invk_exit, IptKey_.add_(IptKey_.Alt, IptKey_.F4)); // WORKAROUND:SWT: xulrunner_v24 no longer sends Alt+F4 to SwtShell; must manually subscribe it to quit; DATE:2015-07-31
Gfo_evt_mgr_.Sub_same(html_box, GfuiElemKeys.Evt_menu_detected, html_itm);
gui_mgr.Bnd_mgr().Bind(Xog_bnd_box_.Tid_browser_html, html_box);
if (!Env_.Mode_testing())
kit.Set_mnu_popup(html_box, gui_mgr.Menu_mgr().Popup().Html_page().Under_mnu());
}
}
public void Switch_mem(Xog_tab_itm comp) {
html_itm.Switch_mem(comp.html_itm); // switch html_itm.owner_tab reference only
Xog_html_itm temp_html_itm = html_itm; // switch .html_itm, since the underlying CTabFolder has reparented the control
this.html_itm = comp.html_itm;
comp.html_itm = temp_html_itm;
Xoae_page temp_page = page; // switch .page, since its underlying html_box has changed and .page must reflect html_box
this.page = comp.page;
comp.page = temp_page;
page.Tab_data().Tab_(this); comp.Page().Tab_data().Tab_(comp);
byte temp_view_mode = view_mode; // switch .view_mode to match .page
this.view_mode = comp.view_mode;
comp.view_mode = temp_view_mode;
Xog_history_mgr temp_history_mgr = history_mgr; // switch .history_mgr along with .page
this.history_mgr = comp.history_mgr;
comp.history_mgr = temp_history_mgr;
}
public Gfui_tab_itm_data Tab_data() {return tab_data;} private Gfui_tab_itm_data tab_data;
public String Tab_key() {return tab_data.Key();}
public int Tab_idx() {return tab_data.Idx();} public void Tab_idx_(int v) {tab_data.Idx_(v);}
public Xog_tab_mgr Tab_mgr() {return tab_mgr;} private Xog_tab_mgr tab_mgr;
public Gfui_tab_itm Tab_box() {return tab_box;} private Gfui_tab_itm tab_box;
public boolean Tab_is_loading() {return tab_is_loading;} private boolean tab_is_loading;
public Xog_html_itm Html_itm() {return html_itm;} private Xog_html_itm html_itm;
public Gfui_html Html_box() {return html_itm.Html_box();}
public Xoae_page Page() {return page;}
public void Page_ref_(Xoae_page v) {
this.page = v;
this.wiki = page.Wikie(); // NOTE: must update wiki else back doesn't work; DATE:2015-03-05
}
public void Page_(Xoae_page page) {
Page_ref_(page);
this.Page_update_ui(); // force tab button to update when page changes
} private Xoae_page page;
public void Page_update_ui() {
this.Tab_name_();
tab_box.Tab_tip_text_(page.Url().To_str());
}
public void Tab_name_() {
byte[] tab_name = page.Html_data().Custom_tab_name(); // Custom_tab_name set by Special:Default_tab or variants; DATE:2015-10-05
if (tab_name == null) tab_name = page.Ttl().Full_txt_w_ttl_case(); // no custom_tab_name; use ttl's text
Tab_name_(String_.new_u8(tab_name));
}
public void Tab_name_(String tab_name) {
tab_name = Xog_tab_itm_.Tab_name_min(tab_name, tab_mgr.Btns__min_chars());
tab_name = Xog_tab_itm_.Tab_name_max(tab_name, tab_mgr.Btns__max_chars());
tab_box.Tab_name_(tab_name);
}
public Xog_history_mgr History_mgr() {return history_mgr;} private Xog_history_mgr history_mgr = new Xog_history_mgr();
public byte View_mode() {return view_mode;} public Xog_tab_itm View_mode_(byte v) {view_mode = v; return this;} private byte view_mode = Xopg_page_.Tid_read;
public void Pin_toggle() {}
public void Show_url_bgn(Xoa_url url) {
this.tab_is_loading = true;
Xoae_app app = win.App(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
// get new_tab_name
this.wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_or_make_init_y(url.Wiki_bry()); // NOTE: must go before wiki.Props().Main_page(); DATE:2016-08-02; NOTE: must load wiki; DATE:2015-07-22
if (url.Page_is_main()) url.Page_bry_(wiki.Props().Main_page()); // NOTE: must go before ttl.Make; DATE:2016-07-31
Xoa_ttl ttl = wiki.Ttl_parse(url.Page_bry());
if (ttl == null) {usr_dlg.Prog_one("", "", "title is invalid: ~{0}", String_.new_u8(url.Raw())); return;}
String new_tab_name = String_.new_u8(ttl.Full_txt_w_ttl_case());
// if clicking on anchor, just scroll; do not load page
if ( url.Anch_str() != null // url has anchor
&& url.Eq_page(page.Url()) // url has same page_name as existing page
&& url.Qargs_ary().length == 0 // url has no args; needed for Category:A?from=b#mw-pages
&& String_.Eq(new_tab_name, tab_data.Name()) // NOTE: name will be null / empty when starting app and last session had page with #anchor; EX:Main_Page#Links; DATE:2016-07-21
) {
html_itm.Scroll_page_by_id_gui(url.Anch_str());
return;
}
if (win.Page__async__working(url)) return;
if (page != null) page.Tab_data().Close_mgr().When_close(this, url); // cancel any current search cmds
app.Log_wtr().Queue_enabled_(true);
usr_dlg.Gui_wkr().Clear();
if (url.Vnt_bry() != null) {
byte[] vnt = url.Vnt_bry();
if (!Bry_.Eq(vnt, wiki.Lang().Vnt_mgr().Cur_itm().Key()))
wiki.Appe().Cfg().Set_bry_wiki(wiki, Xowe_wiki.Cfg__variant__current, vnt);
}
Tab_name_(new_tab_name);
usr_dlg.Prog_one("", "", "loading: ~{0}", String_.new_u8(ttl.Raw()));
if (wiki.Html_mgr().Head_mgr().Popup_mgr().Enabled())
this.Html_box().Html_js_eval_script("if (window.xowa_popups_hide_all != null) window.xowa_popups_hide_all();"); // should be more configurable; DATE:2014-07-09
app.Thread_mgr_old().Page_load_mgr().Add_at_end(new Load_page_wkr(this, wiki, url, ttl)).Run();
}
private void Show_url_loaded(Load_page_wkr wkr) {
Xowe_wiki wiki = wkr.Wiki(); Xoae_page page = wkr.Page();
Xoa_url url = page.Url(); Xoa_ttl ttl = page.Ttl();
Xoae_app app = wiki.Appe(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
try {
if (page.Tab_data().Cancel_show()) return; // Special:Search canceled show; NOTE: must be inside try b/c finally handles thread
wiki.Parser_mgr().Ctx().Page_(page);
if ( page.Db().Page().Exists_n()
&& !page.Commons_mgr().Xowa_mockup()) { // do not enter "missing" section if File_mockup; EX:en.wikipedia.org/wiki/File:Protoplanetary-disk.jpg DATE:2016-11-13
if (wiki.Db_mgr().Save_mgr().Create_enabled()) {
page = Xoae_page.New_edit(wiki, ttl);
view_mode = Xopg_page_.Tid_edit;
history_mgr.Add(page); // NOTE: must put new_page on stack so that pressing back will pop new_page, not previous page
Xog_tab_itm_read_mgr.Show_page(this, page, false);
}
else {
wkr.Page().Tab_data().Tab().Page_(page); // NOTE: must set tab's page to current page, so that switching to it will update url bar; EX:pt.b:A"MANUAL_DE_PROCEDURI_.Sectiunea:""CONTABILITATE_SI_MANAGEMENT_FINANCIAR""" DATE:2015-09-17
if (page.Redirect_trail().Itms__len() > 0)
usr_dlg.Prog_many("", "", "could not find page in wiki: ~{0} (redirected from ~{1})", String_.new_u8(page.Url().Page_bry()), page.Redirect_trail().Itms__get_at_0th_or_null());
else {
if (ttl.Ns().Id_is_file())
usr_dlg.Prog_one("", "", "commons.wikimedia.org must be installed in order to view the file. See [[App/Wiki_types/Commons]]: ~{0}", String_.new_u8(url.Raw()));// HOME
else
usr_dlg.Prog_one("", "", "could not find page in wiki: ~{0}", String_.new_u8(url.Raw()));
}
}
app.Log_wtr().Queue_enabled_(false);
return;
}
// if (!page.Redirected()) page.Url_(url); // NOTE: handle redirect from commons; COMMENTED: part of redirect rewrite; DATE:2016-07-05
if (page.Ttl().Anch_bgn() != Bry_find_.Not_found) page.Url().Anch_bry_(page.Ttl().Anch_txt()); // NOTE: occurs when page is a redirect to an anchor; EX: w:Duck race -> Rubber duck#Races
history_mgr.Add(page);
Xog_tab_itm_read_mgr.Show_page(this, page, true);
if (app.Usere().History_mgr().Enabled()) {
app.Usere().History_mgr().Add(page);
app.User().User_db_mgr().History_mgr().Update_async(app.Async_mgr(), ttl, url);
}
usr_dlg.Prog_none("", "", "rendering html");
// html_itm.Html_box().Size_(tab_mgr.Tab_mgr().Size()); // COMMENTED: causes clicks on macosx to be off by 4 px; NOTE: must resize tab here, else scrolling to anchor in background tab doesn't work (html_box has size of 0, 0) DATE:2015-05-03
// win.Page__async__bgn(this);
Gfo_thread_wkr async_wkr = null;
if (page.Html_data().Hdump_exists()) {
// wiki.File_mgr().Init_file_mgr_by_load(wiki);
// Xof_fsdb_mgr fsdb_mgr = wiki.File_mgr().Fsdb_mgr();
// async_wkr = new Xof_file_wkr(wiki.File__orig_mgr(), fsdb_mgr.Bin_mgr(), fsdb_mgr.Mnt_mgr(), app.Usere().User_db_mgr().Cache_mgr(), wiki.File__repo_mgr(), html_itm, page, page.Hdump_mgr().Imgs());
async_wkr = new Load_files_wkr(this);
if (wiki.Html__hdump_enabled() && page.Db().Page().Html_db_id() == -1) {
wiki.Html__hdump_mgr().Save_mgr().Save(page);
}
}
else
async_wkr = new Load_files_wkr(this);
page.Html_data().Mode_wtxt_shown_y_();
app.Thread_mgr_old().File_load_mgr().Add_at_end(async_wkr).Run();
// app.Thread_mgr().Get_by_or_new("on_page_load").Add(new Xopg_img_thread(), new Xopg_rl_thread());
}
finally {
app.Thread_mgr_old().Page_load_mgr().Resume();
this.tab_is_loading = false;
}
}
public void Exec_async_hdump(Xoa_app app, Xow_wiki wiki, gplx.xowa.guis.cbks.js.Xog_js_wkr js_wkr, gplx.core.threads.Gfo_thread_pool thread_pool, Xoa_page page, List_adp imgs, int[] redlink_ary) {
if (imgs.Count() > 0) {
Xof_file_wkr file_thread = new Xof_file_wkr
( wiki.File__orig_mgr(), wiki.File__bin_mgr(), wiki.File__mnt_mgr()
, app.User().User_db_mgr().Cache_mgr(), wiki.File__repo_mgr(), html_itm, page, imgs
);
thread_pool.Add_at_end(file_thread); thread_pool.Run();
}
if (redlink_ary.length > 0) {
Xog_redlink_thread redlink_thread = new Xog_redlink_thread(redlink_ary, js_wkr);
thread_pool.Add_at_end(redlink_thread); thread_pool.Run();
}
}
public void Exec_notify(boolean pass, String msg) {
this.Html_box().Html_js_eval_proc_as_str("xowa.cmds.exec_by_str", "xowa.notify", "{\"text\":\"" + msg + "\",\"status\":\"" + (pass ? "success" : "error") + "\"}");
}
@gplx.Internal protected void Show_url_failed(Load_page_wkr wkr) {
try {
Xog_tab_itm_read_mgr.Show_page_err(win, this, wkr.Wiki(), wkr.Url(), wkr.Ttl(), wkr.Exec_err());
} finally {
wkr.Wiki().Appe().Thread_mgr_old().Page_load_mgr().Resume();
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_show_url_loaded_swt)) this.Show_url_loaded((Load_page_wkr)m.ReadObj("v"));
else if (ctx.Match(k, Invk_show_url_failed_swt)) this.Show_url_failed((Load_page_wkr)m.ReadObj("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Invk_show_url_loaded_swt = "show_url_loaded_swt", Invk_show_url_failed_swt = "show_url_failed_swt";
}
class Load_files_wkr implements Gfo_thread_wkr {
private Xog_tab_itm tab;
public Load_files_wkr(Xog_tab_itm tab) {this.tab = tab;}
public String Thread__name() {return "xowa.load_files_wkr";}
public boolean Thread__resume() {return true;}
public void Thread__exec() {
try {Xog_async_wkr.Async(tab);}
catch (Exception e) {
tab.Tab_mgr().Win().App().Usr_dlg().Warn_many("error while running file wkr; page=~{0} err=~{1}", tab.Page().Url().To_str(), Err_.Message_gplx_full(e));
}
}
}

View File

@@ -1,30 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Xog_tab_itm_ {
public static String Tab_name_min(String name, int min) {
int name_len = String_.Len(name);
return min == Tab_name_min_disabled || name_len > min ? name : name + String_.Repeat(" ", min - name_len);
}
public static String Tab_name_max(String name, int max) {
int name_len = String_.Len(name);
return max == Tab_name_max_disabled || name_len <= max ? name : String_.Mid(name, 0, max) + "...";
}
public static final int Tab_name_min_disabled = -1, Tab_name_max_disabled = -1;
public static final Xog_tab_itm Null = null;
}

View File

@@ -1,132 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.controls.standards.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Xog_tab_itm_edit_mgr {
public static void Save(Xog_tab_itm tab, boolean quick_save) {
if (tab.View_mode() != Xopg_page_.Tid_edit) return; // exit if not edit; handles ctrl+s being pressed in read/html modes
Xoae_page page = tab.Page(); Xowe_wiki wiki = tab.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
byte[] new_text = Get_new_text(tab, page.Db().Text().Text_bry());
if (page.Edit_mode() == Xoa_page_.Edit_mode_create) {
int page_id = wiki.Db_mgr().Save_mgr().Data_create(page.Ttl(), new_text);
page.Db().Page().Id_(page_id);
page.Edit_mode_update_(); // set to update so that next save does not try to create
}
else {
wiki.Db_mgr().Save_mgr().Data_update(page, new_text);
}
Invalidate(wiki);
page.Db().Text().Text_bry_(new_text);
wiki.Parser_mgr().Parse(page, true); // refresh html
if (wiki.Html__hdump_enabled()) wiki.Html__hdump_mgr().Save_mgr().Save(page); // must go after wiki.Parse
win_itm.Usr_dlg().Prog_one("", "", "saved page ~{0}", String_.new_u8(page.Ttl().Full_txt_raw())); // NOTE: show message after Parse, b/c Parse will flash "Loading page"; DATE:2014-05-17
if (!quick_save) { // full_save; save page and go to read mode
page.Html_data().Edit_preview_(Bry_.Empty);
Xoae_page stack_page = tab.History_mgr().Cur_page(wiki); // NOTE: must be to CurPage() else changes will be lost when going Bwd,Fwd
stack_page.Db().Text().Text_bry_(page.Db().Text().Text_bry()); // NOTE: overwrite with "saved" changes
stack_page.Wikie().Parser_mgr().Parse(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
page.Url_(Xoa_url.New(tab.Wiki().Domain_bry(), tab.Page().Ttl().Full_db()));
win_itm.Page__mode_(Xopg_page_.Tid_read);
win_itm.Page__async__bgn(tab);
}
// wiki.Db_mgr().Hdump_mgr().Save(page);
}
public static void Preview(Xog_tab_itm tab) {
if (tab.View_mode() != Xopg_page_.Tid_edit) return; // exit if not edit; handles preview somehow being called?
Xoae_page page = tab.Page(); Xowe_wiki wiki = tab.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
Xog_html_itm html_itm = tab.Html_itm();
byte[] new_text = Get_new_text(tab, null);
Xoae_page new_page = Xoae_page.New(wiki, page.Ttl());
new_page.Db().Page().Id_(page.Db().Page().Id()); // NOTE: page_id needed for sqlite (was not needed for xdat)
new_page.Db().Text().Text_bry_(new_text);
wiki.Parser_mgr().Parse(new_page, true); // refresh html
tab.Page_(new_page); new_page.Tab_data().Tab_(tab); // replace old page with new_page; DATE:2014-10-09
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read);
wkr.Write_body(tmp_bfr, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Basic, new_page);
byte[] new_html = tmp_bfr.To_bry_and_rls();
new_page.Html_data().Edit_preview_(new_html);
Invalidate(wiki);
win_itm.Page__mode_(Xopg_page_.Tid_edit);
html_itm.Scroll_page_by_id_gui(Xog_html_itm.Elem_id__first_heading);// NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
win_itm.Page__async__bgn(tab); // NOTE: needed to show images during preview; DATE:2014-06-21
}
public static void Rename(Xog_tab_itm tab) {
if (tab.View_mode() != Xopg_page_.Tid_edit) return; // exit if not edit; handles ctrl+r being pressed
Xoae_page page = tab.Page(); Xowe_wiki wiki = tab.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
if (Bry_.Eq(page.Ttl().Page_db(), wiki.Props().Main_page())) {
win_itm.Usr_dlg().Warn_many("", "", "The Main Page cannot be renamed");
win_itm.Kit().Ask_ok("", "", "The Main Page cannot be renamed");
return;
}
byte[] new_text = Bry_.new_u8(tab.Html_itm().Get_elem_value(Xog_html_itm.Elem_id__xowa_edit_rename_box));
if (Bry_.Len_eq_0(new_text)) return; // no ttl given; exit
new_text = Xoa_ttl.Replace_spaces(new_text); // ttls cannot have spaces; only underscores
Xoa_ttl new_ttl = Xoa_ttl.Parse(wiki, new_text);
int new_ns_id = new_ttl.Ns().Id();
if (new_ns_id != Xow_ns_.Tid__main) {
win_itm.Usr_dlg().Warn_many("", "", "The new page name must remain in the same namespace");
return;
}
wiki.Db_mgr().Save_mgr().Data_rename(page, new_ns_id, new_text);
page.Ttl_(Xoa_ttl.Parse(wiki, Bry_.Add(page.Ttl().Ns().Name_db_w_colon(), new_text)));
win_itm.Page__mode_(Xopg_page_.Tid_read);
win_itm.Usr_dlg().Prog_one("", "", "renamed page to {0}", String_.new_u8(page.Ttl().Full_txt_raw()));
}
public static void Focus(Xog_win_itm win, String elem_focus_id) {
Gfui_html html_box = win.Active_html_box();
html_box.Focus();
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__elem_focus, elem_focus_id);
}
public static void Debug(Xog_win_itm win, byte view_tid) {
Xog_tab_itm tab = win.Tab_mgr().Active_tab(); Xoae_page page = tab.Page();
Xowe_wiki wiki = tab.Wiki(); Xop_ctx ctx = wiki.Parser_mgr().Ctx();
ctx.Defn_trace().Clear(); // TODO_OLD: move_me
ctx.Defn_trace_(Xot_defn_trace_dbg.Instance);
Xoa_ttl ttl = page.Ttl();
Xoae_page new_page = Xoae_page.New(wiki, ttl);
byte[] data = tab.Html_itm().Get_elem_value_for_edit_box_as_bry();
new_page.Db().Text().Text_bry_(data);
wiki.Parser_mgr().Parse(new_page, true);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_m001();
bfr.Add(new_page.Root().Root_src());
wiki.Parser_mgr().Ctx().Defn_trace().Print(data, bfr);
new_page.Db().Text().Text_bry_(bfr.To_bry_and_rls());
byte old = tab.View_mode();
tab.View_mode_(view_tid);
Xog_tab_itm_read_mgr.Show_page(tab, new_page, false);
tab.History_mgr().Add(new_page);
tab.View_mode_(old);
}
private static void Invalidate(Xowe_wiki wiki) {// invalidate everything on updates; especially needed for page transclusion; {{/my_subpage}} DATE:2014-04-10
wiki.Parser_mgr().Scrib().Core_term();
wiki.Cache_mgr().Free_mem__all();
}
private static byte[] Get_new_text(Xog_tab_itm tab, byte[] orig) {
byte[] rv = tab.Html_itm().Get_elem_value_for_edit_box_as_bry();
if (orig != null) // orig == null for Preview
rv = tab.Wiki().Parser_mgr().Hdr__section_editable__mgr().Merge_section(tab.Page().Url(), rv, orig);
rv = Bry_.Trim(rv, 0, rv.length, false, true, Bry_.Trim_ary_ws); // MW: trim all trailing ws; REF:EditPage.php!safeUnicodeInput; DATE:2014-04-25
return rv;
}
}

View File

@@ -1,87 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.threads.*;
import gplx.gfui.*; import gplx.gfui.controls.standards.*; import gplx.xowa.guis.langs.*; import gplx.xowa.guis.history.*;
import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.*;
public class Xog_tab_itm_read_mgr {
public static void Show_page(Xog_tab_itm tab, Xoae_page new_page, boolean reset_to_read) {Show_page(tab, new_page, reset_to_read, false, false, Xog_history_stack.Nav_fwd);}
public static void Show_page(Xog_tab_itm tab, Xoae_page new_page, boolean reset_to_read, boolean new_page_is_same, boolean show_is_err, byte history_nav_type) {
if (reset_to_read)
tab.View_mode_(Xopg_page_.Tid_read);
if (new_page.Url().Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit))
tab.View_mode_(Xopg_page_.Tid_edit);
Xoae_page cur_page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm(); Gfui_html html_box = html_itm.Html_box();
Xog_win_itm win = tab.Tab_mgr().Win();
if (cur_page != null && !new_page_is_same) { // if new_page_is_same, don't update DocPos; will "lose" current position
cur_page.Html_data().Bmk_pos_(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Win__vpos_get));
tab.History_mgr().Update_html_doc_pos(cur_page, history_nav_type); // HACK: old_page is already in stack, but need to update its hdoc_pos
}
win.Usr_dlg().Prog_none("", "", "locating images");
Xowe_wiki wiki = new_page.Wikie();
try {tab.Html_itm().Show(new_page);}
catch (Exception e) {
if (String_.Eq(Err_.Message_lang(e), "class org.eclipse.swt.SWTException Widget is disposed")) return; // ignore errors caused by user closing tab early; DATE:2014-07-26
if (show_is_err) { // trying to show error page, but failed; don't show again, else recursion until out of memory; TODO_OLD:always load error page; no reason it should fail; WHEN:html_skin; DATE:2014-06-08
Gfo_usr_dlg_.Instance.Warn_many("", "", "fatal error trying to load error page; page=~{0} err=~{1}" + new_page.Url().To_str(), Err_.Message_gplx_full(e));
return;
}
else
Show_page_err(win, tab, wiki, new_page.Url(), new_page.Ttl(), e);
return;
}
tab.Page_(new_page);
if (tab == tab.Tab_mgr().Active_tab())
Update_selected_tab(win, new_page.Url(), new_page.Ttl());
Xol_font_info lang_font = wiki.Lang().Gui_font();
if (lang_font.Name() == null) lang_font = win.Gui_mgr().Win_cfg().Font();
Xog_win_itm_.Font_update(win, lang_font);
tab.Tab_mgr().Tab_mgr().Focus();
html_box.Focus();
win.Usr_dlg().Prog_none("", "", ""); // blank out status bar
if (tab.View_mode() == Xopg_page_.Tid_read)
html_itm.Scroll_page_by_bmk_gui();
else
Gfo_invk_.Invk_by_val(tab.Html_itm().Cmd_async(), Xog_html_itm.Invk_html_elem_focus, Xog_html_itm.Elem_id__xowa_edit_data_box); // NOTE: must be async, else won't work; DATE:2014-06-05
}
public static void Update_selected_tab_blank(Xog_win_itm win) {Update_selected_tab(win, null, null);} // called when all tabs are null
public static void Update_selected_tab(Xog_win_itm win, Xoa_url url, Xoa_ttl ttl) {
String url_str = "", win_str = Win_text_blank;
if (url != null && ttl != null) {
url_str = url.To_str();
win_str = String_.new_u8(Bry_.Add(ttl.Full_txt_w_ttl_case(), Win_text_suffix_page));
}
win.Url_box().Text_(url_str);
win.Win_box().Text_(win_str);
}
private static final byte[] Win_text_suffix_page = Bry_.new_a7(" - XOWA"); private static final String Win_text_blank = "XOWA";
public static void Show_page_err(Xog_win_itm win, Xog_tab_itm tab, Xowe_wiki wiki, Xoa_url url, Xoa_ttl ttl, Exception e) {
String err_msg = String_.Format("page_load fail: page={0} err={1}", String_.new_u8(url.Raw()), Err_.Message_gplx_full(e));
win.Usr_dlg().Warn_many("", "", err_msg);
win.App().Log_wtr().Queue_enabled_(false);
Xoae_page fail_page = wiki.Data_mgr().Load_page_by_ttl(ttl);
tab.View_mode_(Xopg_page_.Tid_edit);
Update_selected_tab(win, url, ttl);
Show_page(tab, fail_page, false, false, true, Xog_history_stack.Nav_fwd);
win.Win_box().Text_(err_msg);
}
public static void Launch(Xog_win_itm win) {
Xog_launcher_tabs.Instance.Launch(win);
}
}

View File

@@ -1,280 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.gfui.draws.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.tabs.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.apps.apis.xowa.gui.browsers.*; import gplx.xowa.specials.*;
import gplx.xowa.apps.urls.*;
public class Xog_tab_mgr implements Gfo_evt_itm {
private Ordered_hash tab_regy = Ordered_hash_.New(); private int tab_uid = 0;
private boolean btns__hide_if_one; private int btns__height;
public Xog_tab_mgr(Xog_win_itm win) {
this.win = win;
ev_mgr = new Gfo_evt_mgr(this);
}
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr;
public Xog_win_itm Win() {return win;} private Xog_win_itm win;
public Gfui_tab_mgr Tab_mgr() {return tab_mgr;} private Gfui_tab_mgr tab_mgr;
public int Btns__min_chars() {return btns__min_chars;} private int btns__min_chars;
public int Btns__max_chars() {return btns__max_chars;} private int btns__max_chars;
public boolean Javascript_enabled() {return javascript_enabled;} private boolean javascript_enabled = true;
private byte page_load_mode;
public boolean Page_load_mode_is_url() {return page_load_mode == Gxw_html_load_tid_.Tid_url;}
public void Init_by_kit(Gfui_kit kit) {
tab_mgr = kit.New_tab_mgr("xowa.tab_mgr", win.Win_box());
active_tab = Xog_tab_itm_.Null;
tab_mgr.Btns_selected_color_(ColorAdp_.White);
tab_mgr.Btns_unselected_color_(ColorAdp_.LightGray);
Gfo_evt_mgr_.Sub_same_many(tab_mgr, this, Gfui_tab_mgr.Evt_tab_selected, Gfui_tab_mgr.Evt_tab_closed, Gfui_tab_mgr.Evt_tab_switched);
win.App().Cfg().Bind_many_app(this, Cfg__javascript_enabled, Cfg__page_load_mode
, Cfg__place_on_top, Cfg__height, Cfg__hide_if_one, Cfg__curved, Cfg__close_btn_visible, Cfg__unselected_close_btn_visible, Cfg__max_chars, Cfg__min_chars);
}
public Xog_tab_itm Active_tab() {return active_tab;} private Xog_tab_itm active_tab;
public Xog_tab_itm Active_tab_assert() {
if (active_tab == Xog_tab_itm_.Null) this.Tabs_new_dflt(true);
return active_tab;
}
public boolean Active_tab_is_null() {return active_tab == Xog_tab_itm_.Null;}
private void Btns_text_recalc() {
int len = this.Tabs_len();
for (int i = 0; i < len; i++) {
Xog_tab_itm tab_itm = this.Tabs_get_at(i);
tab_itm.Tab_name_();
}
}
public int Tabs_len() {return tab_regy.Count();}
public Xog_tab_itm Tabs_new_init(Xowe_wiki wiki, Xoae_page page) {return this.Tabs_new(true, true, wiki, page);}
public Xog_tab_itm Tabs_get_at(int i) {return (Xog_tab_itm)tab_regy.Get_at(i);}
public Xog_tab_itm Tabs_new_dflt() {return Tabs_new_dflt(false);}
public Xog_tab_itm Tabs_new_dflt(boolean focus) {
boolean active_tab_is_null = this.Active_tab_is_null();
Xowe_wiki cur_wiki = active_tab_is_null ? win.App().Usere().Wiki() : active_tab.Wiki();
Xoa_ttl ttl = Xoa_ttl.Parse(cur_wiki, Xow_special_meta_.Itm__default_tab.Ttl_bry());
Xoa_url url = cur_wiki.Utl__url_parser().Parse_by_urlbar_or_null(ttl.Full_db_as_str()); if (url == null) throw Err_.new_("url", "invalid url", "url", url);
Xog_tab_itm rv = Tabs_new(focus, active_tab_is_null, cur_wiki, Xoae_page.New(cur_wiki, ttl));
rv.Page_update_ui();
rv.Show_url_bgn(url);
return rv;
}
private Xog_tab_itm Tabs_new(boolean focus, boolean active_tab_is_null, Xowe_wiki wiki, Xoae_page page) {
String tab_key = "tab_" + Int_.To_str(tab_uid++); int tab_idx = tab_regy.Count();
Gfui_tab_itm_data tab_data = new Gfui_tab_itm_data(tab_key, tab_idx);
Xog_tab_itm rv = new Xog_tab_itm(this, tab_data, wiki, page);
Gfui_tab_itm tab_box = tab_mgr.Tabs_add(tab_data);
rv.Make_html_box(tab_uid, tab_box, win, tab_mgr);
rv.Html_itm().Js_enabled_(javascript_enabled);
tab_box.Subs_add(rv.Html_itm().Html_box());
tab_regy.Add(tab_key, rv);
if ( focus
|| active_tab_is_null // NOTE: must select 1st tab, else nothing will show in tab box
) {
tab_mgr.Tabs_select_by_idx(rv.Tab_idx());
active_tab = rv;
}
Tabs_hide_if_one_chk(false);
return rv;
}
public void Tabs_new_dupe(boolean focus) {
if (this.Active_tab_is_null()) return;
String url = active_tab.Page().Url().To_str();
Tabs_new_dflt(focus);
win.Page__navigate_by_url_bar(url);
}
public void Tabs_javascript_enabled_(boolean v) {
this.javascript_enabled = v;
int len = tab_regy.Count();
for (int i = 0; i < len; i++) {
Xog_tab_itm tab = Tabs_get_by_idx_or_warn(i);
tab.Html_itm().Js_enabled_(v);
}
}
private void Tabs_selected(String key) {
Xog_tab_itm tab = Tabs_get_by_key_or_warn(key); if (tab == null) return;
active_tab = tab;
Xoae_page page = tab.Page();
Xog_tab_itm_read_mgr.Update_selected_tab(win, page.Url(), page.Ttl());
tab.Html_itm().Tab_selected(page);
}
public void Tabs_close_cur() {
if (this.Active_tab_is_null()) return;
Tabs__pub_close(active_tab);
tab_mgr.Tabs_close_by_idx(active_tab.Tab_idx());
Xog_tab_itm cur_tab = this.Active_tab(); // get new current tab for line below
if (cur_tab != null) cur_tab.Html_box().Focus(); // NOTE: needed to focus tab box else tab button will be focused; DATE:2014-07-13
}
public void Tabs_close_others() {this.Tabs_close_to_bgn(); this.Tabs_close_to_end();}
public void Tabs_close_to_bgn() {if (Active_tab_is_null()) return; Tabs_close_rng(0 , active_tab.Tab_idx());}
public void Tabs_close_to_end() {if (Active_tab_is_null()) return; Tabs_close_rng(active_tab.Tab_idx() + 1 , tab_regy.Count());}
public void Tabs_close_rng(int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xog_tab_itm tab = Tabs_get_at(bgn);
if (!Tabs__pub_close(tab)) return;
}
for (int i = bgn; i < end; i++)
tab_mgr.Tabs_close_by_idx(bgn); // NOTE: close at bgn, not at i, b/c each close will remove a tab from collection
}
public boolean Tabs__pub_close_all() {return Tabs__pub_close_rng(0, this.Tabs_len());}
public boolean Tabs__pub_close_rng(int bgn, int end) {
boolean rv = true;
for (int i = bgn; i < end; i++) {
Xog_tab_itm tab = Tabs_get_at(i);
boolean close_allowed = Tabs__pub_close(tab);
if (!close_allowed) rv = false;
}
return rv;
}
public boolean Tabs__pub_close(Xog_tab_itm tab) {
return tab.Page().Tab_data().Close_mgr().When_close(tab, Xoa_url.Null);
}
public void Tabs_close_undo() {
if (closed_undo_list.Count() == 0) return;
String url = (String)List_adp_.Pop(closed_undo_list);
Tabs_new_dflt(true);
win.Page__navigate_by_url_bar(url);
}
private List_adp closed_undo_list = List_adp_.New();
private void Tabs_closed(String key) {
Xog_tab_itm itm = Tabs_get_by_key_or_warn(key); if (itm == null) return;
itm.Html_box().Html_dispose();
closed_undo_list.Add(itm.Page().Url().To_str());
tab_regy.Del(key);
if (tab_regy.Count() == 0) {
active_tab = Xog_tab_itm_.Null;
Xog_tab_itm_read_mgr.Update_selected_tab_blank(win);
}
else
Tabs_recalc_idx();
Tabs_hide_if_one_chk(false);
}
private Xog_tab_itm Tabs_get_by_key_or_warn(String key) {
Xog_tab_itm rv = (Xog_tab_itm)tab_regy.Get_by(key); if (rv == null) win.App().Usr_dlg().Warn_many("", "", "tab.selected could not find tab; key={0}", key);
return rv;
}
private Xog_tab_itm Tabs_get_by_idx_or_warn(int idx) {
Xog_tab_itm rv = (Xog_tab_itm)tab_regy.Get_at(idx); if (rv == null) win.App().Usr_dlg().Warn_many("", "", "tab.selected could not find tab; idx={0}", idx);
return rv;
}
private void Tabs_recalc_idx() {
int len = tab_regy.Count();
for (int i = 0; i < len; i++) {
Xog_tab_itm itm = Tabs_get_by_idx_or_warn(i);
itm.Tab_idx_(i);
}
}
public void Tabs_select(boolean fwd) {
if (this.Active_tab_is_null()) return;
int new_idx = TabBox_.Cycle(fwd, active_tab.Tab_idx(), tab_regy.Count());
tab_mgr.Tabs_select_by_idx(new_idx);
}
public void Tabs_select_by_idx(int v) {
if (v < 0 || v >= tab_regy.Count()) return;
tab_mgr.Tabs_select_by_idx(v);
}
public void Tabs_move(boolean fwd) {
if (this.Active_tab_is_null()) return;
int src_idx = active_tab.Tab_idx();
int trg_idx = TabBox_.Cycle(fwd, src_idx, tab_regy.Count());
tab_mgr.Tabs_switch(src_idx, trg_idx);
}
private void Tabs_switched(String src_key, String trg_key) {
Xog_tab_itm src_itm = Tabs_get_by_key_or_warn(src_key);
Xog_tab_itm trg_itm = Tabs_get_by_key_or_warn(trg_key);
src_itm.Switch_mem(trg_itm);
active_tab = trg_itm; // NOTE: src_itm initiated switch, but trg_itm is now active b/c everything in src_itm has now been reparented to trg_itm; DATE:2014-05-12
}
public void Tabs_new_link(boolean focus, String link) { // handle empty link
if (String_.Len_eq_0(link)) {
if (this.Active_tab_is_null()) return;
link = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Decode_str(active_tab.Html_itm().Html_selected_get_active_or_selection()); // NOTE: must decode else url-encoded special pages don't work; EX:home/wiki/Special:XowaCfg%3Fgrp%3Dxowa.html.css; DATE:2017-01-02
}
if (String_.Len_eq_0(link)) {win.App().Usr_dlg().Prog_many("", "", "no link or text selected"); return;}
Tabs_new_link(link, focus);
}
public void Tabs_new_link(String link, boolean focus) {
Xowe_wiki wiki = active_tab.Wiki();
Xog_tab_itm new_tab = Tabs_new(focus, false, wiki, Xoae_page.New(wiki, active_tab.Page().Ttl())); // NOTE: do not use ttl from link, else middle-clicking pages with anchors won't work; DATE:2015-05-03
Xoa_url url = wiki.Utl__url_parser().Parse_by_urlbar_or_null(link); if (url == null) return; // NOTE: link must be of form domain/wiki/page; DATE:2014-05-27
new_tab.Show_url_bgn(url);
if (focus)
tab_mgr.Tabs_select_by_idx(new_tab.Tab_idx());
}
private void Tabs_hide_if_one_chk(boolean force) {
if (btns__hide_if_one || force) {// run code only if enabled or forced
if (tab_regy.Count() == 1) {
int desired_height = btns__hide_if_one ? 0 : btns__height;
if (tab_mgr.Btns_height() != desired_height)
tab_mgr.Btns_height_(desired_height);
}
else {
if (tab_mgr.Btns_height() != btns__height)
tab_mgr.Btns_height_(btns__height);
}
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tabs_new_dflt__at_dflt__focus_y)) Tabs_new_dflt(Bool_.Y);
else if (ctx.Match(k, Invk_tabs_new_link__at_dflt__focus_n)) Tabs_new_link(Bool_.N, m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_tabs_new_link__at_dflt__focus_y)) Tabs_new_link(Bool_.Y, m.ReadStrOr("v", null));
else if (ctx.Match(k, Gfui_tab_mgr.Evt_tab_selected)) Tabs_selected(m.ReadStr("key"));
else if (ctx.Match(k, Gfui_tab_mgr.Evt_tab_closed)) Tabs_closed(m.ReadStr("key"));
else if (ctx.Match(k, Gfui_tab_mgr.Evt_tab_switched)) Tabs_switched(m.ReadStr("src"), m.ReadStr("trg"));
else if (ctx.Match(k, Invk_tabs_close_cur)) Tabs_close_cur();
else if (ctx.Match(k, Invk_tabs_select_bwd)) Tabs_select(Bool_.N);
else if (ctx.Match(k, Invk_tabs_select_fwd)) Tabs_select(Bool_.Y);
else if (ctx.Match(k, Invk_tabs_switch_cur_bwd)) Tabs_move(Bool_.N);
else if (ctx.Match(k, Invk_tabs_switch_cur_fwd)) Tabs_move(Bool_.Y);
else if (ctx.Match(k, Cfg__place_on_top)) tab_mgr.Btns_place_on_top_(m.ReadYn("v"));
else if (ctx.Match(k, Cfg__height)) {btns__height = m.ReadInt("v"); tab_mgr.Btns_height_(btns__height);}
else if (ctx.Match(k, Cfg__hide_if_one)) {btns__hide_if_one = m.ReadYn("v"); Tabs_hide_if_one_chk(true);}
else if (ctx.Match(k, Cfg__curved)) tab_mgr.Btns_curved_(m.ReadYn("v"));
else if (ctx.Match(k, Cfg__close_btn_visible)) tab_mgr.Btns_close_visible_(m.ReadYn("v"));
else if (ctx.Match(k, Cfg__unselected_close_btn_visible)) tab_mgr.Btns_unselected_close_visible_(m.ReadYn("v"));
else if (ctx.Match(k, Cfg__max_chars)) {btns__max_chars = m.ReadInt("v"); Btns_text_recalc();}
else if (ctx.Match(k, Cfg__min_chars)) {btns__min_chars = m.ReadInt("v"); Btns_text_recalc();}
else if (ctx.Match(k, Cfg__javascript_enabled)) Tabs_javascript_enabled_(m.ReadYnOrY("v")); // NOTE: must be "OrY" else broken cfg.db will break cfg_maint; DATE:2016-12-15
else if (ctx.Match(k, Cfg__page_load_mode)) Page_load_mode_(m.ReadStr("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private void Page_load_mode_(String v) {
page_load_mode = Gxw_html_load_tid_.Xto_tid(v);
// Gfo_evt_mgr_.Pub_val(this, Evt_load_tid_changed, load_tid);
}
public static final String
Invk_tabs_select_fwd = "tabs_select_fwd" , Invk_tabs_select_bwd = "tabs_select_bwd"
, Invk_tabs_switch_cur_fwd = "tabs_switch_cur_fwd" , Invk_tabs_switch_cur_bwd = "tabs_switch_cur_bwd"
, Invk_tabs_new_dflt__at_dflt__focus_y = "tabs_new_dflt__at_dflt__focus_y"
, Invk_tabs_new_link__at_dflt__focus_n = "tabs_new_link__at_dflt__focus_n"
, Invk_tabs_new_link__at_dflt__focus_y = "tabs_new_link__at_dflt__focus_y"
, Invk_tabs_close_cur = "tabs_close_cur"
;
private static final String
Cfg__place_on_top = "xowa.gui.tabs.place_on_top"
, Cfg__height = "xowa.gui.tabs.height"
, Cfg__hide_if_one = "xowa.gui.tabs.hide_if_one"
, Cfg__curved = "xowa.gui.tabs.curved"
, Cfg__close_btn_visible = "xowa.gui.tabs.close_btn_visible"
, Cfg__unselected_close_btn_visible = "xowa.gui.tabs.unselected_close_btn_visible"
, Cfg__max_chars = "xowa.gui.tabs.max_chars"
, Cfg__min_chars = "xowa.gui.tabs.min_chars"
, Cfg__javascript_enabled = "xowa.gui.html_box.javascript_enabled"
, Cfg__page_load_mode = "xowa.gui.html_box.page_load_mode"
;
}

View File

@@ -1,353 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.threads.*; import gplx.core.envs.*;
import gplx.gfui.*; import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.guis.*; import gplx.xowa.guis.history.*; import gplx.xowa.guis.langs.*; import gplx.xowa.guis.urls.*; import gplx.xowa.guis.views.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.apps.urls.*; import gplx.xowa.files.*;
import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.math.*;
public class Xog_win_itm implements Gfo_invk, Gfo_evt_itm {
private Gfo_invk sync_cmd;
private Xog_url_box__selection_changed url_box__selection_changed;
public Xog_win_itm(Xoae_app app, Xoa_gui_mgr gui_mgr) {
this.app = app; this.gui_mgr = gui_mgr;
this.tab_mgr = new Xog_tab_mgr(this);
}
public Gfui_kit Kit() {return kit;} private Gfui_kit kit;
public Xoa_gui_mgr Gui_mgr() {return gui_mgr;} private Xoa_gui_mgr gui_mgr;
public GfuiWin Win_box() {return win_box;} private GfuiWin win_box;
public GfuiBtn Go_bwd_btn() {return go_bwd_btn;} private GfuiBtn go_bwd_btn;
public GfuiBtn Go_fwd_btn() {return go_fwd_btn;} private GfuiBtn go_fwd_btn;
public GfuiComboBox Url_box() {return url_box;} private GfuiComboBox url_box;
public GfuiBtn Url_exec_btn() {return url_exec_btn;} private GfuiBtn url_exec_btn;
public GfuiTextBox Search_box() {return search_box;} private GfuiTextBox search_box;
public GfuiBtn Search_exec_btn() {return search_exec_btn;} private GfuiBtn search_exec_btn;
public GfuiTextBox Find_box() {return find_box;} private GfuiTextBox find_box;
public GfuiBtn Find_close_btn() {return find_close_btn;} private GfuiBtn find_close_btn;
public GfuiBtn Find_fwd_btn() {return find_fwd_btn;} private GfuiBtn find_fwd_btn;
public GfuiBtn Find_bwd_btn() {return find_bwd_btn;} private GfuiBtn find_bwd_btn;
public GfuiTextBox Prog_box() {return prog_box;} private GfuiTextBox prog_box;
public GfuiTextBox Info_box() {return info_box;} private GfuiTextBox info_box;
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} private Gfo_evt_mgr evt_mgr;
public Xoae_app App() {return app;} private Xoae_app app;
public Xog_tab_mgr Tab_mgr() {return tab_mgr;} private Xog_tab_mgr tab_mgr;
public Xog_tab_itm Active_tab() {return tab_mgr.Active_tab();}
public Xoae_page Active_page() {return tab_mgr.Active_tab().Page();} public void Active_page_(Xoae_page v) {tab_mgr.Active_tab().Page_(v);}
public Xowe_wiki Active_wiki() {return tab_mgr.Active_tab().Wiki();}
public Xog_html_itm Active_html_itm() {return tab_mgr.Active_tab().Html_itm();}
public Gfui_html Active_html_box() {return tab_mgr.Active_tab().Html_itm().Html_box();}
public Xog_resizer Resizer() {return resizer;} private Xog_resizer resizer = new Xog_resizer();
public Gfo_usr_dlg Usr_dlg() {return app.Usr_dlg();}
public Xog_win_itm_cfg Cfg() {return cfg;} private final Xog_win_itm_cfg cfg = new Xog_win_itm_cfg();
public void Refresh_win_size() {
if (win_box != null) // NOTE: will be null when html box adjustment pref is set and application is starting
resizer.Exec_win_resize(app, win_box.Width(), win_box.Height());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_link_click)) Win__link_click();
else if (ctx.Match(k, Invk_link_print)) Xog_win_itm__prog_href_mgr.Print(this);
else if (ctx.Match(k, Gfui_html.Evt_location_changed)) Win__link_clicked(m.ReadStr("v"));
else if (ctx.Match(k, Gfui_html.Evt_location_changing)) Page__navigate_by_href(tab_mgr.Active_tab(), Xoh_href_gui_utl.Standardize_xowa_link(m.ReadStr("v")));
else if (ctx.Match(k, Gfui_html.Evt_win_resized)) Refresh_win_size();
else if (ctx.Match(k, Invk_page_refresh)) Page__refresh();
else if (ctx.Match(k, Invk_page_async_exec)) Xog_async_wkr.Async(((Xog_tab_itm)m.ReadObj("v")));
else if (ctx.Match(k, Invk_page_view_read)) Page__mode_(Xopg_page_.Tid_read);
else if (ctx.Match(k, Invk_page_view_edit)) Page__mode_(Xopg_page_.Tid_edit);
else if (ctx.Match(k, Invk_page_view_html)) Page__mode_(Xopg_page_.Tid_html);
else if (ctx.Match(k, Invk_page_edit_save)) Xog_tab_itm_edit_mgr.Save(tab_mgr.Active_tab(), Bool_.N);
else if (ctx.Match(k, Invk_page_edit_save_draft)) Xog_tab_itm_edit_mgr.Save(tab_mgr.Active_tab(), Bool_.Y);
else if (ctx.Match(k, Invk_page_edit_preview)) Xog_tab_itm_edit_mgr.Preview(tab_mgr.Active_tab());
else if (ctx.Match(k, Invk_page_edit_rename)) Xog_tab_itm_edit_mgr.Rename(tab_mgr.Active_tab());
else if (ctx.Match(k, Invk_page_edit_focus_box)) Xog_tab_itm_edit_mgr.Focus(this, Xog_html_itm.Elem_id__xowa_edit_data_box);
else if (ctx.Match(k, Invk_page_edit_focus_first)) Xog_tab_itm_edit_mgr.Focus(this, Xog_html_itm.Elem_id__first_heading);
else if (ctx.Match(k, Invk_page_dbg_html)) Xog_tab_itm_edit_mgr.Debug(this, Xopg_page_.Tid_html);
else if (ctx.Match(k, Invk_page_dbg_wiki)) Xog_tab_itm_edit_mgr.Debug(this, Xopg_page_.Tid_edit);
else if (ctx.Match(k, Invk_page_goto)) Page__navigate_by_url_bar(m.ReadStr("v"));
else if (ctx.Match(k, Invk_page_goto_recent)) Page__navigate_by_url_bar(app.Usere().History_mgr().Get_at_last());
else if (ctx.Match(k, Invk_history_bwd)) {Page__navigate_by_history(Bool_.N);}
else if (ctx.Match(k, Invk_history_fwd)) {Page__navigate_by_history(Bool_.Y);}
else if (ctx.Match(k, Invk_eval)) App__eval(m.ReadStr("cmd"));
else if (ctx.Match(k, Invk_page_async_cancel_wait)) Page__async__cancel__wait();
else if (ctx.Match(k, Invk_page_async_restart)) Page__async__restart();
else if (ctx.Match(k, Invk_search)) Page__navigate_by_search();
else if (ctx.Match(k, Invk_window_font_changed)) Xog_win_itm_.Font_update(this, (Xol_font_info)m.CastObj("font"));
else if (ctx.Match(k, Invk_app)) return app;
else if (ctx.Match(k, Invk_page)) return this.Active_page();
else if (ctx.Match(k, Invk_wiki)) return this.Active_tab().Wiki();
else if (ctx.Match(k, Invk_exit)) App__exit();
else if (ctx.Match(k, Gfui_html.Evt_link_hover)) {
if (this.Active_tab() != null) // NOTE: this.Active_tab() should not be null, but is null when running on raspberry pi; DATE:2016-09-23
Xog_win_itm__prog_href_mgr.Hover(app, cfg.Status__show_short_url(), this.Active_tab().Wiki(), this.Active_page(), Xoh_href_gui_utl.Standardize_xowa_link(m.ReadStr("v")));
}
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_page_async_exec = "page_async_exec"
, Invk_page_async_cancel_wait = "page_async_cancel_wait", Invk_page_async_restart = "page_async_restart"
;
public static final String
Invk_app = "app", Invk_wiki = "wiki", Invk_page = "page", Invk_shortcuts = "shortcuts"
, Invk_link_click = "link_click", Invk_link_print = "link_print"
, Invk_window_font_changed = "winow_font_changed"
, Invk_search = "search"
, Invk_page_view_edit = "page_view_edit", Invk_page_view_read = "page_view_read", Invk_page_view_html = "page_view_html"
, Invk_history_fwd = "history_fwd", Invk_history_bwd = "history_bwd"
, Invk_page_refresh = "page_refresh"
, Invk_page_edit_focus_box = "page_edit_focus_box", Invk_page_edit_focus_first = "page_edit_focus_first"
, Invk_page_edit_save = "page_edit_save", Invk_page_edit_save_draft = "page_edit_save_draft", Invk_page_edit_preview = "page_edit_preview", Invk_page_edit_rename = "page_edit_rename"
, Invk_page_dbg_wiki = "page_dbg_wiki", Invk_page_dbg_html = "page_dbg_html"
, Invk_eval = "eval"
, Invk_exit = "exit"
// xowa.gfs: shortcuts
, Invk_page_goto = "page_goto", Invk_page_goto_recent = "page_goto_recent"
;
private void Win__link_click() { // NOTE: only applies when content_editable=y; if n, then link_click will be handled by SwtBrowser location changed (Win__link_clicked)
// COMMENT: ignore content editable; DATE:2016-12-25
//Xog_tab_itm tab = tab_mgr.Active_tab(); Xowe_wiki wiki = tab.Wiki();
//if (wiki.Gui_mgr().Cfg_browser().Content_editable()) {
// String href = tab.Html_itm().Html_box().Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_active_for_editable_mode, Gfui_html.Atr_href, null);
// if (String_.Len_eq_0(href)) return; // NOTE: href can be null for images; EX: [[File:Loudspeaker.svg|11px|link=|alt=play]]; link= basically means don't link to image
// Page__navigate_by_href(tab, href);
//}
}
private void Win__link_clicked(String anchor_raw) {
String url = url_box.Text();
int pos = String_.FindFwd(url, gplx.langs.htmls.Gfh_tag_.Anchor_str);
if (pos != Bry_find_.Not_found) url = String_.Mid(url, 0, pos);
String anchor_str = Parse_evt_location_changing(anchor_raw);
byte[] anchor_bry = Bry_.new_u8(anchor_str);
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoae_page page = tab.Page();
if (anchor_str != null) { // link has anchor
url_box.Text_(url + "#" + anchor_str); // update url box
page.Html_data().Bmk_pos_(Xog_history_itm.Html_doc_pos_toc); // HACK: anchor clicked; set docPos of curentPage to TOC (so back will go back to TOC)
tab.History_mgr().Update_html_doc_pos(page, Xog_history_stack.Nav_by_anchor); // HACK: update history_mgr; note that this must occur before setting Anchor (since Anchor will generate a new history itm)
page.Url().Anch_bry_(anchor_bry); // update url
}
tab.History_mgr().Add(page);
app.Usere().History_mgr().Add(page.Wiki().App(), page.Url(), page.Ttl(), Bry_.Add_w_dlm(Byte_ascii.Hash, page.Url().Page_bry(), anchor_bry));
}
public void App__exit() {
kit.Kit_term(); // NOTE: Kit_term calls shell.close() which in turn is hooked up to app.Term_cbk() event; DATE:2014-09-09
}
private void App__eval(String s) {
String snippet = this.Active_html_itm().Html_elem_atr_get_str(s, Gfui_html.Atr_innerHTML);
app.Gfs_mgr().Run_str(snippet);
}
private static String Parse_evt_location_changing(String v) { // EX: about:blank#anchor -> anchor
int pos = String_.FindFwd(v, gplx.langs.htmls.Gfh_tag_.Anchor_str);
return pos == Bry_find_.Not_found
? null
: String_.Mid(v, pos + 1);
}
public void Page__mode_(byte new_mode_tid) {
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoae_page page = tab.Page(); Xowe_wiki wiki = tab.Wiki();
if ( new_mode_tid == Xopg_page_.Tid_read // used to be && cur_view_tid == Edit; removed clause else redlinks wouldn't show when going form html to read (or clicking read multiple times) DATE: 2013-11-26;
&& page.Db().Page().Exists() // if new page, don't try to reload
) {
// NOTE: if moving from "Edit" to "Read", reload page (else Preview changes will still show); NOTE: do not call Exec_page_reload / Exec_page_refresh, which will fire redlinks code
page = tab_mgr.Active_tab().History_mgr().Cur_page(wiki); // NOTE: must set to CurPage() else changes will be lost when going Bwd,Fwd
tab.Page_(page);
wiki.Parser_mgr().Parse(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
Xoa_url url = page.Url();
if (url.Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit)) // url has ?action=edit
url = tab.Wiki().Utl__url_parser().Parse(url.To_bry_full_wo_qargs()); // remove all query args; handle (1) s.w:Earth?action=edit; (2) click on Read; DATE:2014-03-06
}
tab.View_mode_(new_mode_tid);
if (page.Db().Page().Exists_n()) return;
Xog_tab_itm_read_mgr.Show_page(tab, page, false);
// Exec_page_refresh(); // commented out; causes lnke to show as [2] instead of [1] when saving page; EX: [http://a.org b] DATE:2014-04-24
}
public void Page__navigate_by_search() {Page__navigate_by_url_bar(app.Gui_mgr().Win_cfg().Search_box_fmtr().Bld_str_many(search_box.Text()));}
public void Page__navigate_by_url_bar(String href) {
Xog_tab_itm tab = tab_mgr.Active_tab_assert();
Xoa_url url = tab.Wiki().Utl__url_parser().Parse_by_urlbar_or_null(href); if (url == null) return;
tab.Show_url_bgn(url);
}
private void Page__navigate_by_href(Xog_tab_itm tab, String href) { // NOTE: different from Navigate_by_url_bar in that it handles "file:///" and other @gplx.Internal protected formats; EX: "/site/", "about:blank"; etc..
Xoa_url url = Xog_url_wkr.Exec_url(this, href);
if (url != Xog_url_wkr.Rslt_handled)
tab.Show_url_bgn(url);
}
public void Page__navigate_by_history(boolean fwd) {
Xog_tab_itm tab = tab_mgr.Active_tab();
if (tab == Xog_tab_itm_.Null) return;
Xoae_page cur_page = tab.Page(); Xowe_wiki cur_wiki = tab.Wiki();
Xoae_page new_page = tab.History_mgr().Go_by_dir(cur_wiki, fwd);
if (new_page.Db().Page().Exists_n()) return;
if (new_page.Ttl().Ns().Id_is_special()) // if Special, reload page; needed for Special:Search (DATE:2015-04-19; async loading) and Special:XowaBookmarks DATE:2015-10-05
new_page = new_page.Wikie().Data_mgr().Load_page_and_parse(new_page.Url(), new_page.Ttl()); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
else {
// WORKAROUND: if wikinews, then reload page; DATE:2016-11-03
// fixes bug wherein dump_html points images to wrong repo and causes images to be blank when going backwards / forwards
// note that this workaround will cause Wikitext Wikinews pages to reload page when going bwd / fwd, but this should be a smalldifference
if (new_page.Wiki().Domain_tid() == gplx.xowa.wikis.domains.Xow_domain_tid_.Tid__wikinews)
new_page = new_page.Wikie().Page_mgr().Load_page(new_page.Url(), new_page.Ttl(), tab);
}
byte history_nav_type = fwd ? Xog_history_stack.Nav_fwd : Xog_history_stack.Nav_bwd;
boolean new_page_is_same = Bry_.Eq(cur_page.Ttl().Full_txt_by_orig(), new_page.Ttl().Full_txt_by_orig());
Xog_tab_itm_read_mgr.Show_page(tab, new_page, true, new_page_is_same, false, history_nav_type);
Page__async__bgn(tab);
}
public void Page__reload() {
Xog_tab_itm tab = tab_mgr.Active_tab();
Xoae_page page = tab.History_mgr().Cur_page(tab.Wiki()); // NOTE: must set to CurPage() else changes will be lost when going Bwd,Fwd
tab.Page_(page);
page = page.Wikie().Page_mgr().Load_page(page.Url(), page.Ttl(), tab); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
Page__refresh();
}
public void Page__refresh() {
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoae_page page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm();
if (page.Ttl().Ns().Id_is_special()) {
page = page.Wikie().Page_mgr().Load_page(page.Url(), page.Ttl(), tab); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
}
page.Html_data().Bmk_pos_(html_itm.Html_box().Html_js_eval_proc_as_str(Xog_js_procs.Win__vpos_get));
html_itm.Show(page);
if (page.Url().Anch_str() == null)
html_itm.Scroll_page_by_bmk_gui();
else
html_itm.Scroll_page_by_id_gui(page.Url().Anch_str());
Page__async__bgn(tab);
}
public void Page__async__bgn(Xog_tab_itm tab) {
page__async__thread = Thread_adp_.Start_by_val(gplx.xowa.apps.Xoa_thread_.Key_page_async, this, Invk_page_async_exec, tab);
} private Thread_adp page__async__thread = Thread_adp.Noop;
public boolean Page__async__working(Xoa_url url) {
if (page__async__thread.Thread__is_alive()) { // cancel pending image downloads
page__async__restart_url = url;
this.Usr_dlg().Canceled_y_();
app.Wmf_mgr().Download_wkr().Download_xrg().Prog_cancel_y_();
Thread_adp_.Start_by_key(Invk_page_async_cancel_wait, this, Invk_page_async_cancel_wait);
return true;
}
return false;
}
private void Page__async__cancel__wait() {
while (page__async__thread.Thread__is_alive()) {
Thread_adp_.Sleep(10);
}
this.Active_page().File_queue().Clear();
this.Usr_dlg().Canceled_n_(); // NOTE: must mark "uncanceled", else one cancelation will stop all future downloads; DATE:2014-05-04
Gfo_invk_.Invk_by_key(sync_cmd, Invk_page_async_restart);
}
private void Page__async__restart() {
tab_mgr.Active_tab().Show_url_bgn(page__async__restart_url);
} private Xoa_url page__async__restart_url;
public void Lang_changed(Xol_lang_itm lang) {
Xoae_app app = gui_mgr.App();
Xog_win_itm_.Update_tiptext(app, go_bwd_btn , Xol_msg_itm_.Id_xowa_window_go_bwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, go_fwd_btn , Xol_msg_itm_.Id_xowa_window_go_fwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, url_box , Xol_msg_itm_.Id_xowa_window_url_box_tooltip);
Xog_win_itm_.Update_tiptext(app, url_exec_btn , Xol_msg_itm_.Id_xowa_window_url_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, search_box , Xol_msg_itm_.Id_xowa_window_search_box_tooltip);
Xog_win_itm_.Update_tiptext(app, search_exec_btn , Xol_msg_itm_.Id_xowa_window_search_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, find_close_btn , Xol_msg_itm_.Id_xowa_window_find_close_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, find_box , Xol_msg_itm_.Id_xowa_window_find_box_tooltip);
Xog_win_itm_.Update_tiptext(app, find_bwd_btn , Xol_msg_itm_.Id_xowa_window_find_bwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, find_fwd_btn , Xol_msg_itm_.Id_xowa_window_find_fwd_btn_tooltip);
Xog_win_itm_.Update_tiptext(app, prog_box , Xol_msg_itm_.Id_xowa_window_prog_box_tooltip);
Xog_win_itm_.Update_tiptext(app, info_box , Xol_msg_itm_.Id_xowa_window_info_box_tooltip);
}
public byte[] App__retrieve_by_url(String url_str, String output_str) {
synchronized (App__retrieve__lock) {
boolean output_html = String_.Eq(output_str, "html");
Xowe_wiki home_wiki = app.Usere().Wiki();
Xoa_url url = home_wiki.Utl__url_parser().Parse_by_urlbar_or_null(url_str); if (url == null) return Bry_.Empty;
Xowe_wiki wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_or_make_init_y(url.Wiki_bry());
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, url.Page_bry());
Xoae_page new_page = wiki.Data_mgr().Load_page_and_parse(url, ttl);
if (new_page.Db().Page().Exists_n()) {return Bry_.Empty;}
gplx.xowa.apps.servers.Gxw_html_server.Assert_tab(app, new_page); // HACK: assert at least 1 tab for Firefox addon; DATE:2015-01-23
Xog_tab_itm tab = tab_mgr.Active_tab();
tab.Page_(new_page);
tab.History_mgr().Add(new_page);
byte[] rv = output_html
? wiki.Html_mgr().Page_wtr_mgr().Gen(new_page, tab.View_mode())
: new_page.Db().Text().Text_bry();
if (app.Shell().Fetch_page_exec_async())
app.Gui_mgr().Browser_win().Page__async__bgn(tab);
return rv;
}
} private Object App__retrieve__lock = new Object();
public void Init_by_kit(Gfui_kit kit) {
this.kit = kit;
win_box = kit.New_win_app("win");
sync_cmd = win_box.Kit().New_cmd_sync(this);
Io_url img_dir = app.Fsys_mgr().Bin_xowa_file_dir().GenSubDir_nest("app.window");
FontAdp ui_font = app.Gui_mgr().Win_cfg().Font().To_font();
go_bwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "go_bwd_btn", "go_bwd.png" );
go_fwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "go_fwd_btn", "go_fwd.png" );
url_box = Xog_win_itm_.new_cbo(app, kit, win_box, ui_font, "url_box" , true);
url_exec_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "url_exec_btn", "url_exec.png" );
search_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "search_box" , true);
search_exec_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "search_exec_btn", "search_exec.png" );
find_close_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "find_close_btn", "find_close.png" );
find_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "find_box" , true);
find_fwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "find_fwd_btn", "find_fwd.png" );
find_bwd_btn = Xog_win_itm_.new_btn(app, kit, win_box, img_dir, "find_bwd_btn", "find_bwd.png" );
prog_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "prog_box" , false);
info_box = Xog_win_itm_.new_txt(app, kit, win_box, ui_font, "note_box" , false);
tab_mgr.Init_by_kit(kit);
this.Lang_changed(app.Usere().Lang());
Gfo_evt_mgr_.Sub_same_many(this, this, Gfui_html.Evt_location_changed, Gfui_html.Evt_location_changing, Gfui_html.Evt_link_hover);
Gfo_evt_mgr_.Sub_same(win_box, Gfui_html.Evt_win_resized, this);
Gfo_evt_mgr_.Sub(app.Gui_mgr().Win_cfg().Font(), Xol_font_info.Font_changed, this, Invk_window_font_changed);
url_box__selection_changed = new Xog_url_box__selection_changed(app, url_box);
Gfo_evt_mgr_.Sub_same(url_box, GfuiComboBox.Evt__selected_changed, url_box__selection_changed);
Gfo_evt_mgr_.Sub_same(url_box, GfuiComboBox.Evt__selected_accepted, url_box__selection_changed);
if ( !Env_.Mode_testing()
&& app.Mode().Tid_is_gui()) // only run for gui; do not run for tcp/http server; DATE:2014-05-03
app.Usr_dlg().Gui_wkr_(new Gfo_usr_dlg__gui__swt(app, kit, prog_box, info_box, info_box));
cfg.Init_by_app(app);
resizer.Init_by_app(app, this);
}
public static String Remove_redirect_if_exists(String text) {
// remove redirect target; EX: "A -> B" -> "A"
int redirect_pos = String_.FindFwd(text, gplx.xowa.addons.wikis.searchs.searchers.rslts.Srch_rslt_row.Str__redirect__text);
if (redirect_pos != Bry_find_.Not_found) {
text = String_.Mid(text, 0, redirect_pos);
}
return text;
}
}
class Xog_url_box__selection_changed implements Gfo_evt_itm {
private final GfuiComboBox url_box;
private final Xoae_app app;
public Xog_url_box__selection_changed(Xoae_app app, GfuiComboBox url_box) {this.app = app; this.url_box = url_box; this.ev_mgr = new Gfo_evt_mgr(this);}
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private final Gfo_evt_mgr ev_mgr;
private void On_selection_changed() {
String text = url_box.Text();
text = Xog_win_itm.Remove_redirect_if_exists(text);
// always move cursor to end; emulates firefox url_bar behavior
url_box.Text_(text);
url_box.Sel_(String_.Len(text), String_.Len(text));
}
private void On_selection_accepted() {
app.Api_root().Nav().Goto(url_box.Text());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, GfuiComboBox.Evt__selected_changed)) On_selection_changed();
else if (ctx.Match(k, GfuiComboBox.Evt__selected_accepted)) On_selection_accepted();
else return Gfo_invk_.Rv_unhandled;
return this;
}
}

View File

@@ -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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.imgs.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.guis.bnds.*; import gplx.xowa.guis.cmds.*;
import gplx.xowa.guis.langs.*;
public class Xog_win_itm_ {
public static void Show_win(Xog_win_itm win) {
Xoae_app app = win.App(); GfuiWin win_box = win.Win_box();
win_box.Focus_able_(false);
win_box.BackColor_(ColorAdp_.White);
win.Tab_mgr().Tab_mgr().BackColor_(ColorAdp_.White);
Xog_startup_win_.Startup(app, win_box);
win.Resizer().Exec_win_resize(app, win_box.Width(), win_box.Height());
win_box.Icon_(IconAdp.file_or_blank(app.Fsys_mgr().Bin_xowa_dir().GenSubFil_nest("file", "app.window", "app_icon.png")));
}
public static GfuiBtn new_btn(Xoae_app app, Gfui_kit kit, GfuiWin win, Io_url img_dir, String id, String file) {
GfuiBtn rv = kit.New_btn(id, win);
rv.Btn_img_(kit.New_img_load(img_dir.GenSubFil(file)));
return rv;
}
public static GfuiComboBox new_cbo(Xoae_app app, Gfui_kit kit, GfuiWin win, FontAdp ui_font, String id, boolean border_on) {
GfuiComboBox rv = kit.New_combo(id, win, Keyval_.new_(GfuiTextBox.CFG_border_on_, border_on));
rv.TextMgr().Font_(ui_font);
return rv;
}
public static GfuiTextBox new_txt(Xoae_app app, Gfui_kit kit, GfuiWin win, FontAdp ui_font, String id, boolean border_on) {
GfuiTextBox rv = kit.New_text_box(id, win, Keyval_.new_(GfuiTextBox.CFG_border_on_, border_on));
rv.TextMgr().Font_(ui_font);
return rv;
}
public static void Update_tiptext(Xoae_app app, GfuiElem elem, int tiptext_id) {
elem.TipText_(Xog_win_itm_.new_tiptext(app, tiptext_id));
}
public static void Font_update(Xog_win_itm win, Xol_font_info itm_font) {
FontAdp gui_font = win.Url_box().TextMgr().Font();
if (!itm_font.Eq(gui_font)) {
FontAdp new_font = itm_font.To_font();
win.Url_box().TextMgr().Font_(new_font);
win.Find_box().TextMgr().Font_(new_font);
win.Prog_box().TextMgr().Font_(new_font);
win.Tab_mgr().Tab_mgr().TextMgr().Font_(new_font);
}
}
public static String new_tiptext(Xoae_app app, int id) {return String_.new_u8(app.Usere().Lang().Msg_mgr().Val_by_id(app.Usere().Wiki(), id));}
}

View File

@@ -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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.*; import gplx.gfui.controls.standards.*; import gplx.xowa.htmls.hrefs.*;
public class Xog_win_itm__prog_href_mgr {
public static void Print(Xog_win_itm win) { // PURPOSE: print href in prog box when in content editable mode
String href = win.Active_html_box().Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_active_for_editable_mode, Gfui_html.Atr_href, "");// get selected href from html_box
href = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Decode_str(href); // remove url encodings
if (!String_.Eq(href, win.Prog_box().Text()))
win.Usr_dlg().Prog_direct(href);
}
public static void Hover(Xoae_app app, boolean show_status_url, Xowe_wiki wiki, Xoae_page page, String href) {
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
if ( String_.Len_eq_0(href) // href is null / empty; occurs when hovering over empty space
|| String_.Eq(href, "file:///")) {
usr_dlg.Prog_direct(""); // clear out previous entry
return;
}
Xoa_url url = Xoa_url.blank();
app.Html__href_parser().Parse_as_url(url, Bry_.new_u8(href), wiki, page.Ttl().Page_txt());
usr_dlg.Prog_direct(String_.new_u8(url.To_bry(!show_status_url, Bool_.Y)));
}
}

View File

@@ -1,30 +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.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
public class Xog_win_itm_cfg implements Gfo_invk {
public boolean Status__show_short_url() {return status__show_short_url;} private boolean status__show_short_url = true;
public void Init_by_app(Xoa_app app) {
app.Cfg().Bind_many_app(this, Cfg__status__show_short_url);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__status__show_short_url)) status__show_short_url = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Cfg__status__show_short_url = "xowa.gui.prog_box.show_short_url";
}

View File

@@ -1,68 +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.views.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
import gplx.core.envs.*;
public class Xog_error_data {
public Xog_error_data(String full_msg, String err_details, String err_msg) {
this.full_msg = full_msg;
this.err_details = err_details;
this.err_msg = err_msg;
}
public String Full_msg() {return full_msg;} private final String full_msg;
public String Err_details() {return err_details;} private final String err_details;
public String Err_msg() {return err_msg;} private final String err_msg;
public static Xog_error_data new_(String err_msg, String err_trace) {
String err_details = String_.Concat_lines_nl_skip_last
( "OS: " + Op_sys.Cur().Os_name()
, "Java: " + System_.Prop__java_version() + " (" + Op_sys.Cur().Bitness_str() + " bit)"
, "Java path: " + System_.Prop__java_home()
, "XOWA: " + Xoa_app_.Version
, "XOWA path: " + Env_.AppUrl().Raw()
, ""
, "Error: " + err_msg
, "Stack: " + err_trace
);
String advice = Make_advice(err_msg);
String full_msg = String_.Concat_lines_nl_skip_last
( "Sorry! XOWA failed to run!"
, ""
, advice
, ""
, "You can also open an issue or send an email with the data below."
, ""
, "Thanks!"
, ""
, "----"
, err_details
);
return new Xog_error_data(full_msg, err_details, err_msg);
}
private static String Make_advice(String err_msg) {
String check_troubleshooting_section = "check the TROUBLESHOOTING section in the readme.txt for known issues.";
if (String_.Has(err_msg, "Cannot load 64-bit SWT libraries on 32-bit JVM"))
return String_.Concat_lines_nl_skip_last
( "Your Java installation looks like it's 32-bit. Please use the 32-bit package of XOWA."
, ""
, "For example, if you downloaded xowa_app_windows_64_v2.10.1.1.zip (64-bit), download xowa_app_windows_v2.10.1.1.zip (32-bit)"
, ""
, "You may also want to " + check_troubleshooting_section
);
else
return "Please " + check_troubleshooting_section;
}
}

View File

@@ -1,116 +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.views.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
import gplx.langs.htmls.encoders.*; import gplx.core.envs.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.*;
import java.awt.*; import java.awt.event.*;
import javax.swing.*;
public class Xog_error_win extends JFrame implements Gfo_invk {
private Xog_error_data error_data;
public Xog_error_win(Xog_error_data error_data) {
super("XOWA Error");
this.setTitle("XOWA Error");
this.error_data = error_data;
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {System.out.println(e.getMessage());}
this.setSize(700, 580);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setBackground(Color.WHITE);
JPanel main_panel = new JPanel();
main_panel.setSize(700, 580);
this.setContentPane(main_panel);
this.setLayout(null);
new_text_area(main_panel, error_data);
new_link_lbl(this, main_panel, 10, 520, Invk_open_site, "<html><a href=\"\">open issue</a></html>");
new_link_lbl(this, main_panel, 605, 520, Invk_send_mail, "<html><a href=\"\">send email</a></html>");
this.setVisible(true);
}
private static JScrollPane new_text_area(JPanel owner, Xog_error_data error_data) {
JTextArea text_area = new JTextArea();
text_area.setForeground(Color.BLACK);
text_area.setBackground(Color.WHITE);
text_area.setMargin(new Insets(0, 0, 0,0));
text_area.setLineWrap(true);
text_area.setWrapStyleWord(true); // else text will wrap in middle of words
text_area.setCaretColor(Color.BLACK);
text_area.getCaret().setBlinkRate(0);
text_area.setText(error_data.Full_msg());
JScrollPane text_scroll_pane = new JScrollPane(text_area);
text_scroll_pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
owner.add(text_scroll_pane);
text_scroll_pane.setSize(675, 500);
text_scroll_pane.setLocation(10, 10);
return text_scroll_pane;
}
private static JLabel new_link_lbl(Gfo_invk invk, JPanel owner, int x, int y, String invk_cmd, String text) {
JLabel rv = new JLabel();
rv.setText(text);
rv.setCursor(new Cursor(Cursor.HAND_CURSOR));
rv.addMouseListener(new Swing_mouse_adapter(Gfo_invk_cmd.New_by_key(invk, invk_cmd)));
rv.setLocation(x, y);
rv.setSize(80, 20);
owner.add(rv);
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_send_mail)) {
try {
Gfo_url_encoder url_encoder = Gfo_url_encoder_.New__fsys_wnt().Make();
String subject = url_encoder.Encode_str("XOWA boot error: " + error_data.Err_msg());
String body = url_encoder.Encode_str(error_data.Err_details());
Desktop.getDesktop().mail(new URI("mailto:gnosygnu+xowa_error_boot@gmail.com?subject=" + subject + "&body=" + body));
}
catch (URISyntaxException ex) {}
catch (IOException ex) {}
}
else if (ctx.Match(k, Invk_open_site)) {
try {
Desktop.getDesktop().browse(new URI("https://github.com/gnosygnu/xowa/issues"));
}
catch (URISyntaxException ex) {}
catch (IOException ex) {}
}
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_send_mail = "send_mail", Invk_open_site = "open_site";
public static void Run(String err_msg, String err_trace) {
Xog_error_data error_data = Xog_error_data.new_(err_msg, err_trace);
Gfo_usr_dlg_.Instance.Log_many("", "", error_data.Err_details());
if (Op_sys.Cur().Tid_is_osx())
gplx.core.consoles.Console_adp__sys.Instance.Write_str(error_data.Err_msg());
else
new Xog_error_win(error_data);
}
}
class Swing_mouse_adapter extends MouseAdapter {
private final Gfo_invk_cmd cmd;
public Swing_mouse_adapter(Gfo_invk_cmd cmd) {this.cmd = cmd;}
@Override public void mouseClicked(MouseEvent ev) {
try {cmd.Exec();}
catch (Exception e) {
System.out.println(Err_.Message_gplx_full(e));
}
}
}

View File

@@ -1,51 +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.views.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
import java.awt.*;
import java.awt.event.*;
public class Xog_splash_win implements Rls_able {
private SplashScreen splash;
private Graphics2D graphics; private boolean graphics_init = true;
public Xog_splash_win(boolean app_mode_is_gui) {
if (app_mode_is_gui) {
this.splash = SplashScreen.getSplashScreen();
if (splash == null) System.out.println("SplashScreen.getSplashScreen() returned null");
}
}
public void Write(String msg) {
if (splash == null) return;
if (graphics_init) {
graphics_init = false;
if (graphics == null) {
graphics = splash.createGraphics();
if (graphics == null) System.out.println("graphics is null");
}
}
if (graphics == null) return;
graphics.setComposite(AlphaComposite.Clear);
graphics.fillRect(120,140,200,40);
graphics.setPaintMode();
graphics.setColor(Color.BLACK);
graphics.drawString(msg, 0, 0);
splash.update();
}
public void Rls() {
if (splash == null) return;
splash.close();
}
}