Beispiel #1
0
        private void OpenFiles( OpenFileInteraction interaction )
        {
            Contract.Requires( interaction != null );

            var saveButton = interaction.DefaultCommand;
            var dialog = new FileOpenPicker();

            dialog.ContinuationData.AddRange( interaction.ContinuationData );
            dialog.FileTypeFilter.AddRange( interaction.FileTypeFilter.FixUpExtensions() );
            dialog.SuggestedStartLocation = SuggestedStartLocation;
            dialog.ViewMode = ViewMode;

            if ( !string.IsNullOrEmpty( SettingsIdentifier ) )
                dialog.SettingsIdentifier = SettingsIdentifier;

            if ( saveButton != null )
                dialog.CommitButtonText = saveButton.Name;

            if ( interaction.Multiselect )
                dialog.PickMultipleFilesAndContinue();
            else
                dialog.PickSingleFileAndContinue();
        }
        public void ConstructorShouldSetMultiselectOption()
        {
            // arrange
            var expected = true;

            // act
            var interaction = new OpenFileInteraction( "", expected );
            var actual = interaction.Multiselect;

            // assert
            Assert.Equal( expected, actual );
        }
        public static Task<IList<IFile>> RequestAsync(
            this InteractionRequest<OpenFileInteraction> interactionRequest,
            string title,
            string acceptButtonText,
            string cancelButtonText,
            IEnumerable<FileType> fileTypeFilter,
            bool multiselect )
        {
            Arg.NotNull( interactionRequest, nameof( interactionRequest ) );
            Arg.NotNull( fileTypeFilter, nameof( fileTypeFilter ) );

            if ( string.IsNullOrEmpty( title ) )
                title = SR.OpenFileTitle;

            if ( string.IsNullOrEmpty( acceptButtonText ) )
                acceptButtonText = SR.Open;

            if ( string.IsNullOrEmpty( cancelButtonText ) )
                cancelButtonText = SR.Cancel;

            var source = new TaskCompletionSource<IList<IFile>>();
            OpenFileInteraction interaction = null;

            interaction = new OpenFileInteraction()
            {
                Title = title,
                Multiselect = multiselect,
                DefaultCommandIndex = 0,
                CancelCommandIndex = 1,
                Commands =
                {
                    new NamedCommand<object>( "Open", acceptButtonText, p => source.TrySetResult( interaction.Files ) ),
                    new NamedCommand<object>( "Cancel", cancelButtonText, p => source.TrySetResult( NoFiles ) )
                }
            };

            interaction.FileTypeFilter.AddRange( fileTypeFilter );
            interactionRequest.Request( interaction );
            return source.Task;
        }
        public void MultiselectShouldWriteExpectedValue()
        {
            // arrange
            var expected = true;
            var interaction = new OpenFileInteraction();

            // act
            Assert.PropertyChanged( interaction, "Multiselect", () => interaction.Multiselect = expected );
            var actual = interaction.Multiselect;

            // assert
            Assert.Equal( expected, actual );
        }