-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the Elmish music player example to use IStorageProvider instea…
…d of the obsoleted OpenFileDialog/OpenFolderDialog
- Loading branch information
Showing
3 changed files
with
52 additions
and
42 deletions.
There are no files selected for viewing
55 changes: 30 additions & 25 deletions
55
src/Examples/Elmish Examples/Examples.Elmish.MusicPlayer/Dialogs.fs
This file contains 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 |
---|---|---|
@@ -1,34 +1,39 @@ | ||
namespace Examples.MusicPlayer | ||
|
||
|
||
module Dialogs = | ||
open System | ||
open Avalonia.Controls | ||
open Avalonia | ||
open Avalonia.Platform.Storage | ||
open Avalonia.Threading | ||
open System.Collections.Generic | ||
|
||
let getMusicFilesDialog (filters: FileDialogFilter seq option) = | ||
let dialog = OpenFileDialog() | ||
let showMusicFilesDialog(provider: IStorageProvider, filters: FilePickerFileType list option) = | ||
|
||
let filters = | ||
match filters with | ||
| Some filter -> filter | ||
| None -> | ||
let filter = FileDialogFilter() | ||
filter.Extensions <- | ||
Collections.Generic.List | ||
(seq { | ||
"mp3" | ||
"wav" }) | ||
filter.Name <- "Music" | ||
seq { filter } | ||
|
||
dialog.AllowMultiple <- true | ||
dialog.Directory <- Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) | ||
dialog.Title <- "Select Your Music Files" | ||
dialog.Filters <- System.Collections.Generic.List(filters) | ||
dialog | ||
|
||
let getFolderDialog = | ||
let dialog = OpenFolderDialog() | ||
dialog.Directory <- Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) | ||
dialog.Title <- "Choose where to look up for music" | ||
dialog | ||
let patterns = [ "*.mp3"; "*.wav" ] | ||
let filter = FilePickerFileType("Music", Patterns = patterns) | ||
[ filter ] | ||
|
||
let options = FilePickerOpenOptions(AllowMultiple = true, Title = "Select Your Music Files", FileTypeFilter = filters) | ||
|
||
async { | ||
let! musicFolder = provider.TryGetWellKnownFolderAsync Platform.Storage.WellKnownFolder.Music |> Async.AwaitTask | ||
options.SuggestedStartLocation <- musicFolder | ||
|
||
return! | ||
Dispatcher.UIThread.InvokeAsync<IReadOnlyList<IStorageFile>> | ||
(fun _ -> provider.OpenFilePickerAsync(options)) |> Async.AwaitTask | ||
} | ||
|
||
let showMusicFolderDialog(provider: IStorageProvider) = | ||
async { | ||
let! musicFolder = provider.TryGetWellKnownFolderAsync Platform.Storage.WellKnownFolder.Music |> Async.AwaitTask | ||
let options = FolderPickerOpenOptions(Title = "Choose where to look up for music", SuggestedStartLocation = musicFolder) | ||
|
||
return! | ||
Dispatcher.UIThread.InvokeAsync<IReadOnlyList<IStorageFolder>> | ||
(fun _ -> provider.OpenFolderPickerAsync(options)) |> Async.AwaitTask | ||
|
||
} |
This file contains 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 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