Skip to content

Commit

Permalink
Properly disabling UI elements if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolocust committed Mar 31, 2024
1 parent ce0bcc2 commit 535d51a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public final class DropViewController extends BaseController {
private final Set<String> _addresses;

/**
* If true, then {@link #_putIntoSeparateArchivesCheckBox} is enabled initially.
* Options to customize the set-up of this DropView.
*/
private final boolean _enablePutIntoSeparateArchivesCheckBox;
private final ViewControllersOptions.DropViewOptions _options;

@FXML
private TextArea _textArea;
Expand All @@ -68,14 +68,13 @@ 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 enablePutIntoSeparateArchivesCheckBox true to enable the checkbox which tells
* to put selected files into separate archives.
* @param theme the {@link CSS} theme to be applied.
* @param options used to customize the set-up of the DropView.
*/
public DropViewController(CSS.Theme theme, boolean enablePutIntoSeparateArchivesCheckBox) {
public DropViewController(CSS.Theme theme, ViewControllersOptions.DropViewOptions options) {
super(theme);
_addresses = new LinkedHashSet<>();
_enablePutIntoSeparateArchivesCheckBox = enablePutIntoSeparateArchivesCheckBox;
_options = options;
}

@FXML
Expand Down Expand Up @@ -150,6 +149,7 @@ 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);
_putIntoSeparateArchivesCheckBox.setSelected(_options.getPreSelectUiElementsForPuttingFilesIntoSeparateArchives());
_putIntoSeparateArchivesCheckBox.setVisible(!_options.getDisableUiElementsForPuttingFilesIntoSeparateArchives());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,16 @@ public static void showAboutView(CSS.Theme theme, Image icon, HostServices hostS
/**
* 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
* @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.
* @param theme the theme to be applied.
* @param icon the icon to be used in the view
* @param options used to customize the set-up of the DropView.
* @return the controller for the view.
*/
public static DropViewController showDropView(CSS.Theme theme, Image icon,
boolean preSelectUiElementsForPuttingFilesIntoSeparateArchives) {
ViewControllersOptions.DropViewOptions options) {

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

final Stage dropView = new Stage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.gzipper.java.presentation.controller.BaseController;
import org.gzipper.java.presentation.controller.DropViewController;
import org.gzipper.java.presentation.controller.ViewControllers;
import org.gzipper.java.presentation.controller.ViewControllersOptions;
import org.gzipper.java.presentation.handler.TextAreaHandler;
import org.gzipper.java.util.Log;
import org.gzipper.java.util.Settings;
Expand Down Expand Up @@ -296,7 +297,14 @@ void handleStartOperationMenuItemAction(ActionEvent evt) {
@FXML
void handleAddManyFilesMenuItemAction(ActionEvent evt) {
if (evt.getSource().equals(_addManyFilesMenuItem)) {
final var dropViewController = ViewControllers.showDropView(theme, iconImage);
final boolean preSelectUiElementsForPuttingFilesIntoSeparateArchives = false;
final boolean disableUiElementsForPuttingFilesIntoSeparateArchives = _decompressRadioButton.isSelected();

final var options = new ViewControllersOptions.DropViewOptions(
preSelectUiElementsForPuttingFilesIntoSeparateArchives,
disableUiElementsForPuttingFilesIntoSeparateArchives);

final var dropViewController = ViewControllers.showDropView(theme, iconImage, options);
performShowDropViewPostAction(dropViewController);
}
}
Expand All @@ -305,8 +313,13 @@ void handleAddManyFilesMenuItemAction(ActionEvent evt) {
void handleAddManyFilesSeparateArchiveMenuItemAction(ActionEvent evt) {
if (evt.getSource().equals(_addManyFilesSeparateArchiveMenuItem)) {
final boolean preSelectUiElementsForPuttingFilesIntoSeparateArchives = true;
final var dropViewController = ViewControllers.showDropView(
theme, iconImage, preSelectUiElementsForPuttingFilesIntoSeparateArchives);
final boolean disableUiElementsForPuttingFilesIntoSeparateArchives = false;

final var options = new ViewControllersOptions.DropViewOptions(
preSelectUiElementsForPuttingFilesIntoSeparateArchives,
disableUiElementsForPuttingFilesIntoSeparateArchives);

final var dropViewController = ViewControllers.showDropView(theme, iconImage, options);
performShowDropViewPostAction(dropViewController);
}
}
Expand Down Expand Up @@ -505,6 +518,7 @@ private File pickFileToBeSaved() {

private void performModeRadioButtonAction(boolean compress, String selectFilesButtonText, String saveAsButtonText) {
_state = compress ? new CompressState(this) : new DecompressState(this);
_addManyFilesSeparateArchiveMenuItem.setDisable(!compress);
_selectFilesButton.setText(I18N.getString(selectFilesButtonText));
_saveAsButton.setText(I18N.getString(saveAsButtonText));
}
Expand Down Expand Up @@ -596,9 +610,9 @@ 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);
_addManyFilesSeparateArchiveMenuItem.setDisable(true);
}

/**
Expand All @@ -614,6 +628,7 @@ void enableUIControls() {
_saveAsButton.disableProperty().unbind();
_addManyFilesMenuItem.disableProperty().unbind();
_addManyFilesSeparateArchiveMenuItem.disableProperty().unbind();
_addManyFilesSeparateArchiveMenuItem.setDisable(_decompressRadioButton.isSelected());
_progressBar.visibleProperty().unbind();
_progressText.visibleProperty().unbind();
}
Expand Down

0 comments on commit 535d51a

Please sign in to comment.