mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Better unsaved warning message
This commit is contained in:
+3
@@ -1,5 +1,6 @@
|
|||||||
package org.diylc.core;
|
package org.diylc.core;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -35,4 +36,6 @@ public interface IView {
|
|||||||
int showConfirmDialog(String message, String title, int optionType, int messageType);
|
int showConfirmDialog(String message, String title, int optionType, int messageType);
|
||||||
|
|
||||||
boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties);
|
boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties);
|
||||||
|
|
||||||
|
File promptFileSave();
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-8
@@ -8,6 +8,7 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.dnd.DnDConstants;
|
import java.awt.dnd.DnDConstants;
|
||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.io.File;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -246,12 +247,22 @@ public class Presenter implements IPlugInPort {
|
|||||||
@Override
|
@Override
|
||||||
public boolean allowFileAction() {
|
public boolean allowFileAction() {
|
||||||
if (projectFileManager.isModified()) {
|
if (projectFileManager.isModified()) {
|
||||||
int response = view
|
int response = view.showConfirmDialog(
|
||||||
.showConfirmDialog(
|
"There are unsaved changes. Would you like to save them?",
|
||||||
"There are unsaved changes. Are you sure you want to abandon these changes?",
|
"Warning", IView.YES_NO_CANCEL_OPTION,
|
||||||
"Warning", IView.YES_NO_OPTION,
|
IView.WARNING_MESSAGE);
|
||||||
IView.WARNING_MESSAGE);
|
if (response == IView.YES_OPTION) {
|
||||||
return response == IView.YES_OPTION;
|
if (this.getCurrentFileName() == null) {
|
||||||
|
File file = view.promptFileSave();
|
||||||
|
if (file == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
saveProjectToFile(file.getAbsolutePath(), false);
|
||||||
|
} else {
|
||||||
|
saveProjectToFile(this.getCurrentFileName(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response != IView.CANCEL_OPTION;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -912,7 +923,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
int dx = (scaledPoint.x - previousDragPoint.x);
|
int dx = (scaledPoint.x - previousDragPoint.x);
|
||||||
int dy = (scaledPoint.y - previousDragPoint.y);
|
int dy = (scaledPoint.y - previousDragPoint.y);
|
||||||
|
|
||||||
Point actualD = moveSelectedComponents(this.controlPointMap, dx, dy, isSnapToGrid());
|
Point actualD = moveSelectedComponents(this.controlPointMap, dx,
|
||||||
|
dy, isSnapToGrid());
|
||||||
if (actualD == null)
|
if (actualD == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -936,7 +948,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Point moveSelectedComponents(
|
private Point moveSelectedComponents(
|
||||||
Map<IDIYComponent<?>, Set<Integer>> controlPointMap, int dx, int dy, boolean snapToGrid) {
|
Map<IDIYComponent<?>, Set<Integer>> controlPointMap, int dx,
|
||||||
|
int dy, boolean snapToGrid) {
|
||||||
// After we make the transfer and snap to grid, calculate actual dx
|
// After we make the transfer and snap to grid, calculate actual dx
|
||||||
// and dy. We'll use them to translate the previous drag point.
|
// and dy. We'll use them to translate the previous drag point.
|
||||||
int actualDx = 0;
|
int actualDx = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user