/// <summary> /// Shows the file browser dialog. /// </summary> /// <returns></returns> /// <exception cref="System.InvalidOperationException"></exception> public async Task <(DialogResult Result, IList <IFileSystemFile> Files)> ShowFileBrowserDialog(FileSystemBrowserOptions options) { if (IsOpen) { throw new InvalidOperationException(Resources.DialogOpenAlready); } var tuple = default((DialogResult Result, IList <IFileSystemFile> Files)); var viewModel = new FileBrowserDialogViewModel(_fileSystemViewModel, options); TitleDetail = string.Empty; Context = viewModel; Title = options.Title; IsCancelVisible = options.CanCancel; using (_messenger.Subscribe <FileSystemInfoChangedMessage>(FileSystemInfoChanged)) { AcceptAction = () => { var items = viewModel.FileSystemViewModel.SelectedItems; tuple = (DialogResult.OK, items.Select(p => p as IFileSystemFile).Where(p => p != null).ToList()); }; CancelAction = () => { var items = viewModel.FileSystemViewModel.SelectedItems; tuple = (DialogResult.Cancel, new List <IFileSystemFile>()); }; await Open().ConfigureAwait(false); } return(tuple); }
/// <summary> /// Shows the folder browser dialog. /// </summary> /// <returns></returns> /// <exception cref="System.InvalidOperationException"></exception> public async Task <(DialogResult Result, IFileSystemDirectory Directory)> ShowFolderBrowserDialog(FileSystemBrowserOptions options) { if (IsOpen) { throw new InvalidOperationException(Resources.DialogOpenAlready); } var tuple = default((DialogResult Result, IFileSystemDirectory Directory)); var viewModel = new FileBrowserDialogViewModel(_fileSystemViewModel, options); TitleDetail = string.Empty; Context = viewModel; Title = options.Title; IsCancelVisible = options.CanCancel; using (_messenger.Subscribe <FileSystemInfoChangedMessage>(FileSystemInfoChanged)) { AcceptAction = () => { var items = viewModel.FileSystemViewModel.SelectedItems; items.Add(viewModel.FileSystemViewModel.SelectedItem); tuple = (DialogResult.OK, items.Distinct().FirstOrDefault() as IFileSystemDirectory); }; CancelAction = () => { var items = viewModel.FileSystemViewModel.SelectedItems; tuple = (DialogResult.Cancel, default(IFileSystemDirectory)); }; await Open().ConfigureAwait(false); } return(tuple); }