Bug 578332

Summary: Make all supported character sets available for selection
Product: [Eclipse Project] Platform Reporter: Tobias Schmidt <tobias.schmidt24080878>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: loskutov
Version: 4.23   
Target Milestone: ---   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/189982
https://bugs.eclipse.org/bugs/show_bug.cgi?id=34421
Whiteboard:
Attachments:
Description Flags
eclipse - Text file encoding
none
eclipse - Proposed "Text file encoding" combo box none

Description Tobias Schmidt CLA 2022-01-22 20:56:42 EST
Created attachment 287878 [details]
eclipse - Text file encoding

In Eclipse one can choose from about 6 predefined character sets.
(e.g. Window->Preferences->General->Workspace->Text file encoding - also see the attachment)

However, Java supports significantly more [1], which can even be used by simply typing them (for example just enter "Cp852").

One can also expand this list using the "org.eclipse.ui.encodings" extension point.

I think that's a bit cumbersome though, so I think it would be better if one would just put all available character sets to choose from there.

[1] https://docs.oracle.com/en/java/javase/11/intl/supported-encodings.html
Comment 1 Tobias Schmidt CLA 2022-01-22 21:25:28 EST
Created attachment 287879 [details]
eclipse - Proposed "Text file encoding" combo box

I also added an image of a possible solution.
Comment 2 Andrey Loskutov CLA 2022-01-28 10:49:02 EST
Please see ancient discussion on bug 34421 why do we have a fixed list of encodings. At least one point is still valid: by adding all encodings, the combo (at least on Linux) becomes unusable.

Note: *if* we will change that, it should go to org.eclipse.ui.WorkbenchEncoding.getDefinedEncodings(), something like this:

diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/WorkbenchEncoding.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/WorkbenchEncoding.java
index d1e38f0..9940633 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/WorkbenchEncoding.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/WorkbenchEncoding.java
@@ -20,2 +20,5 @@
 import java.util.List;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
 import org.eclipse.core.runtime.IConfigurationElement;
@@ -101,4 +104,7 @@
 		}
-
-		return definedEncodings;
+		SortedMap<String, Charset> charsets = new TreeMap<>(Charset.availableCharsets());
+		Charset dummy = Charset.defaultCharset();
+		definedEncodings.forEach(e -> charsets.putIfAbsent(e, dummy));
+		Set<String> all = charsets.keySet();
+		return Collections.synchronizedList(new ArrayList<>(all));
 	}