| Author | Karl Tauber <email> |
|---|---|
| Date | 2015-07-29 11:43:10 GMT+0200 |
| Commit | 50c0f3055d92ff0b94d961baf641f89628443436 |
| Parent | 13238a9 |
| Delta | 5 lines added, 17 lines removed, 12-line decrease |
| private final ReadOnlyBooleanWrapper modified = new ReadOnlyBooleanWrapper(); | ||
| boolean isModified() { return modified.get(); } | ||
| - ReadOnlyBooleanProperty modifiedProperty() { return modified; } | ||
| + ReadOnlyBooleanProperty modifiedProperty() { return modified.getReadOnlyProperty(); } | ||
| // 'canUndo' property |
| private final TabPane tabPane; | ||
| private final ReadOnlyObjectWrapper<FileEditor> activeFileEditor = new ReadOnlyObjectWrapper<>(); | ||
| - private final ReadOnlyBooleanWrapper activeFileEditorModified = new ReadOnlyBooleanWrapper(); | ||
| private final ReadOnlyBooleanWrapper anyFileEditorModified = new ReadOnlyBooleanWrapper(); | ||
| FileEditorTabPane(MainWindow mainWindow) { | ||
| this.mainWindow = mainWindow; | ||
| tabPane = new TabPane(); | ||
| tabPane.setFocusTraversable(false); | ||
| tabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS); | ||
| - // update activeFileEditor and activeFileEditorModified properties | ||
| + // update activeFileEditor property | ||
| tabPane.getSelectionModel().selectedItemProperty().addListener((observable, oldTab, newTab) -> { | ||
| - if (newTab != null) { | ||
| - activeFileEditor.set((FileEditor) newTab.getUserData()); | ||
| - activeFileEditorModified.bind(activeFileEditor.get().modifiedProperty()); | ||
| - } else { | ||
| - activeFileEditor.set(null); | ||
| - activeFileEditorModified.unbind(); | ||
| - activeFileEditorModified.set(false); | ||
| - } | ||
| + activeFileEditor.set((newTab != null) ? (FileEditor) newTab.getUserData() : null); | ||
| }); | ||
| ReadOnlyObjectProperty<FileEditor> activeFileEditorProperty() { | ||
| return activeFileEditor.getReadOnlyProperty(); | ||
| - } | ||
| - | ||
| - ReadOnlyBooleanProperty activeFileEditorModifiedProperty() { | ||
| - return activeFileEditorModified.getReadOnlyProperty(); | ||
| } | ||
| fileCloseMenuItem.disableProperty().bind(fileEditorTabPane.activeFileEditorProperty().isNull()); | ||
| fileCloseAllMenuItem.disableProperty().bind(fileEditorTabPane.activeFileEditorProperty().isNull()); | ||
| - fileSaveMenuItem.disableProperty().bind(Bindings.not(fileEditorTabPane.activeFileEditorModifiedProperty())); | ||
| + fileSaveMenuItem.disableProperty().bind(createActiveBooleanProperty(FileEditor::modifiedProperty).not()); | ||
| fileSaveAllMenuItem.disableProperty().bind(Bindings.not(fileEditorTabPane.anyFileEditorModifiedProperty())); | ||
| Button editRedoButton = createToolBarButton(REPEAT, "Redo", "Shortcut+Y", e -> editRedo()); | ||
| - fileSaveButton.disableProperty().bind(Bindings.not(fileEditorTabPane.activeFileEditorModifiedProperty())); | ||
| + fileSaveButton.disableProperty().bind(createActiveBooleanProperty(FileEditor::modifiedProperty).not()); | ||
| editUndoButton.disableProperty().bind(createActiveBooleanProperty(FileEditor::canUndoProperty).not()); | ||