Ghidra is a software reverse engineering (SRE) framework
GP-1795 - Added help service method to show a HelpLocation
dragonmacherf98e0d5c5458
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DefaultHelpService.java b/Ghidra/Framework/Docking/src/main/java/docking/DefaultHelpService.javaindex dae71b8322..feb1e90b06 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/DefaultHelpService.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/DefaultHelpService.java@@ -39,6 +39,11 @@ public class DefaultHelpService implements HelpService {// no-op}+ @Override+ public void showHelp(HelpLocation location) {+ // no-op+ }+@Overridepublic void excludeFromHelp(Object helpObject) {// no-opdiff --git a/Ghidra/Framework/Docking/src/main/java/docking/help/HelpManager.java b/Ghidra/Framework/Docking/src/main/java/docking/help/HelpManager.javaindex 24318f17be..fb4a5f78e0 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/help/HelpManager.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/help/HelpManager.java@@ -175,12 +175,6 @@ public class HelpManager implements HelpService {return false;}- /**- * Returns the Help location associated with the specified object- * or null if no help has been registered for the object.- * @param helpObj help object- * @return help location- */@Overridepublic HelpLocation getHelpLocation(Object helpObj) {return helpLocations.get(helpObj);@@ -194,15 +188,6 @@ public class HelpManager implements HelpService {return mainHS;}- /**- * Display the help page for the given URL. This is a specialty method for displaying- * help when a specific file is desired, like an introduction page. Showing help for- * objects within the system is accomplished by calling- * {@link #showHelp(Object, boolean, Component)}.- *- * @param url the URL to display- * @see #showHelp(Object, boolean, Component)- */@Overridepublic void showHelp(URL url) {if (!isValidHelp) {@@ -211,12 +196,22 @@ public class HelpManager implements HelpService {return;}- KeyboardFocusManager keyboardFocusManager =- KeyboardFocusManager.getCurrentKeyboardFocusManager();- Window window = keyboardFocusManager.getActiveWindow();+ Window window = getBestParent(null);displayHelp(url, window);}+ @Override+ public void showHelp(HelpLocation loc) {+ if (!isValidHelp) {+ Msg.warn(this, "Help is not in a valid state. " ++ "This can happen when help has not been built.");+ return;+ }++ Window window = getBestParent(null);+ showHelpLocation(loc, window);+ }+@Overridepublic void showHelp(Object helpObj, boolean infoOnly, Component owner) {@@ -226,44 +221,62 @@ public class HelpManager implements HelpService {return;}- while (owner != null && !(owner instanceof Window)) {- owner = owner.getParent();+ Window window = getBestParent(owner);+ HelpLocation loc = findHelpLocation(helpObj);++ if (infoOnly) {+ displayHelpInfo(helpObj, loc, window);}+ else {+ showHelpLocation(loc, window);+ }+ }- Window window = (Window) owner;- Dialog modalDialog = WindowUtilities.findModalestDialog();- if (modalDialog != null) {- window = modalDialog;+ private void showHelpLocation(HelpLocation loc, Window window) {+ if (loc == null) {+ displayHelp(mainHS.getHomeID(), window); // show the default help page+ return;}- HelpLocation loc = findHelpLocation(helpObj);+ URL url = loc.getHelpURL();+ if (url != null) {+ displayHelp(url, window);+ return;+ }- if (infoOnly) {- displayHelpInfo(helpObj, loc, window);+ String helpId = loc.getHelpId();+ if (helpId == null) {+ displayHelp(mainHS.getHomeID(), window); // show the default help pagereturn;}- if (loc != null) {+ try {+ displayHelp(createHelpID(helpId), window);+ }+ catch (BadIDException e) {+ Msg.info(this, "Could not find help for ID: \"" + helpId ++ "\" from HelpLocation: " + loc);+ }+ }- URL url = loc.getHelpURL();- if (url != null) {- displayHelp(url, window);- return;- }+ private Window getBestParent(Component c) {- String helpIDString = loc.getHelpId();- if (helpIDString != null) {- try {- displayHelp(createHelpID(helpIDString), window);- return;- }- catch (BadIDException e) {- Msg.info(this, "Could not find help for ID: \"" + helpIDString +- "\" from HelpLocation: " + loc);- }- }+ if (c == null) {+ KeyboardFocusManager keyboardFocusManager =+ KeyboardFocusManager.getCurrentKeyboardFocusManager();+ c = keyboardFocusManager.getActiveWindow();+ }++ while (c != null && !(c instanceof Window)) {+ c = c.getParent();+ }++ Window window = (Window) c;+ Dialog modalDialog = WindowUtilities.findModalestDialog();+ if (modalDialog != null) {+ window = modalDialog;}- displayHelp(mainHS.getHomeID(), window);+ return window;}private ID createHelpID(String helpIDString) {diff --git a/Ghidra/Framework/Docking/src/main/java/docking/help/HelpService.java b/Ghidra/Framework/Docking/src/main/java/docking/help/HelpService.javaindex dcb896ca6a..13faa88019 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/help/HelpService.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/help/HelpService.java@@ -21,8 +21,7 @@ import java.net.URL;import ghidra.util.HelpLocation;/**- * <code>HelpService</code> defines a service for displaying Help content by- * an ID or URL.+ * <code>HelpService</code> defines a service for displaying Help content by an ID or URL.*/public interface HelpService {@@ -41,8 +40,8 @@ public interface HelpService {/*** Display the help page for the given URL. This is a specialty method for displaying- * help when a specific file is desired, like an introduction page. Showing help for- * objects within the system is accomplished by calling+ * help when a specific file is desired, like an introduction page. Showing help for+ * objects within the system is accomplished by calling* {@link #showHelp(Object, boolean, Component)}.** @param url the URL to display@@ -51,7 +50,15 @@ public interface HelpService {public void showHelp(URL url);/**- * Signals to the help system to ignore the given object when searching for and validating+ * Display the help page for the given help location.+ *+ * @param location the location to display.+ * @see #showHelp(Object, boolean, Component)+ */+ public void showHelp(HelpLocation location);++ /**+ * Signals to the help system to ignore the given object when searching for and validating* help. Once this method has been called, no help can be registered for the given object.** @param helpObject the object to exclude from the help system.@@ -68,7 +75,7 @@ public interface HelpService {public boolean isExcludedFromHelp(Object helpObject);/**- * Register help for a specific object.+ * Register help for a specific object.** <P>Do not call this method will a <code>null</code> help location. Instead, to signal that* an item has no help, call {@link #excludeFromHelp(Object)}.@@ -79,8 +86,8 @@ public interface HelpService {public void registerHelp(Object helpObject, HelpLocation helpLocation);/**- * Removes this object from the help system. This method is useful, for example,- * when a single Java {@link Component} will have different help locations+ * Removes this object from the help system. This method is useful, for example,+ * when a single Java {@link Component} will have different help locations* assigned over its lifecycle.** @param helpObject the object for which to clear help@@ -88,7 +95,7 @@ public interface HelpService {public void clearHelp(Object helpObject);/**- * Returns the registered (via {@link #registerHelp(Object, HelpLocation)} help+ * Returns the registered (via {@link #registerHelp(Object, HelpLocation)} help* location for the given object; null if there is no registered* help.*