Skip to content

Commit b890aaf

Browse files
committed
Replace updater custom stage to default dialog window
1 parent c349596 commit b890aaf

File tree

4 files changed

+22
-87
lines changed

4 files changed

+22
-87
lines changed

src/main/java/com/github/introfog/gitwave/controller/ExecuteController.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Objects;
2929
import javafx.fxml.FXML;
3030
import javafx.scene.control.Button;
31+
import javafx.scene.control.ButtonType;
3132
import javafx.scene.control.TextField;
3233
import javafx.stage.DirectoryChooser;
3334
import javafx.stage.Stage;
@@ -133,11 +134,14 @@ protected void saveCommand() {
133134
specifySourceCommand(commandDto);
134135
// TODO MINOR if DTO is already existed, nothing was happened, is it OK?
135136
} else {
136-
FxmlStageHolder holder = StageFactory.createModalStage("view/updater.fxml", "Command updater");
137-
UpdateController updateController = holder.getFxmlLoader().getController();
138-
// TODO add required methods for all stages where necessary
139-
updateController.setRequiredFields(this, sourceCommand, commandDto);
140-
holder.getStage().showAndWait();
137+
ButtonType result = DialogFactory.createSaveOrUpdateAlert();
138+
if (ButtonType.YES == result) {
139+
AppConfig.getInstance().addCommand(commandDto);
140+
specifySourceCommand(commandDto);
141+
} else if (ButtonType.NO == result) {
142+
AppConfig.getInstance().updateExistedCommand(sourceCommand, commandDto);
143+
specifySourceCommand(commandDto);
144+
}
141145
}
142146
}
143147

src/main/java/com/github/introfog/gitwave/controller/UpdateController.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/main/java/com/github/introfog/gitwave/model/DialogFactory.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,17 @@ public static void createCloseConfirmationAlert(Stage primaryStage) {
5252
}
5353
});
5454
}
55+
56+
public static ButtonType createSaveOrUpdateAlert() {
57+
Alert confirmationDialog = new Alert(AlertType.CONFIRMATION);
58+
Stage stage = (Stage) confirmationDialog.getDialogPane().getScene().getWindow();
59+
stage.getIcons().add(new Image(StageFactory.class.getResourceAsStream(AppConstants.PATH_TO_LOGO)));
60+
confirmationDialog.setTitle("Confirmation");
61+
confirmationDialog.setHeaderText("Do you want to save command as a new instance?\nSelect 'No' if update existed.");
62+
confirmationDialog.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
63+
64+
ButtonType[] pressedButton = {null};
65+
confirmationDialog.showAndWait().ifPresent(response -> pressedButton[0] = response);
66+
return pressedButton[0];
67+
}
5568
}

src/main/resources/com/github/introfog/gitwave/view/updater.fxml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)