mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Table: added unsaved indicator
This commit is contained in:
parent
b08e5aa1dc
commit
ce4b58aa4f
2 changed files with 13 additions and 5 deletions
|
@ -4,6 +4,7 @@ import es.kauron.jstudy.Main;
|
|||
import es.kauron.jstudy.model.AppPrefs;
|
||||
import es.kauron.jstudy.model.TestItem;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.event.ActionEvent;
|
||||
|
@ -163,7 +164,11 @@ public class Controller implements Initializable {
|
|||
FXMLLoader loader = new FXMLLoader(Main.class.getResource("view/table.fxml"));
|
||||
Parent tableRoot = loader.load();
|
||||
|
||||
((TableController) loader.getController()).setData(name, list, this, file);
|
||||
TableController tController = loader.getController();
|
||||
tController.setData(name, list, this, file);
|
||||
tab.textProperty().bind(Bindings.format("%s%s",
|
||||
Bindings.when(tController.saved).then("").otherwise("*"),
|
||||
tController.name));
|
||||
tabMap.put(tab, loader.getController());
|
||||
|
||||
MenuItem duplicate = new MenuItem("Duplicate table");
|
||||
|
|
|
@ -5,6 +5,8 @@ import es.kauron.jstudy.model.AppPrefs;
|
|||
import es.kauron.jstudy.model.TestItem;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
|
@ -40,7 +42,7 @@ public class TableController implements Initializable {
|
|||
private ObservableList<TestItem> data;
|
||||
private Controller parent;
|
||||
private File file;
|
||||
private String name;
|
||||
StringProperty name;
|
||||
BooleanProperty saved = new SimpleBooleanProperty();
|
||||
|
||||
@Override
|
||||
|
@ -59,7 +61,7 @@ public class TableController implements Initializable {
|
|||
}
|
||||
|
||||
void setData(String name, List<TestItem> list, Controller controller, File file) {
|
||||
this.name = name;
|
||||
this.name = new SimpleStringProperty(name);
|
||||
this.data = FXCollections.observableArrayList(list);
|
||||
this.parent = controller;
|
||||
table.setItems(data);
|
||||
|
@ -68,7 +70,7 @@ public class TableController implements Initializable {
|
|||
}
|
||||
|
||||
List<TestItem> getData() {return new ArrayList<>(data);}
|
||||
String getName() {return file == null ? name : file.getName().substring(0, file.getName().lastIndexOf('.'));}
|
||||
String getName() {return name.get();}
|
||||
|
||||
@FXML
|
||||
protected void onSaveAction(ActionEvent event) {
|
||||
|
@ -76,12 +78,13 @@ public class TableController implements Initializable {
|
|||
FileChooser chooser = new FileChooser();
|
||||
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JStudy file", "*.jsdb"));
|
||||
if (AppPrefs.lastDir != null) chooser.setInitialDirectory(AppPrefs.lastDir);
|
||||
chooser.setInitialFileName(name);
|
||||
chooser.setInitialFileName(name.get());
|
||||
file = chooser.showSaveDialog(table.getScene().getWindow());
|
||||
if (!file.getName().endsWith(".jsdb"))
|
||||
file = new File(file.getPath() + ".jsdb");
|
||||
if (file != null)
|
||||
AppPrefs.lastDir = file.getParentFile();
|
||||
name.set(file.getName().substring(0, file.getName().lastIndexOf('.')));
|
||||
}
|
||||
if (file == null) return;
|
||||
TestItem.saveTo(file, data);
|
||||
|
|
Loading…
Reference in a new issue