mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Gui: Strip about:/wiki/
from links [#823]
This commit is contained in:
parent
aeef520228
commit
0ef5058cfd
@ -185,25 +185,6 @@ 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_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 {
|
||||
public Swt_core_cmds_html(Swt_html html_box, Control control) {super(control);}
|
||||
@ -253,7 +234,7 @@ class Swt_html_lnr_status implements StatusTextListener {
|
||||
if (html_box.Kit().Kit_mode__term()) return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29
|
||||
|
||||
// 2020-09-22|ISSUE#:799|normalize URL due to SWT 4.16
|
||||
String ev_text = Swt_html.NormalizeSwtUrl(ev.text);
|
||||
String ev_text = Swt_html_utl.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"
|
||||
@ -276,7 +257,7 @@ class Swt_html_lnr_location implements LocationListener {
|
||||
@Override public void changing(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changing);}
|
||||
private void Pub_evt(LocationEvent arg, String evt) {
|
||||
// 2020-09-22|ISSUE#:799|normalize URL due to SWT 4.16
|
||||
String location = Swt_html.NormalizeSwtUrl(arg.location);
|
||||
String location = Swt_html_utl.NormalizeSwtUrl(arg.location);
|
||||
|
||||
// location_changing fires once when page is loaded -> ignore
|
||||
if (String_.Eq(location, String_.Empty)) {
|
||||
|
40
150_gfui/src/gplx/gfui/kits/swts/Swt_html_utl.java
Normal file
40
150_gfui/src/gplx/gfui/kits/swts/Swt_html_utl.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
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.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfui.kits.swts;
|
||||
|
||||
import gplx.String_;
|
||||
|
||||
public class Swt_html_utl {
|
||||
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;
|
||||
}
|
||||
}
|
@ -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,10 +13,36 @@ 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.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.*;
|
||||
package gplx.xowa.guis.views;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.Err_;
|
||||
import gplx.GfoMsg;
|
||||
import gplx.Gfo_evt_itm;
|
||||
import gplx.Gfo_evt_mgr;
|
||||
import gplx.Gfo_evt_mgr_;
|
||||
import gplx.Gfo_invk_;
|
||||
import gplx.GfsCtx;
|
||||
import gplx.Int_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.String_;
|
||||
import gplx.gfui.controls.gxws.Gxw_html_load_tid_;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_itm;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_itm_data;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_mgr;
|
||||
import gplx.gfui.controls.tabs.TabBox_;
|
||||
import gplx.gfui.kits.core.Gfui_kit;
|
||||
import gplx.gfui.kits.swts.Swt_html_utl;
|
||||
import gplx.xowa.Xoa_ttl;
|
||||
import gplx.xowa.Xoa_url;
|
||||
import gplx.xowa.Xoae_page;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
import gplx.xowa.htmls.hrefs.Xoh_href_;
|
||||
import gplx.xowa.specials.Xow_special_meta_;
|
||||
|
||||
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;
|
||||
@ -195,7 +221,16 @@ public class Xog_tab_mgr implements Gfo_evt_itm {
|
||||
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
|
||||
link = active_tab.Html_itm().Html_selected_get_active_or_selection();
|
||||
// 2020-12-16|ISSUE#:823|Open in new tab creates links like `about:/wiki/PAGE_NAME` or `about:/site/WIKI_NAME/wiki/PAGE_NAME`
|
||||
link = Swt_html_utl.NormalizeSwtUrl(link);
|
||||
if (link.startsWith(Xoh_href_.Str__site)) {
|
||||
link = link.substring(Xoh_href_.Str__site.length());
|
||||
}
|
||||
else if (link.startsWith(Xoh_href_.Str__wiki)) {
|
||||
link = active_tab.Wiki().Domain_str() + link;
|
||||
}
|
||||
link = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Decode_str(link); // 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);
|
||||
|
Loading…
Reference in New Issue
Block a user