diff --git a/src/main/java/es/kauron/jstudy/controller/Controller.java b/src/main/java/es/kauron/jstudy/controller/Controller.java index d695568..ea7eac9 100644 --- a/src/main/java/es/kauron/jstudy/controller/Controller.java +++ b/src/main/java/es/kauron/jstudy/controller/Controller.java @@ -7,6 +7,7 @@ import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; +import javafx.collections.ListChangeListener; import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; @@ -55,14 +56,20 @@ public class Controller implements Initializable { private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false); private final Map tabMap = new HashMap<>(); private String updateURL, updateFileName; + private Tab theTest = null; @Override public void initialize(URL url, ResourceBundle resourceBundle) { tabPane.getSelectionModel().selectedItemProperty().addListener((ob, o, n) -> { - tabIsTable.set(tabMap.get(n) != null); - menuCloseTab.setDisable(!n.isClosable()); - menuSave.setDisable(!tabMap.containsKey(n) || tabMap.get(n).saved.get()); + if (theTest == o && AppPrefs.lockTabsOnTest.get()) { // optionally disallow switching from test + tabPane.getSelectionModel().select(o); + } else { // update if in table tab + tabIsTable.set(tabMap.get(n) != null); + menuCloseTab.setDisable(!n.isClosable()); + menuSave.setDisable(!tabMap.containsKey(n) || tabMap.get(n).saved.get()); + } }); + tabPane.getTabs().removeListener((ListChangeListener) c -> theTest = null); Platform.runLater(() -> root.getScene().getWindow().setOnCloseRequest(event -> { for (Tab tab : tabPane.getTabs()) { @@ -316,7 +323,8 @@ public class Controller implements Initializable { ((TestController) loader.getController()).setList(new ArrayList<>(list)); - tabPane.getTabs().add(new Tab("Test: " + tabPane.getSelectionModel().getSelectedItem().getText(), root)); + theTest = new Tab("Test: " + tabPane.getSelectionModel().getSelectedItem().getText(), root); + tabPane.getTabs().add(theTest); tabPane.getSelectionModel().selectLast(); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/es/kauron/jstudy/controller/SettingsController.java b/src/main/java/es/kauron/jstudy/controller/SettingsController.java index 8f3baf0..eb719a1 100644 --- a/src/main/java/es/kauron/jstudy/controller/SettingsController.java +++ b/src/main/java/es/kauron/jstudy/controller/SettingsController.java @@ -10,7 +10,7 @@ import java.util.ResourceBundle; public class SettingsController implements Initializable { @FXML - private CheckBox repeatMistakes, showFeedback, repeatImmediately; + private CheckBox repeatMistakes, showFeedback, repeatImmediately, lockTabsOnTest; @Override public void initialize(URL location, ResourceBundle resources) { @@ -18,6 +18,7 @@ public class SettingsController implements Initializable { repeatImmediately.selectedProperty().bindBidirectional(AppPrefs.repeatImmediately); repeatMistakes.selectedProperty().bindBidirectional(AppPrefs.repeatWrong); showFeedback.selectedProperty().bindBidirectional(AppPrefs.showFeedback); + lockTabsOnTest.selectedProperty().bindBidirectional(AppPrefs.lockTabsOnTest); repeatMistakes.selectedProperty().addListener((obj, o, n) -> { if (!n) repeatImmediately.setSelected(false); }); diff --git a/src/main/java/es/kauron/jstudy/model/AppPrefs.java b/src/main/java/es/kauron/jstudy/model/AppPrefs.java index 96670eb..6343b7f 100644 --- a/src/main/java/es/kauron/jstudy/model/AppPrefs.java +++ b/src/main/java/es/kauron/jstudy/model/AppPrefs.java @@ -13,6 +13,7 @@ public class AppPrefs { public static final BooleanPref repeatWrong = new BooleanPref(false, "repeatWrong"); public static final BooleanPref showFeedback = new BooleanPref(true, "showFeedback"); public static final BooleanPref repeatImmediately = new BooleanPref(false, "repeatImmediately"); + public static final BooleanPref lockTabsOnTest = new BooleanPref(false, "lockTabsOnTest"); public static File lastDir; static { diff --git a/src/main/resources/es/kauron/jstudy/view/settings.fxml b/src/main/resources/es/kauron/jstudy/view/settings.fxml index 9fb5496..6397683 100644 --- a/src/main/resources/es/kauron/jstudy/view/settings.fxml +++ b/src/main/resources/es/kauron/jstudy/view/settings.fxml @@ -9,6 +9,7 @@ +