public void ShowHelpMessageLater(string message, ConsoleColor?color = null) { _cons.DoGraphicsLater(g => ShowHelpMessage(message, g, color)); }
public ScfeApp(File startingFile, string[] columnsToAdd) { CurrentDir = startingFile ?? new File(Directory.GetCurrentDirectory()); _filter = new AndFilter <File>( new BoolFilter <File>(f => ShowHiddenFiles || !f.IsHidden()), new BranchingFilter <File>(() => _filterOnBoxInput && TextBoxHandler == null, new StringFilter <File>(file => file.GetFileName().ToLowerInvariant(), () => TextBox.Text.ToLowerInvariant()), new TrueFilter <File>())); FileSorting = FileSorters[0]; _noSearchFilter = new BoolFilter <File>(f => ShowHiddenFiles || !f.IsHidden()); Tasks = new TaskPool <string>((task, tresult) => { _cons?.DoGraphicsLater(g => { if (tresult.Message != null) { ShowHelpMessage(tresult.Message, g, tresult.Success ? ConsoleColor.Green : ConsoleColor.Red); } }); }); _main = new Parent(new BorderStrategy()); AddMainBindings(); var p = new Parent(new LineStrategy()); _main.AddComponent(p, BorderStrategy.Top); var p2 = new Parent(new BorderStrategy()); p.AddComponent(p2); p2.AddComponent(new TextComponent("dir: ") { Foreground = ConsoleColor.DarkGray }, BorderStrategy.Left); _filePath = new TextComponent(CurrentDir.Path) { CutOverflowFrom = HorizontalAlignment.Centered, ClearBlankSpaceOnReprint = true }; p2.AddComponent(_filePath, BorderStrategy.Center); _elementsCount = new TextComponent("[...]") { ClearBlankSpaceOnReprint = true }; p2.AddComponent(_elementsCount, BorderStrategy.Right); p.AddComponent(new Separator { Foreground = ConsoleColor.DarkGray }); p = new Parent(new LineStrategy()); _main.AddComponent(p, BorderStrategy.Bottom); p.AddComponent(new Separator { Foreground = ConsoleColor.DarkGray }); p2 = new Parent(new BorderStrategy()); p.AddComponent(p2); var p3 = new Parent(new FlowStrategy(1)); p2.AddComponent(p3, BorderStrategy.Left); _mode = new TextComponent("xxx"); p3.AddComponent(_mode); p3.AddComponent(new Separator { Orientation = Orientation.Vertical, Foreground = ConsoleColor.DarkGray }); p3.AddComponent(new TextComponent("")); // To have an extra separator at the end _help = new TextComponent("Welcome to SCFE!") { ClearBlankSpaceOnReprint = true }; p2.AddComponent(_help, BorderStrategy.Center); p2 = new Parent(new BorderStrategy()); p.AddComponent(p2); p2.AddComponent(new TextComponent("~> "), BorderStrategy.Left); TextBox = new TextField { PlaceholderText = "Press E or M (in NAV mode, with Ctrl in SEA mode) to switch modes. Ctrl+Enter or (Ctrl+)Shift+M for COM mode.", ShowLine = false }; TextBox.OnTextChanged += (sender, args) => { if (_filterOnBoxInput && TextBoxHandler == null) { SwitchToFolder(CurrentDir, args.Graphics); } }; TextBox.ActionOnComponent += (sender, args) => { if (TextBoxHandler != null) { TextBoxHandler(sender, args); } else if (_filterOnBoxInput) { if (_table.Data.Count == 1 && _table.Data[0] != null) { HandlerOpenFileInTable(_table.Data[0], args.Graphics); } TextBox.SetFocused(false, args.Graphics); _table.SetFocused(true, args.Graphics); } }; TextBox.ActionMap.Put(StandardActionNames.CancelAction, (o, args) => { args.Graphics.SetCursorVisible(false); if (TextBoxHandler != null) { CancelTextBoxHandler(args.Graphics); } else if (_filterOnBoxInput) { ResetTextBox(args.Graphics); SwitchToFolder(CurrentDir, args.Graphics); ResetFocusableStates(args.Graphics); } }); p2.AddComponent(TextBox, BorderStrategy.Center); _wrapper = new Parent { ClearAreaBeforePrint = true }; _wrapper.Strategy = new SwitcherStrategy(_wrapper); _main.AddComponent(_wrapper, BorderStrategy.Center); _extensions.Add(new BaseExtension(this)); _extensions.Add(new ComExtension(this)); var gitExt = new GitExtension(this); ColorScheme = gitExt; _extensions.Add(gitExt); _extensions.Add(new FileWatchExtension(this)); _table = new ScfeTable(this); InstallOnActionMap(_table.ActionMap); _table.ActionOnComponent += (o, args) => HandlerOpenFileInTable(_table.FocusedElement, args.Graphics); _table.AddColumn(new IndicatorColumnType <File>()); var columnsAvailable = _extensions.SelectMany(e => e.GetColumns()).ToList(); foreach (var colName in columnsToAdd) { var col = columnsAvailable.FirstOrDefault(c => c.GetTitle(_table, int.MaxValue) == colName); if (col != null) { _table.AddColumn(col); } } _wrapper.AddComponent(_table, 0); ((SwitcherStrategy)_wrapper.Strategy).SwitchToComponentWithHint(0, null); _tableInputMap = new SwappableAddinHierDic <KeyStroke, string>(_table.InputMap); _table.InputMap = _tableInputMap; InstallExtensionsOnFileOptionsPanel(); SwitchToFolder(CurrentDir); ChangeModeTo(NavigationMode.NavMode, null); }