Ask to save before loading a new maze

model:
* Deprecate modified from MazeAppModel, which was misused and
  misunderstood
* Add saved to MazeAppModel to keep track if a maze (or some
  modification) was saved into a file or not

ui:
* Use the new saved attribute to know if the maze was saved or not
* Move the box asking whether to save the maze or not from QuitMenuItem
  to SaveBox and call SaveBox from QuitMenuItem
* SaveBox now checks if the maze has a source file or not, if not it
  prompts a box to ask where to save the maze
* If the maze was modified, the Load Maze button will pop SaveBox before
  erasing the current maze
This commit is contained in:
regar42 committed 2017-12-26 15:24:00 +01:00
1 parent 80ffabdd69
commit 9b272e5f25
4 files changed
+59 -22

No files matched your search

+6 -5
View File
@@ -21,7 +21,7 @@ public class MazeAppModel extends Observable {
private Previous previous;
private ArrayList<VertexInterface> shortest;
private ArrayList<VertexInterface> boxList;
private Boolean modified = false;
private boolean saved = true;
public MazeAppModel() {
maze = new Maze(Maze.emptyMaze(10));
@@ -45,7 +45,7 @@ public class MazeAppModel extends Observable {
this.filename = new String(filename);
maze = new Maze(this.filename);
initModelFromMaze();
modified = true;
saved = true;
setChanged();
notifyObservers(MazeAppModelMessage.MazeRenewal);
}
@@ -58,18 +58,19 @@ public class MazeAppModel extends Observable {
return filename;
}
public boolean isModified() {
return modified;
public boolean isSaved() {
return saved;
}
public void saveToFile() {
maze.saveToTextFile(filename);
saved = true;
}
public void saveToFile(String filename) {
this.filename = new String(filename);
maze.saveToTextFile(this.filename);
modified = true;
saved = true;
setChanged();
notifyObservers(MazeAppModelMessage.FileChange);
}