Usage of MultiPageEditorActionBarContributor [message #212136] |
Sat, 18 March 2006 18:52 |
Eclipse User |
|
|
|
Originally posted by: dutz.c-ware.de
Hi.
I am working on a gephical editor and simply cant get the kebindings to
work. Everything is working fine except that. I implemented my own
contributor extending MultiPageEditorActionBarContributor and added all the
action code from the "normal" ActionBarContributor. Unfortunately my Hotkeys
still won't work. Any help is greatly appreciated ;)
Chris
package de.tud.cs.qpe.editors.net.gef;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.DeleteRetargetAction;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.gef.ui.actions.RedoRetargetAction;
import org.eclipse.gef.ui.actions.UndoRetargetAction;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
public class NetEditorActionBarContributor extends
MultiPageEditorActionBarContributor {
private ActionRegistry registry = new ActionRegistry();
private List<RetargetAction> retargetActions = new
ArrayList<RetargetAction>();
private List<String> globalActionKeys = new ArrayList<String>();
public void init(IActionBars bars) {
buildActions();
declareGlobalActionKeys();
super.init(bars);
}
protected void addAction(IAction action) {
getActionRegistry().registerAction(action);
}
protected void addGlobalActionKey(String key) {
globalActionKeys.add(key);
}
protected void addRetargetAction(RetargetAction action) {
addAction(action);
retargetActions.add(action);
getPage().addPartListener(action);
addGlobalActionKey(action.getId());
}
protected IAction getAction(String id) {
return getActionRegistry().getAction(id);
}
protected ActionRegistry getActionRegistry() {
return registry;
}
protected void buildActions() {
IWorkbenchWindow workbenchWindow = getPage().getWorkbenchWindow();
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());
addRetargetAction((RetargetAction)
ActionFactory.COPY.create(workbenchWindow));
addRetargetAction((RetargetAction)
ActionFactory.PASTE.create(workbenchWindow));
addRetargetAction(new DeleteRetargetAction());
addRetargetAction((RetargetAction)
ActionFactory.SELECT_ALL.create(workbenchWindow));
}
public void contributeToToolBar(IToolBarManager toolBarManager) {
toolBarManager.add(new Separator());
toolBarManager.add(getAction(ActionFactory.UNDO.getId()));
toolBarManager.add(getAction(ActionFactory.REDO.getId()));
toolBarManager.add(getAction(ActionFactory.COPY.getId()));
toolBarManager.add(getAction(ActionFactory.PASTE.getId()));
toolBarManager.add(getAction(ActionFactory.DELETE.getId()));
toolBarManager.add(getAction(ActionFactory.SELECT_ALL.getId( )));
}
public void contributeToMenu(IMenuManager menuManager) {
IMenuManager editMenu =
menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_ED IT);
GEFActionConstants.addStandardActionGroups(editMenu);
editMenu.appendToGroup(GEFActionConstants.GROUP_UNDO,
getAction(ActionFactory.UNDO.getId()));
editMenu.appendToGroup(GEFActionConstants.GROUP_UNDO,
getAction(ActionFactory.REDO.getId()));
editMenu.appendToGroup(GEFActionConstants.GROUP_EDIT,
getAction(ActionFactory.COPY.getId()));
editMenu.appendToGroup(GEFActionConstants.GROUP_EDIT,
getAction(ActionFactory.PASTE.getId()));
editMenu.add(new Separator("de.tud.cs.qpe.editors.net.group.select"));
editMenu.appendToGroup("de.tud.cs.qpe.editors.net.group.select ",
getAction(ActionFactory.DELETE.getId()));
editMenu.appendToGroup("de.tud.cs.qpe.editors.net.group.select ",
getAction(ActionFactory.SELECT_ALL.getId()));
}
protected void declareGlobalActionKeys() {
addGlobalActionKey(ActionFactory.UNDO.getId());
addGlobalActionKey(ActionFactory.REDO.getId());
addGlobalActionKey(ActionFactory.COPY.getId());
addGlobalActionKey(ActionFactory.PASTE.getId());
addGlobalActionKey(ActionFactory.DELETE.getId());
addGlobalActionKey(ActionFactory.SELECT_ALL.getId());
}
public void setActivePage(IEditorPart activeEditor) {
ActionRegistry registry = (ActionRegistry)
activeEditor.getAdapter(ActionRegistry.class);
IActionBars bars = getActionBars();
for (int i = 0; i < globalActionKeys.size(); i++) {
String id = (String) globalActionKeys.get(i);
bars.setGlobalActionHandler(id, registry.getAction(id));
}
getActionBars().updateActionBars();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.14865 seconds