From b206a6caf75db494cc6b0cfbe1034ffbdc6f777c Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Tue, 25 Sep 2018 15:00:45 +0200 Subject: [PATCH] Add key listener to unfollow by pressing the delete key --- .../java/ctbrec/ui/CtbrecApplication.java | 7 +-- src/main/java/ctbrec/ui/FollowedTab.java | 13 +++++ src/main/java/ctbrec/ui/ThumbOverviewTab.java | 49 +++++++++---------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/main/java/ctbrec/ui/CtbrecApplication.java b/src/main/java/ctbrec/ui/CtbrecApplication.java index 932f3721..fd0ce230 100644 --- a/src/main/java/ctbrec/ui/CtbrecApplication.java +++ b/src/main/java/ctbrec/ui/CtbrecApplication.java @@ -83,9 +83,9 @@ public class CtbrecApplication extends Application { tabPane.getTabs().add(createTab("Male", BASE_URI + "/male-cams/")); tabPane.getTabs().add(createTab("Couples", BASE_URI + "/couple-cams/")); tabPane.getTabs().add(createTab("Trans", BASE_URI + "/trans-cams/")); - FollowedTab tab = new FollowedTab("Followed", BASE_URI + "/followed-cams/"); - tab.setRecorder(recorder); - tabPane.getTabs().add(tab); + FollowedTab followedTab = new FollowedTab("Followed", BASE_URI + "/followed-cams/"); + followedTab.setRecorder(recorder); + tabPane.getTabs().add(followedTab); RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder); tabPane.getTabs().add(modelsTab); RecordingsTab recordingsTab = new RecordingsTab("Recordings", recorder, config); @@ -97,6 +97,7 @@ public class CtbrecApplication extends Application { int windowWidth = Config.getInstance().getSettings().windowWidth; int windowHeight = Config.getInstance().getSettings().windowHeight; primaryStage.setScene(new Scene(tabPane, windowWidth, windowHeight)); + followedTab.setScene(primaryStage.getScene()); primaryStage.getScene().getStylesheets().add("/ctbrec/ui/ThumbCell.css"); 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()); diff --git a/src/main/java/ctbrec/ui/FollowedTab.java b/src/main/java/ctbrec/ui/FollowedTab.java index 6b3bec9e..9578feb7 100644 --- a/src/main/java/ctbrec/ui/FollowedTab.java +++ b/src/main/java/ctbrec/ui/FollowedTab.java @@ -1,7 +1,10 @@ package ctbrec.ui; import javafx.concurrent.WorkerStateEvent; +import javafx.scene.Scene; import javafx.scene.control.Label; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; public class FollowedTab extends ThumbOverviewTab { private Label status; @@ -29,4 +32,14 @@ public class FollowedTab extends ThumbOverviewTab { status.setText("Logging in..."); super.selected(); } + + public void setScene(Scene scene) { + scene.addEventFilter(KeyEvent.KEY_PRESSED, event -> { + if(this.isSelected()) { + if(event.getCode() == KeyCode.DELETE) { + follow(selectedThumbCells, false); + } + } + }); + } } diff --git a/src/main/java/ctbrec/ui/ThumbOverviewTab.java b/src/main/java/ctbrec/ui/ThumbOverviewTab.java index 3eff90dd..f1eaf052 100644 --- a/src/main/java/ctbrec/ui/ThumbOverviewTab.java +++ b/src/main/java/ctbrec/ui/ThumbOverviewTab.java @@ -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); newCell.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> { suspendUpdates(true); @@ -299,18 +299,18 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { private ContextMenu createContextMenu(ThumbCell cell) { MenuItem openInPlayer = new MenuItem("Open in Player"); - openInPlayer.setOnAction((e) -> startPlayer(cell)); + openInPlayer.setOnAction((e) -> startPlayer(getSelectedThumbCells(cell))); 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"); - stop.setOnAction((e) -> startStopAction(cell, false)); + stop.setOnAction((e) -> startStopAction(getSelectedThumbCells(cell), false)); MenuItem startStop = recorder.isRecording(cell.getModel()) ? stop : start; MenuItem follow = new MenuItem("Follow"); - follow.setOnAction((e) -> follow(cell, true)); + follow.setOnAction((e) -> follow(getSelectedThumbCells(cell), true)); MenuItem unfollow = new MenuItem("Unfollow"); - unfollow.setOnAction((e) -> follow(cell, false)); + unfollow.setOnAction((e) -> follow(getSelectedThumbCells(cell), false)); MenuItem copyUrl = new MenuItem("Copy URL"); copyUrl.setOnAction((e) -> { @@ -343,33 +343,32 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { return contextMenu; } - private void follow(ThumbCell cell, boolean follow) { + private List getSelectedThumbCells(ThumbCell cell) { if(selectedThumbCells.isEmpty()) { - cell.follow(follow); + return Collections.singletonList(cell); } else { - for (ThumbCell thumbCell : selectedThumbCells) { - thumbCell.follow(follow); - } + return selectedThumbCells; } } - private void startStopAction(ThumbCell cell, boolean start) { - if(selectedThumbCells.isEmpty()) { - cell.startStopAction(start); - } else { - for (ThumbCell thumbCell : selectedThumbCells) { - thumbCell.startStopAction(start); - } + void follow(List selection, boolean follow) { + for (ThumbCell thumbCell : selection) { + thumbCell.follow(follow); + } + if(!follow) { + selectedThumbCells.clear(); } } - private void startPlayer(ThumbCell cell) { - if(selectedThumbCells.isEmpty()) { - cell.startPlayer(); - } else { - for (ThumbCell thumbCell : selectedThumbCells) { - thumbCell.startPlayer(); - } + private void startStopAction(List selection, boolean start) { + for (ThumbCell thumbCell : selection) { + thumbCell.startStopAction(start); + } + } + + private void startPlayer(List selection) { + for (ThumbCell thumbCell : selection) { + thumbCell.startPlayer(); } }