Home » Eclipse Projects » Eclipse Platform » PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false(isContextHelpDisplayed() doesn't behave as its API description. Even though the context sensitive help is open, it returns false.)
PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed() always return false [message #948085] |
Wed, 17 October 2012 18:47 |
Cory Huang Messages: 2 Registered: October 2012 |
Junior Member |
|
|
Hi guys,
I was trying to use IWorkbenchHelpSystem.isContextHelpDisplayed() (http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fui%2Fhelp%2FIWorkbenchHelpSystem.html) to check if the context sensitive help is open alreay or not. However, I came across a problem that this method doesn't work properly as its description "Returns whether the context-sensitive help window is currently being displayed."
Basically, the problem is: when the context sensitive help is shown, this method also returns false. I looked into the source code, and here is my findings.
---------------------------------------------------------------------------------
Problem 1:
First, the entry of the isContextHelpDisplay() method.
WorkbenchHelpSystem.java
public boolean isContextHelpDisplayed() {
if (!isInitialized) {
return false;
}
AbstractHelpUI helpUI = getHelpUI();
return helpUI != null && helpUI.isContextHelpDisplayed();
}
When isInitialized = true and helpUI != null, we goes into DefaultHelpUI.isContextHelpDisplayed()
/**
* Returns <code>true</code> if the context-sensitive help window is currently being
* displayed, <code>false</code> if not.
*/
public boolean isContextHelpDisplayed() {
if (f1Dialog == null) {
return false;
}
return f1Dialog.isShowing();
}
However, f1Dialog = null, even though I have already pressed F1 and the Help view is shown out there. Then, I checked the code where f1Dialog is created, it is in the function
private void displayContextAsInfopop(IContext context, int x, int y, IWorkbenchPart activePart, Control c){
...
else {
f1Dialog = new ContextHelpDialog(context, x, y);
f1Dialog.open();
}
...
}
,
which is only called in
void displayContext(IContext context, int x, int y, boolean noInfopop) {
...
if (!noInfopop && winfopop) {
IWorkbenchPart activePart = page.getActivePart();
Control c = window.getShell().getDisplay().getFocusControl();
displayContextAsInfopop(context, x, y, activePart, c);
return;
}
...
}
It seems that we need to have winfopop=true to get f1Dialog created. I guess that's why no matter how I press F1 to open the Help view, f1Dialog is still null. I am not sure if my understanding here is correct. If it is correct, why we need winfopop if the Help view is already open?
---------------------------------------------------------------------------------
Problem 2: when Help is open at startup, it seems something should be initialized as true while it is false. Please see below:
WorkbenchHelpSystem.java
public boolean isContextHelpDisplayed() {
if (!isInitialized) {
return false; // here return false
}
AbstractHelpUI helpUI = getHelpUI();
return helpUI != null && helpUI.isContextHelpDisplayed();
}
isInitialized is only evaluated in the getHelpUI() as below:
private AbstractHelpUI getHelpUI() {
if (!isInitialized) {
isInitialized = initializePluggableHelpUI();
if (!isInitialized)
WorkbenchPlugin.log("Unable to instantiate help UI");//$NON-NLS-1$
}
return pluggableHelpUI;
}
I don't know why isInitialized is supposed to not to be initialized as true if the Help view is open at startup. This is not a problem if I reopen the Help view by hand (aka press F1).
---------------------------------------------------------------------------------
For those people who have the same problems of using PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed(), I found a workaround here http://www.eclipse.org/forums/index.php/m/720403/. So, my code which checks if the Help view is shown or not is:
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart helpView = activePage.findView("org.eclipse.help.ui.HelpView");
if (helpView == null) {
return;
}
But I still want to know why isContextHelpDisplayed() doesn't behave properly (or my understanding is incorrect). Thank you all guys for viewing my post and I really appreciate if someone can come up and help me with this.
Cory
|
|
| | | |
Goto Forum:
Current Time: Sat Apr 20 02:54:35 GMT 2024
Powered by FUDForum. Page generated in 0.03166 seconds
|