Skip to content

Commit

Permalink
#23 Fix checking that path to bash is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
introfog committed Nov 1, 2024
1 parent 24dc148 commit 6c9e093
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,21 @@ 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;

@Override
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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<children>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Label fx:id="pathToBashText" prefHeight="17.0" prefWidth="430.0" text="Path to bash to execute commands" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Button fx:id="browse" mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
<Label prefHeight="17.0" prefWidth="430.0" text="Path to bash to execute commands" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Button mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
<font>
<Font name="Verdana" size="12.0" />
</font>
</Button>
<Separator prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
<TextField fx:id="pathToBashExe" prefHeight="25.0" prefWidth="426.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="30.0" />
<TextField fx:id="pathToBash" prefHeight="25.0" prefWidth="426.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="30.0" />
</children>
</AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Label prefHeight="30.0" prefWidth="510.0" text="Automatic bash path finding hasn't been success. Set path to bash, it is required to execute git commands." wrapText="true" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<TextField fx:id="pathToBashExe" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="80.0" />
<TextField fx:id="pathToBash" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="80.0" />
<Separator prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
<Button mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0" />
<Label layoutY="62.0" prefHeight="30.0" prefWidth="510.0" text="On Unix likes systems usaully it is &quot;/usr/bin/bash&quot;, on Windows &quot;PATH_TO_GIT/bin/bash.exe&quot;." wrapText="true" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" />
Expand Down

0 comments on commit 6c9e093

Please sign in to comment.