From f30714f34033706786023280504c249f7c92bf22 Mon Sep 17 00:00:00 2001 From: Konloch Date: Mon, 19 Jul 2021 04:22:29 -0700 Subject: [PATCH] Better Plugin Writer --- .../bytecodeviewer/plugin/PluginWriter.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java index 6514b2b4..01ffe1d5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java @@ -1,5 +1,6 @@ package the.bytecode.club.bytecodeviewer.plugin; +import me.konloch.kontainer.io.DiskReader; import me.konloch.kontainer.io.DiskWriter; import org.apache.commons.compress.utils.FileNameUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -67,12 +68,14 @@ public class PluginWriter extends JFrame JMenuBar menuBar = new JMenuBar(); JMenu menu = new TranslatedJMenu("File", Translation.FILE); + JMenuItem menuOpen = new TranslatedJMenuItem("Open...", Translation.OPEN); JMenuItem menuRun = new TranslatedJMenuItem("Run", Translation.RUN); menuSaveAs = new TranslatedJMenuItem("Save As...", Translation.SAVE_AS); menuSave = new TranslatedJMenuItem("Save...", Translation.SAVE); menuSave.setVisible(false); menuBar.add(menu); + menu.add(menuOpen); menu.add(menuSaveAs); menu.add(menuSave); menu.add(menuRun); @@ -81,6 +84,7 @@ public class PluginWriter extends JFrame add(area.getScrollPane()); add(run, BorderLayout.SOUTH); + menuOpen.addActionListener((l)->openPlugin()); run.addActionListener((l)->runPlugin()); menuRun.addActionListener((l)->runPlugin()); menuSaveAs.addActionListener((l)-> save()); @@ -89,6 +93,37 @@ public class PluginWriter extends JFrame this.setLocationRelativeTo(null); } + public void setPluginName(String name) + { + this.pluginName = name; + setTitle("Editing BCV Plugin: " + name); + } + + public void openPlugin() + { + final File file = DialogueUtils.fileChooser("Select External Plugin", + "External Plugin", + Configuration.getLastPluginDirectory(), + PluginManager.fileFilter(), + (f)-> Configuration.lastPluginDirectory = f.getAbsolutePath(), + FileChooser.EVERYTHING); + + if(file == null || !file.exists()) + return; + + try + { + area.setText(DiskReader.loadAsString(file.getAbsolutePath())); + area.setCaretPosition(0); + } + catch (Exception e) + { + e.printStackTrace(); + } + + setSourceFile(file); + } + public void runPlugin() { File tempFile = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + fs + pluginName); @@ -115,12 +150,6 @@ public class PluginWriter extends JFrame } } - public void setPluginName(String name) - { - this.pluginName = name; - setTitle("Editing BCV Plugin: " + name); - } - public void save() { Thread exportThread = new Thread(() ->