|
Re: Actions are disabled if editor loses focus. Why? [message #763261 is a reply to message #763238] |
Fri, 09 December 2011 12:57 |
Philipp Bouillon Messages: 16 Registered: July 2009 |
Junior Member |
|
|
Ok, I found a "solution", but it seems like a dirty hack to me...
The action in the toolbar is disabled, because the ActionContributionItem is disabled. The ACI is disabled, because it receives an update of the "enable" property and "isEnabledAllowed()" returns false.
Hence, I extended ActionContributionItem and "hacked" the update method in a way that ignored the isEnabledAllowed state... It works, but I don't know which demons from hell I conjured up .
For the daring, here's the extension:
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionManagerOverrides;
public class GeometryEditorActionContributionItem extends
ActionContributionItem {
public GeometryEditorActionContributionItem(IAction action) {
super(action);
}
public void update(String propertyName) {
final IAction action = getAction();
if (getWidget() != null) {
boolean enableStateChanged = propertyName == null
|| propertyName.equals(IAction.ENABLED)
|| propertyName.equals(IContributionManagerOverrides.P_ENABLED);
if (enableStateChanged) {
if (action.isEnabled() && !isEnabledAllowed()) {
return;
}
}
}
super.update(propertyName);
}
}
To use it (in your EditorActionBarContributor class):
private final void add(IToolBarManager toolBarManager, IAction action) {
GeometryEditorActionContributionItem item = new GeometryEditorActionContributionItem(action);
toolBarManager.add(item);
}
public void contributeToToolBar(IToolBarManager toolBarManager) {
super.contributeToToolBar(toolBarManager);
add(toolBarManager, zoomInAction);
add(toolBarManager, zoomOutAction);
...
}
Maybe, this helps someone
Kind regards,
Philipp
[Updated on: Fri, 09 December 2011 12:58] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03432 seconds