Bug 570790 - Command icons for save/saveall not always activated
Summary: Command icons for save/saveall not always activated
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.19   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-31 09:04 EST by Wim Jongman CLA
Modified: 2021-01-31 11:01 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wim Jongman CLA 2021-01-31 09:04:52 EST
I have a situation in my mixed E4/E3 app where part.setDirty() is not activating the global save/saveall icons.

I could solve this by calling 

  IEvaluationService.requestEvaluation("activePart"); 

### Scenario
I have a stack of POJO parts that call setDirty() on the MPart whenever content changes.

When one editor is open, the part becomes *dirty, and the save buttons are activated. 

When a second editor is open, the part becomes *dirty, but the save buttons are not activated. 

Closing any *dirty part results in the normal "do you want to save?" dialog.

There is no immediate action required. I just wanted to file this in case someone else also runs into this or finds this interesting. I hope I can find some time to trace this out. 

It tried this on 4.17, 4.18, and 4.19 IBuilds
Comment 1 Thomas Wolf CLA 2021-01-31 09:40:38 EST
We've seen something similar in EGit but with "Save As..." as far back as Neon.3.

It's not just the icon. The action itself is not enabled.

Compare https://git.eclipse.org/r/c/egit/egit/+/157783/4/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java#262 , where EGit used exactly the same hack to work around this. In EGit the issue is somewhat obfuscated since it occurs in a multi-page editor that embeds a stand-alone read-only text editor, and it's not related to the dirty state.
Comment 2 Wim Jongman CLA 2021-01-31 10:50:35 EST
(In reply to Thomas Wolf from comment #1)

> https://git.eclipse.org/r/c/egit/egit/+/157783/4/org.eclipse.egit.ui/src/org/

I could feel your pain reading that comment :D  I too spent a lot of time trying to figure out how to force the update. This is how I found it:

I noticed that lose focus / get focus would update the enablement. So there was a call that could be made somewhere. 

First I worked with setDirty for a while, using MDirtyable, running it in a different thread, etc.: it was a dead end.

Then I got the MPArt and tried all methods that could possibly trigger evaluation: setvisible, setOntop, ...

When this did not work, I got the EpartService and played around with that. No luck there either.

Then I figured that a UIEvent could be sent so I examined that class and stumbled upon UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, mmm..

First I tried sending this topic myself after setDirty, but this did not work.

Then I opened the call hierarchy for this topic and found a handful of methods using it. IEvaluationService#requestEvaluation(String) seemed like a proper API to try. To find the value of the property parameter, I launched a "normal" eclipse to debug that method. When making a normal editor dirty, I saw it being called with "activePart". (in retrospect I could have found the value looking up the API usage like you probably did)

When calling this method the same way just after setting my part to dirty it finally flipped the enablement!!!
Comment 3 Thomas Wolf CLA 2021-01-31 11:01:18 EST
(In reply to Wim Jongman from comment #2)
> I could feel your pain reading that comment :D 
:-)
> (in retrospect I could have found the
> value looking up the API usage like you probably did)

No, I just figured out which class implements the handler for "Save As...", then looked at AbstractSaveHandler and found getEnabledWhenExpression(). So I knew fairly quickly what would need to be evaluated. But then I spent some time trying to figure out why "activePart" was not evaluated correctly (got nowhere), and then it took me some time to figure out the right incantation to actually get it re-evaluated.

I also thought (and still think) that explicitly re-evaluating "activePart" should never be necessary in client code.