GP-1795 - Added help service method to show a HelpLocation

This commit is contained in:
dragonmacher 2022-03-04 11:21:27 -05:00
parent 35e9c3328d
commit f98e0d5c54
3 changed files with 82 additions and 57 deletions

View File

@ -39,6 +39,11 @@ public class DefaultHelpService implements HelpService {
// no-op
}
@Override
public void showHelp(HelpLocation location) {
// no-op
}
@Override
public void excludeFromHelp(Object helpObject) {
// no-op

View File

@ -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
*/
@Override
public 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)
*/
@Override
public 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);
}
@Override
public 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 = (Window) owner;
Dialog modalDialog = WindowUtilities.findModalestDialog();
if (modalDialog != null) {
window = modalDialog;
}
Window window = getBestParent(owner);
HelpLocation loc = findHelpLocation(helpObj);
if (infoOnly) {
displayHelpInfo(helpObj, loc, window);
}
else {
showHelpLocation(loc, window);
}
}
private void showHelpLocation(HelpLocation loc, Window window) {
if (loc == null) {
displayHelp(mainHS.getHomeID(), window); // show the default help page
return;
}
if (loc != null) {
URL url = loc.getHelpURL();
if (url != null) {
displayHelp(url, window);
return;
}
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);
}
}
URL url = loc.getHelpURL();
if (url != null) {
displayHelp(url, window);
return;
}
displayHelp(mainHS.getHomeID(), window);
String helpId = loc.getHelpId();
if (helpId == null) {
displayHelp(mainHS.getHomeID(), window); // show the default help page
return;
}
try {
displayHelp(createHelpID(helpId), window);
}
catch (BadIDException e) {
Msg.info(this, "Could not find help for ID: \"" + helpId +
"\" from HelpLocation: " + loc);
}
}
private Window getBestParent(Component c) {
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;
}
return window;
}
private ID createHelpID(String helpIDString) {

View File

@ -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.
*