diff options
| author | 2020-07-06 18:48:36 +0200 | |
|---|---|---|
| committer | 2020-07-06 12:48:36 -0400 | |
| commit | 57af19a99b2c7358d78f102b91482b2073126881 (patch) | |
| tree | c61f16b670a4ee9eed736b38cb7351900587a166 /enigma-swing/src/main/java/cuchaz | |
| parent | Fix crash on remapping [T (#261) (diff) | |
| download | enigma-57af19a99b2c7358d78f102b91482b2073126881.tar.gz enigma-57af19a99b2c7358d78f102b91482b2073126881.tar.xz enigma-57af19a99b2c7358d78f102b91482b2073126881.zip | |
Add menu entry to reload jar & mappings from disk (#263)
* Add button to reload jar & mappings from disk
* Disable menu entry when currently loading
* Add menu entry that reloads mappings only
* Remove duplicate user query code
Diffstat (limited to 'enigma-swing/src/main/java/cuchaz')
3 files changed, 47 insertions, 5 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index ec68d0df..8f105058 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -393,7 +393,6 @@ public class Gui { | |||
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | public void onCloseJar() { | 395 | public void onCloseJar() { |
| 396 | |||
| 397 | // update gui | 396 | // update gui |
| 398 | this.frame.setTitle(Enigma.NAME); | 397 | this.frame.setTitle(Enigma.NAME); |
| 399 | setObfClasses(null); | 398 | setObfClasses(null); |
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 124ad07e..2f5e5e1e 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -178,6 +178,28 @@ public class GuiController implements ClientPacketHandler { | |||
| 178 | chp.invalidateMapped(); | 178 | chp.invalidateMapped(); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | public void reloadAll() { | ||
| 182 | Path jarPath = this.project.getJarPath(); | ||
| 183 | MappingFormat loadedMappingFormat = this.loadedMappingFormat; | ||
| 184 | Path loadedMappingPath = this.loadedMappingPath; | ||
| 185 | if (jarPath != null) { | ||
| 186 | this.closeJar(); | ||
| 187 | CompletableFuture<Void> f = this.openJar(jarPath); | ||
| 188 | if (loadedMappingFormat != null && loadedMappingPath != null) { | ||
| 189 | f.whenComplete((v, t) -> this.openMappings(loadedMappingFormat, loadedMappingPath)); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | public void reloadMappings() { | ||
| 195 | MappingFormat loadedMappingFormat = this.loadedMappingFormat; | ||
| 196 | Path loadedMappingPath = this.loadedMappingPath; | ||
| 197 | if (loadedMappingFormat != null && loadedMappingPath != null) { | ||
| 198 | this.closeMappings(); | ||
| 199 | this.openMappings(loadedMappingFormat, loadedMappingPath); | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 181 | public CompletableFuture<Void> dropMappings() { | 203 | public CompletableFuture<Void> dropMappings() { |
| 182 | if (project == null) return CompletableFuture.completedFuture(null); | 204 | if (project == null) return CompletableFuture.completedFuture(null); |
| 183 | 205 | ||
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 768bc410..d6c60e04 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 | |||
| @@ -40,6 +40,8 @@ public class MenuBar { | |||
| 40 | private final JMenu saveMappingsAsMenu = new JMenu(I18n.translate("menu.file.mappings.save_as")); | 40 | private final JMenu saveMappingsAsMenu = new JMenu(I18n.translate("menu.file.mappings.save_as")); |
| 41 | private final JMenuItem closeMappingsItem = new JMenuItem(I18n.translate("menu.file.mappings.close")); | 41 | private final JMenuItem closeMappingsItem = new JMenuItem(I18n.translate("menu.file.mappings.close")); |
| 42 | private final JMenuItem dropMappingsItem = new JMenuItem(I18n.translate("menu.file.mappings.drop")); | 42 | private final JMenuItem dropMappingsItem = new JMenuItem(I18n.translate("menu.file.mappings.drop")); |
| 43 | private final JMenuItem reloadMappingsItem = new JMenuItem(I18n.translate("menu.file.reload_mappings")); | ||
| 44 | private final JMenuItem reloadAllItem = new JMenuItem(I18n.translate("menu.file.reload_all")); | ||
| 43 | private final JMenuItem exportSourceItem = new JMenuItem(I18n.translate("menu.file.export.source")); | 45 | private final JMenuItem exportSourceItem = new JMenuItem(I18n.translate("menu.file.export.source")); |
| 44 | private final JMenuItem exportJarItem = new JMenuItem(I18n.translate("menu.file.export.jar")); | 46 | private final JMenuItem exportJarItem = new JMenuItem(I18n.translate("menu.file.export.jar")); |
| 45 | private final JMenuItem statsItem = new JMenuItem(I18n.translate("menu.file.stats")); | 47 | private final JMenuItem statsItem = new JMenuItem(I18n.translate("menu.file.stats")); |
| @@ -83,6 +85,9 @@ public class MenuBar { | |||
| 83 | this.fileMenu.add(this.closeMappingsItem); | 85 | this.fileMenu.add(this.closeMappingsItem); |
| 84 | this.fileMenu.add(this.dropMappingsItem); | 86 | this.fileMenu.add(this.dropMappingsItem); |
| 85 | this.fileMenu.addSeparator(); | 87 | this.fileMenu.addSeparator(); |
| 88 | this.fileMenu.add(this.reloadMappingsItem); | ||
| 89 | this.fileMenu.add(this.reloadAllItem); | ||
| 90 | this.fileMenu.addSeparator(); | ||
| 86 | this.fileMenu.add(this.exportSourceItem); | 91 | this.fileMenu.add(this.exportSourceItem); |
| 87 | this.fileMenu.add(this.exportJarItem); | 92 | this.fileMenu.add(this.exportJarItem); |
| 88 | this.fileMenu.addSeparator(); | 93 | this.fileMenu.addSeparator(); |
| @@ -117,6 +122,8 @@ public class MenuBar { | |||
| 117 | this.saveMappingsItem.addActionListener(_e -> this.onSaveMappingsClicked()); | 122 | this.saveMappingsItem.addActionListener(_e -> this.onSaveMappingsClicked()); |
| 118 | this.closeMappingsItem.addActionListener(_e -> this.onCloseMappingsClicked()); | 123 | this.closeMappingsItem.addActionListener(_e -> this.onCloseMappingsClicked()); |
| 119 | this.dropMappingsItem.addActionListener(_e -> this.gui.getController().dropMappings()); | 124 | this.dropMappingsItem.addActionListener(_e -> this.gui.getController().dropMappings()); |
| 125 | this.reloadMappingsItem.addActionListener(_e -> this.onReloadMappingsClicked()); | ||
| 126 | this.reloadAllItem.addActionListener(_e -> this.onReloadAllClicked()); | ||
| 120 | this.exportSourceItem.addActionListener(_e -> this.onExportSourceClicked()); | 127 | this.exportSourceItem.addActionListener(_e -> this.onExportSourceClicked()); |
| 121 | this.exportJarItem.addActionListener(_e -> this.onExportJarClicked()); | 128 | this.exportJarItem.addActionListener(_e -> this.onExportJarClicked()); |
| 122 | this.statsItem.addActionListener(_e -> StatsDialog.show(this.gui)); | 129 | this.statsItem.addActionListener(_e -> StatsDialog.show(this.gui)); |
| @@ -143,6 +150,8 @@ public class MenuBar { | |||
| 143 | this.saveMappingsItem.setEnabled(jarOpen && this.gui.enigmaMappingsFileChooser.getSelectedFile() != null && connectionState != ConnectionState.CONNECTED); | 150 | this.saveMappingsItem.setEnabled(jarOpen && this.gui.enigmaMappingsFileChooser.getSelectedFile() != null && connectionState != ConnectionState.CONNECTED); |
| 144 | this.saveMappingsAsMenu.setEnabled(jarOpen); | 151 | this.saveMappingsAsMenu.setEnabled(jarOpen); |
| 145 | this.closeMappingsItem.setEnabled(jarOpen); | 152 | this.closeMappingsItem.setEnabled(jarOpen); |
| 153 | this.reloadMappingsItem.setEnabled(jarOpen); | ||
| 154 | this.reloadAllItem.setEnabled(jarOpen); | ||
| 146 | this.exportSourceItem.setEnabled(jarOpen); | 155 | this.exportSourceItem.setEnabled(jarOpen); |
| 147 | this.exportJarItem.setEnabled(jarOpen); | 156 | this.exportJarItem.setEnabled(jarOpen); |
| 148 | this.statsItem.setEnabled(jarOpen); | 157 | this.statsItem.setEnabled(jarOpen); |
| @@ -169,21 +178,33 @@ public class MenuBar { | |||
| 169 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); | 178 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); |
| 170 | } | 179 | } |
| 171 | 180 | ||
| 172 | private void onCloseMappingsClicked() { | 181 | private void openMappingsDiscardPrompt(Runnable then) { |
| 173 | if (this.gui.getController().isDirty()) { | 182 | if (this.gui.getController().isDirty()) { |
| 174 | this.gui.showDiscardDiag((response -> { | 183 | this.gui.showDiscardDiag((response -> { |
| 175 | if (response == JOptionPane.YES_OPTION) { | 184 | if (response == JOptionPane.YES_OPTION) { |
| 176 | this.gui.saveMapping(); | 185 | this.gui.saveMapping(); |
| 177 | this.gui.getController().closeMappings(); | 186 | then.run(); |
| 178 | } else if (response == JOptionPane.NO_OPTION) | 187 | } else if (response == JOptionPane.NO_OPTION) |
| 179 | this.gui.getController().closeMappings(); | 188 | then.run(); |
| 180 | return null; | 189 | return null; |
| 181 | }), I18n.translate("prompt.close.save"), I18n.translate("prompt.close.discard"), I18n.translate("prompt.close.cancel")); | 190 | }), I18n.translate("prompt.close.save"), I18n.translate("prompt.close.discard"), I18n.translate("prompt.close.cancel")); |
| 182 | } else { | 191 | } else { |
| 183 | this.gui.getController().closeMappings(); | 192 | then.run(); |
| 184 | } | 193 | } |
| 185 | } | 194 | } |
| 186 | 195 | ||
| 196 | private void onCloseMappingsClicked() { | ||
| 197 | openMappingsDiscardPrompt(() -> this.gui.getController().closeMappings()); | ||
| 198 | } | ||
| 199 | |||
| 200 | private void onReloadMappingsClicked() { | ||
| 201 | openMappingsDiscardPrompt(() -> this.gui.getController().reloadMappings()); | ||
| 202 | } | ||
| 203 | |||
| 204 | private void onReloadAllClicked() { | ||
| 205 | openMappingsDiscardPrompt(() -> this.gui.getController().reloadAll()); | ||
| 206 | } | ||
| 207 | |||
| 187 | private void onExportSourceClicked() { | 208 | private void onExportSourceClicked() { |
| 188 | if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 209 | if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 189 | this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); | 210 | this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); |