Remove notes from config, if new note is an empty string

This commit is contained in:
0xboobface 2019-04-11 14:00:27 +02:00
parent 6c6fadd742
commit 62c6f9a885
1 changed files with 17 additions and 1 deletions

View File

@ -1,7 +1,11 @@
package ctbrec.ui.action;
import java.io.IOException;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.ui.JavaFxModel;
@ -12,6 +16,7 @@ import javafx.scene.Node;
import javafx.scene.control.TableView;
public class EditNotesAction {
private static final transient Logger LOG = LoggerFactory.getLogger(EditNotesAction.class);
private Node source;
private Model model;
@ -29,7 +34,18 @@ public class EditNotesAction {
Platform.runLater(() -> {
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
Optional<String> newNotes = Dialogs.showTextInput("Model Notes", "Notes for " + model.getName(), notes);
newNotes.ifPresent(n -> Config.getInstance().getSettings().modelNotes.put(model.getUrl(), n));
newNotes.ifPresent(n -> {
if(!n.trim().isEmpty()) {
Config.getInstance().getSettings().modelNotes.put(model.getUrl(), n);
} else {
Config.getInstance().getSettings().modelNotes.remove(model.getUrl());
}
try {
Config.getInstance().save();
} catch (IOException e) {
LOG.warn("Couldn't save config", e);
}
});
table.refresh();
source.setCursor(Cursor.DEFAULT);
});