-
Notifications
You must be signed in to change notification settings - Fork 42
Introduce IFilePickerService and move SettingsModal and filter modals to EventLogExpert.Components #515
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
Draft
jschick04
wants to merge
1
commit into
jschick/debug-log-filters
Choose a base branch
from
jschick/move-modals-to-components
base: jschick/debug-log-filters
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Introduce IFilePickerService and move SettingsModal and filter modals to EventLogExpert.Components #515
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // // Copyright (c) Microsoft Corporation. | ||
| // // Licensed under the MIT License. | ||
|
|
||
| namespace EventLogExpert.UI.Interfaces; | ||
|
|
||
| public interface IFilePickerService | ||
| { | ||
| /// <summary> | ||
| /// Opens a system "Open File" dialog filtered to <paramref name="extensions" />; returns the picked path or | ||
| /// <c>null</c> if the user cancelled. | ||
| /// </summary> | ||
| Task<string?> PickAsync(string pickerTitle, IReadOnlyList<string> extensions); | ||
|
|
||
| /// <summary> | ||
| /// Opens a multi-select "Open File" dialog filtered to <paramref name="extensions" />; returns the picked | ||
| /// paths (empty if the user cancelled). | ||
| /// </summary> | ||
| Task<IReadOnlyList<string>> PickMultipleAsync(string pickerTitle, IReadOnlyList<string> extensions); | ||
| } | ||
|
|
||
| public static class FilePickerServiceFileTypes | ||
| { | ||
| public static readonly IReadOnlyList<string> Database = [".db", ".zip"]; | ||
| public static readonly IReadOnlyList<string> Json = [".json"]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // // Copyright (c) Microsoft Corporation. | ||
| // // Licensed under the MIT License. | ||
|
|
||
| using EventLogExpert.UI.Interfaces; | ||
|
|
||
| namespace EventLogExpert.Services; | ||
|
|
||
| public sealed class MauiFilePickerService : IFilePickerService | ||
| { | ||
| public Task<string?> PickAsync(string pickerTitle, IReadOnlyList<string> extensions) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(pickerTitle); | ||
| ArgumentNullException.ThrowIfNull(extensions); | ||
|
|
||
| if (extensions.Count == 0) | ||
| { | ||
| throw new ArgumentException( | ||
| "At least one extension must be supplied.", nameof(extensions)); | ||
| } | ||
|
|
||
| return MainThread.InvokeOnMainThreadAsync(async () => | ||
| { | ||
| var options = BuildOptions(pickerTitle, extensions); | ||
| var result = await FilePicker.Default.PickAsync(options); | ||
| return string.IsNullOrEmpty(result?.FullPath) ? null : result.FullPath; | ||
| }); | ||
| } | ||
|
|
||
| public Task<IReadOnlyList<string>> PickMultipleAsync( | ||
| string pickerTitle, | ||
| IReadOnlyList<string> extensions) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(pickerTitle); | ||
| ArgumentNullException.ThrowIfNull(extensions); | ||
|
|
||
| if (extensions.Count == 0) | ||
| { | ||
| throw new ArgumentException( | ||
| "At least one extension must be supplied.", nameof(extensions)); | ||
| } | ||
|
|
||
| return MainThread.InvokeOnMainThreadAsync<IReadOnlyList<string>>(async () => | ||
| { | ||
| var options = BuildOptions(pickerTitle, extensions); | ||
| var results = await FilePicker.Default.PickMultipleAsync(options) ?? []; | ||
| var paths = new List<string>(); | ||
|
|
||
| foreach (var result in results) | ||
| { | ||
| var path = result?.FullPath; | ||
|
|
||
| if (!string.IsNullOrEmpty(path)) | ||
| { | ||
| paths.Add(path); | ||
| } | ||
| } | ||
|
|
||
| return paths; | ||
| }); | ||
| } | ||
|
|
||
| private static PickOptions BuildOptions(string pickerTitle, IReadOnlyList<string> extensions) => | ||
| new() | ||
| { | ||
| PickerTitle = pickerTitle, | ||
| FileTypes = new FilePickerFileType( | ||
| new Dictionary<DevicePlatform, IEnumerable<string>> | ||
| { | ||
| { DevicePlatform.WinUI, extensions } | ||
| }) | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.