Adding a close listener and validating with user if the file has changed. #117.

This commit is contained in:
Rob Greene 2023-10-20 16:58:33 -05:00
parent e3a0844fbd
commit c9dcb73b33
2 changed files with 9 additions and 0 deletions

View File

@ -41,6 +41,7 @@ public class ByteArrayImageLayout {
*/ */
public ByteArrayImageLayout(byte[] diskImage) { public ByteArrayImageLayout(byte[] diskImage) {
setDiskImage(diskImage); setDiskImage(diskImage);
changed = false; // setDiskImage by default sets to true but we don't want that
} }
/** /**

View File

@ -19,6 +19,7 @@
*/ */
package com.webcodepro.applecommander.ui.swt; package com.webcodepro.applecommander.ui.swt;
import com.webcodepro.applecommander.ui.swt.util.SwtUtil;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
@ -74,6 +75,13 @@ public class DiskWindow {
dispose(event); dispose(event);
} }
}); });
shell.addListener(SWT.Close, (event) -> {
if (disks[0].hasChanged()) {
int button = SwtUtil.showYesNoDialog(shell, "Are you sure?",
"The disk has been modified. Are you certain you want to quit?");
event.doit = button == SWT.YES;
}
});
CTabFolder tabFolder = new CTabFolder(shell, SWT.BOTTOM); CTabFolder tabFolder = new CTabFolder(shell, SWT.BOTTOM);
new DiskExplorerTab(tabFolder, disks, imageManager, this); new DiskExplorerTab(tabFolder, disks, imageManager, this);