Better Plugin Writer
This commit is contained in:
parent
9a866831c8
commit
f30714f340
1 changed files with 35 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
package the.bytecode.club.bytecodeviewer.plugin;
|
package the.bytecode.club.bytecodeviewer.plugin;
|
||||||
|
|
||||||
|
import me.konloch.kontainer.io.DiskReader;
|
||||||
import me.konloch.kontainer.io.DiskWriter;
|
import me.konloch.kontainer.io.DiskWriter;
|
||||||
import org.apache.commons.compress.utils.FileNameUtils;
|
import org.apache.commons.compress.utils.FileNameUtils;
|
||||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||||
|
@ -67,12 +68,14 @@ public class PluginWriter extends JFrame
|
||||||
|
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
JMenu menu = new TranslatedJMenu("File", Translation.FILE);
|
JMenu menu = new TranslatedJMenu("File", Translation.FILE);
|
||||||
|
JMenuItem menuOpen = new TranslatedJMenuItem("Open...", Translation.OPEN);
|
||||||
JMenuItem menuRun = new TranslatedJMenuItem("Run", Translation.RUN);
|
JMenuItem menuRun = new TranslatedJMenuItem("Run", Translation.RUN);
|
||||||
menuSaveAs = new TranslatedJMenuItem("Save As...", Translation.SAVE_AS);
|
menuSaveAs = new TranslatedJMenuItem("Save As...", Translation.SAVE_AS);
|
||||||
menuSave = new TranslatedJMenuItem("Save...", Translation.SAVE);
|
menuSave = new TranslatedJMenuItem("Save...", Translation.SAVE);
|
||||||
menuSave.setVisible(false);
|
menuSave.setVisible(false);
|
||||||
|
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
|
menu.add(menuOpen);
|
||||||
menu.add(menuSaveAs);
|
menu.add(menuSaveAs);
|
||||||
menu.add(menuSave);
|
menu.add(menuSave);
|
||||||
menu.add(menuRun);
|
menu.add(menuRun);
|
||||||
|
@ -81,6 +84,7 @@ public class PluginWriter extends JFrame
|
||||||
add(area.getScrollPane());
|
add(area.getScrollPane());
|
||||||
add(run, BorderLayout.SOUTH);
|
add(run, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
menuOpen.addActionListener((l)->openPlugin());
|
||||||
run.addActionListener((l)->runPlugin());
|
run.addActionListener((l)->runPlugin());
|
||||||
menuRun.addActionListener((l)->runPlugin());
|
menuRun.addActionListener((l)->runPlugin());
|
||||||
menuSaveAs.addActionListener((l)-> save());
|
menuSaveAs.addActionListener((l)-> save());
|
||||||
|
@ -89,6 +93,37 @@ public class PluginWriter extends JFrame
|
||||||
this.setLocationRelativeTo(null);
|
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()
|
public void runPlugin()
|
||||||
{
|
{
|
||||||
File tempFile = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + fs + pluginName);
|
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()
|
public void save()
|
||||||
{
|
{
|
||||||
Thread exportThread = new Thread(() ->
|
Thread exportThread = new Thread(() ->
|
||||||
|
|
Loading…
Reference in a new issue