public ViuDemo() { var mainContainer = new Parent { ClearAreaBeforePrint = true }; var cons = new ConsoleParent(mainContainer); cons.SetTitle("Viu/SCFE Demo"); var switcher = new SwitcherStrategy(mainContainer); mainContainer.Strategy = switcher; var menu = new Parent(new LineStrategy { Centered = true }); mainContainer.AddComponent(menu); menu.AddComponent(new TextComponent("~ SCFE Demo ~") { Foreground = ConsoleColor.Yellow, HAlign = HorizontalAlignment.Centered }); menu.AddComponent(new Separator()); switcher.SwitchToComponent(menu, null); var table = new TableComponent <ViuDemoType> { Data = _demos }; menu.AddComponent(table); table.AddColumn(new IndicatorColumnType <ViuDemoType>()); table.AddColumn( new BasicColumnType <ViuDemoType>("Choose a demo to get started. Exit a demo with the Escape key.", vdt => vdt.Name)); table.ActionOnListElement += (sender, args) => { switcher.SwitchToComponent(args.Item.Parent, args.Graphics); mainContainer.Validate(); mainContainer.Print(args.Graphics); }; foreach (var vdt in _demos) { mainContainer.AddComponent(vdt.Parent); } mainContainer.ActionMap.Put(StandardActionNames.CancelAction, (o, args) => { mainContainer.SetFocused(false, args.Graphics); switcher.SwitchToComponent(menu, args.Graphics); mainContainer.Validate(); mainContainer.SetFocused(true, args.Graphics); mainContainer.Print(args.Graphics); }); cons.Validate(); cons.FocusFirst(); cons.Print(); }
public void Show() { _cons = new ConsoleParent(_main) { ExceptionHandler = (e, g) => { ShowHelpMessage(e.Message.Replace("\n", " - "), g, ConsoleColor.Red); } }; _cons.Validate(); // Only once the table is actually added _cons.FocusFirst(); _cons.Print(); _cons.SetTitle("SCFE - " + CurrentDir.Path); }
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)); }