Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gui): editor theme loading and error/fallback handling improved #1478

Merged
merged 2 commits into from
May 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -71,6 +72,7 @@
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -112,6 +114,7 @@
import jadx.gui.treemodel.JRoot;
import jadx.gui.ui.codearea.AbstractCodeArea;
import jadx.gui.ui.codearea.AbstractCodeContentPanel;
import jadx.gui.ui.codearea.EditorTheme;
import jadx.gui.ui.codearea.EditorViewState;
import jadx.gui.ui.dialog.ADBDialog;
import jadx.gui.ui.dialog.AboutDialog;
Expand Down Expand Up @@ -1298,15 +1301,32 @@ public void setLocationAndPosition() {
}

private void setEditorTheme(String editorThemePath) {
try {
URL themeUrl = getClass().getResource(editorThemePath);
if (themeUrl != null) {
try (InputStream is = themeUrl.openStream()) {
editorTheme = Theme.load(is);
return;
}
}
Path themePath = Paths.get(editorThemePath);
if (Files.isRegularFile(themePath)) {
try (InputStream is = Files.newInputStream(themePath)) {
editorTheme = Theme.load(is);
return;
}
}
} catch (Exception e) {
LOG.error("Failed to load editor theme: {}", editorThemePath, e);
}
LOG.warn("Falling back to default editor theme", editorThemePath);
skylot marked this conversation as resolved.
Show resolved Hide resolved
editorThemePath = EditorTheme.getDefaultTheme().getPath();
try (InputStream is = getClass().getResourceAsStream(editorThemePath)) {
editorTheme = Theme.load(is);
return;
} catch (Exception e) {
LOG.error("Can't load editor theme from classpath: {}", editorThemePath);
try (InputStream is = new FileInputStream(editorThemePath)) {
editorTheme = Theme.load(is);
} catch (Exception ex) {
LOG.error("Can't load editor theme from file: {}", editorThemePath);
}
LOG.error("Failed to load default editor theme: {}", editorThemePath, e);
editorTheme = new Theme(new RSyntaxTextArea());
}
}

Expand Down