Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve UX for saving files #801

Merged
merged 2 commits into from
Jan 27, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.wpi.grip.ui;

import edu.wpi.grip.core.GripFileManager;
import edu.wpi.grip.core.Palette;
import edu.wpi.grip.core.Pipeline;
import edu.wpi.grip.core.PipelineRunner;
Expand Down Expand Up @@ -33,7 +34,6 @@
import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Platform;
Expand Down Expand Up @@ -154,11 +154,7 @@ private boolean showConfirmationDialogAndWait() {
} else if (dialog.getResult().equals(save)) {
// If the user chose "Save", automatically show a save dialog and block until the user
// has had a chance to save the project.
try {
return saveProject();
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e.getCause());
}
return saveProject();
}
}
return true;
Expand Down Expand Up @@ -219,10 +215,18 @@ public void openProject() {
* @return true if the user does not cancel the save
*/
@FXML
public boolean saveProject() throws IOException {
public boolean saveProject() {
if (project.getFile().isPresent()) {
// Immediately save the project to whatever file it was loaded from or last saved to.
project.save(project.getFile().get());
try {
project.save(project.getFile().get());
} catch (IOException e) {
eventBus.post(new WarningEvent("Could not save project",
"The project could not be saved to " + project.getFile().get().getAbsolutePath()
+ ".\n\nCause: " + e.getMessage()
));
return false;
}
return true;
} else {
return saveProjectAs();
Expand All @@ -237,10 +241,11 @@ public boolean saveProject() throws IOException {
* @return true if the user does not cancel the save
*/
@FXML
public boolean saveProjectAs() throws IOException {
public boolean saveProjectAs() {
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Project As");
fileChooser.getExtensionFilters().add(new ExtensionFilter("GRIP File", "*.grip"));
fileChooser.setInitialDirectory(GripFileManager.GRIP_DIRECTORY);

project.getFile().ifPresent(file -> fileChooser.setInitialDirectory(file.getParentFile()));

Expand All @@ -249,7 +254,14 @@ public boolean saveProjectAs() throws IOException {
return false;
}

project.save(file);
try {
project.save(file);
} catch (IOException e) {
eventBus.post(new WarningEvent("Could not save project",
"The project could not be saved to " + file.getAbsolutePath()
+ ".\n\nCause: " + e.getMessage()));
return false;
}
return true;
}

Expand Down