Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new reusable FileSelector control allowing tools to get one or many files as input. #308

Merged
merged 5 commits into from
Jan 30, 2022

Conversation

veler
Copy link
Collaborator

@veler veler commented Jan 30, 2022

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Internationalization and localization
  • Other (please describe):

What is the current behavior?

More and more tools are getting the ability to accept files as an input, in particular tools in the Graphic category.
Unfortunately, each tools were copying the UI and implementation for letting the user selecting a file, leading to a bunch of duplicated code.

Issue Number: #244, #151

What is the new behavior?

Created a control FileSelector which basically unify the UI and implementation for such a need.
The control has several parameters:

  • AllowedFileExtensions - Defines the exhaustive list of file type that the user can select through the control. Using "*" or a null value corresponds to allowing any kind of file.
  • AllowMultipleFileSelection - Tells whether the user will be able to select a single or multiple files. Changing this value changes the way the Drag & Drop instructions are displayed. Setting this value to true also display a Browse folders option, which allows the user to select a folder. The control will then pick up the files in this folder (but not sub-folders) that match AllowedFileExtensions.
  • AllowPasteImage - The "Paste" button allows the user to paste one or several files that he has in the clipboard. Enabling this option will additionally allow the user to paste an image from the clipboard such as a screenshot.
  • FilesSelectedCommand - A MVVM command that is invoked once the user selected a file, so the tool can reacts to the user interaction.

The control filters automatically the selected / dropped / pasted files based on the AllowedFileExtensions and shows a message when the files don't respect the filter. However, it doesn't show this message when selecting a folder.

Here is how to use the control:

<controls:FileSelector
            AllowedFileExtensions="png;jpg;jpeg;bmp"
            AllowMultipleFileSelection="False"
            AllowPasteImage="True"
            FilesSelectedCommand="{x:Bind ViewModel.FilesSelectedCommand}"/>
<!-- or -->
<controls:FileSelector
            AllowedFileExtensions="*"
            FilesSelectedCommand="{x:Bind ViewModel.FilesSelectedCommand}"/>
        FilesSelectedCommand = new RelayCommand<StorageFile[]>(ExecuteFilesSelectedCommand);

        [...]

        public IRelayCommand<StorageFile[]> FilesSelectedCommand { get; } = new RelayCommand<StorageFile[]>(ExecuteFilesSelectedCommand);

        private void ExecuteFilesSelectedCommand(StorageFile[]? files)
        {
            if (files is not null)
            {
                foreach (StorageFile file in files)
                {
                    QueueNewConversion(file);
                }
            }
        }

Other information

image

image

image

image

image

Quality check

Before creating this PR, have you:

  • Followed the code style guideline as described in CONTRIBUTING.md
  • Verified that the change work in Release build configuration
  • Checked all unit tests pass

@veler veler requested a review from btiteux January 30, 2022 06:56
@veler veler linked an issue Jan 30, 2022 that may be closed by this pull request
@veler veler mentioned this pull request Jan 30, 2022
11 tasks
@veler veler linked an issue Jan 30, 2022 that may be closed by this pull request
@veler veler merged commit dc6b289 into main Jan 30, 2022
@veler veler deleted the fileSelectorControl branch January 30, 2022 18:36
veler added a commit that referenced this pull request Mar 31, 2023
…r many files as input. (#308)

* Added a new reusable FileSelector control allowing tools to get one or many files as input.

* Fixed typo

* Fixed a bug where PickSingleFolderAsync would crash on some machines

* updated language manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make a reusable control for file selection Replace original files in the PNG/JPEG compression
1 participant