/// <summary> /// For Actor. /// </summary> public static void ShowHistory() { var m = new UI.CommandHistoryMenu(string.Empty); string code = m.Show(); if (code == null) { return; } // insert to command lines switch (Far.Api.Window.Kind) { case WindowKind.Panels: Far.Api.CommandLine.Text = Entry.CommandInvoke1.Prefix + ": " + code; return; case WindowKind.Editor: var editor = Far.Api.Editor; if (!(editor.Host is Interactive)) { break; } editor.GoToEnd(true); editor.InsertText(code); editor.Redraw(); return; case WindowKind.Dialog: var dialog = Far.Api.Dialog; var typeId = dialog.TypeId; if (typeId != UI.InputDialog.TypeId) { break; } var line = Far.Api.Line; if (line == null || line.IsReadOnly) { break; } line.Text = code; return; } // show "Invoke commands" var ui = new UI.InputDialog() { Title = Res.Me, History = Res.History, Prompt = new string[] { Res.InvokeCommands }, Text = code }; if (!ui.Show()) { return; } // invoke input A.Psf.Act(ui.Text, null, true); }
/// <summary> /// For Actor. /// </summary> public static void ShowHistory() { var m = new UI.CommandHistoryMenu(string.Empty); string code = m.Show(); if (code == null) { return; } // insert to command lines switch (Far.Api.Window.Kind) { case WindowKind.Panels: Far.Api.CommandLine.Text = Entry.CommandInvoke1.Prefix + ": " + code; return; case WindowKind.Editor: var editor = Far.Api.Editor; if (!(editor.Host is Interactive)) { break; } editor.GoToEnd(true); editor.InsertText(code); editor.Redraw(); return; case WindowKind.Dialog: var dialog = Far.Api.Dialog; var typeId = dialog.TypeId; if (typeId != UI.InputDialog.TypeId) { break; } var line = Far.Api.Line; if (line == null || line.IsReadOnly) { break; } line.Text = code; return; } InvokeInputCode(code); }
public static void ShowHistory() { var m = new UI.CommandHistoryMenu(string.Empty); string code = m.Show(); if (code == null) return; // insert to command lines switch (Far.Api.Window.Kind) { case WindowKind.Panels: Far.Api.CommandLine.Text = Entry.CommandInvoke1.Prefix + ": " + code; return; case WindowKind.Editor: var editor = Far.Api.Editor; if (!(editor.Host is EditorConsole)) break; editor.GoToEnd(true); editor.InsertText(code); editor.Redraw(); return; case WindowKind.Dialog: var dialog = Far.Api.Dialog; var typeId = dialog.TypeId; if (typeId != UI.InputConsole.TypeId && typeId != UI.InputDialog.TypeId) break; var line = Far.Api.Line; if (line == null || line.IsReadOnly) break; line.Text = code; return; } // show "Invoke commands" var ui = new UI.InputDialog() { Caption = Res.Me, History = Res.History, Prompt = new string[] { Res.InvokeCommands }, Text = code }; if (!ui.Show()) return; // invoke input A.Psf.Act(ui.Text, null, true); }
void OnKeyDown(object sender, KeyEventArgs e) { // drop pipeline now, if any PowerShell = null; // skip if selected if (Editor.SelectionExists) return; // current line var currentLine = Editor.Line; switch (e.Key.VirtualKeyCode) { case KeyCode.Enter: { if (e.Key.Is()) { // invoke, copy, or pass e.Ignore = Invoke(); } else if (e.Key.IsShift()) { // similar to ISE e.Ignore = true; Editor.InsertLine(); Editor.Redraw(); } return; } case KeyCode.Tab: { if (e.Key.Is()) { if (GetCommandArea() != null && EditorKit.NeedsTabExpansion(Editor)) { e.Ignore = true; InitTabExpansion(); EditorKit.ExpandCode(currentLine, Runspace); Editor.Redraw(); } } return; } case KeyCode.Escape: { if (e.Key.Is()) { if (IsLastLineCurrent && currentLine.Length > 0) { e.Ignore = true; currentLine.Text = string.Empty; currentLine.Caret = 0; Editor.Redraw(); } } return; } case KeyCode.End: { if (e.Key.Is()) { if (!IsLastLineCurrent) return; if (currentLine.Caret != currentLine.Length) return; UI.CommandHistoryMenu m = new UI.CommandHistoryMenu(currentLine.Text); string code = m.Show(); if (code == null) return; e.Ignore = true; currentLine.Text = code; currentLine.Caret = -1; Editor.Redraw(); } return; } case KeyCode.UpArrow: goto case KeyCode.DownArrow; case KeyCode.DownArrow: { if (e.Key.Is()) { if (!IsLastLineCurrent) return; var command = History.GetNextCommand(e.Key.VirtualKeyCode == KeyCode.UpArrow, currentLine.Text); e.Ignore = true; currentLine.Text = command; currentLine.Caret = -1; Editor.Redraw(); } return; } case KeyCode.Delete: { if (e.Key.Is()) { if (!IsLastLineCurrent) return; if (currentLine.Length > 0) return; e.Ignore = true; Point pt = Editor.Caret; for (int i = pt.Y - 1; i >= 0; --i) { string text = Editor[i].Text; if (text == OutputMark1) { Editor.SelectText(0, i, -1, pt.Y, PlaceKind.Stream); Editor.DeleteText(); Editor.GoTo(0, i); Editor.InsertText(OutputMark3 + "\r"); Editor.GoToEnd(false); break; } if (text == OutputMark2 || text == OutputMark3) { pt = new Point(-1, i + 1); continue; } } Editor.Redraw(); } return; } case KeyCode.F1: { if (e.Key.IsShift()) { e.Ignore = true; Help.ShowHelpForContext(); } return; } default: { if (e.Key.Character != 0) History.Cache = null; return; } } }