This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 386292 - IEvaluationContext.getVariable(ISources.ACTIVE_EDITOR_ID_NAME) returns nothing if active editor has not focus
Summary: IEvaluationContext.getVariable(ISources.ACTIVE_EDITOR_ID_NAME) returns nothin...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.2.2   Edit
Assignee: Michael Rennie CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-31 04:40 EDT by Tobias Melcher CLA
Modified: 2013-01-17 13:51 EST (History)
6 users (show)

See Also:


Attachments
Sample project showing the issue (4.82 KB, application/x-zip-compressed)
2012-10-12 11:28 EDT, Dobrin Alexiev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Melcher CLA 2012-07-31 04:40:32 EDT
Version: 4.2.0
Build id: I20120608-1400

Hi colleagues,

in eclipse 4.2, the call org.eclipse.core.expressions.IEvaluationContext.getVariable(ISources.ACTIVE_EDITOR_ID_NAME) doesn't return the editorId as String when the active visible editor has not the focus. This is an incompatible change compared to eclipse 3.7 and makes a problem for following case:

- add an eclipse main toolbar menu contribution and use the "with variable=activePart" mechanism to define the visibility of the toolbar entry. Here an example:
<menuContribution
  allPopups="true"
  locationURI="toolbar:myToolbar">
  <command commandId="myCommandId"
           icon="icons/myicon.gif"
           label="%command.label"
           style="push">
     <visibleWhen>
        <iterate operator="or">
           <with variable="activePart">
             <instanceof value="myEditorId">
             </instanceof>
          </with>
        </iterate>
     </visibleWhen>
  </command>
</menuContribution>

The toolbar entry gets visible when editor with id "myEditorId" is opened. If this editor now brings up a popup dialog or a progress dialog (by starting an eclipse ui job), then the toolbar menu item immediately disappears and appears again when the dialog is closed. The toolbar now starts flickering when a progress monitor dialog is opened for a short timeframe. 

Is this incompatible change of IEvaluationContext.getVariable(ISources.ACTIVE_EDITOR_ID_NAME) intended? 
Is there another option to define a toolbar menu contribution which is always then visible when a specified editor is visible whithout having the focus?

With best regards,
Tobias
Comment 1 Paul Webster CLA 2012-08-10 14:46:24 EDT
(In reply to comment #0)
> - add an eclipse main toolbar menu contribution and use the "with
> variable=activePart" mechanism to define the visibility of the toolbar
> entry. Here an example:
> <menuContribution
>   allPopups="true"
>   locationURI="toolbar:myToolbar">
>   <command commandId="myCommandId"
>            icon="icons/myicon.gif"
>            label="%command.label"
>            style="push">
>      <visibleWhen>
>         <iterate operator="or">
>            <with variable="activePart">
>              <instanceof value="myEditorId">
>              </instanceof>
>           </with>
>         </iterate>
>      </visibleWhen>
>   </command>
> </menuContribution>
> 

Could you please update your example?  Above, you're asking for the activePart, which is an instance of IWorkbenchPart.  From there, your instanceof wouldn't be related to an ID, but to the part implementation class name.

PW
Comment 2 Dobrin Alexiev CLA 2012-10-12 11:27:02 EDT
Here is another use case that exposes this problem we believe. 

What I want to achieve with this example (MyPlugin2):
1. Add multiple actions ( menus and toolbars ) and only make them visible in my perspectives. 
2. My users to be able to easily hide or show all my actions if they are not planning to use them.

How I made it ( and it worked in Eclipse 3.8). 
1. I contributed a action set "myplugin2.myActionSet" that is not visible - I want my actions to be visible only in my perspective. 
2. I contributed a perspective "myplugin2.perspective1" and added “myplugin2.myActionSet” to my perspective. 
3. I contributed a menu item and a toolbar and made them visible when the active context had "myplugin2.myActionSet" in it. 

When I run Eclipse 4.x with my plugin my actions appear only in my perspective. 
If I open a model dialog in my perspective my actions disappear, that creates lots of flickering.
Comment 3 Dobrin Alexiev CLA 2012-10-12 11:28:46 EDT
Created attachment 222235 [details]
Sample project showing the issue
Comment 4 Paul Webster CLA 2013-01-11 14:14:36 EST
This has been fixed in the latest M builds for 4.2.2

PW
Comment 5 Tobias Melcher CLA 2013-01-14 12:21:31 EST
Thanks a lot for providing the fix. It solves my problem.
Comment 6 Paul Elder CLA 2013-01-17 13:51:19 EST
Verified in 4.2.2 (M20130116-1800)