Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

added shortcuts Ctrl+Tab and Ctrl+Shift+Tab to switch to next/previous tab

AuthorKarl Tauber <email>
Date2015-07-29 12:39:31 GMT+0200
Commit09b204285f42cc47afc8e522c9663492554c7f3c
Parenta38d99a
Delta23 lines added, 0 lines removed, 23-line increase
src/main/java/org/markdownwriterfx/FileEditor.java
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
+import javafx.scene.control.SingleSelectionModel;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyCombination;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
+import javafx.scene.control.TabPane;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Text;
import org.fxmisc.undo.UndoManager;
+import org.fxmisc.wellbehaved.event.EventHandlerHelper;
+import org.fxmisc.wellbehaved.event.EventPattern;
import org.markdownwriterfx.editor.MarkdownEditorPane;
import org.markdownwriterfx.preview.MarkdownPreviewPane;
tab.setTooltip((path != null) ? new Tooltip(path.toString()) : null);
tab.setGraphic(isModified() ? new Text("*") : null);
+ }
+
+ private void selectNextPreviousTab(int offset) {
+ TabPane tabPane = tab.getTabPane();
+ SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
+
+ int selectIndex = selectionModel.getSelectedIndex() + offset;
+ if (selectIndex < 0)
+ selectionModel.selectLast();
+ else if(selectIndex >= tabPane.getTabs().size())
+ selectionModel.selectFirst();
+ else
+ selectionModel.select(selectIndex);
}
markdownEditorPane.installEditorShortcuts(mainWindow.getEditorShortcuts());
+ markdownEditorPane.installEditorShortcuts(EventHandlerHelper
+ .on(EventPattern.keyPressed(KeyCode.TAB, KeyCombination.CONTROL_DOWN)).act(e -> selectNextPreviousTab(1))
+ .on(EventPattern.keyPressed(KeyCode.TAB, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)).act(e -> selectNextPreviousTab(-1))
+ .create());
load();