Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to listen to ActiveEditor changes and is IEditorActionDelegate deprecated?
How to listen to ActiveEditor changes and is IEditorActionDelegate deprecated? [message #328293] Tue, 20 May 2008 21:58 Go to next message
Kobi Perl is currently offline Kobi PerlFriend
Messages: 7
Registered: July 2009
Junior Member
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.)
Re: How to listen to ActiveEditor changes and is IEditorActionDelegate deprecated? [message #328920 is a reply to message #328293] Fri, 06 June 2008 17:53 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Once you have the listener, you can simply have it call
org.eclipse.ui.commands.ICommandService.refreshElements(Stri ng, Map)

That will eventually call into your updateElement(*) method.

As for the where ... you could have it lazily done in your bundle
activator. i.e. in your handler updateElement(*) method:
Activator.getDefault().activateListener();

where the code simply registers the listener on the first call and
becomes a no-op after that.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Programatically Fire a Selection Event
Next Topic:Enabling Handlers based on Perspective
Goto Forum:
  


Current Time: Thu Aug 08 12:22:21 GMT 2024

Powered by FUDForum. Page generated in 0.02988 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top