mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-3813 - Help - Added developer refresh button
This commit is contained in:
parent
3998da036a
commit
4a2a6c8c19
2 changed files with 79 additions and 9 deletions
|
@ -16,6 +16,7 @@
|
||||||
package docking.help;
|
package docking.help;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.geom.*;
|
import java.awt.geom.*;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
@ -39,11 +40,11 @@ import docking.util.AnimationPainter;
|
||||||
import docking.util.AnimationUtils;
|
import docking.util.AnimationUtils;
|
||||||
import generic.theme.GColor;
|
import generic.theme.GColor;
|
||||||
import ghidra.framework.preferences.Preferences;
|
import ghidra.framework.preferences.Preferences;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.*;
|
||||||
import ghidra.util.Swing;
|
|
||||||
import ghidra.util.bean.GGlassPane;
|
import ghidra.util.bean.GGlassPane;
|
||||||
import help.CustomTOCView;
|
import help.CustomTOCView;
|
||||||
import help.GHelpBroker;
|
import help.GHelpBroker;
|
||||||
|
import resources.Icons;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An extension of the {@link GHelpBroker} that allows {@code Docking} classes to be installed.
|
* An extension of the {@link GHelpBroker} that allows {@code Docking} classes to be installed.
|
||||||
|
@ -129,6 +130,23 @@ public class DockingHelpBroker extends GHelpBroker {
|
||||||
|
|
||||||
ToggleNavigationAid action = new ToggleNavigationAid();
|
ToggleNavigationAid action = new ToggleNavigationAid();
|
||||||
toolbar.add(new JButton(action));
|
toolbar.add(new JButton(action));
|
||||||
|
|
||||||
|
if (SystemUtilities.isInDevelopmentMode()) {
|
||||||
|
|
||||||
|
Action refreshAction = new AbstractAction() {
|
||||||
|
|
||||||
|
{
|
||||||
|
putValue(Action.SMALL_ICON, Icons.REFRESH_ICON);
|
||||||
|
putValue(Action.SHORT_DESCRIPTION, "Reload the current page");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
reloadHelpPage(getCurrentURL());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
toolbar.add(new JButton(refreshAction));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // opened access
|
@Override // opened access
|
||||||
|
|
|
@ -16,9 +16,12 @@
|
||||||
package help;
|
package help;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.help.*;
|
import javax.help.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -26,6 +29,7 @@ import javax.swing.text.Document;
|
||||||
|
|
||||||
import generic.theme.GIcon;
|
import generic.theme.GIcon;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
|
import ghidra.util.Swing;
|
||||||
import ghidra.util.bean.GGlassPane;
|
import ghidra.util.bean.GGlassPane;
|
||||||
import resources.Icons;
|
import resources.Icons;
|
||||||
import resources.MultiIconBuilder;
|
import resources.MultiIconBuilder;
|
||||||
|
@ -82,16 +86,25 @@ public class GHelpBroker extends DefaultHelpBroker {
|
||||||
|
|
||||||
/* Perform some shenanigans to force Java Help to reload the given URL */
|
/* Perform some shenanigans to force Java Help to reload the given URL */
|
||||||
protected void reloadHelpPage(URL url) {
|
protected void reloadHelpPage(URL url) {
|
||||||
|
|
||||||
clearContentViewer();
|
clearContentViewer();
|
||||||
showNavigationAid(url);
|
showNavigationAid(url);
|
||||||
try {
|
try {
|
||||||
|
// Page loading is asynchronous. Listen for the page to be loaded and then restore the
|
||||||
|
// users current view state.
|
||||||
|
htmlEditorPane.addPropertyChangeListener(new PageLocationUpdater());
|
||||||
htmlEditorPane.setPage(url);
|
htmlEditorPane.setPage(url);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
Msg.error(this, "Unexpected error loading help page: " + url, e);
|
Msg.error(this, "Unexpected error loading help page: " + url, e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reloadHelpPage() {
|
||||||
|
reloadHelpPage(getCurrentURL());
|
||||||
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
clearHighlights();
|
clearHighlights();
|
||||||
initialized = false;
|
initialized = false;
|
||||||
|
@ -241,8 +254,8 @@ public class GHelpBroker extends DefaultHelpBroker {
|
||||||
JToolBar toolbar = (JToolBar) component;
|
JToolBar toolbar = (JToolBar) component;
|
||||||
toolbar.addSeparator();
|
toolbar.addSeparator();
|
||||||
|
|
||||||
ImageIcon icon = new MultiIconBuilder(new EmptyIcon(24, 24))
|
ImageIcon icon =
|
||||||
.addCenteredIcon(ZOOM_OUT_ICON)
|
new MultiIconBuilder(new EmptyIcon(24, 24)).addCenteredIcon(ZOOM_OUT_ICON)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Icon zoomOutIcon = icon;
|
Icon zoomOutIcon = icon;
|
||||||
|
@ -253,12 +266,11 @@ public class GHelpBroker extends DefaultHelpBroker {
|
||||||
|
|
||||||
// Need to reload the page to force the scroll panes to resize properly. A
|
// Need to reload the page to force the scroll panes to resize properly. A
|
||||||
// simple revalidate/repaint won't do it.
|
// simple revalidate/repaint won't do it.
|
||||||
reloadHelpPage(getCurrentURL());
|
reloadHelpPage();
|
||||||
});
|
});
|
||||||
toolbar.add(zoomOutBtn);
|
toolbar.add(zoomOutBtn);
|
||||||
|
|
||||||
icon = new MultiIconBuilder(new EmptyIcon(24, 24))
|
icon = new MultiIconBuilder(new EmptyIcon(24, 24)).addCenteredIcon(ZOOM_IN_ICON)
|
||||||
.addCenteredIcon(ZOOM_IN_ICON)
|
|
||||||
.build();
|
.build();
|
||||||
Icon zoomInIcon = icon;
|
Icon zoomInIcon = icon;
|
||||||
JButton zoomInBtn = new JButton(zoomInIcon);
|
JButton zoomInBtn = new JButton(zoomInIcon);
|
||||||
|
@ -268,7 +280,7 @@ public class GHelpBroker extends DefaultHelpBroker {
|
||||||
|
|
||||||
// Need to reload the page to force the scroll panes to resize properly. A
|
// Need to reload the page to force the scroll panes to resize properly. A
|
||||||
// simple revalidate/repaint won't do it.
|
// simple revalidate/repaint won't do it.
|
||||||
reloadHelpPage(getCurrentURL());
|
reloadHelpPage();
|
||||||
});
|
});
|
||||||
toolbar.add(zoomInBtn);
|
toolbar.add(zoomInBtn);
|
||||||
|
|
||||||
|
@ -356,4 +368,44 @@ public class GHelpBroker extends DefaultHelpBroker {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Inner Classes
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
private class PageLocationUpdater implements PropertyChangeListener {
|
||||||
|
|
||||||
|
private URL url;
|
||||||
|
private int caretPosition;
|
||||||
|
private Rectangle viewPosition;
|
||||||
|
|
||||||
|
PageLocationUpdater() {
|
||||||
|
url = getCurrentURL();
|
||||||
|
caretPosition = htmlEditorPane.getCaretPosition();
|
||||||
|
viewPosition = htmlEditorPane.getVisibleRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
|
String name = evt.getPropertyName();
|
||||||
|
if (!name.equals("page")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlEditorPane.removePropertyChangeListener(this);
|
||||||
|
|
||||||
|
URL currentUrl = getCurrentURL();
|
||||||
|
if (!Objects.equals(currentUrl, url)) {
|
||||||
|
return; // new page loaded; ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlEditorPane.setCaretPosition(caretPosition);
|
||||||
|
// not sure why this needs to be done later, but setting the caret seems to trigger a
|
||||||
|
// view updated, so try to run after that
|
||||||
|
Swing.runLater(() -> {
|
||||||
|
htmlEditorPane.scrollRectToVisible(viewPosition);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue