diff options
| author | 2025-09-13 09:18:47 +0100 | |
|---|---|---|
| committer | 2025-09-13 09:18:47 +0100 | |
| commit | eca0ab1bbddcb4b9797d75a8d3d0a05b02336276 (patch) | |
| tree | 7888590928d0ed93b88930e69f0334a318fdff09 /enigma-swing | |
| parent | Provide access to the jar index in the API (diff) | |
| download | enigma-eca0ab1bbddcb4b9797d75a8d3d0a05b02336276.tar.gz enigma-eca0ab1bbddcb4b9797d75a8d3d0a05b02336276.tar.xz enigma-eca0ab1bbddcb4b9797d75a8d3d0a05b02336276.zip | |
Remove legacy mapping handling (#560)
* Remove legacy mapping handling
* Minor cleanup
* More cleanup
Diffstat (limited to 'enigma-swing')
3 files changed, 10 insertions, 56 deletions
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 1853a9fc..a2b3bd9d 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -31,7 +31,6 @@ import javax.swing.JFrame; | |||
| 31 | import javax.swing.JOptionPane; | 31 | import javax.swing.JOptionPane; |
| 32 | import javax.swing.SwingUtilities; | 32 | import javax.swing.SwingUtilities; |
| 33 | 33 | ||
| 34 | import org.jetbrains.annotations.ApiStatus; | ||
| 35 | import org.jetbrains.annotations.Nullable; | 34 | import org.jetbrains.annotations.Nullable; |
| 36 | 35 | ||
| 37 | import cuchaz.enigma.Enigma; | 36 | import cuchaz.enigma.Enigma; |
| @@ -172,12 +171,6 @@ public class GuiController implements ClientPacketHandler, GuiView, DataInvalida | |||
| 172 | this.gui.onCloseJar(); | 171 | this.gui.onCloseJar(); |
| 173 | } | 172 | } |
| 174 | 173 | ||
| 175 | @ApiStatus.Internal | ||
| 176 | public CompletableFuture<Void> openMappings(MappingFormat format, Path path, boolean useMappingIo) { | ||
| 177 | System.getProperties().setProperty("enigma.use_mappingio", useMappingIo ? "true" : "false"); | ||
| 178 | return openMappings(format, path); | ||
| 179 | } | ||
| 180 | |||
| 181 | public CompletableFuture<Void> openMappings(MappingFormat format, Path path) { | 174 | public CompletableFuture<Void> openMappings(MappingFormat format, Path path) { |
| 182 | if (project == null) { | 175 | if (project == null) { |
| 183 | return CompletableFuture.completedFuture(null); | 176 | return CompletableFuture.completedFuture(null); |
| @@ -220,12 +213,6 @@ public class GuiController implements ClientPacketHandler, GuiView, DataInvalida | |||
| 220 | return saveMappings(path, loadedMappingFormat); | 213 | return saveMappings(path, loadedMappingFormat); |
| 221 | } | 214 | } |
| 222 | 215 | ||
| 223 | @ApiStatus.Internal | ||
| 224 | public CompletableFuture<Void> saveMappings(Path path, MappingFormat format, boolean useMappingIo) { | ||
| 225 | System.getProperties().setProperty("enigma.use_mappingio", useMappingIo ? "true" : "false"); | ||
| 226 | return saveMappings(path, format); | ||
| 227 | } | ||
| 228 | |||
| 229 | /** | 216 | /** |
| 230 | * Saves the mappings, with a dialog popping up, showing the progress. | 217 | * Saves the mappings, with a dialog popping up, showing the progress. |
| 231 | * | 218 | * |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java index b9ad19e8..0ed500e3 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java | |||
| @@ -18,7 +18,6 @@ import java.nio.file.Path; | |||
| 18 | import java.nio.file.Paths; | 18 | import java.nio.file.Paths; |
| 19 | import java.util.EnumSet; | 19 | import java.util.EnumSet; |
| 20 | import java.util.List; | 20 | import java.util.List; |
| 21 | import java.util.Locale; | ||
| 22 | import java.util.Set; | 21 | import java.util.Set; |
| 23 | 22 | ||
| 24 | import joptsimple.OptionException; | 23 | import joptsimple.OptionException; |
| @@ -148,8 +147,6 @@ public class Main { | |||
| 148 | 147 | ||
| 149 | if (Files.isDirectory(mappingsPath)) { | 148 | if (Files.isDirectory(mappingsPath)) { |
| 150 | controller.openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsPath); | 149 | controller.openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsPath); |
| 151 | } else if (mappingsPath.getFileName().toString().toLowerCase(Locale.ROOT).endsWith(".zip")) { | ||
| 152 | controller.openMappings(MappingFormat.ENIGMA_ZIP, mappingsPath); | ||
| 153 | } else { | 150 | } else { |
| 154 | controller.openMappings(MappingFormat.ENIGMA_FILE, mappingsPath); | 151 | controller.openMappings(MappingFormat.ENIGMA_FILE, mappingsPath); |
| 155 | } | 152 | } |
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 02fa9e36..e8917864 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 | |||
| @@ -405,28 +405,13 @@ public class MenuBar { | |||
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { | 407 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { |
| 408 | // Mapping-IO readers | 408 | for (MappingFormat format : MappingFormat.getReadableFormats()) { |
| 409 | for (MappingFormat format : MappingFormat.values()) { | 409 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), |
| 410 | if (format.getMappingIoCounterpart() != null) { | 410 | format, openMappingsMenu, gui); |
| 411 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), | ||
| 412 | format, true, openMappingsMenu, gui); | ||
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | openMappingsMenu.addSeparator(); | ||
| 417 | |||
| 418 | // Enigma's own readers | ||
| 419 | String legacySuffix = " (" + I18n.translate("legacy") + ")"; | ||
| 420 | |||
| 421 | for (MappingFormat format : MappingFormat.values()) { | ||
| 422 | if (format.getReader() != null) { | ||
| 423 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + legacySuffix, | ||
| 424 | format, false, openMappingsMenu, gui); | ||
| 425 | } | ||
| 426 | } | 411 | } |
| 427 | } | 412 | } |
| 428 | 413 | ||
| 429 | private static void addOpenMappingsMenuEntry(String text, MappingFormat format, boolean mappingIo, JMenu openMappingsMenu, Gui gui) { | 414 | private static void addOpenMappingsMenuEntry(String text, MappingFormat format, JMenu openMappingsMenu, Gui gui) { |
| 430 | JMenuItem item = new JMenuItem(text); | 415 | JMenuItem item = new JMenuItem(text); |
| 431 | item.addActionListener(event -> { | 416 | item.addActionListener(event -> { |
| 432 | ExtensionFileFilter.setupFileChooser(gui.mappingsFileChooser, format); | 417 | ExtensionFileFilter.setupFileChooser(gui.mappingsFileChooser, format); |
| @@ -434,7 +419,7 @@ public class MenuBar { | |||
| 434 | 419 | ||
| 435 | if (gui.mappingsFileChooser.showOpenDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 420 | if (gui.mappingsFileChooser.showOpenDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 436 | File selectedFile = gui.mappingsFileChooser.getSelectedFile(); | 421 | File selectedFile = gui.mappingsFileChooser.getSelectedFile(); |
| 437 | gui.getController().openMappings(format, selectedFile.toPath(), mappingIo); | 422 | gui.getController().openMappings(format, selectedFile.toPath()); |
| 438 | UiConfig.setLastSelectedDir(gui.mappingsFileChooser.getCurrentDirectory().toString()); | 423 | UiConfig.setLastSelectedDir(gui.mappingsFileChooser.getCurrentDirectory().toString()); |
| 439 | } | 424 | } |
| 440 | }); | 425 | }); |
| @@ -442,28 +427,13 @@ public class MenuBar { | |||
| 442 | } | 427 | } |
| 443 | 428 | ||
| 444 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { | 429 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { |
| 445 | // Mapping-IO writers | 430 | for (MappingFormat format : MappingFormat.getWritableFormats()) { |
| 446 | for (MappingFormat format : MappingFormat.values()) { | 431 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), |
| 447 | if (format.hasMappingIoWriter()) { | 432 | format, saveMappingsAsMenu, saveMappingsItem, gui); |
| 448 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), | ||
| 449 | format, true, saveMappingsAsMenu, saveMappingsItem, gui); | ||
| 450 | } | ||
| 451 | } | ||
| 452 | |||
| 453 | saveMappingsAsMenu.addSeparator(); | ||
| 454 | |||
| 455 | // Enigma's own writers | ||
| 456 | String legacySuffix = " (" + I18n.translate("legacy") + ")"; | ||
| 457 | |||
| 458 | for (MappingFormat format : MappingFormat.values()) { | ||
| 459 | if (format.getWriter() != null) { | ||
| 460 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + legacySuffix, | ||
| 461 | format, false, saveMappingsAsMenu, saveMappingsItem, gui); | ||
| 462 | } | ||
| 463 | } | 433 | } |
| 464 | } | 434 | } |
| 465 | 435 | ||
| 466 | private static void addSaveMappingsAsMenuEntry(String text, MappingFormat format, boolean mappingIo, JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { | 436 | private static void addSaveMappingsAsMenuEntry(String text, MappingFormat format, JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { |
| 467 | JMenuItem item = new JMenuItem(text); | 437 | JMenuItem item = new JMenuItem(text); |
| 468 | item.addActionListener(event -> { | 438 | item.addActionListener(event -> { |
| 469 | JFileChooser fileChooser = gui.mappingsFileChooser; | 439 | JFileChooser fileChooser = gui.mappingsFileChooser; |
| @@ -475,7 +445,7 @@ public class MenuBar { | |||
| 475 | 445 | ||
| 476 | if (fileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 446 | if (fileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 477 | Path savePath = ExtensionFileFilter.getSavePath(fileChooser); | 447 | Path savePath = ExtensionFileFilter.getSavePath(fileChooser); |
| 478 | gui.getController().saveMappings(savePath, format, mappingIo); | 448 | gui.getController().saveMappings(savePath, format); |
| 479 | saveMappingsItem.setEnabled(true); | 449 | saveMappingsItem.setEnabled(true); |
| 480 | UiConfig.setLastSelectedDir(fileChooser.getCurrentDirectory().toString()); | 450 | UiConfig.setLastSelectedDir(fileChooser.getCurrentDirectory().toString()); |
| 481 | } | 451 | } |