forked from j62/ctbrec
1
0
Fork 0

Add optional confirmation dialog to ignore action

This commit is contained in:
0xb00bface 2020-12-27 14:35:35 +01:00
parent ac3f91eb03
commit 616be8e252
3 changed files with 80 additions and 13 deletions

View File

@ -0,0 +1,65 @@
package ctbrec.ui.action;
import java.util.List;
import java.util.function.Consumer;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.Settings;
import ctbrec.recorder.Recorder;
import ctbrec.ui.JavaFxModel;
import ctbrec.ui.controls.Dialogs;
import javafx.scene.Node;
public class IgnoreModelsAction {
private Node source;
private List<? extends Model> selectedModels;
private Recorder recorder;
private boolean withRemoveDialog;
public IgnoreModelsAction(Node source, List<? extends Model> selectedModels, Recorder recorder, boolean withRemoveDialog) {
this.source = source;
this.selectedModels = selectedModels;
this.recorder = recorder;
this.withRemoveDialog = withRemoveDialog;
}
public void execute() {
execute(model -> {});
}
public void execute(Consumer<Model> callback) {
Settings settings = Config.getInstance().getSettings();
boolean confirmed = true;
if (settings.confirmationForDangerousActions) {
int n = selectedModels.size();
String plural = n > 1 ? "s" : "";
String header = "This will add " + n + " model" + plural + " to the ignore list";
confirmed = Dialogs.showConfirmDialog("Ignore Models", "Continue?", header, source.getScene());
}
if (confirmed) {
for (Model model : selectedModels) {
Model modelToIgnore = unwrap(model);
settings.modelsIgnored.add(modelToIgnore);
}
if (withRemoveDialog) {
boolean removeAsWell = Dialogs.showConfirmDialog("Ignore Model", null, "Remove as well?", source.getScene());
if (removeAsWell) {
new StopRecordingAction(source, selectedModels, recorder).execute(callback);
}
} else {
for (Model model : selectedModels) {
callback.accept(model);
}
}
}
}
private Model unwrap(Model model) {
if (model instanceof JavaFxModel) {
return ((JavaFxModel) model).getDelegate();
} else {
return model;
}
}
}

View File

@ -42,6 +42,7 @@ import ctbrec.ui.StreamSourceSelectionDialog;
import ctbrec.ui.action.CheckModelAccountAction;
import ctbrec.ui.action.EditNotesAction;
import ctbrec.ui.action.FollowAction;
import ctbrec.ui.action.IgnoreModelsAction;
import ctbrec.ui.action.OpenRecordingsDir;
import ctbrec.ui.action.PauseAction;
import ctbrec.ui.action.PlayAction;
@ -709,14 +710,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
}
private void ignore(ObservableList<JavaFxModel> selectedModels) {
for (JavaFxModel fxModel : selectedModels) {
Model modelToIgnore = fxModel.getDelegate();
Config.getInstance().getSettings().modelsIgnored.add(modelToIgnore);
}
boolean removeAsWell = Dialogs.showConfirmDialog("Ignore Model", null, "Remove as well?", getTabPane().getScene());
if (removeAsWell) {
stopAction(selectedModels);
}
new IgnoreModelsAction(table, selectedModels, recorder, true).execute();
}
private void follow(ObservableList<JavaFxModel> selectedModels) {

View File

@ -38,6 +38,7 @@ import ctbrec.ui.DesktopIntegration;
import ctbrec.ui.SiteUiFactory;
import ctbrec.ui.TipDialog;
import ctbrec.ui.TokenLabel;
import ctbrec.ui.action.IgnoreModelsAction;
import ctbrec.ui.action.OpenRecordingsDir;
import ctbrec.ui.action.SetStopDateAction;
import ctbrec.ui.controls.FasterVerticalScrollPaneSkin;
@ -622,12 +623,19 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
}
protected void ignore(List<ThumbCell> selection) {
for (ThumbCell thumbCell : selection) {
Model model = thumbCell.getModel();
Config.getInstance().getSettings().modelsIgnored.add(model);
Map<Model, ThumbCell> thumbcells = new HashMap<>();
List<Model> selectedModels = selection.stream()
.map(tc -> {
thumbcells.put(tc.getModel(), tc);
return tc;
})
.map(ThumbCell::getModel)
.collect(Collectors.toList());
new IgnoreModelsAction(grid, selectedModels, recorder, false).execute(m -> {
ThumbCell thumbCell = thumbcells.get(m);
grid.getChildren().remove(thumbCell);
}
selectedThumbCells.clear();
selectedThumbCells.remove(thumbCell);
});
}
private void showAddToFollowedAnimation(ThumbCell thumbCell) {