From 0a8c7063f948d32857b90842a609fc5425e8cbcd Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 6 Sep 2024 18:15:01 +0200 Subject: [PATCH] fix: registering CSS theme via UI fails --- .../preferences/ThemePreferencePage.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index 19569bb66..b8ed42852 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -165,14 +165,20 @@ protected void createButtons() { final var themePath = Path.of(res); final var themeFileName = themePath.getFileName().toString(); try { - final var rawTheme = RawThemeReader.readTheme(IThemeSource.fromFile(themePath)); - final var rawThemeName = rawTheme.getName(); - final String name = rawThemeName == null - ? themeFileName.substring(0, themeFileName.lastIndexOf('.')) - : rawThemeName; - return new Theme(name, themePath.toAbsolutePath().toString(), name, false); + final String themeName; + if (themeFileName.endsWith(".css")) { + themeName = themeFileName.substring(0, themeFileName.lastIndexOf('.')); + } else { + final var rawTheme = RawThemeReader.readTheme(IThemeSource.fromFile(themePath)); + final var rawThemeName = rawTheme.getName(); + themeName = rawThemeName == null + ? themeFileName.substring(0, themeFileName.lastIndexOf('.')) + : rawThemeName; + } + return new Theme(themeName, themePath.toAbsolutePath().toString(), themeName, false); } catch (final Exception ex) { MessageDialog.openError(getShell(), "Invalid theme file", "Failed to parse [" + themePath + "]: " + ex); + TMUIPlugin.logError(ex); return null; }