Skip to content

Commit

Permalink
Dont depend on PreferenceConverter in ColorManager.initializeDefaults()
Browse files Browse the repository at this point in the history
This change adjusts ColorManager.initializeDefaults() to not depend on
PreferenceConverter, to prevent the creation of an SWT Display object
when in headless mode. With this change, start-up errors are avoided in
headless mode.

Fixes: #1486

Signed-off-by: Simeon Andreev <[email protected]>
  • Loading branch information
trancexpress authored and iloveeclipse committed Dec 31, 2024
1 parent 177fe6b commit c220b37
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ public static IColorManager getDefault() {
}

public static void initializeDefaults(IPreferenceStore store) {
PreferenceConverter.setDefault(store, P_DEFAULT, DEFAULT);
PreferenceConverter.setDefault(store, P_PROC_INSTR, PROC_INSTR);
PreferenceConverter.setDefault(store, P_STRING, STRING);
PreferenceConverter.setDefault(store, P_EXTERNALIZED_STRING, EXTERNALIZED_STRING);
PreferenceConverter.setDefault(store, P_TAG, TAG);
PreferenceConverter.setDefault(store, P_XML_COMMENT, XML_COMMENT);
PreferenceConverter.setDefault(store, P_HEADER_KEY, HEADER_KEY);
PreferenceConverter.setDefault(store, P_HEADER_OSGI, HEADER_OSGI);
setDefault(store, P_DEFAULT, DEFAULT);
setDefault(store, P_PROC_INSTR, PROC_INSTR);
setDefault(store, P_STRING, STRING);
setDefault(store, P_EXTERNALIZED_STRING, EXTERNALIZED_STRING);
setDefault(store, P_TAG, TAG);
setDefault(store, P_XML_COMMENT, XML_COMMENT);
setDefault(store, P_HEADER_KEY, HEADER_KEY);
setDefault(store, P_HEADER_OSGI, HEADER_OSGI);
store.setDefault(P_HEADER_OSGI + IPDEColorConstants.P_BOLD_SUFFIX, true);
PreferenceConverter.setDefault(store, P_HEADER_VALUE, HEADER_VALUE);
PreferenceConverter.setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ATTRIBUTES);
setDefault(store, P_HEADER_VALUE, HEADER_VALUE);
setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ATTRIBUTES);
store.setDefault(P_HEADER_ATTRIBUTES + IPDEColorConstants.P_ITALIC_SUFFIX, true);
PreferenceConverter.setDefault(store, P_HEADER_ASSIGNMENT, HEADER_ASSIGNMENT);
setDefault(store, P_HEADER_ASSIGNMENT, HEADER_ASSIGNMENT);
if (!PlatformUI.isWorkbenchRunning()) {
return;
}
try {
Display display = PlatformUI.getWorkbench().getDisplay();
Runnable runnable = () -> {
if (!display.isDisposed() && display.getHighContrast()) {
PreferenceConverter.setDefault(store, P_DEFAULT, DEFAULT_HIGH_CONTRAST);
PreferenceConverter.setDefault(store, P_HEADER_VALUE, HEADER_VALUE_HIGH_CONTRAST);
PreferenceConverter.setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ASSIGNMENT_HIGH_CONTRAST);
setDefault(store, P_DEFAULT, DEFAULT_HIGH_CONTRAST);
setDefault(store, P_HEADER_VALUE, HEADER_VALUE_HIGH_CONTRAST);
setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ASSIGNMENT_HIGH_CONTRAST);
}
};
if (display == Display.getCurrent()) {
Expand Down Expand Up @@ -142,4 +142,8 @@ public void handlePropertyChangeEvent(PropertyChangeEvent event) {
putColor(event.getProperty(), StringConverter.asRGB(color.toString()));
}
}

private static void setDefault(IPreferenceStore store, String name, RGB value) {
store.setDefault(name, StringConverter.asString(value));
}
}

0 comments on commit c220b37

Please sign in to comment.