Skip to content

Commit 0308df7

Browse files
committed
Show info window when specified directory doesn't exist
1 parent d418d75 commit 0308df7

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,18 @@ protected void runCommand() {
112112
if (menuController.isValid() && directoryTabController.isValid()
113113
&& commandTabController.isValid() && parametersTabController.isValid()) {
114114

115-
AppConfig.getInstance().setLastRunFolder(directoryTabController.getDirectory());
115+
File directoryToRunIn = new File(directoryTabController.getDirectory());
116+
if (!directoryToRunIn.exists() || !directoryToRunIn.isDirectory()) {
117+
DialogFactory.createInfoAlert("Invalid directory",
118+
"Specified directory either doesn't exist or isn't a directory.");
119+
return;
120+
}
121+
AppConfig.getInstance().setLastRunFolder(directoryToRunIn.getAbsolutePath());
116122

117123
new Thread(() -> {
118124
switchRunButton(true);
119-
final File scriptFile = CommandExecutor.searchGitRepositoriesAndCreateScriptFile(
120-
directoryTabController.getDirectory(), commandTabController.getCommandWithParameters());
125+
final File scriptFile = CommandExecutor.searchGitRepositoriesAndCreateScriptFile(directoryToRunIn,
126+
commandTabController.getCommandWithParameters());
121127
switchRunButton(false);
122128
CommandExecutor.executeScriptFileWithCommand(scriptFile);
123129
}).start();

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,17 @@ private CommandExecutor() {
3333
// Empty constructor
3434
}
3535

36-
public static File searchGitRepositoriesAndCreateScriptFile(String folderPath, String command) {
37-
File folder = new File(folderPath);
38-
if (folder.exists() && folder.isDirectory()) {
39-
LOGGER.info("Start searching git repositories in '{}' path.", folderPath);
40-
List<File> repositoriesToRunCommand = new ArrayList<>();
41-
searchGitRepositories(folder, repositoriesToRunCommand);
42-
LOGGER.info("'{}' git repositories were found to run command.", repositoriesToRunCommand.size());
43-
try {
44-
return createAndFillScriptFileWithCommand(command, repositoriesToRunCommand);
45-
} catch (IOException e) {
46-
LOGGER.error("Something goes wrong with creation temp script file with command.", e);
47-
}
48-
} else {
49-
LOGGER.error("'{}' folder either doesn't exist or isn't a directory, running command was skipped.", folderPath);
36+
public static File searchGitRepositoriesAndCreateScriptFile(File directory, String command) {
37+
LOGGER.info("Start searching git repositories in '{}' path.", directory.getAbsolutePath());
38+
List<File> repositoriesToRunCommand = new ArrayList<>();
39+
searchGitRepositories(directory, repositoriesToRunCommand);
40+
LOGGER.info("'{}' git repositories were found to run command.", repositoriesToRunCommand.size());
41+
try {
42+
return createAndFillScriptFileWithCommand(command, repositoriesToRunCommand);
43+
} catch (IOException e) {
44+
LOGGER.error("Something goes wrong with creation temp script file with command.", e);
5045
}
46+
5147
return null;
5248
}
5349

@@ -79,8 +75,7 @@ private static void executeScriptFile(File scriptFile) throws IOException {
7975
}
8076
stdout.close();
8177

82-
BufferedReader stderr = new BufferedReader(new InputStreamReader(
83-
powerShellProcess.getErrorStream()));
78+
BufferedReader stderr = new BufferedReader(new InputStreamReader(powerShellProcess.getErrorStream()));
8479
while ((line = stderr.readLine()) != null) {
8580
LOGGER.error("Error output of executed command '{}'", line);
8681
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public static void createErrorAlert(String header, String msg) {
3939
alert.showAndWait();
4040
}
4141

42+
public static void createInfoAlert(String header, String msg) {
43+
Alert alert = new Alert(AlertType.INFORMATION);
44+
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
45+
stage.getIcons().add(new Image(StageFactory.class.getResourceAsStream(AppConstants.PATH_TO_LOGO)));
46+
alert.setTitle("GitWave info");
47+
alert.setHeaderText(header);
48+
alert.setContentText(msg);
49+
alert.getDialogPane().setStyle(COMMON_STYLES);
50+
alert.showAndWait();
51+
}
52+
4253
public static ButtonType createCloseConfirmationAlert() {
4354
Alert dialog = new Alert(AlertType.CONFIRMATION);
4455
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
<font>
128128
<Font name="Verdana" size="12.0" />
129129
</font></Button>
130-
<Hyperlink layoutY="25.0" onAction="#foundIssue" text="Found an issue?" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0">
130+
<Hyperlink focusTraversable="false" layoutY="25.0" onAction="#foundIssue" text="Found an issue?" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0">
131131
<font>
132132
<Font name="Verdana" size="12.0" />
133133
</font></Hyperlink>

0 commit comments

Comments
 (0)