How to listen to ActiveEditor changes and is IEditorActionDelegate deprecated? [message #328293] |
Tue, 20 May 2008 17:58  |
Eclipse User |
|
|
|
Hi,
I need help.
I have a toggle button in my editor that changes its view mode.
Originally, it was an IEditorActionDelegate, but during the migration to
eclipse3.3 I changed it to be a menu contribution connected to a command
with a handler, that works when the active editor is an instanceof my
editor. This handler is also an IElementUpdater (So I can update the
toggle button according to the editor view mode).
I want the toggle button state to be updated when moving between editors,
according to their view mode. Meaning that if one presses the button, it
changes the view mode for the active editor only (And not all editors)...
The toggle button needs to update when:
1. The active editor changes between two instances of my editor.
2. The active editor changes back from an editor that isn't my editor to
my editor. (The handler is becoming active)
3. The current editor view mode is changed, either programmatically or by
pushing my toggle button. (I have a listener in the editor for that)
2 works fine, because the handler updateElement method is called
automatically when the command handler is available once more.
1,3 are problematic.
I don't want that my editor would notify that the UIElement connected with
the command should refresh itself, because I don't my editor to know that
the button\command exist at all.
So I want to write the code in my handler.
I have done the following things in order to fix it:
1. In the updateElement I have added a listener to the page, that if the
activePart is changed, it will change the UI according to the active
editor.
2. Also, I have added the current active editor a listener to view mode
changes. I disconnect and reconnect the listener each time the active part
is cahnged (for parts that are editors). I receive the change in the
activeEditor from 1.
Now, let's move to things I wanted to ask you:
1. How to listen to active editor change? Adding an IPartListener2 to the
ActivePage is annoying because it has a lot of methods I don't need. Also
in the partActivated I must check if the part is an editor reference, to
decide if it's an active editor change, and last, I must check if the
editor has really changed, or is it just returning from one view to the
active editor. Also, what if the page will be change, do I need to
consider it too?
2. Where to put the code that adds the listener to the ActivePage in the
first place? I'm not sure that the updateElement method is the right place
(Although I can get the WorkbenchWindow thanks to IServiceLocator).
The other options are also bad:
A. The Ctor doesn't know about UI elements, so it won't fit there.
B. Execute will be called for the first time, only when the command will
be executed.
3. IEditorActionDelegate should solve everything for me, but it looks like
it is getting deprecated by the second. What do you think? Is it
deprecated? (I still remember why, I've decided to move to commands and
menu contribution - Action delegates are awful. it stinks that one needs 4
different extension points for his actions, and that he can't really use
another action delegate run method from his action delegate and also that
menu url is so much better than path, and that the idea of handlers is
better.)
|
|
|
|
Powered by
FUDForum. Page generated in 0.04717 seconds