From fa6263bf6e11293783931619461b5e88ef33f9aa Mon Sep 17 00:00:00 2001 From: Thog Date: Mon, 15 Aug 2016 13:10:09 +0200 Subject: "Close mappings" option now check if you have change your mappings and if you want to save them --- .../java/cuchaz/enigma/gui/elements/MenuBar.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (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 038698b..befe129 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -146,7 +146,30 @@ public class MenuBar extends JMenuBar { { JMenuItem item = new JMenuItem("Close Mappings"); menu.add(item); - item.addActionListener(event -> this.gui.getController().closeMappings()); + item.addActionListener(event -> { + if (this.gui.getController().isDirty()) + { + this.gui.showDiscardDiag((response -> { + if (response == JOptionPane.YES_OPTION) + { + try + { + gui.saveMapping(); + this.gui.getController().closeMappings(); + } catch (IOException e) + { + throw new Error(e); + } + } + else if (response == JOptionPane.NO_OPTION) + this.gui.getController().closeMappings(); + return null; + }), "Save and close", "Discard changes", "Cancel"); + } + else + this.gui.getController().closeMappings(); + + }); this.closeMappingsMenu = item; } menu.addSeparator(); -- cgit v1.2.3