1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-11-13 07:33:44 +01:00

Test: option to lock switching tabs

This commit is contained in:
Carlos Galindo 2019-09-12 22:07:32 +02:00
parent 0d4b50a78c
commit d3d07b7541
Signed by: kauron
GPG key ID: 83E68706DEE119A3
4 changed files with 16 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import javafx.application.Platform;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
@ -55,14 +56,20 @@ public class Controller implements Initializable {
private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false); private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false);
private final Map<Tab, TableController> tabMap = new HashMap<>(); private final Map<Tab, TableController> tabMap = new HashMap<>();
private String updateURL, updateFileName; private String updateURL, updateFileName;
private Tab theTest = null;
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
tabPane.getSelectionModel().selectedItemProperty().addListener((ob, o, n) -> { tabPane.getSelectionModel().selectedItemProperty().addListener((ob, o, n) -> {
tabIsTable.set(tabMap.get(n) != null); if (theTest == o && AppPrefs.lockTabsOnTest.get()) { // optionally disallow switching from test
menuCloseTab.setDisable(!n.isClosable()); tabPane.getSelectionModel().select(o);
menuSave.setDisable(!tabMap.containsKey(n) || tabMap.get(n).saved.get()); } 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<Tab>) c -> theTest = null);
Platform.runLater(() -> Platform.runLater(() ->
root.getScene().getWindow().setOnCloseRequest(event -> { root.getScene().getWindow().setOnCloseRequest(event -> {
for (Tab tab : tabPane.getTabs()) { for (Tab tab : tabPane.getTabs()) {
@ -316,7 +323,8 @@ public class Controller implements Initializable {
((TestController) loader.getController()).setList(new ArrayList<>(list)); ((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(); tabPane.getSelectionModel().selectLast();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -10,7 +10,7 @@ import java.util.ResourceBundle;
public class SettingsController implements Initializable { public class SettingsController implements Initializable {
@FXML @FXML
private CheckBox repeatMistakes, showFeedback, repeatImmediately; private CheckBox repeatMistakes, showFeedback, repeatImmediately, lockTabsOnTest;
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
@ -18,6 +18,7 @@ public class SettingsController implements Initializable {
repeatImmediately.selectedProperty().bindBidirectional(AppPrefs.repeatImmediately); repeatImmediately.selectedProperty().bindBidirectional(AppPrefs.repeatImmediately);
repeatMistakes.selectedProperty().bindBidirectional(AppPrefs.repeatWrong); repeatMistakes.selectedProperty().bindBidirectional(AppPrefs.repeatWrong);
showFeedback.selectedProperty().bindBidirectional(AppPrefs.showFeedback); showFeedback.selectedProperty().bindBidirectional(AppPrefs.showFeedback);
lockTabsOnTest.selectedProperty().bindBidirectional(AppPrefs.lockTabsOnTest);
repeatMistakes.selectedProperty().addListener((obj, o, n) -> { repeatMistakes.selectedProperty().addListener((obj, o, n) -> {
if (!n) repeatImmediately.setSelected(false); if (!n) repeatImmediately.setSelected(false);
}); });

View file

@ -13,6 +13,7 @@ public class AppPrefs {
public static final BooleanPref repeatWrong = new BooleanPref(false, "repeatWrong"); public static final BooleanPref repeatWrong = new BooleanPref(false, "repeatWrong");
public static final BooleanPref showFeedback = new BooleanPref(true, "showFeedback"); public static final BooleanPref showFeedback = new BooleanPref(true, "showFeedback");
public static final BooleanPref repeatImmediately = new BooleanPref(false, "repeatImmediately"); public static final BooleanPref repeatImmediately = new BooleanPref(false, "repeatImmediately");
public static final BooleanPref lockTabsOnTest = new BooleanPref(false, "lockTabsOnTest");
public static File lastDir; public static File lastDir;
static { static {

View file

@ -9,6 +9,7 @@
<CheckBox fx:id="repeatMistakes" text="_Repeat mistakes"/> <CheckBox fx:id="repeatMistakes" text="_Repeat mistakes"/>
<CheckBox fx:id="repeatImmediately" text="_Always repeat immediately"/> <CheckBox fx:id="repeatImmediately" text="_Always repeat immediately"/>
<CheckBox fx:id="showFeedback" text="Show _feedback while testing"/> <CheckBox fx:id="showFeedback" text="Show _feedback while testing"/>
<CheckBox fx:id="lockTabsOnTest" text="Don't allow tab switching when on a test"/>
</children> </children>
<padding> <padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/> <Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>