Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
Don't show the rename dialog without files
Only count actually renamed files
Update the list more often (numbering more consistent)
Working github page for linux
  • Loading branch information
Jelmerro committed Oct 12, 2016
1 parent 87f98b5 commit d30267a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
14 changes: 8 additions & 6 deletions src/f2utility/AboutAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ public AboutAlert() {
getDialogPane().setGraphic(icon);
//Content
setTitle("About");
setHeaderText("F2Utility 1.0.0");
setHeaderText("F2Utility 1.0.1");
setContentText("An easy and effective batch file rename tool\nCreated by Jelmerro\nMIT License");
//Github button
Button githubButton = (Button) getDialogPane().lookupButton(ButtonType.OK);
githubButton.setText("Github");
githubButton.setOnAction(e -> {
//Try opening the default desktop browser
//Else show the url in an alert
try {
Desktop.getDesktop().browse(new URI("https://github.com/Jelmerro/F2Utility"));
} catch (Exception ex) {
new Alert(Alert.AlertType.NONE, "URL: https://github.com/Jelmerro/F2Utility", ButtonType.CLOSE).showAndWait();
}
new Thread(() -> {
try {
Desktop.getDesktop().browse(new URI("https://github.com/Jelmerro/F2Utility"));
} catch (Exception ex) {
new Alert(Alert.AlertType.NONE, "URL: https://github.com/Jelmerro/F2Utility", ButtonType.CLOSE).showAndWait();
}
}).start();
e.consume();
});
setOnCloseRequest(e -> {
Expand Down
3 changes: 3 additions & 0 deletions src/f2utility/FileList.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void showDirChooser() {
} catch (NullPointerException ex) {

}
ToolBox.getInstance().updateNewNames();
}

/**
Expand All @@ -202,6 +203,7 @@ public void showFileChooser() {
} catch (NullPointerException ex) {

}
ToolBox.getInstance().updateNewNames();
}

/**
Expand Down Expand Up @@ -232,6 +234,7 @@ public void addFiles(List<java.io.File> files) {
public void removeSelectedFiles() {
fileList.getItems().removeAll(fileList.getSelectionModel().getSelectedItems());
fileList.getSelectionModel().clearSelection();
ToolBox.getInstance().updateNewNames();
}

private FileList() {
Expand Down
2 changes: 2 additions & 0 deletions src/f2utility/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static MenuBar getInstance() {
for (File file : selectedCells) {
FileList.getInstance().getSelectionModel().select(file);
}
ToolBox.getInstance().updateNewNames();
});
moveUpItem.setAccelerator(KeyCombination.valueOf("["));
//Move down item
Expand All @@ -86,6 +87,7 @@ public static MenuBar getInstance() {
for (File file : selectedCells) {
FileList.getInstance().getSelectionModel().select(file);
}
ToolBox.getInstance().updateNewNames();
});
moveDownItem.setAccelerator(KeyCombination.valueOf("]"));
//Delete item
Expand Down
49 changes: 27 additions & 22 deletions src/f2utility/ToolBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ public static ToolBox getInstance() {
}
//No failed items means the renaming was a success
//Otherwise a the list of failed items is shown
if (failedItems.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Rename success");
alert.setHeaderText("Succesfully renamed all files");
alert.setContentText(results.size() + " files and folders were renamed with succes");
alert.showAndWait();
} else {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Rename error");
alert.setHeaderText("Some files were not renamed correctly");
TextArea list = new TextArea(failedItems);
alert.getDialogPane().setContent(list);
alert.showAndWait();
//Only show a message if there were files in the list
if (results.size() > 0) {
if (failedItems.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Rename success");
alert.setHeaderText("Succesfully renamed all files");
alert.setContentText(results.size() + " files and folders were renamed with success");
alert.showAndWait();
} else {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Rename error");
alert.setHeaderText("Some files were not renamed correctly");
TextArea list = new TextArea(failedItems);
alert.getDialogPane().setContent(list);
alert.showAndWait();
}
}
});
buttonBox.getChildren().add(renameButton);
Expand Down Expand Up @@ -118,23 +121,25 @@ public static ToolBox getInstance() {
}

/**
* Renames all the items and returns the list with results
* Renames all the items and returns the list with results, skips unchanged ones
*
* @return results HashMap<File, Boolean>
*/
public HashMap<File, Boolean> rename() {
HashMap<File, Boolean> map = new HashMap<>();
for (File file : FileList.getInstance().getItems()) {
boolean success = file.rename();
if (success) {
String ext = file.getExt();
if (ext.equals("-")) {
FileList.getInstance().getItems().set(FileList.getInstance().getItems().indexOf(file), new File(file.getParent() + File.separator + file.getNewName()));
} else {
FileList.getInstance().getItems().set(FileList.getInstance().getItems().indexOf(file), new File(file.getParent() + File.separator + file.getNewName() + "." + ext));
if (!file.getName().equals(file.getNewName())) {
boolean success = file.rename();
if (success) {
String ext = file.getExt();
if (ext.equals("-")) {
FileList.getInstance().getItems().set(FileList.getInstance().getItems().indexOf(file), new File(file.getParent() + File.separator + file.getNewName()));
} else {
FileList.getInstance().getItems().set(FileList.getInstance().getItems().indexOf(file), new File(file.getParent() + File.separator + file.getNewName() + "." + ext));
}
}
map.put(file, success);
}
map.put(file, success);
}
return map;
}
Expand Down

0 comments on commit d30267a

Please sign in to comment.