Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenFileDialogWrapper"/> class.
        /// </summary>
        /// <param name="settings">The settings for the open file dialog.</param>
        public OpenFileDialogWrapper(OpenFileDialogSettings settings)
        {
            dialog = new OpenFileDialog();
            sync   = new OpenFileDialogSettingsSync(dialog, settings);

            // Update dialog
            sync.ToDialog();
        }
Ejemplo n.º 2
0
        public void ToDialog()
        {
            // Arrange
            var dialog   = new OpenFileDialog();
            var settings = new OpenFileDialogSettings();
            var sync     = new OpenFileDialogSettingsSync(dialog, settings);

            settings.AddExtension     = !settings.AddExtension;
            settings.CheckFileExists  = !settings.CheckFileExists;
            settings.CheckPathExists  = !settings.CheckPathExists;
            settings.CustomPlaces     = new List <FileDialogCustomPlace>(new[] { new FileDialogCustomPlace(Guid.NewGuid()) });
            settings.DefaultExt       = "txt";
            settings.DereferenceLinks = !settings.DereferenceLinks;
            settings.FileName         = "SomeFile.txt";
            settings.FileNames        = new[] { "SomeFile.txt" };
            settings.Filter           = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*";
            settings.FilterIndex      = 2;
            settings.InitialDirectory = @"C:\temp";
            settings.Multiselect      = !settings.Multiselect;
            settings.ReadOnlyChecked  = !settings.ReadOnlyChecked;
            settings.SafeFileName     = "SomeFile.txt";
            settings.SafeFileNames    = new [] { "SomeFile.txt" };
            settings.ShowReadOnly     = !settings.ShowReadOnly;
            settings.Title            = "Some Title";
            settings.ValidateNames    = !settings.ValidateNames;

            // Act
            sync.ToDialog();

            // Assert
            Assert.That(dialog.AddExtension, Is.EqualTo(settings.AddExtension));
            Assert.That(dialog.CheckFileExists, Is.EqualTo(settings.CheckFileExists));
            Assert.That(dialog.CheckPathExists, Is.EqualTo(settings.CheckPathExists));
            Assert.That(dialog.CustomPlaces, Is.EqualTo(settings.CustomPlaces));
            Assert.That(dialog.DefaultExt, Is.EqualTo(settings.DefaultExt));
            Assert.That(dialog.DereferenceLinks, Is.EqualTo(settings.DereferenceLinks));
            Assert.That(dialog.FileName, Is.EqualTo(settings.FileName));
            Assert.That(dialog.FileNames, Is.EqualTo(settings.FileNames));
            Assert.That(dialog.Filter, Is.EqualTo(settings.Filter));
            Assert.That(dialog.FilterIndex, Is.EqualTo(settings.FilterIndex));
            Assert.That(dialog.InitialDirectory, Is.EqualTo(settings.InitialDirectory));
            Assert.That(dialog.Multiselect, Is.EqualTo(settings.Multiselect));
            Assert.That(dialog.ReadOnlyChecked, Is.EqualTo(settings.ReadOnlyChecked));
            Assert.That(dialog.SafeFileName, Is.EqualTo(settings.SafeFileName));
            Assert.That(dialog.SafeFileNames, Is.EqualTo(settings.SafeFileNames));
            Assert.That(dialog.ShowReadOnly, Is.EqualTo(settings.ShowReadOnly));
            Assert.That(dialog.Title, Is.EqualTo(settings.Title));
            Assert.That(dialog.ValidateNames, Is.EqualTo(settings.ValidateNames));
        }
        private void OpenFile()
        {
            var settings = new OpenFileDialogSettings
            {
                Title = "This Is The Title",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
            };

            bool? success = dialogService.ShowOpenFileDialog(this, settings);
            if (success == true)
            {
                Path = settings.FileName;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenFileDialogWrapper"/> class.
        /// </summary>
        /// <param name="settings">The settings for the open file dialog.</param>
        public OpenFileDialogWrapper(OpenFileDialogSettings settings)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));

            openFileDialog = new OpenFileDialog
            {
                AddExtension     = settings.AddExtension,
                CheckFileExists  = settings.CheckFileExists,
                CheckPathExists  = settings.CheckPathExists,
                DefaultExt       = settings.DefaultExt,
                FileName         = settings.FileName,
                Filter           = settings.Filter,
                FilterIndex      = settings.FilterIndex,
                InitialDirectory = settings.InitialDirectory,
                Multiselect      = settings.Multiselect,
                Title            = settings.Title
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenFileDialogWrapper"/> class.
        /// </summary>
        /// <param name="settings">The settings for the open file dialog.</param>
        public OpenFileDialogWrapper(OpenFileDialogSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.settings = settings;

            openFileDialog = new OpenFileDialog
            {
                AddExtension = settings.AddExtension,
                CheckFileExists = settings.CheckFileExists,
                CheckPathExists = settings.CheckPathExists,
                DefaultExt = settings.DefaultExt,
                FileName = settings.FileName,
                Filter = settings.Filter,
                InitialDirectory = settings.InitialDirectory,
                Multiselect = settings.Multiselect,
                Title = settings.Title
            };
        }
Ejemplo n.º 6
0
        public void ToSettings()
        {
            // Arrange
            var dialog   = new OpenFileDialog();
            var settings = new OpenFileDialogSettings();
            var sync     = new OpenFileDialogSettingsSync(dialog, settings);

            dialog.FileName    = "SomeFile.txt";
            dialog.FilterIndex = 2;

            // Act
            sync.ToSettings();

            // Assert
            Assert.That(settings.FileName, Is.EqualTo(dialog.FileName));
            Assert.That(settings.FileNames, Is.EqualTo(dialog.FileNames));
            Assert.That(settings.FilterIndex, Is.EqualTo(dialog.FilterIndex));
            Assert.That(settings.SafeFileName, Is.EqualTo(dialog.SafeFileName));
            Assert.That(settings.SafeFileNames, Is.EqualTo(dialog.SafeFileNames));
        }
 public void SetUp()
 {
     dialog   = new OpenFileDialog();
     settings = new OpenFileDialogSettings();
     sync     = new OpenFileDialogSettingsSync(dialog, settings);
 }
 public OpenFileDialogSettingsSync(OpenFileDialog dialog, OpenFileDialogSettings settings)
 {
     this.dialog   = dialog ?? throw new ArgumentNullException(nameof(dialog));
     this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
 }