forked from j62/ctbrec
Remove notes from config, if new note is an empty string
This commit is contained in:
parent
6c6fadd742
commit
62c6f9a885
|
@ -1,7 +1,11 @@
|
||||||
package ctbrec.ui.action;
|
package ctbrec.ui.action;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.ui.JavaFxModel;
|
import ctbrec.ui.JavaFxModel;
|
||||||
|
@ -12,6 +16,7 @@ import javafx.scene.Node;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
|
|
||||||
public class EditNotesAction {
|
public class EditNotesAction {
|
||||||
|
private static final transient Logger LOG = LoggerFactory.getLogger(EditNotesAction.class);
|
||||||
|
|
||||||
private Node source;
|
private Node source;
|
||||||
private Model model;
|
private Model model;
|
||||||
|
@ -29,7 +34,18 @@ public class EditNotesAction {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
|
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
|
||||||
Optional<String> newNotes = Dialogs.showTextInput("Model Notes", "Notes for " + model.getName(), notes);
|
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();
|
table.refresh();
|
||||||
source.setCursor(Cursor.DEFAULT);
|
source.setCursor(Cursor.DEFAULT);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue