forked from j62/ctbrec
Jump to next recording with letter keys
This commit is contained in:
parent
dbeb814465
commit
d6574a63b9
|
@ -232,6 +232,8 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
} else if (event.getCode() == KeyCode.ENTER && status == FINISHED) {
|
||||
play(recordings.get(0));
|
||||
} else {
|
||||
jumpToNextModel(event.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -416,6 +418,35 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
return contextMenu;
|
||||
}
|
||||
|
||||
private void jumpToNextModel(KeyCode code) {
|
||||
if (!table.getItems().isEmpty() && (code.isLetterKey() || code.isDigitKey())) {
|
||||
// determine where to start looking for the next model
|
||||
int startAt = 0;
|
||||
if (table.getSelectionModel().getSelectedIndex() >= 0) {
|
||||
startAt = table.getSelectionModel().getSelectedIndex() + 1;
|
||||
if (startAt >= table.getItems().size()) {
|
||||
startAt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
String c = code.getChar().toLowerCase();
|
||||
int i = startAt;
|
||||
do {
|
||||
JavaFxRecording current = table.getItems().get(i);
|
||||
if (current.getModel().getName().toLowerCase().replaceAll("[^0-9a-z]", "").startsWith(c)) {
|
||||
table.getSelectionModel().clearAndSelect(i);
|
||||
table.scrollTo(i);
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
if (i >= table.getItems().size()) {
|
||||
i = 0;
|
||||
}
|
||||
} while (i != startAt);
|
||||
}
|
||||
}
|
||||
|
||||
private void onOpenDirectory(JavaFxRecording first) {
|
||||
String recordingsDir = Config.getInstance().getSettings().recordingsDir;
|
||||
String path = first.getPath();
|
||||
|
|
Loading…
Reference in New Issue