Skip to content

Commit 6c9e093

Browse files
committed
#23 Fix checking that path to bash is valid
1 parent 24dc148 commit 6c9e093

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,21 @@ public class SettingsController extends BaseController {
4141
private static final Logger LOGGER = LoggerFactory.getLogger(SettingsController.class);
4242

4343
@FXML
44-
private TextField pathToBashExe;
44+
private TextField pathToBash;
4545

4646
@FXML
4747
private Button save;
4848

49-
@FXML
50-
private Button browse;
51-
52-
@FXML
53-
private Label pathToBashText;
54-
5549
@FXML
5650
private Label done;
5751

5852
@Override
5953
public void initialize(FxmlStageHolder fxmlStageHolder) {
6054
super.initialize(fxmlStageHolder);
6155
super.setClosingOnEscapePressing(fxmlStageHolder);
62-
final String pathToGitBashExeStr = AppConfig.getInstance().getPathToBash();
63-
if (pathToGitBashExeStr != null) {
64-
pathToBashExe.setText(pathToGitBashExeStr);
56+
final String pathToGitBashStr = AppConfig.getInstance().getPathToBash();
57+
if (pathToGitBashStr != null) {
58+
pathToBash.setText(pathToGitBashStr);
6559
}
6660
save.requestFocus();
6761
if (done != null) {
@@ -71,11 +65,10 @@ public void initialize(FxmlStageHolder fxmlStageHolder) {
7165

7266
@FXML
7367
protected void save() {
74-
File bashFile = new File(pathToBashExe.getText());
75-
if (bashFile.exists() && AppConfig.getInstance().setPathToBash(bashFile.getAbsolutePath())) {
68+
if (AppConfig.getInstance().setPathToBash(pathToBash.getText())) {
7669
closeStage();
7770
} else {
78-
LOGGER.error("Wrong path to bash '{}'", bashFile.getAbsolutePath());
71+
LOGGER.error("Wrong path to bash '{}'", pathToBash.getText());
7972
DialogFactory.createErrorAlert("Bash hasn't been specified",
8073
"Bash hasn't been specified correctly. Either specify path manually or find via file browser.", 210);
8174
}
@@ -122,14 +115,8 @@ protected void browseGitBashExe() {
122115

123116
File selectedFile = fileChooser.showOpenDialog(getStage());
124117
if (selectedFile != null) {
125-
if (selectedFile.exists()) {
126-
pathToBashExe.setText(selectedFile.getAbsolutePath());
127-
} else {
128-
LOGGER.error("Wrong browsed path to bash '{}'", selectedFile);
129-
DialogFactory.createErrorAlert("Provided file wasn't found", "Provided file wasn't found, try again");
130-
}
131-
} else {
132-
// It means that file chooser dialog window was just closed without choosing a file
118+
pathToBash.setText(selectedFile.getAbsolutePath());
133119
}
120+
// ELSE: It means that file chooser dialog window was just closed without choosing a file
134121
}
135122
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
<children>
2626
<AnchorPane prefHeight="200.0" prefWidth="200.0">
2727
<children>
28-
<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" />
29-
<Button fx:id="browse" mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
28+
<Label prefHeight="17.0" prefWidth="430.0" text="Path to bash to execute commands" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
29+
<Button mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
3030
<font>
3131
<Font name="Verdana" size="12.0" />
3232
</font>
3333
</Button>
3434
<Separator prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
35-
<TextField fx:id="pathToBashExe" prefHeight="25.0" prefWidth="426.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="30.0" />
35+
<TextField fx:id="pathToBash" prefHeight="25.0" prefWidth="426.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="30.0" />
3636
</children>
3737
</AnchorPane>
3838
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<AnchorPane prefHeight="200.0" prefWidth="200.0">
2424
<children>
2525
<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" />
26-
<TextField fx:id="pathToBashExe" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="80.0" />
26+
<TextField fx:id="pathToBash" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="80.0" />
2727
<Separator prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
2828
<Button mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0" />
2929
<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" />

0 commit comments

Comments
 (0)