Ejemplo n.º 1
0
        /// <summary>Shows a modal <see cref="FileSystemBrowserWindow"/> when the button is clicked.</summary>
        /// <param name="sender">The sender object of the event handler.</param>
        /// <param name="e">The state information of the event handler.</param>
        private void ShowDialogButton_Click(object sender, RoutedEventArgs e)
        {
            FilteringMode filteringMode = (FilteringMode)Enum.Parse(typeof(FilteringMode), this.filteringModeComboBox.SelectedValue.ToString());

            BrowserFilter browserFilter = new BrowserFilter(filteringMode);

            foreach (string extension in this.extensionsTextBox.Text.Split(';'))
            {
                browserFilter.AddExtension(extension);
            }

            BrowserSettings browserSettings = new BrowserSettings();

            CultureInfo currentCultureInfo = Thread.CurrentThread.CurrentCulture;

            browserSettings.BrowsingMode          = (BrowsingMode)Enum.Parse(typeof(BrowsingMode), this.browsingModeComboBox.SelectedValue.ToString());
            browserSettings.ByteMultiple          = (ByteMultiple)Enum.Parse(typeof(ByteMultiple), this.byteMultipleComboBox.SelectedValue.ToString());
            browserSettings.HasAvailableFreeSpace = (bool)this.hasAvailableFreeSpace.IsChecked;
            browserSettings.HasDriveFormat        = (bool)this.hasDriveFormat.IsChecked;
            browserSettings.HasDriveType          = (bool)this.hasDriveType.IsChecked;
            browserSettings.HasRootDirectory      = (bool)this.hasRootDirectory.IsChecked;
            browserSettings.HasTotalFreeSpace     = (bool)this.hasTotalFreeSpace.IsChecked;
            browserSettings.HasTotalSize          = (bool)this.hasTotalSize.IsChecked;
            browserSettings.HasVolumeLabel        = (bool)this.hasVolumeLabel.IsChecked;
            browserSettings.MaximumFiles          = int.Parse(this.maximumFilesTextBox.Text, currentCultureInfo);
            browserSettings.MaximumDirectories    = int.Parse(this.maximumDirectoriesTextBox.Text, currentCultureInfo);
            browserSettings.MinimumFiles          = int.Parse(this.minimumFilesTextBox.Text, currentCultureInfo);
            browserSettings.MinimumDirectories    = int.Parse(this.minimumDirectoriesTextBox.Text, currentCultureInfo);
            browserSettings.Path = this.pathTextBox.Text;

            FileSystemBrowserWindow fileSystemBrowserWindow = new FileSystemBrowserWindow(browserFilter, browserSettings);

            fileSystemBrowserWindow.Owner = this;

            if (fileSystemBrowserWindow.ShowDialog() ?? true)
            {
                foreach (string directory in fileSystemBrowserWindow.SelectedDirectories)
                {
                    this.resultListView.Items.Add(new { Type = "Directory", Path = directory });
                }

                foreach (string file in fileSystemBrowserWindow.SelectedFiles)
                {
                    this.resultListView.Items.Add(new { Type = "File", Path = file });
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>Initialises a new instance of the <see cref="FileSystemBrowserWindow"/> class.</summary>
        /// <param name="browserFilter">The file filter for the browser.</param>
        /// <param name="browserSettings">The settings for the browser.</param>
        public FileSystemBrowserWindow(BrowserFilter browserFilter, BrowserSettings browserSettings)
        {
            this.browserFilter   = browserFilter;
            this.browserSettings = browserSettings;

            if (browserSettings == null)
            {
                throw new ArgumentNullException(nameof(browserSettings));
            }

            if (this.browserSettings.MinimumFiles > this.browserSettings.MaximumFiles)
            {
                throw new MinimumGreaterThanMaximumException("The minimum number of files is greater than the maximum number of files.");
            }

            if (this.browserSettings.MinimumDirectories > this.browserSettings.MaximumDirectories)
            {
                throw new MinimumGreaterThanMaximumException("The minimum number of folders is greater than the maximum number of folders.");
            }

            InitializeComponent();
            fileSystemListView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(onClick), true);
            fileSystemListViewItems        = new ObservableCollection <FileSystemItem>();
            CollectionView                 = CollectionViewSource.GetDefaultView(fileSystemListViewItems);
            fileSystemListView.ItemsSource = CollectionView;

            /*
             * Get grid view column references.
             */

            GridView fileSystemGridView = (GridView)fileSystemListView.View;

            nameGridViewColumn = fileSystemGridView.Columns[0];
            UpdateSortDescriptions("Name", ListSortDirection.Ascending);
            nameGridViewColumn.HeaderTemplate = (DataTemplate)Resources["HeaderTemplateArrowUp"];


            sizeGridViewColumn               = fileSystemGridView.Columns[1];
            lastAccessTimeGridViewColumn     = fileSystemGridView.Columns[2];
            lastWriteTimeGridViewColumn      = fileSystemGridView.Columns[3];
            creationTimeGridViewColumn       = fileSystemGridView.Columns[4];
            volumeLabelGridViewColumn        = fileSystemGridView.Columns[5];
            rootDirectoryGridViewColumn      = fileSystemGridView.Columns[6];
            driveTypeGridViewColumn          = fileSystemGridView.Columns[7];
            driveFormatGridViewColumn        = fileSystemGridView.Columns[8];
            availableFreeSpaceGridViewColumn = fileSystemGridView.Columns[9];
            totalFreeSpaceGridViewColumn     = fileSystemGridView.Columns[10];
            totalSizeGridViewColumn          = fileSystemGridView.Columns[11];

            /*
             * this.Title
             */

            switch (this.browserSettings.BrowsingMode)
            {
            case BrowsingMode.Open:
                if (this.browserSettings.MaximumFiles == 1 && this.browserSettings.MaximumDirectories == 0)
                {
                    this.Title = Titles.OpenFile;
                }
                else if (this.browserSettings.MaximumFiles > 1 && this.browserSettings.MaximumDirectories == 0)
                {
                    this.Title = Titles.OpenFiles;
                }
                else if (this.browserSettings.MaximumFiles == 0 && this.browserSettings.MaximumDirectories == 1)
                {
                    this.Title = Titles.OpenFolder;
                }
                else if (this.browserSettings.MinimumFiles == 0 && this.browserSettings.MaximumDirectories > 1)
                {
                    this.Title = Titles.OpenFolders;
                }
                else if (this.browserSettings.MaximumFiles == 1 && this.browserSettings.MaximumDirectories == 1)
                {
                    this.Title = Titles.OpenFolderAndFile;
                }
                else if (this.browserSettings.MaximumFiles > 1 && this.browserSettings.MaximumDirectories == 1)
                {
                    this.Title = Titles.OpenFolderAndFiles;
                }
                else if (this.browserSettings.MaximumFiles == 1 && this.browserSettings.MaximumDirectories > 1)
                {
                    this.Title = Titles.OpenFoldersAndFile;
                }
                else if (this.browserSettings.MaximumFiles > 1 && this.browserSettings.MaximumDirectories > 1)
                {
                    this.Title = Titles.OpenFoldersAndFiles;
                }

                break;

            case BrowsingMode.Select:
                if (this.browserSettings.MaximumFiles == 1 && this.browserSettings.MaximumDirectories == 0)
                {
                    this.Title = Titles.SelectFile;
                }
                else if (this.browserSettings.MaximumFiles > 1 && this.browserSettings.MaximumDirectories == 0)
                {
                    this.Title = Titles.SelectFiles;
                }
                else if (this.browserSettings.MaximumFiles == 0 && this.browserSettings.MaximumDirectories == 1)
                {
                    this.Title = Titles.SelectFolder;
                }
                else if (this.browserSettings.MinimumFiles == 0 && this.browserSettings.MaximumDirectories > 1)
                {
                    this.Title = Titles.SelectFolders;
                }
                else if (this.browserSettings.MaximumFiles == 1 && this.browserSettings.MaximumDirectories == 1)
                {
                    this.Title = Titles.SelectFolderAndFile;
                }
                else if (this.browserSettings.MaximumFiles > 1 && this.browserSettings.MaximumDirectories == 1)
                {
                    this.Title = Titles.SelectFolderAndFiles;
                }
                else if (this.browserSettings.MaximumFiles == 1 && this.browserSettings.MaximumDirectories > 1)
                {
                    this.Title = Titles.SelectFoldersAndFile;
                }
                else if (this.browserSettings.MaximumFiles > 1 && this.browserSettings.MaximumDirectories > 1)
                {
                    this.Title = Titles.SelectFoldersAndFiles;
                }

                break;
            }

            /*
             * this.navigationStackPanel
             */

            PathButton desktopNavigationButton   = new PathButton(NavigationButtons.Desktop, Environment.GetFolderPath(Environment.SpecialFolder.Desktop), new RoutedEventHandler(PathButton_Click));
            PathButton recentNavigationButton    = new PathButton(NavigationButtons.Recent, Environment.GetFolderPath(Environment.SpecialFolder.Recent), new RoutedEventHandler(PathButton_Click));
            PathButton documentsNavigationButton = new PathButton(NavigationButtons.Documents, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), new RoutedEventHandler(PathButton_Click));
            PathButton musicNavigationButton     = new PathButton(NavigationButtons.Music, Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), new RoutedEventHandler(PathButton_Click));
            PathButton picturesNavigationButton  = new PathButton(NavigationButtons.Pictures, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), new RoutedEventHandler(PathButton_Click));
            PathButton videosNavigationButton    = new PathButton(NavigationButtons.Videos, Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), new RoutedEventHandler(PathButton_Click));

            navigationStackPanel.Children.Add(desktopNavigationButton);
            navigationStackPanel.Children.Add(recentNavigationButton);
            navigationStackPanel.Children.Add(documentsNavigationButton);
            navigationStackPanel.Children.Add(musicNavigationButton);
            navigationStackPanel.Children.Add(picturesNavigationButton);
            navigationStackPanel.Children.Add(videosNavigationButton);

            /*
             * this.actionButton, this.cancelButton
             */

            switch (this.browserSettings.BrowsingMode)
            {
            case BrowsingMode.Open:
                actionButton.Content = Buttons.Open;

                break;

            case BrowsingMode.Select:
                actionButton.Content = Buttons.Select;

                break;
            }

            cancelButton.Content = Buttons.Cancel;

            /*
             * this.NavigateFileSystem
             */

            path = PathManipulator.Sanitise(this.browserSettings.Path);

            NavigateFileSystem(path);
        }
Ejemplo n.º 3
0
 /// <summary>Initialises a new instance of the <see cref="FileSystemBrowserWindow"/> class.</summary>
 /// <param name="browserSettings">The settings for the browser.</param>
 public FileSystemBrowserWindow(BrowserSettings browserSettings)
     : this(new BrowserFilter(), browserSettings)
 {
 }