diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index 17e1cbcfb..4fdbc68d2 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java @@ -451,6 +451,7 @@ public void onCloseJar() { public EditorPanel openClass(ClassEntry entry) { EditorPanel editorPanel = editors.computeIfAbsent(entry, e -> { + this.controller.getClassHandleProvider().setDecompilerRemoveImports(!UiConfig.shouldShowImports()); ClassHandle ch = controller.getClassHandleProvider().openClass(entry); if (ch == null) return null; EditorPanel ed = new EditorPanel(this); diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index f990f98c4..c3f8c4607 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java @@ -548,6 +548,7 @@ public void openStats(Set includedMembers, String topLevelPackage, public void setDecompiler(DecompilerService service) { if (chp != null) { chp.setDecompilerService(service); + chp.setDecompilerRemoveImports(!UiConfig.shouldShowImports()); } } diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java index 8ad6fbbed..b2bef0849 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java @@ -70,6 +70,14 @@ public static void setDecompiler(Decompiler d) { ui.data().section("Decompiler").setEnum("Current", d); } + public static boolean shouldShowImports() { + return ui.data().section("Decompiler").setIfAbsentBool("Show Imports", false); + } + + public static void setShowImports(boolean showImports) { + ui.data().section("Decompiler").setBool("Show Imports", showImports); + } + private static Color fromComponents(int rgb, double alpha) { int rgba = rgb & 0xFFFFFF | (int) (alpha * 255) << 24; return new Color(rgba, true); diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index d5d657dc1..6c9aebb39 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -50,6 +50,7 @@ public class MenuBar { private final JMenuItem exitItem = new JMenuItem(); private final JMenu decompilerMenu = new JMenu(); + private final JCheckBoxMenuItem decompilerShowImportsItem = new JCheckBoxMenuItem(); private final JMenu viewMenu = new JMenu(); private final JMenu themesMenu = new JMenu(); @@ -101,6 +102,9 @@ public MenuBar(Gui gui) { this.fileMenu.add(this.exitItem); this.ui.add(this.fileMenu); + this.decompilerMenu.addSeparator(); + this.decompilerMenu.add(this.decompilerShowImportsItem); + this.decompilerShowImportsItem.setSelected(UiConfig.shouldShowImports()); this.ui.add(this.decompilerMenu); this.viewMenu.add(this.themesMenu); @@ -134,6 +138,7 @@ public MenuBar(Gui gui) { this.exportJarItem.addActionListener(_e -> this.onExportJarClicked()); this.statsItem.addActionListener(_e -> StatsDialog.show(this.gui)); this.exitItem.addActionListener(_e -> this.gui.close()); + this.decompilerShowImportsItem.addActionListener(_e -> this.onSourceSettingsClicked()); this.customScaleItem.addActionListener(_e -> this.onCustomScaleClicked()); this.fontItem.addActionListener(_e -> this.onFontClicked(this.gui)); this.searchItem.addActionListener(_e -> this.onSearchClicked()); @@ -181,6 +186,7 @@ public void retranslateUi() { this.exitItem.setText(I18n.translate("menu.file.exit")); this.decompilerMenu.setText(I18n.translate("menu.decompiler")); + this.decompilerShowImportsItem.setText(I18n.translate("menu.decompiler.show_imports")); this.viewMenu.setText(I18n.translate("menu.view")); this.themesMenu.setText(I18n.translate("menu.view.themes")); @@ -268,6 +274,10 @@ private void onExportJarClicked() { } } + private void onSourceSettingsClicked() { + UiConfig.setShowImports(this.decompilerShowImportsItem.isSelected()); + } + private void onCustomScaleClicked() { String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), JOptionPane.QUESTION_MESSAGE, null, null, Float.toString(ScaleUtil.getScaleFactor() * 100)); diff --git a/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java b/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java index f56e908d9..2efeff9c1 100644 --- a/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java +++ b/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java @@ -86,6 +86,16 @@ public DecompilerService getDecompilerService() { return ds; } + /** + * Sets the source settings of the decompiler to new source settings, + * with the provided {@code removeImports} setting. + * + * @param removeImports whether imports should be removed when decompiling + */ + public void setDecompilerRemoveImports(boolean removeImports) { + this.decompiler.setSourceSettings(new SourceSettings(removeImports, true)); + } + private Decompiler createDecompiler() { return ds.create(new CachingClassProvider(new ObfuscationFixClassProvider(project.getClassProvider(), project.getJarIndex())), new SourceSettings(true, true)); } diff --git a/enigma/src/main/java/cuchaz/enigma/source/Decompiler.java b/enigma/src/main/java/cuchaz/enigma/source/Decompiler.java index 938a73627..51446f512 100644 --- a/enigma/src/main/java/cuchaz/enigma/source/Decompiler.java +++ b/enigma/src/main/java/cuchaz/enigma/source/Decompiler.java @@ -10,4 +10,6 @@ default Source getSource(String className) { } Source getSource(String className, @Nullable EntryRemapper remapper); + + void setSourceSettings(SourceSettings settings); } diff --git a/enigma/src/main/java/cuchaz/enigma/source/cfr/CfrDecompiler.java b/enigma/src/main/java/cuchaz/enigma/source/cfr/CfrDecompiler.java index ffc4788c1..a4f59d38e 100644 --- a/enigma/src/main/java/cuchaz/enigma/source/cfr/CfrDecompiler.java +++ b/enigma/src/main/java/cuchaz/enigma/source/cfr/CfrDecompiler.java @@ -30,7 +30,7 @@ public class CfrDecompiler implements Decompiler { private final DCCommonState state; // cfr doesn't add final on params so final setting is ignored - private final SourceSettings settings; + private SourceSettings settings; public CfrDecompiler(ClassProvider classProvider, SourceSettings sourceSettings) { Map options = new HashMap<>(); @@ -100,4 +100,9 @@ public Source getSource(String className, @Nullable EntryRemapper mapper) { tree.analyseTop(state, typeUsageCollector); return new CfrSource(settings, tree, state, typeUsageCollector.getRealTypeUsageInformation(), options, mapper); } + + @Override + public void setSourceSettings(SourceSettings settings) { + this.settings = settings; + } } diff --git a/enigma/src/main/java/cuchaz/enigma/source/procyon/ProcyonDecompiler.java b/enigma/src/main/java/cuchaz/enigma/source/procyon/ProcyonDecompiler.java index bc3d07255..948430a84 100644 --- a/enigma/src/main/java/cuchaz/enigma/source/procyon/ProcyonDecompiler.java +++ b/enigma/src/main/java/cuchaz/enigma/source/procyon/ProcyonDecompiler.java @@ -22,7 +22,7 @@ import org.objectweb.asm.tree.ClassNode; public class ProcyonDecompiler implements Decompiler { - private final SourceSettings settings; + private SourceSettings settings; private final DecompilerSettings decompilerSettings; private final MetadataSystem metadataSystem; @@ -94,6 +94,11 @@ public Source getSource(String className, @Nullable EntryRemapper remapper) { return new ProcyonSource(source, decompilerSettings); } + @Override + public void setSourceSettings(SourceSettings settings) { + this.settings = settings; + } + private static boolean getSystemPropertyAsBoolean(String property, boolean defValue) { String value = System.getProperty(property); return value == null ? defValue : Boolean.parseBoolean(value); diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index 8195bb1f8..557a0a08b 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json @@ -32,6 +32,7 @@ "menu.file.stats.generate": "Generate Diagram", "menu.file.exit": "Exit", "menu.decompiler": "Decompiler", + "menu.decompiler.show_imports": "Show imports", "menu.view": "View", "menu.view.themes": "Themes", "menu.view.themes.default": "Default", diff --git a/enigma/src/main/resources/lang/fr_fr.json b/enigma/src/main/resources/lang/fr_fr.json index 43bea4de5..c77ff94a4 100644 --- a/enigma/src/main/resources/lang/fr_fr.json +++ b/enigma/src/main/resources/lang/fr_fr.json @@ -32,6 +32,7 @@ "menu.file.stats.generate": "Générer le diagramme", "menu.file.exit": "Quitter", "menu.decompiler": "Décompilateur", + "menu.decompiler.show_imports": "Afficher les importations", "menu.view": "Affichage", "menu.view.themes": "Thèmes", "menu.view.themes.default": "Par défaut",