Skip to content

Commit

Permalink
Merge pull request #11 from turbolocust/new-menu-items
Browse files Browse the repository at this point in the history
New menu item (put into separate archives)
  • Loading branch information
turbolocust authored Mar 30, 2024
2 parents 2ac13ef + 93d8ed0 commit e431e2d
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public final class DropViewController extends BaseController {
*/
private final Set<String> _addresses;

/**
* If true, then {@link #_putIntoSeparateArchivesCheckBox} is enabled initially.
*/
private final boolean _enablePutIntoSeparateArchivesCheckBox;

@FXML
private TextArea _textArea;
@FXML
Expand All @@ -63,11 +68,14 @@ public final class DropViewController extends BaseController {
/**
* Constructs a controller for Drop View with the specified CSS theme.
*
* @param theme the {@link CSS} theme to be applied.
* @param theme the {@link CSS} theme to be applied.
* @param enablePutIntoSeparateArchivesCheckBox true to enable the checkbox which tells
* to put selected files into separate archives.
*/
public DropViewController(CSS.Theme theme) {
public DropViewController(CSS.Theme theme, boolean enablePutIntoSeparateArchivesCheckBox) {
super(theme);
_addresses = new LinkedHashSet<>();
_enablePutIntoSeparateArchivesCheckBox = enablePutIntoSeparateArchivesCheckBox;
}

@FXML
Expand All @@ -82,12 +90,9 @@ void handleSubmitButtonAction(ActionEvent evt) {
if (evt.getSource().equals(_submitButton)) {
final String text = _textArea.getText();
if (!text.isEmpty()) {
// tokenize file paths
final StringTokenizer tokenizer
= new StringTokenizer(text, "\"\n");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
// only add token if it's a valid file or directory
final var filePathsTokenizer = new StringTokenizer(text, "\"\n");
while (filePathsTokenizer.hasMoreTokens()) {
String token = filePathsTokenizer.nextToken();
if (FileUtils.isValid(token)) {
_addresses.add(token);
}
Expand Down Expand Up @@ -145,5 +150,6 @@ public boolean isPutInSeparateArchives() {
public void initialize(URL location, ResourceBundle resources) {
_titleText.setFont(Font.font("System", FontWeight.BOLD, -1));
_appendAddressesCheckBox.setTooltip(new Tooltip(I18N.getString("appendAddressesTooltip.text")));
_putIntoSeparateArchivesCheckBox.setSelected(_enablePutIntoSeparateArchivesCheckBox);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,24 @@ public static void showAboutView(CSS.Theme theme, Image icon, HostServices hostS
* @return the controller for the view.
*/
public static DropViewController showDropView(CSS.Theme theme, Image icon) {
final boolean preSelectPutIntoSeparateArchivesElements = false;
return showDropView(theme, icon, preSelectPutIntoSeparateArchivesElements);
}

/**
* Shows the drop view in a separate window.
*
* @param theme the theme to be applied.
* @param icon the icon to be used in the view
* @param preSelectUiElementsForPuttingFilesIntoSeparateArchives true to pre-select UI elements, which allow to
* put selected files into separate archives.
* @return the controller for the view.
*/
public static DropViewController showDropView(CSS.Theme theme, Image icon,
boolean preSelectUiElementsForPuttingFilesIntoSeparateArchives) {

final FXMLLoader fxmlLoader = initFXMLLoader(DROP_VIEW_RES);
DropViewController controller = new DropViewController(theme);
var controller = new DropViewController(theme, preSelectUiElementsForPuttingFilesIntoSeparateArchives);
fxmlLoader.setController(controller);

final Stage dropView = new Stage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ boolean isPutFilesIntoSeparateArchives() {
@FXML
private MenuItem _addManyFilesMenuItem;
@FXML
private MenuItem _addManyFilesSeparateArchiveMenuItem;
@FXML
private MenuItem _hashingMenuItem;
@FXML
private MenuItem _resetAppMenuItem;
Expand Down Expand Up @@ -294,26 +296,18 @@ void handleStartOperationMenuItemAction(ActionEvent evt) {
@FXML
void handleAddManyFilesMenuItemAction(ActionEvent evt) {
if (evt.getSource().equals(_addManyFilesMenuItem)) {
final DropViewController dropViewController = ViewControllers.showDropView(theme, iconImage);
final List<String> filePaths = dropViewController.getAddresses();
if (!ListUtils.isNullOrEmpty(filePaths)) {
_putFilesIntoSeparateArchives = dropViewController.isPutInSeparateArchives();
final int size = filePaths.size();
_selectedFiles = new ArrayList<>(size);
_startButton.setDisable(false);
if (size > 10) { // threshold, to avoid flooding text area
filePaths.forEach((filePath) -> _selectedFiles.add(new File(filePath)));
Log.i(I18N.getString("manyFilesSelected.text"), true, size);
} else { // log files in detail
filePaths.stream()
.peek((filePath) -> _selectedFiles.add(new File(filePath)))
.forEachOrdered((filePath) -> Log.i("{0}: {1}",
true, I18N.getString("fileSelected.text"), filePath));
}
} else {
Log.i(I18N.getString("noFilesSelected.text"), true);
_startButton.setDisable(ListUtils.isNullOrEmpty(_selectedFiles));
}
final var dropViewController = ViewControllers.showDropView(theme, iconImage);
performShowDropViewPostAction(dropViewController);
}
}

@FXML
void handleAddManyFilesSeparateArchiveMenuItemAction(ActionEvent evt) {
if (evt.getSource().equals(_addManyFilesSeparateArchiveMenuItem)) {
final boolean preSelectUiElementsForPuttingFilesIntoSeparateArchives = true;
final var dropViewController = ViewControllers.showDropView(
theme, iconImage, preSelectUiElementsForPuttingFilesIntoSeparateArchives);
performShowDropViewPostAction(dropViewController);
}
}

Expand Down Expand Up @@ -527,6 +521,28 @@ private void performGzipSelectionAction() {
}
}

private void performShowDropViewPostAction(DropViewController dropViewController) {
final var filePaths = dropViewController.getAddresses();
if (!ListUtils.isNullOrEmpty(filePaths)) {
_putFilesIntoSeparateArchives = dropViewController.isPutInSeparateArchives();
final int size = filePaths.size();
_selectedFiles = new ArrayList<>(size);
_startButton.setDisable(false);
if (size > 10) { // threshold, to avoid flooding text area
filePaths.forEach((filePath) -> _selectedFiles.add(new File(filePath)));
Log.i(I18N.getString("manyFilesSelected.text"), true, size);
} else { // log files in detail
filePaths.stream()
.peek((filePath) -> _selectedFiles.add(new File(filePath)))
.forEachOrdered((filePath) -> Log.i("{0}: {1}",
true, I18N.getString("fileSelected.text"), filePath));
}
} else {
Log.i(I18N.getString("noFilesSelected.text"), true);
_startButton.setDisable(ListUtils.isNullOrEmpty(_selectedFiles));
}
}

private void resetFilter() {
final boolean wasApplied = _state.getFilterPredicate() != null;
_state.setFilterPredicate(null);
Expand Down Expand Up @@ -580,6 +596,7 @@ void disableUIControlsAsLongAsAnyTaskIsActive() {
_saveAsButton.disableProperty().bind(runningProperty);
_selectFilesButton.disableProperty().bind(runningProperty);
_addManyFilesMenuItem.disableProperty().bind(runningProperty);
_addManyFilesSeparateArchiveMenuItem.disableProperty().bind(runningProperty);
_progressBar.visibleProperty().bind(runningProperty);
_progressText.visibleProperty().bind(runningProperty);
}
Expand All @@ -596,6 +613,7 @@ void enableUIControls() {
_selectFilesButton.disableProperty().unbind();
_saveAsButton.disableProperty().unbind();
_addManyFilesMenuItem.disableProperty().unbind();
_addManyFilesSeparateArchiveMenuItem.disableProperty().unbind();
_progressBar.visibleProperty().unbind();
_progressText.visibleProperty().unbind();
}
Expand Down
Loading

0 comments on commit e431e2d

Please sign in to comment.