Add key listener to unfollow by pressing the delete key

This commit is contained in:
0xboobface 2018-09-25 15:00:45 +02:00
parent e6c38081d9
commit b206a6caf7
3 changed files with 41 additions and 28 deletions

View File

@ -83,9 +83,9 @@ public class CtbrecApplication extends Application {
tabPane.getTabs().add(createTab("Male", BASE_URI + "/male-cams/")); tabPane.getTabs().add(createTab("Male", BASE_URI + "/male-cams/"));
tabPane.getTabs().add(createTab("Couples", BASE_URI + "/couple-cams/")); tabPane.getTabs().add(createTab("Couples", BASE_URI + "/couple-cams/"));
tabPane.getTabs().add(createTab("Trans", BASE_URI + "/trans-cams/")); tabPane.getTabs().add(createTab("Trans", BASE_URI + "/trans-cams/"));
FollowedTab tab = new FollowedTab("Followed", BASE_URI + "/followed-cams/"); FollowedTab followedTab = new FollowedTab("Followed", BASE_URI + "/followed-cams/");
tab.setRecorder(recorder); followedTab.setRecorder(recorder);
tabPane.getTabs().add(tab); tabPane.getTabs().add(followedTab);
RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder); RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder);
tabPane.getTabs().add(modelsTab); tabPane.getTabs().add(modelsTab);
RecordingsTab recordingsTab = new RecordingsTab("Recordings", recorder, config); RecordingsTab recordingsTab = new RecordingsTab("Recordings", recorder, config);
@ -97,6 +97,7 @@ public class CtbrecApplication extends Application {
int windowWidth = Config.getInstance().getSettings().windowWidth; int windowWidth = Config.getInstance().getSettings().windowWidth;
int windowHeight = Config.getInstance().getSettings().windowHeight; int windowHeight = Config.getInstance().getSettings().windowHeight;
primaryStage.setScene(new Scene(tabPane, windowWidth, windowHeight)); primaryStage.setScene(new Scene(tabPane, windowWidth, windowHeight));
followedTab.setScene(primaryStage.getScene());
primaryStage.getScene().getStylesheets().add("/ctbrec/ui/ThumbCell.css"); primaryStage.getScene().getStylesheets().add("/ctbrec/ui/ThumbCell.css");
primaryStage.getScene().widthProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowWidth = newVal.intValue()); primaryStage.getScene().widthProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowWidth = newVal.intValue());
primaryStage.getScene().heightProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowHeight = newVal.intValue()); primaryStage.getScene().heightProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowHeight = newVal.intValue());

View File

@ -1,7 +1,10 @@
package ctbrec.ui; package ctbrec.ui;
import javafx.concurrent.WorkerStateEvent; import javafx.concurrent.WorkerStateEvent;
import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
public class FollowedTab extends ThumbOverviewTab { public class FollowedTab extends ThumbOverviewTab {
private Label status; private Label status;
@ -29,4 +32,14 @@ public class FollowedTab extends ThumbOverviewTab {
status.setText("Logging in..."); status.setText("Logging in...");
super.selected(); super.selected();
} }
public void setScene(Scene scene) {
scene.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if(this.isSelected()) {
if(event.getCode() == KeyCode.DELETE) {
follow(selectedThumbCells, false);
}
}
});
}
} }

View File

@ -270,7 +270,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
} }
private ThumbCell createThumbCell(ThumbOverviewTab thumbOverviewTab, Model model, Recorder recorder2, HttpClient client2) { ThumbCell createThumbCell(ThumbOverviewTab thumbOverviewTab, Model model, Recorder recorder2, HttpClient client2) {
ThumbCell newCell = new ThumbCell(this, model, recorder, client); ThumbCell newCell = new ThumbCell(this, model, recorder, client);
newCell.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> { newCell.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> {
suspendUpdates(true); suspendUpdates(true);
@ -299,18 +299,18 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
private ContextMenu createContextMenu(ThumbCell cell) { private ContextMenu createContextMenu(ThumbCell cell) {
MenuItem openInPlayer = new MenuItem("Open in Player"); MenuItem openInPlayer = new MenuItem("Open in Player");
openInPlayer.setOnAction((e) -> startPlayer(cell)); openInPlayer.setOnAction((e) -> startPlayer(getSelectedThumbCells(cell)));
MenuItem start = new MenuItem("Start Recording"); MenuItem start = new MenuItem("Start Recording");
start.setOnAction((e) -> startStopAction(cell, true)); start.setOnAction((e) -> startStopAction(getSelectedThumbCells(cell), true));
MenuItem stop = new MenuItem("Stop Recording"); MenuItem stop = new MenuItem("Stop Recording");
stop.setOnAction((e) -> startStopAction(cell, false)); stop.setOnAction((e) -> startStopAction(getSelectedThumbCells(cell), false));
MenuItem startStop = recorder.isRecording(cell.getModel()) ? stop : start; MenuItem startStop = recorder.isRecording(cell.getModel()) ? stop : start;
MenuItem follow = new MenuItem("Follow"); MenuItem follow = new MenuItem("Follow");
follow.setOnAction((e) -> follow(cell, true)); follow.setOnAction((e) -> follow(getSelectedThumbCells(cell), true));
MenuItem unfollow = new MenuItem("Unfollow"); MenuItem unfollow = new MenuItem("Unfollow");
unfollow.setOnAction((e) -> follow(cell, false)); unfollow.setOnAction((e) -> follow(getSelectedThumbCells(cell), false));
MenuItem copyUrl = new MenuItem("Copy URL"); MenuItem copyUrl = new MenuItem("Copy URL");
copyUrl.setOnAction((e) -> { copyUrl.setOnAction((e) -> {
@ -343,33 +343,32 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
return contextMenu; return contextMenu;
} }
private void follow(ThumbCell cell, boolean follow) { private List<ThumbCell> getSelectedThumbCells(ThumbCell cell) {
if(selectedThumbCells.isEmpty()) { if(selectedThumbCells.isEmpty()) {
cell.follow(follow); return Collections.singletonList(cell);
} else { } else {
for (ThumbCell thumbCell : selectedThumbCells) { return selectedThumbCells;
thumbCell.follow(follow);
}
} }
} }
private void startStopAction(ThumbCell cell, boolean start) { void follow(List<ThumbCell> selection, boolean follow) {
if(selectedThumbCells.isEmpty()) { for (ThumbCell thumbCell : selection) {
cell.startStopAction(start); thumbCell.follow(follow);
} else { }
for (ThumbCell thumbCell : selectedThumbCells) { if(!follow) {
thumbCell.startStopAction(start); selectedThumbCells.clear();
}
} }
} }
private void startPlayer(ThumbCell cell) { private void startStopAction(List<ThumbCell> selection, boolean start) {
if(selectedThumbCells.isEmpty()) { for (ThumbCell thumbCell : selection) {
cell.startPlayer(); thumbCell.startStopAction(start);
} else { }
for (ThumbCell thumbCell : selectedThumbCells) { }
thumbCell.startPlayer();
} private void startPlayer(List<ThumbCell> selection) {
for (ThumbCell thumbCell : selection) {
thumbCell.startPlayer();
} }
} }