Skip to content

Commit a4e42c2

Browse files
committed
Prevent opening multiple "About" windows
1 parent 0cd815b commit a4e42c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/com/airsquared/blobsaver/Controller.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javafx.scene.layout.VBox;
3434
import javafx.scene.paint.Color;
3535
import javafx.stage.DirectoryChooser;
36+
import javafx.stage.Stage;
3637
import javafx.stage.WindowEvent;
3738
import org.json.JSONArray;
3839

@@ -514,15 +515,23 @@ public void helpLabelHandler(MouseEvent evt) {
514515
}
515516
}
516517

518+
private Stage aboutStage = null;
519+
517520
@SuppressWarnings("ResultOfMethodCallIgnored")
518521
public void aboutMenuHandler() {
522+
if (aboutStage != null) { // prevent opening multiple "About" windows
523+
aboutStage.toFront();
524+
aboutStage.requestFocus();
525+
return;
526+
}
519527
ButtonType githubRepo = new ButtonType("Github Repo");
520528
ButtonType viewLicense = new ButtonType("View License");
521529
ButtonType librariesUsed = new ButtonType("Libraries Used");
522530
ButtonType donate = new ButtonType("Donate!");
523531
ButtonType customOK = new ButtonType("OK", ButtonBar.ButtonData.CANCEL_CLOSE);
524532
Alert alert = new Alert(Alert.AlertType.INFORMATION, "About text here",
525533
librariesUsed, viewLicense, donate, githubRepo, customOK);
534+
526535
alert.setTitle("About");
527536

528537
//Deactivate default behavior for librariesUsed Button:
@@ -538,6 +547,9 @@ public void aboutMenuHandler() {
538547
"This program is licensed under GNU GPL v3.0-only");
539548

540549
resizeAlertButtons(alert);
550+
551+
aboutStage = (Stage) alert.getDialogPane().getScene().getWindow();
552+
541553
alert.showAndWait();
542554
switch (alert.getResult().getText()) {
543555
case "Github Repo":
@@ -581,6 +593,7 @@ public void aboutMenuHandler() {
581593
donate();
582594
break;
583595
}
596+
aboutStage = null;
584597
}
585598

586599
private void useMacOSMenuBar() {

0 commit comments

Comments
 (0)