| | import com.scrivenvar.service.events.Notification; |
| | import com.scrivenvar.service.events.Notifier; |
| | -import javafx.application.Platform; |
| | import javafx.beans.binding.Bindings; |
| | import javafx.beans.property.BooleanProperty; |
 |
| | import static java.nio.charset.StandardCharsets.UTF_8; |
| | import static java.util.Locale.ENGLISH; |
| | +import static javafx.application.Platform.runLater; |
| | |
| | /** |
 |
| | setOnSelectionChanged( e -> { |
| | if( isSelected() ) { |
| | - Platform.runLater( this::activated ); |
| | + runLater( this::activated ); |
| | } |
| | } ); |
 |
| | } |
| | |
| | - // Switch to the tab without loading if the contents are already in memory. |
| | - if( getContent() != null ) { |
| | - getEditorPane().requestFocus(); |
| | - return; |
| | + // If the tab is devoid of content, load it. |
| | + if( getContent() == null ) { |
| | + readFile(); |
| | + initLayout(); |
| | + initUndoManager(); |
| | } |
| | - |
| | - // Load the text and update the preview before the undo manager. |
| | - load(); |
| | |
| | - // Track undo requests -- can only be called *after* load. |
| | - initUndoManager(); |
| | - initLayout(); |
| | - initFocus(); |
| | + requestFocus(); |
| | } |
| | |
| | private void initLayout() { |
| | setContent( getScrollPane() ); |
| | - } |
| | - |
| | - private void initFocus() { |
| | - getEditorPane().requestFocus(); |
| | } |
| | |
| | + /** |
| | + * Tracks undo requests, but can only be called <em>after</em> load. |
| | + */ |
| | private void initUndoManager() { |
| | final UndoManager<?> undoManager = getUndoManager(); |
| | undoManager.forgetHistory(); |
| | |
| | // Bind the editor undo manager to the properties. |
| | mModified.bind( Bindings.not( undoManager.atMarkedPositionProperty() ) ); |
| | canUndo.bind( undoManager.undoAvailableProperty() ); |
| | canRedo.bind( undoManager.redoAvailableProperty() ); |
| | + } |
| | + |
| | + private void requestFocus() { |
| | + runLater( () -> getEditorPane().requestFocus() ); |
| | } |
| | |
 |
| | * Reads the entire file contents from the path associated with this tab. |
| | */ |
| | - private void load() { |
| | + private void readFile() { |
| | final Path path = getPath(); |
| | final File file = path.toFile(); |