mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-1795 - Added help service method to show a HelpLocation
This commit is contained in:
parent
35e9c3328d
commit
f98e0d5c54
3 changed files with 82 additions and 57 deletions
|
@ -39,6 +39,11 @@ public class DefaultHelpService implements HelpService {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showHelp(HelpLocation location) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void excludeFromHelp(Object helpObject) {
|
public void excludeFromHelp(Object helpObject) {
|
||||||
// no-op
|
// no-op
|
||||||
|
|
|
@ -175,12 +175,6 @@ public class HelpManager implements HelpService {
|
||||||
return false;
|
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
|
@Override
|
||||||
public HelpLocation getHelpLocation(Object helpObj) {
|
public HelpLocation getHelpLocation(Object helpObj) {
|
||||||
return helpLocations.get(helpObj);
|
return helpLocations.get(helpObj);
|
||||||
|
@ -194,15 +188,6 @@ public class HelpManager implements HelpService {
|
||||||
return mainHS;
|
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
|
@Override
|
||||||
public void showHelp(URL url) {
|
public void showHelp(URL url) {
|
||||||
if (!isValidHelp) {
|
if (!isValidHelp) {
|
||||||
|
@ -211,12 +196,22 @@ public class HelpManager implements HelpService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardFocusManager keyboardFocusManager =
|
Window window = getBestParent(null);
|
||||||
KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
|
||||||
Window window = keyboardFocusManager.getActiveWindow();
|
|
||||||
displayHelp(url, window);
|
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
|
@Override
|
||||||
public void showHelp(Object helpObj, boolean infoOnly, Component owner) {
|
public void showHelp(Object helpObj, boolean infoOnly, Component owner) {
|
||||||
|
|
||||||
|
@ -226,44 +221,62 @@ public class HelpManager implements HelpService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (owner != null && !(owner instanceof Window)) {
|
Window window = getBestParent(owner);
|
||||||
owner = owner.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
Window window = (Window) owner;
|
|
||||||
Dialog modalDialog = WindowUtilities.findModalestDialog();
|
|
||||||
if (modalDialog != null) {
|
|
||||||
window = modalDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
HelpLocation loc = findHelpLocation(helpObj);
|
HelpLocation loc = findHelpLocation(helpObj);
|
||||||
|
|
||||||
if (infoOnly) {
|
if (infoOnly) {
|
||||||
displayHelpInfo(helpObj, loc, window);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loc != null) {
|
URL url = loc.getHelpURL();
|
||||||
|
if (url != null) {
|
||||||
URL url = loc.getHelpURL();
|
displayHelp(url, window);
|
||||||
if (url != null) {
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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) {
|
private ID createHelpID(String helpIDString) {
|
||||||
|
|
|
@ -21,8 +21,7 @@ import java.net.URL;
|
||||||
import ghidra.util.HelpLocation;
|
import ghidra.util.HelpLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>HelpService</code> defines a service for displaying Help content by
|
* <code>HelpService</code> defines a service for displaying Help content by an ID or URL.
|
||||||
* an ID or URL.
|
|
||||||
*/
|
*/
|
||||||
public interface HelpService {
|
public interface HelpService {
|
||||||
|
|
||||||
|
@ -50,6 +49,14 @@ public interface HelpService {
|
||||||
*/
|
*/
|
||||||
public void showHelp(URL url);
|
public void showHelp(URL url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* 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.
|
* help. Once this method has been called, no help can be registered for the given object.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue