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); }
static void AddItem(FarItem item, ModuleToolOptions from) { if (from == ModuleToolOptions.None) { from = ModuleToolOptions.F11Menus; } if (0 < (from & ModuleToolOptions.Dialog)) { _menuDialog.Items.Add(item); } if (0 < (from & ModuleToolOptions.Editor)) { _menuEditor.Items.Add(item); } if (0 < (from & ModuleToolOptions.Panels)) { _menuPanels.Items.Add(item); } if (0 < (from & ModuleToolOptions.Viewer)) { _menuViewer.Items.Add(item); } }
void DoUp() { int selected2 = _ListBox2.Selected; if (selected2 > 0 && selected2 < _ListBox2.Items.Count - 1) { FarItem item = _ListBox2.Items[selected2]; FarItem prev = _ListBox2.Items[selected2 - 1]; _ListBox2.Items[selected2] = prev; _ListBox2.Items[selected2 - 1] = item; _ListBox2.Selected = selected2 - 1; } }
void DoDown() { int selected2 = _ListBox2.Selected; if (selected2 >= 0 && selected2 < _ListBox2.Items.Count - 2) { FarItem item = _ListBox2.Items[selected2]; FarItem next = _ListBox2.Items[selected2 + 1]; _ListBox2.Items[selected2] = next; _ListBox2.Items[selected2 + 1] = item; _ListBox2.Selected = selected2 + 1; } }
void DoAdd() { int selected1 = _ListBox1.Selected; if (selected1 >= 0) { FarItem item = _ListBox1.Items[selected1]; _ListBox1.Items.RemoveAt(selected1); int selected2 = _ListBox2.Selected; _ListBox2.Items.Insert(selected2, item); _ListBox2.Selected = selected2 + 1; } }
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; } } }
public static void Show(IList <IModuleDrawer> drawers, string helpTopic) { if (drawers == null) { return; } IMenu menu = Far.Api.CreateMenu(); menu.AutoAssignHotkeys = true; menu.HelpTopic = helpTopic; menu.Title = Res.ModuleDrawers; foreach (IModuleDrawer it in drawers) { menu.Add(Utility.FormatConfigMenu(it)).Data = it; } while (menu.Show()) { FarItem mi = menu.Items[menu.Selected]; IModuleDrawer drawer = (IModuleDrawer)mi.Data; var dialog = new ConfigDrawerDialog(drawer, helpTopic); while (dialog.Dialog.Show()) { var mask = ConfigTool.ValidateMask(dialog.Mask.Text); if (mask == null) { continue; } int priority; string priorityText = dialog.Priority.Text.Trim(); if (!int.TryParse(priorityText, out priority)) { Far.Api.Message("Invalid Priority."); continue; } // set drawer.Mask = mask; drawer.Priority = priority; drawer.Manager.SaveSettings(); break; } } }
public static void Show(IList <IModuleEditor> editors, string helpTopic) { if (editors == null) { return; } IMenu menu = Far.Api.CreateMenu(); menu.AutoAssignHotkeys = true; menu.HelpTopic = helpTopic; menu.Title = Res.ModuleEditors; foreach (IModuleEditor it in editors) { menu.Add(Utility.FormatConfigMenu(it)).Data = it; } while (menu.Show()) { FarItem mi = menu.Items[menu.Selected]; IModuleEditor editor = (IModuleEditor)mi.Data; IInputBox ib = Far.Api.CreateInputBox(); ib.EmptyEnabled = true; ib.HelpTopic = helpTopic; ib.History = "Masks"; ib.Prompt = "Mask"; ib.Text = editor.Mask; ib.Title = editor.Name; if (!ib.Show()) { continue; } var mask = ConfigTool.ValidateMask(ib.Text); if (mask == null) { continue; } // set editor.Mask = mask; editor.Manager.SaveSettings(); } }
void DoRemove() { int selected2 = _ListBox2.Selected; if (selected2 >= 0 && selected2 < _ListBox2.Items.Count - 1) { FarItem item = _ListBox2.Items[selected2]; int index2 = (int)item.Data; _ListBox2.Items.RemoveAt(selected2); for (int i = 0; i < _ListBox1.Items.Count; ++i) { int index1 = (int)_ListBox1.Items[i].Data; if (index2 < index1) { _ListBox1.Items.Insert(i, item); return; } } _ListBox1.Items.Add(item); } }
/// <summary> /// Returns e.g. MyDrive: /// </summary> internal static string SelectDrive(string select, bool extras) { IMenu m = Far.Api.CreateMenu(); m.AutoAssignHotkeys = true; m.Title = "Power panel"; m.HelpTopic = Far.Api.GetHelpTopic("MenuPanels"); if (extras) { m.Add("Folder &tree"); m.Add("&Any objects"); m.Add(string.Empty).IsSeparator = true; } int i = extras ? 2 : -1; foreach (var o in A.InvokeCode(GetPowerShellFarDriveName)) { ++i; FarItem mi = m.Add(o.ToString()); if (mi.Text.Length == 0) { mi.IsSeparator = true; continue; } if (mi.Text == select) { m.Selected = i; } mi.Text += ':'; } if (!m.Show()) { return(null); } return(m.Items[m.Selected].Text); }
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); }
public static void Show(IList <IModuleCommand> commands, string helpTopic) { if (commands == null) { return; } IMenu menu = Far.Api.CreateMenu(); menu.AutoAssignHotkeys = true; menu.HelpTopic = helpTopic; menu.Title = Res.ModuleCommands; for (; ;) { int widthName = 9; // Name int widthPref = 6; // Prefix foreach (IModuleCommand it in commands) { if (widthName < it.Name.Length) { widthName = it.Name.Length; } if (widthPref < it.Prefix.Length) { widthPref = it.Prefix.Length; } } string format = "{0,-" + widthPref + "} : {1,-" + widthName + "} : {2}"; menu.Items.Clear(); menu.Add(string.Format(null, format, "Prefix", "Name", "Address")).Disabled = true; foreach (IModuleCommand it in commands) { menu.Add(string.Format(null, format, it.Prefix, it.Name, it.Manager.ModuleName + "\\" + it.Id)).Data = it; } if (!menu.Show()) { return; } FarItem mi = menu.Items[menu.Selected]; IModuleCommand command = (IModuleCommand)mi.Data; IInputBox ib = Far.Api.CreateInputBox(); ib.EmptyEnabled = true; ib.HelpTopic = helpTopic; ib.Prompt = "Prefix"; ib.Text = command.Prefix; ib.Title = command.Name; string prefix = null; while (ib.Show()) { prefix = ib.Text.Trim(); if (prefix.IndexOf(' ') >= 0 || prefix.IndexOf(':') >= 0) { Far.Api.Message("Prefix must not contain ' ' or ':'."); prefix = null; continue; } break; } if (prefix == null) { continue; } // reset command.Prefix = prefix; command.Manager.SaveSettings(); } }
internal static void ShowJobs() { IMenu menu = Far.Api.CreateMenu(); menu.Title = Res.BackgroundJobs; menu.ShowAmpersands = true; menu.HelpTopic = Far.Api.GetHelpTopic(HelpTopic.BackgroundJobsMenu); menu.AddKey(KeyCode.F3); menu.AddKey(KeyCode.F5); menu.AddKey(KeyCode.Delete); menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed); for (int show = 0; ; ++show) { WatchJobs(); if (show > 0 && JobList.Count == 0) { return; } menu.Items.Clear(); FarItem item = menu.Add(string.Format(null, MenuFormatString, "State", "Output", "Name/Command")); item.Disabled = true; foreach (Job job in JobList) { item = menu.Add(string.Format(null, MenuFormatString, job.StateText, job.Length, job.ToLine(100))); item.Data = job; } while (menu.Show()) { // refresh if (menu.Key.Is(KeyCode.F5)) { menu.Items.Clear(); break; } Job job = (Job)menu.SelectedData; if (job == null) { break; } // delete if (menu.Key.Is(KeyCode.Delete)) { if (job.IsRunning) { job.StopJob(); if (job.Length > 0) { break; } } job.Dispose(); break; } // delete all if (menu.Key.IsShift(KeyCode.Delete)) { // copy and then traverse var jobsToKill = new List <Job>(JobList); foreach (Job jobToKill in jobsToKill) { if (jobToKill.IsRunning) { jobToKill.StopJob(); if (jobToKill.Length > 0) { continue; } } jobToKill.Dispose(); } break; } // view if (job.FileName != null) { // file can be removed if the job is discarded if (!File.Exists(job.FileName)) { break; } // file exists, view it IViewer v = Far.Api.CreateViewer(); v.FileName = job.FileName; v.DisableHistory = true; if (menu.Key.VirtualKeyCode == KeyCode.F3) { v.Open(OpenMode.Modal); break; } else { v.Open(OpenMode.None); return; } } } if (menu.Selected < 0) { return; } } }