mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Gui: Strip blank:
from links [#799]
This commit is contained in:
parent
7550894dda
commit
567e03dc1d
@ -185,11 +185,24 @@ public class Swt_html implements Gxw_html, Swt_control, FocusListener, Gfo_evt_m
|
||||
, Browser_tid_mozilla = SWT.MOZILLA
|
||||
, Browser_tid_webkit = SWT.WEBKIT
|
||||
;
|
||||
private static final String URL_ABOUT_PREFIX = "about:";
|
||||
public static String StripAboutFromUrl(String url) {
|
||||
return String_.Has_at_bgn(url, URL_ABOUT_PREFIX)
|
||||
? String_.Mid(url, URL_ABOUT_PREFIX.length())
|
||||
: url;
|
||||
|
||||
private static final String URL_PREFIX_ABOUT = "about:";
|
||||
private static final String URL_PREFIX_BLANK = "blank";
|
||||
public static String NormalizeSwtUrl(String url) {
|
||||
String rv = url;
|
||||
|
||||
// 2020-09-19|ISSUE#:799|strip "about:" from url due to SWT 4.16
|
||||
rv = String_.Has_at_bgn(rv, URL_PREFIX_ABOUT)
|
||||
? String_.Mid(rv, URL_PREFIX_ABOUT.length())
|
||||
: rv;
|
||||
|
||||
// 2015-06-09|webkit prefixes "about:blank" to anchors; causes TOC to fail when clicking on links; EX:about:blank#TOC1
|
||||
// 2020-09-22|removed webkit check due to SWT 4.16; `html_box.Browser_tid() == Swt_html.Browser_tid_webkit`
|
||||
// still strip "blank"; note that SWT 4.16 changes anchors from "file:///#anchor" to "en.w/wiki/page/#anchor"
|
||||
rv = String_.Has_at_bgn(rv, URL_PREFIX_BLANK)
|
||||
? String_.Mid(rv, URL_PREFIX_BLANK.length())
|
||||
: rv;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Swt_core_cmds_html extends Swt_core__basic {
|
||||
@ -238,8 +251,10 @@ class Swt_html_lnr_status implements StatusTextListener {
|
||||
public void Host_set(Gfo_evt_itm host) {this.host = host;} Gfo_evt_itm host;
|
||||
@Override public void changed(StatusTextEvent ev) {
|
||||
if (html_box.Kit().Kit_mode__term()) return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29
|
||||
String ev_text = ev.text;
|
||||
ev_text = Swt_html.StripAboutFromUrl(ev_text); // 2020-09-19|ISSUE#:799|strip "about:/" from url due to SWT 4.16
|
||||
|
||||
// 2020-09-22|ISSUE#:799|normalize URL due to SWT 4.16
|
||||
String ev_text = Swt_html.NormalizeSwtUrl(ev.text);
|
||||
|
||||
String load_by_url_path = html_box.Load_by_url_path();
|
||||
if (load_by_url_path != null) ev_text = String_.Replace(ev_text, load_by_url_path, ""); // remove "C:/xowa/tab_1.html"
|
||||
// if (String_.Has(ev_text, "Loading [MathJax]")) return; // suppress MathJax messages; // NOTE: disabled for 2.1 (which no longer outputs messages to status); DATE:2013-05-03
|
||||
@ -260,23 +275,15 @@ class Swt_html_lnr_location implements LocationListener {
|
||||
@Override public void changed(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changed);}
|
||||
@Override public void changing(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changing);}
|
||||
private void Pub_evt(LocationEvent arg, String evt) {
|
||||
String location = arg.location;
|
||||
// 2020-09-22|ISSUE#:799|normalize URL due to SWT 4.16
|
||||
String location = Swt_html.NormalizeSwtUrl(arg.location);
|
||||
|
||||
// location_changing fires once when page is loaded; ignore
|
||||
if (String_.Eq(location, "about:blank")) {
|
||||
// location_changing fires once when page is loaded -> ignore
|
||||
if (String_.Eq(location, String_.Empty)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// webkit prefixes "about:blank" to anchors; causes TOC to fail when clicking on links; EX:about:blank#TOC1; DATE:2015-06-09
|
||||
if (html_box.Browser_tid() == Swt_html.Browser_tid_webkit
|
||||
&& String_.Has_at_bgn(location, "about:blank")) {
|
||||
location = String_.Mid(location, 11); // 11 = "about:blank".length
|
||||
}
|
||||
|
||||
// 2020-09-19|ISSUE#:799|strip "about:/" from url due to SWT 4.16
|
||||
location = Swt_html.StripAboutFromUrl(location);
|
||||
|
||||
// navigating to file://page.html will fire location event; ignore if url mode
|
||||
// navigating to file://page.html will fire location event; ignore if url mode (loading pages from file)
|
||||
if (html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url
|
||||
&& String_.Has_at_bgn(location, "file:")
|
||||
&& String_.Has_at_end(location, ".html")
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@ -13,7 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.guis.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
package gplx.xowa.guis.history;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.xowa.Xoa_ttl;
|
||||
import gplx.xowa.Xoa_url;
|
||||
import gplx.xowa.Xoa_url_;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
|
||||
public class Xog_history_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry(); private final Xog_history_stack stack = new Xog_history_stack();
|
||||
public int Count() {return hash.Count();}
|
||||
@ -30,7 +42,12 @@ public class Xog_history_mgr {
|
||||
return rv;
|
||||
}
|
||||
public void Add(Xoae_page page) {
|
||||
Xog_history_itm new_itm = Xog_history_mgr.new_(page);
|
||||
this.Add(page, Xog_history_mgr.new_(page));
|
||||
}
|
||||
public void Add(Xoae_page page, Xoa_url url) {
|
||||
this.Add(page, Xog_history_mgr.new_(url, page.Html_data().Bmk_pos()));
|
||||
}
|
||||
private void Add(Xoae_page page, Xog_history_itm new_itm) {
|
||||
stack.Add(new_itm);
|
||||
byte[] page_key = Build_page_key(page);
|
||||
if (!hash.Has(page_key))
|
||||
@ -72,4 +89,13 @@ public class Xog_history_mgr {
|
||||
if (bmk_pos == null) bmk_pos = Xog_history_itm.Html_doc_pos_toc; // never allow null doc_pos; set to top
|
||||
return new Xog_history_itm(wiki, page, anch, qarg, redirect_force, bmk_pos);
|
||||
}
|
||||
public static Xog_history_itm new_(Xoa_url url, String bmk_pos) {
|
||||
byte[] wiki = url.Wiki_bry();
|
||||
byte[] page = url.Page_bry();
|
||||
byte[] anch = url.Anch_bry();
|
||||
byte[] qarg = url.Qargs_mgr().To_bry();
|
||||
boolean redirect_force = url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no);
|
||||
if (bmk_pos == null) bmk_pos = Xog_history_itm.Html_doc_pos_toc; // never allow null doc_pos; set to top
|
||||
return new Xog_history_itm(wiki, page, anch, qarg, redirect_force, bmk_pos);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@ -13,12 +13,20 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.guis.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.core.envs.*;
|
||||
import gplx.gfui.controls.standards.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.doms.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
package gplx.xowa.guis.urls;
|
||||
|
||||
import gplx.Bry_;
|
||||
import gplx.Err_;
|
||||
import gplx.String_;
|
||||
import gplx.xowa.Xoa_ttl;
|
||||
import gplx.xowa.Xoa_url;
|
||||
import gplx.xowa.Xoa_url_;
|
||||
import gplx.xowa.Xoae_app;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
import gplx.xowa.guis.views.Xog_js_procs;
|
||||
import gplx.xowa.guis.views.Xog_win_itm;
|
||||
|
||||
public class Xog_url_wkr {
|
||||
private final Xoa_url tmp_url = Xoa_url.blank();
|
||||
private Xoae_app app; private Xog_win_itm win; private Xowe_wiki wiki; private Xoae_page page;
|
||||
@ -56,7 +64,18 @@ public class Xog_url_wkr {
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_anchor(Xog_win_itm win) { // EX: #anchor
|
||||
win.Active_html_itm().Scroll_page_by_id_gui(tmp_url.Anch_str()); // NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
|
||||
// 2014-05-03|was originally called directly; changed to call on thread
|
||||
win.Active_html_itm().Scroll_page_by_id_gui(tmp_url.Anch_str());
|
||||
|
||||
// 2020-09-22|ISSUE#:799|SWT 4.16 changes anchors from "file:///#anchor" to "en.w/wiki/page/#anchor"
|
||||
if (app.Mode().Tid_is_gui()) {
|
||||
// manually update url box
|
||||
win.Gui_mgr().Browser_win().Url_box().Text_(tmp_url.To_str());
|
||||
|
||||
// manually register url; note that tmp_url needs to be passed b/c page.Url() doesn't have #anchor info
|
||||
win.Tab_mgr().Active_tab().History_mgr().Add(page, tmp_url);
|
||||
}
|
||||
|
||||
return Rslt_handled;
|
||||
}
|
||||
private Xoa_url Exec_url_file(Xoae_app app, Xowe_wiki cur_wiki, Xoae_page page, Xog_win_itm win, byte[] href_bry) { // EX: file:///xowa/A.png
|
||||
|
Loading…
Reference in New Issue
Block a user