void OnEdit(object sender, MenuEventArgs e) { if (!(_menu.SelectedData is Breakpoint bp) || string.IsNullOrEmpty(bp.Script)) { e.Ignore = true; return; } _toStop = true; IEditor editor = _editor; LineBreakpoint lbp = bp as LineBreakpoint; // the target script is opened now if (editor != null && Kit.Equals(editor.FileName, bp.Script)) { // it is a line breakpoint, go to line if (lbp != null) { editor.GoToLine(lbp.Line - 1); return; } return; } editor = Far.Api.CreateEditor(); editor.FileName = bp.Script; if (lbp != null) { editor.GoToLine(lbp.Line - 1); } editor.Open(); }
void OnLineBreakpoint(object sender, EventArgs e) { if (_menu.Key.VirtualKeyCode != 0) { return; } string file = null; int line = 0; LineBreakpoint bpFound = null; if (_editor != null) { // location file = _editor.FileName; line = _editor.Caret.Y + 1; // find foreach (PSObject o in _breakpoints) { if (o.BaseObject is LineBreakpoint lbp && lbp.Action == null && line == lbp.Line && Kit.Equals(file, lbp.Script)) { bpFound = lbp; break; } } // found? if (bpFound != null) { switch (Far.Api.Message("Breakpoint exists", "Line breakpoint", MessageOptions.None, new string[] { "&Remove", bpFound.Enabled ? "&Disable" : "&Enable", "&Modify", "&Add", "&Cancel" })) { case 0: A.RemoveBreakpoint(bpFound); return; case 1: if (bpFound.Enabled) { A.DisableBreakpoint(bpFound); } else { A.InvokeCode("Enable-PSBreakpoint -Breakpoint $args[0]", bpFound); } return; case 2: break; case 3: bpFound = null; break; default: return; } } } // go BreakpointDialog ui = new BreakpointDialog(0, file, line); if (!ui.Show()) { return; } // remove old if (bpFound != null) { A.RemoveBreakpoint(bpFound); } // set new A.SetBreakpoint(ui.Script, int.Parse(ui.Matter, null), ui.Action); }
public DebuggerDialog(DebuggerStopEventArgs e) { _InvocationInfo = e.InvocationInfo; int maxLine = 0; string[] lines = null; if (!string.IsNullOrEmpty(e.InvocationInfo.ScriptName) && File.Exists(e.InvocationInfo.ScriptName)) { try { lines = File.ReadAllLines(e.InvocationInfo.ScriptName, Encoding.Default); foreach (string s in lines) { if (s.Length > maxLine) { maxLine = s.Length; } } } catch (IOException) { } } int dw = Math.Max(Math.Min(Far.Api.UI.WindowSize.X - 7, maxLine + 12), 73); int dh = 22; string title; int h1; if (e.Breakpoints.Count > 0) { title = "DEBUG: Hit breakpoint(s)"; h1 = e.Breakpoints.Count + 2; } else { title = "DEBUG: Step"; h1 = 2; } _Dialog = Far.Api.CreateDialog(-1, -1, dw, dh); _Dialog.HelpTopic = Far.Api.GetHelpTopic("DebuggerDialog"); _Dialog.AddBox(3, 1, dw - 4, dh - 2, title); _List1 = _Dialog.AddListBox(4, 2, dw - 5, h1 + 1, null); _List1.Disabled = true; _List1.NoBox = true; _List1.NoClose = true; _List1.NoFocus = true; if (e.Breakpoints.Count > 0) { foreach (Breakpoint bp in e.Breakpoints) { CommandBreakpoint bpc = bp as CommandBreakpoint; if (bpc != null && Kit.Equals(bpc.Command, Commands.AssertFarCommand.MyName)) { A.InvokeCode("Remove-PSBreakpoint -Breakpoint $args[0]", bpc); } } } foreach (string s in e.InvocationInfo.PositionMessage.Trim().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) { _List1.Add(s); } _Dialog.AddText(0, -_List1.Rect.Height, 0, null).Separator = 1; _List2 = _Dialog.AddListBox(4, _List1.Rect.Bottom + 2, dw - 5, dh - 5, null); _List2.NoBox = true; _List2.NoClose = true; if (lines != null) { foreach (string s in lines) { _List2.Add(s); } int i = e.InvocationInfo.ScriptLineNumber - 1; _List2.Items[i].Checked = true; } _Dialog.AddText(0, -_List2.Rect.Height, 0, null).Separator = 1; _Step = _Dialog.AddButton(0, -1, BtnStep); _Step.CenterGroup = true; _Over = _Dialog.AddButton(0, 0, BtnOver); _Over.CenterGroup = true; _Out = _Dialog.AddButton(0, 0, BtnOut); _Out.CenterGroup = true; _Console = _Dialog.AddButton(0, 0, BtnInteractive); _Console.CenterGroup = true; _Console.NoBrackets = true; _Edit = _Dialog.AddButton(0, 0, BtnEdit); _Edit.CenterGroup = true; _Edit.NoBrackets = true; // to be completed on show _View = _Dialog.AddButton(0, 0, BtnView); _View.CenterGroup = true; _View.NoBrackets = true; _View.NoClose = true; _Goto = _Dialog.AddButton(0, 0, BtnLine); _Goto.CenterGroup = true; _Goto.NoBrackets = true; _Goto.NoClose = true; _Goto.ButtonClicked += OnGoto; _Quit = _Dialog.AddButton(0, 0, BtnQuit); _Quit.CenterGroup = true; _Quit.NoBrackets = true; _Dialog.Initialized += OnInitialized; }