Auto-clear persisted workbench state when Eclipse is launched with a different locale#4166
Conversation
|
@merks : When you get some time, can you review this please? |
merks
left a comment
There was a problem hiding this comment.
I think the whole thing could be cleaner and more "modern" if you use Path/Files instead of File.
| } | ||
| } catch (IOException e) { | ||
| // Cannot read - safe to skip, don't trigger clear | ||
| return false; |
There was a problem hiding this comment.
If this occurs for whatever reason that the file will never be written.
There was a problem hiding this comment.
Good catch. Replaced return false with localeChanged = true so that execution falls through to the write block regardless - meaning a corrupt or unreadable file gets repaired or recreated on the same launch rather than staying broken indefinitely.
| boolean localeChanged = false; | ||
|
|
||
| // Read previously saved locale if file exists | ||
| if (nlFile.exists()) { |
There was a problem hiding this comment.
It's a nit, but if it's a directory it also exists.
There was a problem hiding this comment.
Fixed. Changed nlFile.exists() to Files.isRegularFile() which returns true only for actual regular files, correctly excluding directories and anything else that isn't a plain file.
| return false; | ||
| } | ||
|
|
||
| File stateDir = new File(instanceLocation.getURL().getFile(), ".metadata" + File.separator //$NON-NLS-1$ |
There was a problem hiding this comment.
If you used Path you could use resolve and wouldn't need to do all the file separator logic...
There was a problem hiding this comment.
Done. Replaced File with Path.of(instanceLocation.getURL().toURI()) and chained .resolve() calls for each path segment - no more manual File.separator concatenation.
|
@merks : Updated the fix now, can you take a look once you get some time please. |
merks
left a comment
There was a problem hiding this comment.
Yes, that looks nice! Thank you!!
Thanks alot for the quick review :) |
The Problem
When Eclipse is launched with -nl and the workspace already has a persisted workbench.xmi from a previous session in a different language, the UI starts up showing stale labels - view tabs like Declaration, Problems and Javadoc remain in the old language until the user manually clicks on each tab. The only workaround today is launching with -clearPersistedState, which throws away the entire workbench layout every time.
Fixes #3108
Root Cause
Eclipse caches view labels and other UI strings directly in workbench.xmi at shutdown. On the next launch, these cached values are rendered before the NL bundles have a chance to supply the correct translated strings. Since nothing was comparing the current locale against the one used in the previous session, stale labels went undetected.
Fix in-detail
A single new private method - hasNlChanged() - is introduced in E4Application. On each startup it does three things:
If the locale is unchanged, or if this is the first ever launch, nothing happens - the user's layout is fully preserved.
What Changes
<workspace>/.metadata/.plugins/org.eclipse.e4.workbench/at first launch, updated on each locale changeNo new dependencies. No schema changes. No impact on the common single-locale case(except that locale is being saved now).
Notes
Without Fix
With Fix