forked from j62/ctbrec
Apply application stylesheets to custom dialogs
This commit is contained in:
parent
62c6f9a885
commit
9696edd002
|
@ -594,7 +594,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
|||
showStreamSwitchErrorDialog(t);
|
||||
return null;
|
||||
};
|
||||
StreamSourceSelectionDialog.show(fxModel.getDelegate(), onSuccess, onFail);
|
||||
StreamSourceSelectionDialog.show(getTabPane().getScene(), fxModel.getDelegate(), onSuccess, onFail);
|
||||
}
|
||||
|
||||
private void showStreamSwitchErrorDialog(Throwable throwable) {
|
||||
|
|
|
@ -9,10 +9,12 @@ import java.util.function.Function;
|
|||
import ctbrec.Model;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.ChoiceDialog;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class StreamSourceSelectionDialog {
|
||||
public static void show(Model model, Function<Model,Void> onSuccess, Function<Throwable, Void> onFail) {
|
||||
public static void show(Scene parent, Model model, Function<Model,Void> onSuccess, Function<Throwable, Void> onFail) {
|
||||
Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() {
|
||||
@Override
|
||||
protected List<StreamSource> call() throws Exception {
|
||||
|
@ -30,6 +32,8 @@ public class StreamSourceSelectionDialog {
|
|||
choiceDialog.setTitle("Stream Quality");
|
||||
choiceDialog.setHeaderText("Select your preferred stream quality");
|
||||
choiceDialog.setResizable(true);
|
||||
Stage stage = (Stage) choiceDialog.getDialogPane().getScene().getWindow();
|
||||
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
|
||||
Optional<StreamSource> selectedSource = choiceDialog.showAndWait();
|
||||
if(selectedSource.isPresent()) {
|
||||
int index = sources.indexOf(selectedSource.get());
|
||||
|
|
|
@ -444,7 +444,7 @@ public class ThumbCell extends StackPane {
|
|||
alert.showAndWait();
|
||||
return null;
|
||||
};
|
||||
StreamSourceSelectionDialog.show(model, onSuccess, onFail);
|
||||
StreamSourceSelectionDialog.show(getScene(), model, onSuccess, onFail);
|
||||
} else {
|
||||
_startStopAction(model, start);
|
||||
}
|
||||
|
|
|
@ -478,7 +478,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
|
||||
MenuItem sendTip = new MenuItem("Send Tip");
|
||||
sendTip.setOnAction((e) -> {
|
||||
TipDialog tipDialog = new TipDialog(site, cell.getModel());
|
||||
TipDialog tipDialog = new TipDialog(sendTip.getParentPopup().getScene(), site, cell.getModel());
|
||||
tipDialog.showAndWait();
|
||||
String tipText = tipDialog.getResult();
|
||||
if(tipText != null) {
|
||||
|
|
|
@ -11,16 +11,18 @@ import ctbrec.Model;
|
|||
import ctbrec.sites.Site;
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.TextInputDialog;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class TipDialog extends TextInputDialog {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(TipDialog.class);
|
||||
private Site site;
|
||||
|
||||
public TipDialog(Site site, Model model) {
|
||||
public TipDialog(Scene parent, Site site, Model model) {
|
||||
this.site = site;
|
||||
setTitle("Send Tip");
|
||||
loadTokenBalance();
|
||||
|
@ -28,6 +30,10 @@ public class TipDialog extends TextInputDialog {
|
|||
setContentText("Amount of tokens to tip:");
|
||||
setResizable(true);
|
||||
getEditor().setDisable(true);
|
||||
if(parent != null) {
|
||||
Stage stage = (Stage) getDialogPane().getScene().getWindow();
|
||||
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTokenBalance() {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class EditNotesAction {
|
|||
new Thread(() -> {
|
||||
Platform.runLater(() -> {
|
||||
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
|
||||
Optional<String> newNotes = Dialogs.showTextInput("Model Notes", "Notes for " + model.getName(), notes);
|
||||
Optional<String> newNotes = Dialogs.showTextInput(source.getScene(), "Model Notes", "Notes for " + model.getName(), notes);
|
||||
newNotes.ifPresent(n -> {
|
||||
if(!n.trim().isEmpty()) {
|
||||
Config.getInstance().getSettings().modelNotes.put(model.getUrl(), n);
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Optional;
|
|||
import ctbrec.ui.AutosizeAlert;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Dialog;
|
||||
|
@ -16,7 +17,12 @@ import javafx.stage.Modality;
|
|||
import javafx.stage.Stage;
|
||||
|
||||
public class Dialogs {
|
||||
// TODO reduce calls to this method and use Dialogs.showError(Scene parent, String header, String text, Throwable t) instead
|
||||
public static void showError(String header, String text, Throwable t) {
|
||||
showError(null, header, text, t);
|
||||
}
|
||||
|
||||
public static void showError(Scene parent, String header, String text, Throwable t) {
|
||||
Runnable r = () -> {
|
||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Error");
|
||||
|
@ -26,6 +32,10 @@ public class Dialogs {
|
|||
content += " " + t.getLocalizedMessage();
|
||||
}
|
||||
alert.setContentText(content);
|
||||
if(parent != null) {
|
||||
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
|
||||
}
|
||||
alert.showAndWait();
|
||||
};
|
||||
|
||||
|
@ -36,7 +46,7 @@ public class Dialogs {
|
|||
}
|
||||
}
|
||||
|
||||
public static Optional<String> showTextInput(String title, String header, String text) {
|
||||
public static Optional<String> showTextInput(Scene parent, String title, String header, String text) {
|
||||
Dialog<String> dialog = new Dialog<>();
|
||||
dialog.setTitle(title);
|
||||
dialog.setHeaderText(header);
|
||||
|
@ -46,6 +56,9 @@ public class Dialogs {
|
|||
InputStream icon = Dialogs.class.getResourceAsStream("/icon.png");
|
||||
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
|
||||
stage.getIcons().add(new Image(icon));
|
||||
if(parent != null) {
|
||||
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
|
||||
}
|
||||
|
||||
GridPane grid = new GridPane();
|
||||
grid.setHgap(10);
|
||||
|
|
|
@ -55,7 +55,7 @@ public class Wizard extends BorderPane {
|
|||
try {
|
||||
validator.run();
|
||||
} catch(IllegalStateException e) {
|
||||
Dialogs.showError("Settings invalid", e.getMessage(), null);
|
||||
Dialogs.showError(Wizard.this.getScene(), "Settings invalid", e.getMessage(), null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue