Better unsaved warning message

This commit is contained in:
bancika
2012-08-17 14:51:14 +00:00
parent 0498eb2c51
commit 10a42b7fcf
2 changed files with 28 additions and 12 deletions
@@ -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();
} }
@@ -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;
} }
@@ -558,24 +569,24 @@ public class Presenter implements IPlugInPort {
if (controlPointMap.isEmpty()) { if (controlPointMap.isEmpty()) {
return false; return false;
} }
// Expand control points to include all stuck components. // Expand control points to include all stuck components.
boolean sticky = ConfigurationManager.getInstance().readBoolean( boolean sticky = ConfigurationManager.getInstance().readBoolean(
IPlugInPort.STICKY_POINTS_KEY, true); IPlugInPort.STICKY_POINTS_KEY, true);
if (ctrlDown) { if (ctrlDown) {
sticky = !sticky; sticky = !sticky;
} }
if (sticky) { if (sticky) {
includeStuckComponents(controlPointMap); includeStuckComponents(controlPointMap);
} }
boolean snapToGrid = ConfigurationManager.getInstance().readBoolean( boolean snapToGrid = ConfigurationManager.getInstance().readBoolean(
IPlugInPort.SNAP_TO_GRID_KEY, true); IPlugInPort.SNAP_TO_GRID_KEY, true);
if (shiftDown) { if (shiftDown) {
snapToGrid = !snapToGrid; snapToGrid = !snapToGrid;
} }
int d; int d;
if (snapToGrid) { if (snapToGrid) {
d = (int) currentProject.getGridSpacing().convertToPixels(); d = (int) currentProject.getGridSpacing().convertToPixels();
@@ -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;