From e27d5967029f4f3da8889dd673ba516dcd9f3ac8 Mon Sep 17 00:00:00 2001 From: gegy1000 Date: Sun, 16 Jun 2019 23:49:25 +0200 Subject: Plugin rework along with API rework: Enigma split from EnigmaProject; plugins now provide services configurable via a profile --- .../java/cuchaz/enigma/gui/elements/MenuBar.java | 33 +++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/main/java/cuchaz/enigma/gui/elements') diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 98275b4..5578325 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -13,10 +13,11 @@ import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.jar.JarFile; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; public class MenuBar extends JMenuBar { @@ -43,17 +44,9 @@ public class MenuBar extends JMenuBar { menu.add(item); item.addActionListener(event -> { this.gui.jarFileChooser.setVisible(true); - File file = new File(this.gui.jarFileChooser.getDirectory() + File.separator + this.gui.jarFileChooser.getFile()); - if (file.exists()) { - // load the jar in a separate thread - new Thread(() -> - { - try { - gui.getController().openJar(new JarFile(file)); - } catch (IOException ex) { - throw new Error(ex); - } - }).start(); + Path path = Paths.get(this.gui.jarFileChooser.getDirectory()).resolve(this.gui.jarFileChooser.getFile()); + if (Files.exists(path)) { + gui.getController().openJar(path); } }); } @@ -106,7 +99,7 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - this.gui.getController().saveMappings(MappingFormat.ENIGMA_FILE, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); + this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.ENIGMA_FILE); this.saveMappingsMenu.setEnabled(true); } }); @@ -118,7 +111,7 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - this.gui.getController().saveMappings(MappingFormat.ENIGMA_DIRECTORY, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); + this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.ENIGMA_DIRECTORY); this.saveMappingsMenu.setEnabled(true); } }); @@ -131,7 +124,7 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - this.gui.getController().saveMappings(MappingFormat.SRG_FILE, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); + this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.SRG_FILE); this.saveMappingsMenu.setEnabled(true); } }); @@ -162,7 +155,7 @@ public class MenuBar extends JMenuBar { menu.add(item); item.addActionListener(event -> { if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile()); + this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); } }); this.exportSourceMenu = item; @@ -173,8 +166,8 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { this.gui.exportJarFileChooser.setVisible(true); if (this.gui.exportJarFileChooser.getFile() != null) { - File file = new File(this.gui.exportJarFileChooser.getDirectory() + File.separator + this.gui.exportJarFileChooser.getFile()); - this.gui.getController().exportJar(file); + Path path = Paths.get(this.gui.exportJarFileChooser.getDirectory(), this.gui.exportJarFileChooser.getFile()); + this.gui.getController().exportJar(path); } }); this.exportJarMenu = item; @@ -202,7 +195,7 @@ public class MenuBar extends JMenuBar { search.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_MASK)); menu.add(search); search.addActionListener(event -> { - if (this.gui.getController().getDeobfuscator() != null) { + if (this.gui.getController().project != null) { new SearchDialog(this.gui).show(); } }); -- cgit v1.2.3