mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-25 17:00:36 -09:00
Merge remote-tracking branch 'origin/GP-XX_jpleasu_open_external_browser_from_help'
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package docking.help;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Image;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
@@ -53,6 +54,8 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
|
||||
|
||||
private static final String G_HELP_STYLE_SHEET = "help/shared/Frontpage.css";
|
||||
|
||||
private static final Pattern EXTERNAL_URL_PATTERN = Pattern.compile("https?://.*");
|
||||
|
||||
/** A pattern to strip the font size value from a line of CSS */
|
||||
private static final Pattern FONT_SIZE_PATTERN = Pattern.compile("font-size:\\s*(\\d{1,2})");
|
||||
private static final String HELP_WINDOW_ZOOM_FACTOR = "HELP.WINDOW.FONT.SIZE.MODIFIER";
|
||||
@@ -116,6 +119,10 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
|
||||
}
|
||||
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
if (isExternalLink(e)) {
|
||||
browseExternalLink(e);
|
||||
return;
|
||||
}
|
||||
Msg.trace(this, "Link activated: " + e.getURL());
|
||||
e = validateURL(e);
|
||||
Msg.trace(this, "Validated event: " + e.getURL());
|
||||
@@ -127,6 +134,28 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExternalLink(HyperlinkEvent e) {
|
||||
String description = e.getDescription();
|
||||
return description != null && EXTERNAL_URL_PATTERN.matcher(description).matches();
|
||||
}
|
||||
|
||||
private void browseExternalLink(HyperlinkEvent e) {
|
||||
String description = e.getDescription();
|
||||
if (!Desktop.isDesktopSupported()) {
|
||||
Msg.info(this, "Unable to launch external browser for " + description);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// use an external browser
|
||||
URI uri = e.getURL().toURI();
|
||||
Desktop.getDesktop().browse(uri);
|
||||
}
|
||||
catch (URISyntaxException | IOException e1) {
|
||||
Msg.error(this, "Error browsing to external URL " + description, e1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the URL of the given event. If the URL is invalid, a new event may be created if
|
||||
* a new, valid URL can be created. Creates a new event with a patched URL if
|
||||
|
||||
Reference in New Issue
Block a user