From 1a6555ca0568a0b89c697d218f6bf07926ffc4dd Mon Sep 17 00:00:00 2001 From: Matthias Fussenegger Date: Sat, 30 Mar 2024 16:25:27 +0100 Subject: [PATCH] New menu items (put into separate archives) --- .../controller/DropViewController.java | 22 ++- .../controller/ViewControllers.java | 18 ++- .../controller/main/MainViewController.java | 58 ++++--- src/main/resources/fxml/MainView.fxml | 150 +++++++++++------- src/main/resources/i18n/gzipper_de.properties | 5 +- src/main/resources/i18n/gzipper_en.properties | 5 +- 6 files changed, 170 insertions(+), 88 deletions(-) diff --git a/src/main/java/org/gzipper/java/presentation/controller/DropViewController.java b/src/main/java/org/gzipper/java/presentation/controller/DropViewController.java index 7b6859c..886b410 100644 --- a/src/main/java/org/gzipper/java/presentation/controller/DropViewController.java +++ b/src/main/java/org/gzipper/java/presentation/controller/DropViewController.java @@ -47,6 +47,11 @@ public final class DropViewController extends BaseController { */ private final Set _addresses; + /** + * If true, then {@link #_putIntoSeparateArchivesCheckBox} is enabled initially. + */ + private final boolean _enablePutIntoSeparateArchivesCheckBox; + @FXML private TextArea _textArea; @FXML @@ -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 @@ -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); } @@ -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); } } diff --git a/src/main/java/org/gzipper/java/presentation/controller/ViewControllers.java b/src/main/java/org/gzipper/java/presentation/controller/ViewControllers.java index 9827ca4..7cb73fd 100644 --- a/src/main/java/org/gzipper/java/presentation/controller/ViewControllers.java +++ b/src/main/java/org/gzipper/java/presentation/controller/ViewControllers.java @@ -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(); diff --git a/src/main/java/org/gzipper/java/presentation/controller/main/MainViewController.java b/src/main/java/org/gzipper/java/presentation/controller/main/MainViewController.java index 8ce2f7f..0cb608b 100644 --- a/src/main/java/org/gzipper/java/presentation/controller/main/MainViewController.java +++ b/src/main/java/org/gzipper/java/presentation/controller/main/MainViewController.java @@ -174,6 +174,8 @@ boolean isPutFilesIntoSeparateArchives() { @FXML private MenuItem _addManyFilesMenuItem; @FXML + private MenuItem _addManyFilesSeparateArchiveMenuItem; + @FXML private MenuItem _hashingMenuItem; @FXML private MenuItem _resetAppMenuItem; @@ -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 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); } } @@ -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); @@ -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); } @@ -596,6 +613,7 @@ void enableUIControls() { _selectFilesButton.disableProperty().unbind(); _saveAsButton.disableProperty().unbind(); _addManyFilesMenuItem.disableProperty().unbind(); + _addManyFilesSeparateArchiveMenuItem.disableProperty().unbind(); _progressBar.visibleProperty().unbind(); _progressText.visibleProperty().unbind(); } diff --git a/src/main/resources/fxml/MainView.fxml b/src/main/resources/fxml/MainView.fxml index 09b0c25..1501dcd 100644 --- a/src/main/resources/fxml/MainView.fxml +++ b/src/main/resources/fxml/MainView.fxml @@ -24,24 +24,32 @@ - + - - + + - + - - @@ -49,103 +57,135 @@ - + - - - - + + + + - - - - - - + - + - + - + + + + + + + + - + - - - - + + + + - + - + - - - - + + + + - + - + - - + + - + - + - - + - + - + - - + + - + -