From 498ea1d82b4a62fd86ffe9171a64acf90476e605 Mon Sep 17 00:00:00 2001 From: Konloch Date: Wed, 23 Mar 2022 14:46:17 -0500 Subject: [PATCH] Add Print Line Numbers Setting To Disassembler Resolves https://github.com/Konloch/bytecode-viewer/pull/398#discussion_r826274523 --- .../the/bytecode/club/bytecodeviewer/SettingsSerializer.java | 2 ++ .../decompilers/bytecode/InstructionPrinter.java | 5 ++++- .../the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java | 3 +++ .../bytecodeviewer/translation/TranslatedComponents.java | 3 ++- src/main/resources/translations/english.json | 3 ++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java index cc2af48c..3d9d57e7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java @@ -200,6 +200,7 @@ public class SettingsSerializer save(Configuration.python2Extra); save(Configuration.python3Extra); save(BytecodeViewer.viewer.getMinSdkVersion()); + save(BytecodeViewer.viewer.printLineNumbers.isSelected()); } catch (Exception e) { BytecodeViewer.handleException(e); } @@ -397,6 +398,7 @@ public class SettingsSerializer Configuration.python2Extra = asBoolean(139); Configuration.python3Extra = asBoolean(140); BytecodeViewer.viewer.minSdkVersionSpinner.setValue(asInt(141)); + BytecodeViewer.viewer.printLineNumbers.setSelected(asBoolean(142)); } catch (IndexOutOfBoundsException e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java index a4a82c7b..ba6e8ac5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java @@ -227,7 +227,10 @@ public class InstructionPrinter implements Opcodes { } protected String printLineNumberNode(LineNumberNode lnn) { - return "// line " + lnn.line; + if(BytecodeViewer.viewer.printLineNumbers.isSelected()) + return "// line " + lnn.line; + + return ""; } protected String printLabelNode(LabelNode label) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 6e7c60c1..d9f5ac2f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -212,6 +212,7 @@ public class MainViewerGUI extends JFrame public SettingsDialog bytecodeDecompilerSettingsDialog; public final JCheckBoxMenuItem appendBracketsToLabels = new TranslatedJCheckBoxMenuItem("Append Brackets To Labels", TranslatedComponents.APPEND_BRACKETS_TO_LABEL); public JCheckBoxMenuItem debugHelpers = new TranslatedJCheckBoxMenuItem("Debug Helpers", TranslatedComponents.DEBUG_HELPERS); + public final JCheckBoxMenuItem printLineNumbers = new TranslatedJCheckBoxMenuItem("Print Line Numbers", TranslatedComponents.PRINT_LINE_NUMBERS); //FernFlower settings public final JMenu fernFlowerSettingsSecondaryMenu = new TranslatedJMenu("FernFlower Settings", TranslatedComponents.FERNFLOWER_SETTINGS); @@ -658,6 +659,7 @@ public class MainViewerGUI extends JFrame settingsMainMenu.add(useNewSettingsDialog ? bytecodeDecompilerSettings : bytecodeDecompilerSettingsSecondaryMenu); bytecodeDecompilerSettingsSecondaryMenu.add(debugHelpers); bytecodeDecompilerSettingsSecondaryMenu.add(appendBracketsToLabels); + bytecodeDecompilerSettingsSecondaryMenu.add(printLineNumbers); bytecodeDecompilerSettingsDialog = new SettingsDialog(bytecodeDecompilerSettingsSecondaryMenu, new JPanel()); bytecodeDecompilerSettings.addActionListener((e)-> bytecodeDecompilerSettingsDialog.showDialog()); @@ -837,6 +839,7 @@ public class MainViewerGUI extends JFrame //CFIDE debugHelpers.setSelected(true); appendBracketsToLabels.setSelected(true); + printLineNumbers.setSelected(false); } public void calledAfterLoad() { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java b/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java index c8005695..a8def54e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java @@ -253,7 +253,8 @@ public enum TranslatedComponents MIN_SDK_VERSION, ANNOTATION_NAME, MATCH_CASE, - EXACT_PATH; + EXACT_PATH, PRINT_LINE_NUMBERS, + ; private final TranslatedComponentReference componentReference; diff --git a/src/main/resources/translations/english.json b/src/main/resources/translations/english.json index 0477d268..eff6d09b 100644 --- a/src/main/resources/translations/english.json +++ b/src/main/resources/translations/english.json @@ -284,5 +284,6 @@ "ANNOTATION_NAME": "Annotation Name", "MATCH_CASE": "Match Case", "EXACT_PATH": "Exact Path", - "MIN_SDK_VERSION": "Minimum SDK version" + "MIN_SDK_VERSION": "Minimum SDK version", + "PRINT_LINE_NUMBERS": "Print Line Numbers" }