summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java10
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java11
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java3
3 files changed, 18 insertions, 6 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 c46bda2e..30bf4d3e 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -17,6 +17,7 @@ import java.awt.Point;
17import java.awt.event.*; 17import java.awt.event.*;
18import java.nio.file.Path; 18import java.nio.file.Path;
19import java.util.*; 19import java.util.*;
20import java.util.concurrent.CompletableFuture;
20import java.util.function.Consumer; 21import java.util.function.Consumer;
21import java.util.function.Function; 22import java.util.function.Function;
22 23
@@ -752,9 +753,10 @@ public class Gui implements LanguageChangeListener {
752 callback.apply(response); 753 callback.apply(response);
753 } 754 }
754 755
755 public void saveMapping() { 756 public CompletableFuture<Void> saveMapping() {
756 if (this.enigmaMappingsFileChooser.getSelectedFile() != null || this.enigmaMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION) 757 if (this.enigmaMappingsFileChooser.getSelectedFile() != null || this.enigmaMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION)
757 this.controller.saveMappings(this.enigmaMappingsFileChooser.getSelectedFile().toPath()); 758 return this.controller.saveMappings(this.enigmaMappingsFileChooser.getSelectedFile().toPath());
759 return CompletableFuture.completedFuture(null);
758 } 760 }
759 761
760 public void close() { 762 public void close() {
@@ -765,8 +767,8 @@ public class Gui implements LanguageChangeListener {
765 // ask to save before closing 767 // ask to save before closing
766 showDiscardDiag((response) -> { 768 showDiscardDiag((response) -> {
767 if (response == JOptionPane.YES_OPTION) { 769 if (response == JOptionPane.YES_OPTION) {
768 this.saveMapping(); 770 this.saveMapping().thenRun(this::exit);
769 exit(); 771 // do not join, as join waits on swing to clear events
770 } else if (response == JOptionPane.NO_OPTION) { 772 } else if (response == JOptionPane.NO_OPTION) {
771 exit(); 773 exit();
772 } 774 }
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 e6f7b832..e28271e7 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java
@@ -149,6 +149,17 @@ public class GuiController implements ClientPacketHandler {
149 return saveMappings(path, loadedMappingFormat); 149 return saveMappings(path, loadedMappingFormat);
150 } 150 }
151 151
152 /**
153 * Saves the mappings, with a dialog popping up, showing the progress.
154 *
155 * <p>Notice the returned completable future has to be completed by
156 * {@link SwingUtilities#invokeLater(Runnable)}. Hence, do not try to
157 * join on the future in gui, but rather call {@code thenXxx} methods.
158 *
159 * @param path the path of the save
160 * @param format the format of the save
161 * @return the future of saving
162 */
152 public CompletableFuture<Void> saveMappings(Path path, MappingFormat format) { 163 public CompletableFuture<Void> saveMappings(Path path, MappingFormat format) {
153 if (project == null) return CompletableFuture.completedFuture(null); 164 if (project == null) return CompletableFuture.completedFuture(null);
154 165
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 a0b2a52b..61f97803 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
@@ -244,8 +244,7 @@ public class MenuBar {
244 if (this.gui.getController().isDirty()) { 244 if (this.gui.getController().isDirty()) {
245 this.gui.showDiscardDiag((response -> { 245 this.gui.showDiscardDiag((response -> {
246 if (response == JOptionPane.YES_OPTION) { 246 if (response == JOptionPane.YES_OPTION) {
247 this.gui.saveMapping(); 247 this.gui.saveMapping().thenRun(then);
248 then.run();
249 } else if (response == JOptionPane.NO_OPTION) 248 } else if (response == JOptionPane.NO_OPTION)
250 then.run(); 249 then.run();
251 return null; 250 return null;