public UIWordMenu(List <string> words, string word, int column, int line) { // menu _menu = Far.Api.CreateListMenu(); _menu.Title = word; _menu.NoInfo = true; _menu.X = column; _menu.Y = line; _menu.HelpTopic = Far.Api.GetHelpTopic("correction-list"); // menu keys _menu.AddKey(KeyCode.D1); _menu.AddKey(KeyCode.D2); _menu.AddKey(KeyCode.D3); // menu items foreach (var it in words) { _menu.Add(it); } // menu commands _menu.Add(string.Empty).IsSeparator = true; _itemIgnore = _menu.Add(My.DoIgnore); _itemIgnoreAll = _menu.Add(My.DoIgnoreAll); _itemAddToDictionary = _menu.Add(My.DoAddToDictionary); }
public void Show() { // active editor if (Far.Api.Window.Kind == WindowKind.Editor) { _editor = Far.Api.Editor; } // menu loop for (_toStop = false; ; _menu.Items.Clear()) { // new breakpoint by types _menu.Add("&Line breakpoint...", OnLineBreakpoint); _menu.Add("&Command breakpoint...", OnCommandBreakpoint); _menu.Add("&Variable breakpoint...", OnVariableBreakpoint); // breakpoint collection _breakpoints = A.InvokeCode("Get-PSBreakpoint"); if (_breakpoints.Count > 0) { // separator _menu.Add("Breakpoints").IsSeparator = true; // breakpoints int n = 0; foreach (PSObject o in _breakpoints) { Breakpoint bp = (Breakpoint)o.BaseObject; ++n; string text = bp.ToString(); if (n <= 9) { text = "&" + Kit.ToString(n) + " " + text; } FarItem mi = _menu.Add(text); mi.Checked = bp.Enabled; mi.Data = bp; } } // go if (!_menu.Show() || _toStop) { return; } } }
protected override void ProcessRecord() { if (InputObject == null) { return; } _menu.Add(Text == null ? InputObject.ToString() : Text.GetString(InputObject)).Data = InputObject; }
public UIWordMenu(List<string> words, string word, int column, int line) { // menu _menu = Far.Api.CreateListMenu(); _menu.Title = word; _menu.NoInfo = true; _menu.X = column; _menu.Y = line; // menu keys _menu.AddKey(KeyCode.D1); _menu.AddKey(KeyCode.D2); _menu.AddKey(KeyCode.D3); // menu items foreach (var it in words) _menu.Add(it); // menu commands _menu.Add(string.Empty).IsSeparator = true; _itemIgnore = _menu.Add(My.DoIgnore); _itemIgnoreAll = _menu.Add(My.DoIgnoreAll); _itemAddToDictionary = _menu.Add(My.DoAddToDictionary); }
static void ShowHistory(bool smart) { var Factor1 = Settings.Default.Factor1; var Factor2 = Settings.Default.Factor2; var Limit0 = Settings.Default.Limit0; // drop smart for the negative factor if (smart && Factor1 < 0) { smart = false; } IListMenu menu = Far.Api.CreateListMenu(); menu.HelpTopic = HelpTopic + "FileHistory"; menu.SelectLast = true; menu.UsualMargins = true; if (smart) { menu.Title = string.Format("File history ({0}/{1}/{2})", Limit0, Factor1, Factor2); } else { menu.Title = "File history (plain)"; } menu.IncrementalOptions = PatternOptions.Substring; menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.F3); menu.AddKey(KeyCode.F3, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.F4); menu.AddKey(KeyCode.F4, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed); for (; ; menu.Items.Clear()) { int group1 = -1; int indexLimit0 = int.MaxValue; foreach (var it in Record.GetHistory(null, DateTime.Now, (smart ? Factor1 : -1), Factor2)) { // separator if (smart) { int group2 = it.Group(Limit0, Factor1, Factor2); if (group1 != group2) { if (group1 >= 0) { menu.Add("").IsSeparator = true; if (group2 == 0) { indexLimit0 = menu.Items.Count; } } group1 = group2; } } // item menu.Add(it.Path).Checked = it.Evidence > 0; } show: //! show and check the result or after Esc index may be > 0 //! e.g. ShiftDel the last record + Esc == index out of range if (!menu.Show() || menu.Selected < 0) { return; } // update: if (menu.Key.IsCtrl(KeyCode.R)) { var algo = new Actor(VesselHost.LogPath); algo.Update(); continue; } // the file int indexSelected = menu.Selected; string path = menu.Items[indexSelected].Text; // delete: if (menu.Key.IsShift(KeyCode.Delete)) { if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel)) { Record.Remove(VesselHost.LogPath, path); continue; } goto show; } // go to: if (menu.Key.IsCtrl(KeyCode.Enter)) { Far.Api.Panel.GoToPath(path); } // view: else if (menu.Key.VirtualKeyCode == KeyCode.F3) { if (!File.Exists(path)) { continue; } IViewer viewer = Far.Api.CreateViewer(); viewer.FileName = path; if (menu.Key.IsCtrl()) { viewer.DisableHistory = true; viewer.Open(OpenMode.Modal); goto show; } viewer.Open(); // post fast training if (smart && indexSelected < indexLimit0) { VesselHost.PathToTrain = path; } } // edit: else { IEditor editor = Far.Api.CreateEditor(); editor.FileName = path; if (menu.Key.IsCtrl(KeyCode.F4)) { editor.DisableHistory = true; editor.Open(OpenMode.Modal); goto show; } editor.Open(); if (menu.Key.IsShift(KeyCode.Enter)) { goto show; } // post fast training if (smart && indexSelected < indexLimit0) { VesselHost.PathToTrain = path; } } UpdateOnce(); return; } }
public static void CompleteText(ILine editLine, string tail, string line, string lastWord, IEnumerable words) { // menu IListMenu menu = Far.Api.CreateListMenu(); var cursor = Far.Api.UI.WindowCursor; menu.X = cursor.X; menu.Y = cursor.Y; Settings.Default.PopupMenu(menu); menu.Incremental = lastWord + "*"; menu.IncrementalOptions = PatternOptions.Prefix; foreach (var it in words) { if (it == null) { continue; } var candidate = it.ToString(); if (candidate.Length == 0) { menu.Add(string.Empty).IsSeparator = true; continue; } if (lastWord.Length == 0 || candidate.StartsWith(lastWord, StringComparison.OrdinalIgnoreCase)) { menu.Add(candidate); } } if (menu.Items.Count == 0) { menu.Add(Res.Empty).Disabled = true; menu.NoInfo = true; menu.Show(); return; } string word; if (menu.Items.Count == 1) { word = menu.Items[0].Text; } else { // show menu if (!menu.Show()) { return; } word = menu.Items[menu.Selected].Text; } // expand last word // head before the last word line = line.Substring(0, line.Length - lastWord.Length); // new caret int caret = line.Length + word.Length; // set new text = old head + expanded + old tail editLine.Text = line + word + tail; // set caret editLine.Caret = caret; }
static void ShowFolders() { var limit = Settings.Default.Limit0; var factor = Settings.Default.Factor2; IListMenu menu = Far.Api.CreateListMenu(); menu.HelpTopic = HelpTopic + "FolderHistory"; menu.SelectLast = true; menu.UsualMargins = true; menu.Title = string.Format("Folder history ({0}/{1})", limit, factor); menu.IncrementalOptions = PatternOptions.Substring; menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed); for (; ; menu.Items.Clear()) { int lastGroup = -1; foreach (var it in Store.GetHistory(1, null, DateTime.Now, factor)) { // separator int nextGroup = it.Group(limit, factor); if (lastGroup != nextGroup) { if (lastGroup > 0) { menu.Add("").IsSeparator = true; } lastGroup = nextGroup; } // item menu.Add(it.Path).Checked = it.Evidence > 0; } show: //! show and check the result or after Esc index may be > 0 //! e.g. ShiftDel the last record + Esc == index out of range if (!menu.Show() || menu.Selected < 0) { return; } // update: if (menu.Key.IsCtrl(KeyCode.R)) { var algo = new Actor(1, VesselHost.LogPath[1], true); algo.Update(); continue; } // the folder int indexSelected = menu.Selected; string path = menu.Items[indexSelected].Text; // delete: if (menu.Key.IsShift(KeyCode.Delete)) { if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel)) { Store.Remove(1, VesselHost.LogPath[1], path); continue; } goto show; } // Enter: if (Far.Api.Window.Kind != WindowKind.Panels && !Far.Api.Window.IsModal) { Far.Api.Window.SetCurrentAt(-1); } Far.Api.Panel.CurrentDirectory = path; Store.Append(VesselHost.LogPath[1], DateTime.Now, Record.OPEN, path); UpdatePeriodically(1); return; } }
static void ShowHistory() { var factor0 = Settings.Default.Limit0; var factor1 = Settings.Default.Factor1; IListMenu menu = Far.Api.CreateListMenu(); menu.HelpTopic = HelpTopic + "FileHistory"; menu.SelectLast = true; menu.UsualMargins = true; menu.Title = string.Format("File history ({0}/{1})", factor0, factor1); menu.IncrementalOptions = PatternOptions.Substring; menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.F3); menu.AddKey(KeyCode.F3, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.F4); menu.AddKey(KeyCode.F4, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed); for (; ; menu.Items.Clear()) { int lastGroup = -1; foreach (var it in Store.GetHistory(0, null, DateTime.Now, factor1)) { // separator int nextGroup = it.Group(factor0, factor1); if (lastGroup != nextGroup) { if (lastGroup > 0) { menu.Add("").IsSeparator = true; } lastGroup = nextGroup; } // item menu.Add(it.Path).Checked = it.Evidence > 0; } show: //! show and check the result or after Esc index may be > 0 //! e.g. ShiftDel the last record + Esc == index out of range if (!menu.Show() || menu.Selected < 0) { return; } // update: if (menu.Key.IsCtrl(KeyCode.R)) { var algo = new Actor(0, VesselHost.LogPath[0]); algo.Update(); continue; } // the file int indexSelected = menu.Selected; string path = menu.Items[indexSelected].Text; // delete: if (menu.Key.IsShift(KeyCode.Delete)) { if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel)) { Store.Remove(0, VesselHost.LogPath[0], path); continue; } goto show; } // go to: if (menu.Key.IsCtrl(KeyCode.Enter)) { Far.Api.Panel.GoToPath(path); } // view: else if (menu.Key.VirtualKeyCode == KeyCode.F3) { if (!File.Exists(path)) { continue; } IViewer viewer = Far.Api.CreateViewer(); viewer.FileName = path; if (menu.Key.IsCtrl()) { viewer.DisableHistory = true; viewer.Open(OpenMode.Modal); goto show; } viewer.Open(); } // edit: else { IEditor editor = Far.Api.CreateEditor(); editor.FileName = path; if (menu.Key.IsCtrl(KeyCode.F4)) { editor.DisableHistory = true; editor.Open(OpenMode.Modal); goto show; } editor.Open(); if (menu.Key.IsShift(KeyCode.Enter)) { goto show; } } UpdatePeriodically(0); return; } }
static void ShowHistory() { var limit = Settings.Default.Limit0; var factor = Settings.Default.Factor1; IListMenu menu = Far.Api.CreateListMenu(); menu.HelpTopic = HelpTopic + "FileHistory"; menu.SelectLast = true; menu.UsualMargins = true; menu.Title = string.Format("File history ({0}/{1})", limit, factor); menu.IncrementalOptions = PatternOptions.Substring; menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.F3); menu.AddKey(KeyCode.F3, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.F4); menu.AddKey(KeyCode.F4, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed); for (; ; menu.Items.Clear()) { var actor = new Actor(0, null); int lastGroup = -1; foreach (var it in actor.GetHistory(DateTime.Now, factor)) { // separator int nextGroup = it.Group(limit, factor); if (lastGroup != nextGroup) { if (lastGroup > 0) { menu.Add("").IsSeparator = true; } lastGroup = nextGroup; } // item var item = menu.Add(it.Path); item.Data = it; if (it.Evidence > 0) { item.Checked = true; } } show: //! show and check the result or after Esc index may be > 0 //! e.g. ShiftDel the last record + Esc == index out of range if (!menu.Show() || menu.Selected < 0) { return; } // update: if (menu.Key.IsCtrl(KeyCode.R)) { var algo = new Actor(0, VesselHost.LogPath[0], true); algo.Update(); continue; } // the file int indexSelected = menu.Selected; string path = menu.Items[indexSelected].Text; // delete: if (menu.Key.IsShift(KeyCode.Delete)) { if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel)) { Store.Remove(0, VesselHost.LogPath[0], path); continue; } goto show; } // missing? if (!File.Exists(path)) { Far.Api.Message("File does not exist."); goto show; } // if it is not logged yet, log the existing Far record(s) if (!actor.IsLoggedPath(path)) { var info = menu.Items[indexSelected].Data as Info; Store.Append(VesselHost.LogPath[0], info.Head, Record.GOTO, path); if (info.Head != info.Tail) { Store.Append(VesselHost.LogPath[0], info.Tail, Record.GOTO, path); } } // go to: if (menu.Key.IsCtrl(KeyCode.Enter)) { Far.Api.Panel.GoToPath(path); Store.Append(VesselHost.LogPath[0], DateTime.Now, Record.GOTO, path); } // view: else if (menu.Key.VirtualKeyCode == KeyCode.F3) { IViewer viewer = Far.Api.CreateViewer(); viewer.FileName = path; viewer.Closed += delegate { Store.Append(VesselHost.LogPath[0], DateTime.Now, Record.VIEW, path); }; if (menu.Key.IsCtrl()) { viewer.Open(OpenMode.Modal); goto show; } viewer.Open(); } // edit: else { IEditor editor = Far.Api.CreateEditor(); editor.FileName = path; editor.Closed += delegate { Store.Append(VesselHost.LogPath[0], DateTime.Now, Record.EDIT, path); }; if (menu.Key.IsCtrl(KeyCode.F4)) { editor.Open(OpenMode.Modal); goto show; } editor.Open(); if (menu.Key.IsShift(KeyCode.Enter)) { goto show; } } UpdatePeriodically(0); return; } }
public static void ExpandText(ILine editLine, int replacementIndex, int replacementLength, IList words) { bool isEmpty = words.Count == 0; var text = editLine.Text; var last = replacementIndex + replacementLength - 1; bool custom = last > 0 && last < text.Length && text[last] == '='; //_140112_150217 last can be out of range // select a word string word; if (words.Count == 1) { // 1 word if (words[0] == null) { return; } word = TECompletionText(words[0]); } else { // make menu IListMenu menu = Far.Api.CreateListMenu(); var cursor = Far.Api.UI.WindowCursor; menu.X = cursor.X; menu.Y = cursor.Y; Settings.Default.PopupMenu(menu); if (isEmpty) { menu.Add(Res.Empty).Disabled = true; menu.NoInfo = true; menu.Show(); return; } menu.Incremental = "*"; menu.IncrementalOptions = PatternOptions.Substring; foreach (var it in words) { if (it == null) { continue; } var item = new SetItem(); item.Text = TEListItemText(it); item.Data = it; menu.Items.Add(item); } if (menu.Items.Count == 0) { return; } if (menu.Items.Count == 1) { word = TECompletionText(menu.Items[0].Data); } else { // show menu if (!menu.Show()) { return; } word = TECompletionText(menu.Items[menu.Selected].Data); } } // replace // head before replaced part string head = text.Substring(0, replacementIndex); // custom pattern int index, caret; if (custom && (index = word.IndexOf('#')) >= 0) { word = word.Substring(0, index) + word.Substring(index + 1); caret = head.Length + index; } // standard else { caret = head.Length + word.Length; } // set new text = old head + expanded + old tail editLine.Text = head + word + text.Substring(replacementIndex + replacementLength); // set caret editLine.Caret = caret; }
static void ShowCommands() { var mode = 2; var store = VesselHost.LogPath[mode]; var limit = Settings.Default.Limit0; IListMenu menu = Far.Api.CreateListMenu(); menu.HelpTopic = HelpTopic + "command-history"; menu.SelectLast = true; menu.UsualMargins = true; menu.Title = $"Command history ({limit})"; menu.IncrementalOptions = PatternOptions.Substring; menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed); menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed); menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed); for (; ; menu.Items.Clear()) { var actor = new Actor(mode, store); int lastGroup = -1; foreach (var it in actor.GetHistory(DateTime.Now)) { // separator int nextGroup = it.Group(limit); if (lastGroup != nextGroup) { if (lastGroup > 0) { menu.Add("").IsSeparator = true; } lastGroup = nextGroup; } // item var item = menu.Add(it.Path); item.Data = it; if (it.Evidence > 0) { item.Checked = true; } } show: //! show and check the result or after Esc index may be > 0 //! e.g. ShiftDel the last record + Esc == index out of range if (!menu.Show() || menu.Selected < 0) { return; } // update: if (menu.Key.IsCtrl(KeyCode.R)) { var algo = new Actor(mode, store, true); algo.Update(); continue; } // the command int indexSelected = menu.Selected; string path = menu.Items[indexSelected].Text; // delete: if (menu.Key.IsShift(KeyCode.Delete)) { if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel)) { Store.Remove(store, path, StringComparison.Ordinal); continue; } goto show; } // Enter | CtrlEnter: if (Far.Api.Window.Kind != WindowKind.Panels && !Far.Api.Window.IsModal) { Far.Api.Window.SetCurrentAt(-1); } // put command Far.Api.CommandLine.Text = path; // invoke command if (!menu.Key.IsCtrl()) { Far.Api.PostMacro("Keys'Enter'"); } // if it is not logged yet, log the existing Far record if (!actor.IsLoggedPath(path)) { var info = menu.Items[indexSelected].Data as Info; Store.Append(store, info.Head, Record.OPEN, path); } // then log the current record Store.Append(store, DateTime.Now, Record.OPEN, path); UpdatePeriodically(mode); return; } }