Exemple #1
0
        /// <summary>
        /// Shows the file browser dialog.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException"></exception>
        public async Task <(bool Result, IList <IFileSystemFile> Files)> ShowFileBrowserDialog(FileSystemBrowserOptions options, CancellationToken token)
        {
            if (IsOpen)
            {
                throw new InvalidOperationException(Resources.DialogOpenAlready);
            }

            var tuple     = default((bool Result, IList <IFileSystemFile> Files));
            var viewModel = new FileBrowserContentDialogViewModel(_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 = (true, items.Select(p => p as IFileSystemFile).Where(p => p != null).ToList());
                };

                CancelAction = () =>
                {
                    var items = viewModel.FileSystemViewModel.SelectedItems;
                    tuple = (false, new List <IFileSystemFile>());
                };

                await Open(token).ConfigureAwait(false);
            }

            return(tuple);
        }
Exemple #2
0
        /// <summary>
        /// Shows the folder browser dialog.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException"></exception>
        public async Task <(bool Result, IFileSystemDirectory Directory)> ShowFolderBrowserDialog(FileSystemBrowserOptions options, CancellationToken token)
        {
            if (IsOpen)
            {
                throw new InvalidOperationException(Resources.DialogOpenAlready);
            }

            var tuple     = default((bool Result, IFileSystemDirectory Directory));
            var viewModel = new FileBrowserContentDialogViewModel(_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 = (true, items.Distinct().FirstOrDefault() as IFileSystemDirectory); // TODO handle multi select option
                };

                CancelAction = () =>
                {
                    var items = viewModel.FileSystemViewModel.SelectedItems;
                    tuple = (false, default(IFileSystemDirectory));
                };

                await Open(token).ConfigureAwait(false);
            }

            return(tuple);
        }