Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » MultiPageEditorActionBarContributor - setGlobalActionHandler not working
MultiPageEditorActionBarContributor - setGlobalActionHandler not working [message #335034] Wed, 18 March 2009 00:39 Go to next message
Matt Gray is currently offline Matt Gray
Messages: 13
Registered: July 2009
Junior Member
I've implemented a multipage editor, which has two pages. The first page
has a TextEditor, and the second page has my own custom EditorPart
subclass (called 'SampleView' for want of a better name).

I've set up a MultiPageEditorActionBarContributor subclass to switch the
global action handlers when setActivePage() is called.

For actions such as copy, paste, delete, etc, the 'Edit' menu of the
workbench works correctly - the commands are handled by the actions that I
set in setActivePage(). However, the key bindings are broken - it seems
that they are stuck bound to the text editor.

e.g. if I have my custom editor visible, and select the 'Delete' command
from the edit menu, the delete action is called in my editor. But if I
press the 'delete' key on the keyboard, a character is deleted from the
invisible text editor.

Here's my code for setActivePage(). I can't see why it would be
correctly setting the menu items, but not the corresponding key bindings.
Any help appreciated.

(As an aside, I started with my editor outside the multipage editor
structure, and was using setGlobalActionHandler() successfully to set key
bindings for delete, copy, paste, etc. It's only since putting it inside
a multipage editor and using MultiPageEditorActionBarContributor that it
has gone funny).

public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;

activeEditorPart = part;

IActionBars actionBars = getActionBars();
if (actionBars != null) {

if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part ;

actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(),
getAction(editor, ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(),
getAction(editor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(
ActionFactory.REDO.getId(),
getAction(editor, ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(),
getAction(editor, ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(),
getAction(editor, ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(),
getAction(editor, ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(),
getAction(editor, ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(
ActionFactory.FIND.getId(),
getAction(editor, ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(
IDEActionFactory.BOOKMARK.getId(),
getAction(editor, IDEActionFactory.BOOKMARK.getId()));
actionBars.updateActionBars();

} else if (part instanceof SampleView) {

SampleView editor = (SampleView) part;

actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(),
getAction(editor, "delete"));
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(),
getAction(editor, "undo"));
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(),
getAction(editor, "cut"));
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(),
getAction(editor, "copy"));
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(),
getAction(editor, "paste"));

actionBars.updateActionBars();

editor.setDrawingType(drawingType);

}
}
}
Re: MultiPageEditorActionBarContributor - setGlobalActionHandler not working [message #335100 is a reply to message #335034] Sun, 22 March 2009 20:27 Go to previous messageGo to next message
Matt Gray is currently offline Matt Gray
Messages: 13
Registered: July 2009
Junior Member
In answer to my own question...

Putting the following line anywhere in the initialisation of my EditorPart
subclass fixes the problem:

getEditorSite().getKeyBindingService();


It seems that the text editor will steal the key binding service, but
putting this call in your own editor stops this from happening.
Re: MultiPageEditorActionBarContributor - setGlobalActionHandler not working [message #538784 is a reply to message #335100] Tue, 08 June 2010 11:44 Go to previous message
John is currently offline John
Messages: 3
Registered: June 2010
Location: UK
Junior Member
Matt,

I would like to be able to switch between FDT and Flash Builder key mappings - two products that edit ActionScript. Did you have any success at switching between graphics editor and text editor key mappings?



John
Previous Topic:Starting Equinox OSGI environment
Next Topic:Where to find feature groups for all Ganymede projects (Ganymede p2 repo)?
Goto Forum:
  


Current Time: Wed Apr 16 03:26:14 EDT 2014

Powered by FUDForum. Page generated in 0.02898 seconds