GP-1981 - Theme Help

This commit is contained in:
dragonmacher 2022-11-14 17:07:46 -05:00 committed by ghidragon
parent edfb5a0877
commit 72e87f8e2d
18 changed files with 587 additions and 438 deletions

View file

@ -16,8 +16,7 @@
package help;
import java.awt.Component;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
import java.net.MalformedURLException;
import java.net.URL;
@ -30,8 +29,7 @@ import javax.help.event.HelpModelEvent;
import javax.help.plaf.HelpNavigatorUI;
import javax.help.plaf.basic.BasicFavoritesCellRenderer;
import javax.help.plaf.basic.BasicFavoritesNavigatorUI;
import javax.swing.JComponent;
import javax.swing.JTree;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import ghidra.util.Msg;
@ -70,6 +68,28 @@ public class CustomFavoritesView extends FavoritesView {
public void setUI(HelpNavigatorUI ui) {
super.setUI(new CustomFavoritesNavigatorUI(this));
}
private Action superGetAddAction() {
return super.getAddAction();
}
@Override
public Action getAddAction() {
//
// Switching themes triggers a UI update. Internally, the Java Help API is not
// correctly updating listeners, which results in that API having a reference to an old
// UI. Using our own custom action to retrieve the currently active action prevents
// this issue, since we are always getting the active target for actionPerformed().
//
return new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Action currentAction = superGetAddAction();
currentAction.actionPerformed(e);
}
};
}
}
class CustomFavoritesNavigatorUI extends BasicFavoritesNavigatorUI {

View file

@ -28,7 +28,8 @@ import generic.theme.GIcon;
import ghidra.util.Msg;
import ghidra.util.bean.GGlassPane;
import resources.Icons;
import resources.ResourceManager;
import resources.MultiIconBuilder;
import resources.icons.EmptyIcon;
// NOTE: for JH 2.0, this class has been rewritten to not
// access the 'frame' and 'dialog' variable directly
@ -240,7 +241,11 @@ public class GHelpBroker extends DefaultHelpBroker {
JToolBar toolbar = (JToolBar) component;
toolbar.addSeparator();
Icon zoomOutIcon = ResourceManager.getScaledIcon(ZOOM_OUT_ICON, 24, 24);
ImageIcon icon = new MultiIconBuilder(new EmptyIcon(24, 24))
.addCenteredIcon(ZOOM_OUT_ICON)
.build();
Icon zoomOutIcon = icon;
JButton zoomOutBtn = new JButton(zoomOutIcon);
zoomOutBtn.setToolTipText("Zoom out");
zoomOutBtn.addActionListener(e -> {
@ -252,7 +257,10 @@ public class GHelpBroker extends DefaultHelpBroker {
});
toolbar.add(zoomOutBtn);
Icon zoomInIcon = ResourceManager.getScaledIcon(ZOOM_IN_ICON, 24, 24);
icon = new MultiIconBuilder(new EmptyIcon(24, 24))
.addCenteredIcon(ZOOM_IN_ICON)
.build();
Icon zoomInIcon = icon;
JButton zoomInBtn = new JButton(zoomInIcon);
zoomInBtn.setToolTipText("Zoom in");
zoomInBtn.addActionListener(e -> {

View file

@ -53,7 +53,8 @@ import utilities.util.FileUtilities;
*/
public class GHelpHTMLEditorKit extends HTMLEditorKit {
private static final String G_HELP_STYLE_SHEET = "help/shared/Frontpage.css";
private static final String G_HELP_STYLE_SHEET = "Frontpage.css";
private static final String DARK_G_HELP_STYLE_SHEET = "DarkStyle.css";
private static final Pattern EXTERNAL_URL_PATTERN = Pattern.compile("https?://.*");
@ -320,12 +321,21 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
}
private URL getGStyleSheetURL() {
URL GStyleSheetURL = ResourceManager.getResource(G_HELP_STYLE_SHEET);
if (GStyleSheetURL != null) {
return GStyleSheetURL;
if (Gui.isDarkTheme()) {
return findStyleSheet(DARK_G_HELP_STYLE_SHEET);
}
return findModuleFile("help/shared/FrontPage.css");
return findStyleSheet(G_HELP_STYLE_SHEET);
}
private URL findStyleSheet(String name) {
URL url = ResourceManager.getResource("help/shared/" + name);
if (url != null) {
return url;
}
return findModuleFile("help/shared/" + name);
}
private URL findApplicationfile(String relativePath) {