Ejemplo n.º 1
0
        public void ChangeDirectory(DirectoryMove move, string path = null)
        {
            switch (move)
            {
            case DirectoryMove.Back:
                var backDir = CurrentDirectory.Parent;
                ChangeDirectory(backDir);
                break;

            case DirectoryMove.ToRoot:
                var root = Path.GetPathRoot(CurrentDirectoryPath);
                ChangeDirectory(new DirectoryInfo(root));
                break;

            case DirectoryMove.Inner when path is not null:
                var next = Path.Combine(CurrentDirectoryPath, path);
                if (!Path.IsPathFullyQualified(next))
                {
                    throw ExceptionsFactory.PathNotExist(next);
                }
                ChangeDirectory(next);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(move), move, null);
            }

            OnDirectoryChanged?.Invoke();
        }
Ejemplo n.º 2
0
        // Navigation
        public bool ListPath(string path, DirectoryMove directoryMove)
        {
            path = FormatURI(path);

            if (!Directory.Exists(path) && path != "")
            {
                return(false);
            }

            if (path != "" && !CanRead(path))
            {
                return(false);
            }


            // History
            switch (directoryMove)
            {
            case DirectoryMove.Unique:
                pathHistory.Push(activePath);
                pathForwardHistory.Clear();
                break;

            case DirectoryMove.Back:
                pathForwardHistory.Push(activePath);
                break;

            case DirectoryMove.Forward:
                pathHistory.Push(activePath);
                break;
            }


            // Load drives or directory
            if (path == "")
            {
                DriveListView.Visibility           = Visibility.Visible;
                DriveListView.IsHitTestVisible     = true;
                DirectoryListView.Visibility       = Visibility.Hidden;
                DirectoryListView.IsHitTestVisible = false;
                SortComboBox.Visibility            = Visibility.Hidden;
                SortComboBox.IsHitTestVisible      = false;

                // Load drives
                // TODO Async loading to not lag app?
                driveItems = new ObservableCollection <DriveItem>(
                    DriveInfo.GetDrives()
                    .Where(x => x.DriveType == DriveType.Fixed || x.DriveType == DriveType.Removable || (Settings.SettingsData.ShowNetworkDrives && x.DriveType == DriveType.Network && x.IsReady == true))
                    .Select(x => new DriveItem(x))
                    .ToList()
                    );

                // Scroll to top
                if (DriveListView.Items.Count > 0)
                {
                    DriveListView.ScrollIntoView(DriveListView.Items[0]);
                }

                Keyboard.Focus(DriveListView);
            }
            else
            {
                DriveListView.Visibility           = Visibility.Hidden;
                DriveListView.IsHitTestVisible     = false;
                DirectoryListView.Visibility       = Visibility.Visible;
                DirectoryListView.IsHitTestVisible = true;
                SortComboBox.Visibility            = Visibility.Visible;
                SortComboBox.IsHitTestVisible      = true;


                directoryItems = new ObservableCollection <DirectoryItem>(
                    Directory.GetDirectories(path + '\\')
                    .Select(u => new DirectoryInfo(u))
                    .Where(i => !i.Attributes.HasFlag(FileAttributes.System) && (Settings.SettingsData.ShowHiddenFiles) || !i.Attributes.HasFlag(FileAttributes.Hidden))
                    .Select(u => new DirectoryItem(u)).ToList()
                    .Concat(
                        Directory.GetFiles(path + '\\')
                        .Select(u => new FileInfo(u))
                        .Where(i => !i.Attributes.HasFlag(FileAttributes.System) && (Settings.SettingsData.ShowHiddenFiles) || !i.Attributes.HasFlag(FileAttributes.Hidden))
                        .Select(u => new DirectoryItem(u)).ToList()
                        ));

                // Scroll to top when changing directories
                if (DirectoryListView.Items.Count > 0)
                {
                    DirectoryListView.ScrollIntoView(DirectoryListView.Items[0]);
                }

                Keyboard.Focus(DirectoryListView);


                _ = UpdateIcons();
            }


            // Update buttons
            (BackDirButton.Content as Image).Source    = pathHistory.Count() > 0 ? arrowLight : arrowDark;
            (ForwardDirButton.Content as Image).Source = pathForwardHistory.Count() > 0 ? arrowLight : arrowDark;

            SortComboBox.SelectedIndex = 0;
            activePath = path;
            OnPropertyChanged();

            return(true);
        }