Skip to content

Commit ce0589e

Browse files
committed
Lines in program view added, and save/load of files
1 parent c7d2c94 commit ce0589e

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/Document.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class Document implements Serializable {
55
protected List<Peripheral> peripherals = new ArrayList<Peripheral>();
66
protected Variables variables = new Variables();
77
protected Node head = new Node();
8+
protected String name;
89

910
public Document() {
1011
reloadPeripherals();
@@ -39,4 +40,12 @@ public void setHead(Node head) {
3940
public Variables getVariables() {
4041
return variables;
4142
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
public String getName() {
49+
return name;
50+
}
4251
}

src/UI/Flowduino.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public void handle(WindowEvent ev) {
172172

173173
Optional<ButtonType> result = alert.showAndWait();
174174
if (result.get() == buttonTypeOne){
175-
// ... user chose "One"
175+
if (!saveFile()) {
176+
ev.consume();
177+
}
176178
} else if (result.get() == buttonTypeTwo) {
177179
// ... user chose "Two"
178180
} else {
@@ -485,26 +487,32 @@ public VBox createButtonBox() {
485487
}
486488

487489

488-
public void saveFile() {
489-
FileChooser fileChooser = new FileChooser();
490-
fileChooser.setTitle("Save Flowduino file");
491-
File file = fileChooser.showSaveDialog(stage);
492-
if (file != null) {
493-
String fileName = file.getAbsoluteFile().toString();
494-
if (!fileName.toLowerCase().endsWith(".fdi")) {
495-
fileName += ".fdi";
496-
}
497-
try {
498-
FileOutputStream fileOut = new FileOutputStream(fileName);
499-
ObjectOutputStream out = new ObjectOutputStream(fileOut);
500-
out.writeObject(d);
501-
out.close();
502-
fileOut.close();
503-
} catch (Exception e) {
504-
System.out.println("Save failed");
505-
e.printStackTrace();
490+
public boolean saveFile() {
491+
if (d.getName() == null) {
492+
FileChooser fileChooser = new FileChooser();
493+
fileChooser.setTitle("Save Flowduino file");
494+
File file = fileChooser.showSaveDialog(stage);
495+
if (file != null) {
496+
String fileName = file.getAbsoluteFile().toString();
497+
if (!fileName.toLowerCase().endsWith(".fdi")) {
498+
fileName += ".fdi";
499+
}
500+
d.setName(fileName);
501+
} else {
502+
return false;
506503
}
507504
}
505+
try {
506+
FileOutputStream fileOut = new FileOutputStream(d.getName());
507+
ObjectOutputStream out = new ObjectOutputStream(fileOut);
508+
out.writeObject(d);
509+
out.close();
510+
fileOut.close();
511+
} catch (Exception e) {
512+
System.out.println("Save failed");
513+
e.printStackTrace();
514+
}
515+
return true;
508516
}
509517

510518
public void openFile() {

0 commit comments

Comments
 (0)