void onClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseUp(e); if (TextView != null && TextView.VisualLinesValid) { foreach (VisualLine line in TextView.VisualLines) { Rect hitRect = new Rect( new Point(0, line.VisualTop - TextView.ScrollOffset.Y), new Point(RenderSize.Width, line.VisualTop - TextView.ScrollOffset.Y + line.Height) ); if (hitRect.Contains(e.GetPosition(this))) { int ln = line.FirstDocumentLine.LineNumber; Debugger.Debug.Breakpoint bp = fileData.BreakPoints.FirstOrDefault(b => b.LineNumber == ln); if (bp == null) { fileData.BreakPoints.Add(new Debugger.Debug.Breakpoint { LineNumber = ln, File = fileData.SectionName, SectionID = fileData.SectionID, Active = true }); } else { bp.Active = !bp.Active; } } } } this.InvalidateVisual(); }
void setBPAtCursor(object who, RoutedEventArgs args) { CodeEditor editor = who as CodeEditor; int ln = editor.editor.TextArea.TextView.HighlightedLine; if (ln <= 0) { return; } Debugger.Debug.Breakpoint bp = editor.data.BreakPoints.FirstOrDefault(b => b.LineNumber == ln); if (bp == null) { editor.data.BreakPoints.Add(new Debugger.Debug.Breakpoint { LineNumber = ln, File = editor.data.SectionName, SectionID = editor.data.SectionID, Active = true }); } else { bp.Active = !bp.Active; } bpMargin.InvalidateVisual(); }
protected override void OnRender(DrawingContext drawingContext) { TextView textView = this.TextView; Size renderSize = this.RenderSize; if (textView != null && textView.VisualLinesValid) { foreach (VisualLine line in textView.VisualLines) { Debugger.Debug.Breakpoint bp = fileData.BreakPoints.FirstOrDefault(b => b.LineNumber == line.FirstDocumentLine.LineNumber); if (bp != null && bp.Active) { drawingContext.DrawEllipse(rb, null, new Point(renderSize.Width / 2, line.VisualTop - textView.ScrollOffset.Y + 9), 9, 9); } else if (bp != null) { drawingContext.DrawEllipse(rb, null, new Point(renderSize.Width / 2, line.VisualTop - textView.ScrollOffset.Y + 9), 9, 9); drawingContext.DrawEllipse(wb, null, new Point(renderSize.Width / 2, line.VisualTop - textView.ScrollOffset.Y + 9), 7, 7); } if (Debugger.Debug.SessionData.inst().CurrentLine == line.FirstDocumentLine.LineNumber && Debugger.Debug.SessionData.inst().CurrentSection == fileData.SectionID) { drawingContext.DrawRectangle(db, null, new Rect { X = 2, Width = renderSize.Width - 2, Y = line.VisualTop - textView.ScrollOffset.Y + 4, Height = renderSize.Width - 8 }); drawingContext.DrawRectangle(lb, null, new Rect { X = 4, Width = renderSize.Width - 4, Y = line.VisualTop - textView.ScrollOffset.Y + 6, Height = renderSize.Width - 10 }); } } } }
void _ReceiveMsg(object o, MessageReceivedEventArgs args) { try { string msg = args.Message.Substring(0, 4).ToLower(); string[] parts = args.Message.Split(' '); /*Regex.Matches(msg, @"[\""].+?[\""]|[^ ]+") * .Cast<Match>() * .Select(m => m.Value) * .ToArray();*/ if (VerboseLog) //if vebose logging then send all messages { MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { Message = args.Message, MsgType = MessageType.Data }); }); } if (msg.Equals("varv")) { //TODO MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { Message = args.Message, MsgType = MessageType.Data }); }); } else if (msg.Equals("reqv")) { string varName = parts[1]; string varValue = parts[2]; //TODO } else if (msg.Equals("locv")) { string code = args.Message.Substring(5); JArray array = JArray.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().LocalData = new Json.JWrapper("Stack Level ", array); //Screens.DebugScreen.inst().LocalsTree.DataContext = null; Screens.DebugScreen.inst().LocalsTree.DataContext = SessionData.inst().LocalData; }); } else if (msg.Equals("glov")) { string code = args.Message.Substring(5).Replace("1.#INF", "\"1.#INF\""); JArray array = JArray.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().GlobalData = new Json.JWrapper("Globals", array); //Screens.DebugScreen.inst().GlobalsTree.DataContext = null; Screens.DebugScreen.inst().GlobalTree.DataContext = SessionData.inst().GlobalData; }); } else if (msg.Equals("this")) { int stackDepth = int.Parse(parts[1]); string code = JoinStringsWith(parts, 2, " "); JObject array = JObject.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().ThisData = new Json.JWrapper("This", array); //Screens.DebugScreen.inst().ThisTree.DataContext = null; Screens.DebugScreen.inst().ThisTree.DataContext = SessionData.inst().ThisData; }); //TODO } else if (msg.Equals("modl")) { JArray array = JArray.Parse(args.Message.Substring(5)); for (int i = 0; i < array.Count; ++i) { if (array[i].Type == JTokenType.String) { string str = array[i].ToString(); MainWindow.inst().Dispatcher.Invoke(delegate() { if (session_.Modules.FirstOrDefault(m => m.Name.Equals(str)) == null) { session_.Modules.Add(new Module { Name = str }); } }); } } } else if (msg.Equals("ctxl")) { } else if (msg.Equals("stck")) { if (parts[1].StartsWith("[")) { //TODO string code = args.Message.Substring(5); JArray array = JArray.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().CallStack.Clear(); //STCK [{"l":47,"c":5,"s":18,"f":"UIElement@ SetValue(LineEdit@, const String&in, bool)"},{"l":471,"c":9,"s":18,"f":"void LoadAttributeEditor(UIElement@, const Variant&in, const AttributeInfo&in, bool, bool, const Variant[]&in)"},{"l":444,"c":9,"s":18,"f":"void LoadAttributeEditor(ListView@, Serializable@[]@, const AttributeInfo&in, uint)"},{"l":785,"c":9,"s":18,"f":"void UpdateAttributes(Serializable@[]@, ListView@, bool&inout)"},{"l":226,"c":9,"s":17,"f":"void UpdateAttributeInspector(bool = true)"},{"l":738,"c":5,"s":2,"f":"void HandleHierarchyListSelectionChange()"}] int i = 0; foreach (JObject obj in array.Children <JObject>()) { session_.CallStack.Add(new Callstack { Line = obj.Property("l").Value.ToObject <int>(), StackFunction = obj.Property("f").Value.ToString(), StackLevel = i, SectionID = obj.Property("s").Value.ToObject <int>() }); ++i; } }); } else { string ctx = parts[1]; int depth = int.Parse(parts[2]); int line = int.Parse(parts[3]); int sectionid = int.Parse(parts[4]); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.CallStack.Add(new Callstack { StackLevel = depth, StackFunction = ctx, SectionID = sectionid, Line = line }); }); } } else if (msg.Equals("scls")) { JArray array = JArray.Parse(args.Message.Substring(5)); foreach (JObject obj in array.Children <JObject>()) { int id = obj.Property("id").Value.ToObject <int>(); string module = obj.Property("mod").Value.ToString(); string name = obj.Property("name").Value.ToString(); //??if (name.Trim().Length == 0) //ignore that empty one for the immediate mode context //?? return; MainWindow.inst().Dispatcher.Invoke(delegate() { FileData fd = session_.Files.FirstOrDefault(file => file.SectionName.Equals(name)); if (fd == null) { session_.Files.Add(new FileData { SectionName = name, Module = module, SectionID = id }); } else { fd.SectionID = id; } }); } } else if (msg.Equals("file")) { int sectionID = int.Parse(parts[1]); int len = sectionID.ToString().Length + 6; string data = args.Message.Substring(len); Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID); if (file != null) { file.Code = data; } //??is there an else case? should presumably know the section ahead of time } else if (msg.Equals("bset")) { int sectionID = int.Parse(parts[1]); int line = int.Parse(parts[2]); Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID); if (file != null) { Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line); if (breakpoint == null) { MainWindow.inst().Dispatcher.Invoke(delegate() { file.BreakPoints.Add(new Breakpoint { LineNumber = line, Active = true, SectionID = sectionID, File = file.SectionName }); }); } else { breakpoint.Active = true; } } else { Debugger.Debug.FileData fd = new FileData { SectionID = sectionID }; } } else if (msg.Equals("brem")) { int sectionID = int.Parse(parts[1]); int line = int.Parse(parts[2]); Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID); if (file != null) { Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line); if (breakpoint != null) { breakpoint.Active = false; } } } else if (msg.Equals("hitl")) { session_.IsDebugging = true; int sectionId = int.Parse(parts[1]); int line = int.Parse(parts[2]); session_.CurrentSection = sectionId; session_.CurrentLine = line; MainWindow.inst().Dispatcher.Invoke(delegate() { Screens.DebugScreen.inst().EditorTabs.OpenFile(sectionId, line); }); } else if (msg.Equals("cont")) { } else if (msg.Equals("secm")) //A file has been changed remotely, send a request for it { int sectionid = int.Parse(parts[1]); socket_.Send(string.Format("GETF {0}", sectionid)); } else if (msg.Equals("logw")) { string m = args.Message.Substring(5); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Warning, Message = JoinStringsWith(parts, 1, " ") }); }); } else if (msg.Equals("loge")) { string m = args.Message.Substring(5); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Error, Message = JoinStringsWith(parts, 1, " ") }); }); } else if (msg.Equals("logi")) { string m = args.Message.Substring(5); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Info, Message = JoinStringsWith(parts, 1, " ") }); }); } else if (msg.Equals("rstr")) { //TODO } else { //Unknown msg MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Data, Message = args.Message }); }); } } catch (Exception ex) { MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Error, Message = ex.Message }); session_.Log.Add(new LogMessage { MsgType = MessageType.Info, Message = args.Message }); }); } }
void _ReceiveMsg(object o, MessageReceivedEventArgs args) { try { string msg = args.Message.Substring(0, 4).ToLower(); string[] parts = args.Message.Split(' '); if (VerboseLog) //if vebose logging then send all messages { MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { Message = args.Message, MsgType = MessageType.Data }); }); } if (msg.Equals("varv")) //Variable Value message //TODO { MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { Message = args.Message, MsgType = MessageType.Data }); }); } else if (msg.Equals("reqv")) // Request Variable Message { string varName = parts[1]; string varValue = parts[2]; //TODO } else if (msg.Equals("locv")) // Local Stack Values Message { string code = args.Message.Substring(5); JArray array = JArray.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().LocalData = new Json.JWrapper("", array); Screens.DebugScreen.inst().LocalsTree.DataContext = SessionData.inst().LocalData; }); } else if (msg.Equals("glov")) // Global Variables Message { string code = args.Message.Substring(5).Replace("1.#INF", "\"1.#INF\""); JArray array = JArray.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().GlobalData = new Json.JWrapper("Globals", array); Screens.DebugScreen.inst().GlobalTree.DataContext = SessionData.inst().GlobalData; }); } else if (msg.Equals("this")) // "This" Object data { int stackDepth = int.Parse(parts[1]); string code = JoinStringsWith(parts, 2, " "); JObject array = JObject.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().ThisData = new Json.JWrapper("This", array); SessionData.inst().ThisData.UserData = stackDepth; //Screens.DebugScreen.inst().ThisTree.DataContext = null; Screens.DebugScreen.inst().ThisTree.DataContext = SessionData.inst().ThisData; }); //TODO } else if (msg.Equals("modl")) // Script Modules Message { JArray array = JArray.Parse(args.Message.Substring(5)); for (int i = 0; i < array.Count; ++i) { if (array[i].Type == JTokenType.String) { string str = array[i].ToString(); MainWindow.inst().Dispatcher.Invoke(delegate() { if (session_.Modules.FirstOrDefault(m => m.Name.Equals(str)) == null) { session_.Modules.Add(new Module { Name = str }); } }); } } } else if (msg.Equals("ctxl")) // Script Context messages, irrelevant in simple AS implementations { } else if (msg.Equals("stck")) // Call stack Message { if (parts[1].StartsWith("[")) { //TODO string code = args.Message.Substring(5); JArray array = JArray.Parse(code); MainWindow.inst().Dispatcher.Invoke(delegate() { SessionData.inst().CallStack.Clear(); //STCK [{"l":47,"c":5,"s":18,"f":"UIElement@ SetValue(LineEdit@, const String&in, bool)"},{"l":471,"c":9,"s":18,"f":"void LoadAttributeEditor(UIElement@, const Variant&in, const AttributeInfo&in, bool, bool, const Variant[]&in)"},{"l":444,"c":9,"s":18,"f":"void LoadAttributeEditor(ListView@, Serializable@[]@, const AttributeInfo&in, uint)"},{"l":785,"c":9,"s":18,"f":"void UpdateAttributes(Serializable@[]@, ListView@, bool&inout)"},{"l":226,"c":9,"s":17,"f":"void UpdateAttributeInspector(bool = true)"},{"l":738,"c":5,"s":2,"f":"void HandleHierarchyListSelectionChange()"}] int i = 0; foreach (JObject obj in array.Children <JObject>()) { session_.CallStack.Add(new Callstack { Line = obj.Property("l").Value.ToObject <int>(), StackFunction = obj.Property("f").Value.ToString(), StackLevel = i, SectionID = obj.Property("s").Value.ToObject <int>() }); ++i; } }); } else { string ctx = parts[1]; int depth = int.Parse(parts[2]); int line = int.Parse(parts[3]); int sectionid = int.Parse(parts[4]); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.CallStack.Add(new Callstack { StackLevel = depth, StackFunction = ctx, SectionID = sectionid, Line = line }); }); } } else if (msg.Equals("scls")) // List of "Script Sections"/files { JArray array = JArray.Parse(args.Message.Substring(5)); foreach (JObject obj in array.Children <JObject>()) { int id = obj.Property("id").Value.ToObject <int>(); string module = obj.Property("mod").Value.ToString(); string name = obj.Property("name").Value.ToString(); if (module.Length == 0) { continue; } MainWindow.inst().Dispatcher.Invoke(delegate() { FileData fd = session_.Files.FirstOrDefault(file => file.SectionName.Equals(name)); if (fd == null) { session_.Files.Add(new FileData { SectionName = name, Module = module, SectionID = id }); } else { fd.SectionID = id; // Faciliates "lost" connection } }); } } else if (msg.Equals("file")) // Script code sent to us { int sectionID = int.Parse(parts[1]); int len = sectionID.ToString().Length + 6; string data = args.Message.Substring(len); Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID); if (file != null) { file.Code = data; } //??is there an else case? should presumably know the section ahead of time } else if (msg.Equals("bset")) // Someone has set a breakpoint { int sectionID = int.Parse(parts[1]); int line = int.Parse(parts[2]); Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID); if (file != null) { Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line); if (breakpoint == null) { MainWindow.inst().Dispatcher.Invoke(delegate() { file.BreakPoints.Add(new Breakpoint { LineNumber = line, Active = true, SectionID = sectionID, File = file.SectionName }); }); } else { breakpoint.Active = true; } } else { Debugger.Debug.FileData fd = new FileData { SectionID = sectionID }; } } else if (msg.Equals("brem")) // Someone has removed a breakpoint { int sectionID = int.Parse(parts[1]); int line = int.Parse(parts[2]); Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID); if (file != null) { Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line); if (breakpoint != null) { breakpoint.Active = false; } } } else if (msg.Equals("hitl")) // "HitLine" current line position // If we had not already halted then play the beep sound if enabled { if (!session_.IsDebugging && session_.Settings.PlayBeepSound) { SystemSounds.Hand.Play(); } session_.IsDebugging = true; int sectionId = int.Parse(parts[1]); int line = int.Parse(parts[2]); session_.CurrentSection = sectionId; session_.CurrentLine = line; MainWindow.inst().Dispatcher.Invoke(delegate() { Screens.DebugScreen.inst().EditorTabs.OpenFile(sectionId, line); }); } else if (msg.Equals("cont")) // Execution resumed by someone { } else if (msg.Equals("secm")) //A file has been changed remotely, send a request for it { int sectionid = int.Parse(parts[1]); socket_.Send(string.Format("GETF {0}", sectionid)); } else if (msg.Equals("logw")) // Log Warning { string m = args.Message.Substring(5); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Warning, Message = JoinStringsWith(parts, 1, " ") }); }); } else if (msg.Equals("loge") || msg.Equals("erro")) // Log Error { string m = args.Message.Substring(5); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Error, Message = JoinStringsWith(parts, 1, " ") }); }); } else if (msg.Equals("logi")) // Log Info { string m = args.Message.Substring(5); MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Info, Message = JoinStringsWith(parts, 1, " ") }); }); } else if (msg.Equals("rstr")) // A restart message //TODO { } else { //Unknown msg MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Data, Message = args.Message }); }); } } catch (Exception ex) { MainWindow.inst().Dispatcher.Invoke(delegate() { session_.Log.Add(new LogMessage { MsgType = MessageType.Error, Message = ex.Message }); session_.Log.Add(new LogMessage { MsgType = MessageType.Info, Message = args.Message }); }); } }