From 6c9e0937b2329146fd2e08e262231c4a1cdb1547 Mon Sep 17 00:00:00 2001 From: Dmitry Chubrick Date: Fri, 1 Nov 2024 19:07:36 +0300 Subject: [PATCH] #23 Fix checking that path to bash is valid --- .../controller/SettingsController.java | 29 +++++-------------- .../introfog/gitwave/view/settings.fxml | 6 ++-- .../github/introfog/gitwave/view/setup.fxml | 2 +- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/github/introfog/gitwave/controller/SettingsController.java b/src/main/java/com/github/introfog/gitwave/controller/SettingsController.java index 36161c8..e706fbc 100644 --- a/src/main/java/com/github/introfog/gitwave/controller/SettingsController.java +++ b/src/main/java/com/github/introfog/gitwave/controller/SettingsController.java @@ -41,17 +41,11 @@ public class SettingsController extends BaseController { private static final Logger LOGGER = LoggerFactory.getLogger(SettingsController.class); @FXML - private TextField pathToBashExe; + private TextField pathToBash; @FXML private Button save; - @FXML - private Button browse; - - @FXML - private Label pathToBashText; - @FXML private Label done; @@ -59,9 +53,9 @@ public class SettingsController extends BaseController { public void initialize(FxmlStageHolder fxmlStageHolder) { super.initialize(fxmlStageHolder); super.setClosingOnEscapePressing(fxmlStageHolder); - final String pathToGitBashExeStr = AppConfig.getInstance().getPathToBash(); - if (pathToGitBashExeStr != null) { - pathToBashExe.setText(pathToGitBashExeStr); + final String pathToGitBashStr = AppConfig.getInstance().getPathToBash(); + if (pathToGitBashStr != null) { + pathToBash.setText(pathToGitBashStr); } save.requestFocus(); if (done != null) { @@ -71,11 +65,10 @@ public void initialize(FxmlStageHolder fxmlStageHolder) { @FXML protected void save() { - File bashFile = new File(pathToBashExe.getText()); - if (bashFile.exists() && AppConfig.getInstance().setPathToBash(bashFile.getAbsolutePath())) { + if (AppConfig.getInstance().setPathToBash(pathToBash.getText())) { closeStage(); } else { - LOGGER.error("Wrong path to bash '{}'", bashFile.getAbsolutePath()); + LOGGER.error("Wrong path to bash '{}'", pathToBash.getText()); DialogFactory.createErrorAlert("Bash hasn't been specified", "Bash hasn't been specified correctly. Either specify path manually or find via file browser.", 210); } @@ -122,14 +115,8 @@ protected void browseGitBashExe() { File selectedFile = fileChooser.showOpenDialog(getStage()); if (selectedFile != null) { - if (selectedFile.exists()) { - pathToBashExe.setText(selectedFile.getAbsolutePath()); - } else { - LOGGER.error("Wrong browsed path to bash '{}'", selectedFile); - DialogFactory.createErrorAlert("Provided file wasn't found", "Provided file wasn't found, try again"); - } - } else { - // It means that file chooser dialog window was just closed without choosing a file + pathToBash.setText(selectedFile.getAbsolutePath()); } + // ELSE: It means that file chooser dialog window was just closed without choosing a file } } diff --git a/src/main/resources/com/github/introfog/gitwave/view/settings.fxml b/src/main/resources/com/github/introfog/gitwave/view/settings.fxml index e153ba6..1ec0bab 100644 --- a/src/main/resources/com/github/introfog/gitwave/view/settings.fxml +++ b/src/main/resources/com/github/introfog/gitwave/view/settings.fxml @@ -25,14 +25,14 @@ - diff --git a/src/main/resources/com/github/introfog/gitwave/view/setup.fxml b/src/main/resources/com/github/introfog/gitwave/view/setup.fxml index b6f8546..dea1384 100644 --- a/src/main/resources/com/github/introfog/gitwave/view/setup.fxml +++ b/src/main/resources/com/github/introfog/gitwave/view/setup.fxml @@ -23,7 +23,7 @@