Exemplo n.º 1
0
        internal void SwitchToFolder(File file, GraphicsContext g = null, File fileToFocus = null)
        {
            var children = file.GetChildren();
            var newFiles = children.Where(_filter.GoesThrough).OrderBy(t => t,
                                                                       UseReverseSorting ? FileSorting.ReversedComparer : FileSorting.Comparer)
                           .ToImmutableList();
            var isFiltered = newFiles.Count != children.Where(_noSearchFilter.GoesThrough).Count();

            var oldFolder = CurrentDir;

            try
            {
                CurrentDir = file;
                var relPath = CurrentDir.GetRelativePath(File.UserHome);
                if (relPath == null || relPath.StartsWith(".."))
                {
                    _filePath.Text = file.Path;
                }
                else
                {
                    _filePath.Text = "~" + Path.DirectorySeparatorChar + relPath;
                }
                _elementsCount.Foreground    = isFiltered ? ConsoleColor.Red : (ConsoleColor?)null;
                _elementsCount.Text          = "[" + newFiles.Count + (isFiltered ? "*" : "") + "]";
                _table.TrackTableChanges     = false;
                _table.QuickClearOnNextPrint = true;
                if (_table.Data == null)
                {
                    _table.Data = _files;
                }
                else
                {
                    _files.Clear();
                }
                if (newFiles.Count > 0)
                {
                    foreach (var f in newFiles)
                    {
                        _files.Add(f);
                    }
                }
                else
                {
                    _files.Add(null);
                }

                _cons?.SetTitle("SCFE - " + CurrentDir.Path);
            }
            finally
            {
                _table.TrackTableChanges = true;
            }

            if (g != null)
            {
                _filePath.Parent.Validate();
                _filePath.Print(g);
                _elementsCount.Print(g);

                if (TextBoxHandler != null)
                {
                    CancelTextBoxHandler(g);
                }

                var doFocus = _table.IsFocused();

                _table.RefreshColumnSizes();

                if (fileToFocus != null && _table.Data.Contains(fileToFocus))
                {
                    _table.FocusedElement = fileToFocus;
                }
                else
                {
                    _table.FocusedIndex = 0;
                }

                _table.ResetSelection();
                _table.Validate();
                _table.Print(g);
                if (doFocus)
                {
                    _table.SetFocused(true, g);
                }

                //g.ClearArea(_filePath.X, _filePath.Y, oldPathText.Length, 1);
                _filePath.Print(g);
            }

            OnFolderViewChanged?.Invoke(this,
                                        new FolderViewChangedEventArgs(oldFolder != CurrentDir, oldFolder, CurrentDir, g));
        }