/// <summary> /// 鼠标取词事件 /// </summary> /// <param name="sender">事件发送者</param> /// <param name="e">事件参数</param> private void luaEditBox_OnWordMouseHover(object sender, ref Fireball.Windows.Forms.CodeEditor.WordMouseEventArgs e) { Word hoveredWord = e.Word; if (e.Word.Index < e.Word.Row.Count - 1) // 行末尾的单词定位不准,暂时取消掉取词 { if (hoveredWord != lastHoveredWord) // 同一个单词只显示一次Tip就够了 { if (handleWordMouseHover != null) { handleWordMouseHover(this, ref e); } lastHoveredWord = hoveredWord; } } }
/// <summary> /// 编辑窗体取词 /// </summary> /// <param name="editForm">编辑窗体</param> /// <param name="e">取词参数</param> private void EditFormWordMouseHover(EditForm editForm, ref WordMouseEventArgs e) { string fileName = editForm.FileName; string varName = e.Word.Text; editForm.luaEditBox.CloseTipText(); if (startDebug && enableFetchWord && mouseFetchWord && !string.IsNullOrEmpty(varName)) { // 只接收合法命名的单词 Regex regex = new Regex(@"[A-Za-z0-9_]+"); if (regex.IsMatch(varName)) { if (ProcessFileName(editForm.FileName) == currentDebugFile) { string message = string.Format("print_var {0}", varName); string receivedMessage = SendAndWaitMessage(message, string.Format("<ldb>print_var: {0}", varName), true); string tipText = null; if (receivedMessage != null) { if (receivedMessage == string.Format("<ldb>print_var: {0} failed!", varName)) { tipText = "无效变量"; } else { receivedMessage = receivedMessage.Replace(string.Format("<ldb>print_var: {0} -> ", varName), ""); receivedMessage = receivedMessage.Replace("<", "<").Replace(">", ">"); // 遇到<和>符号的时候会出bug,先暂时替换掉 receivedMessage = receivedMessage.Replace("\n", "<BR>"); // 替换换行符 tipText = string.Format("<b>{0}</b><BR>{1}", varName, receivedMessage); } } else { tipText = "接收消息超时"; } TextPoint location = new TextPoint(e.Word.Column + e.Word.Text.Length, e.Word.Row.Index); editForm.luaEditBox.SetTipText(tipText, location); } } } }
private void SetMouseCursor(int x, int y) { if (_CodeEditor.LockCursorUpdate) { this.Cursor = _CodeEditor.Cursor; return; } if (View.Action == XTextAction.xtDragText) { this.Cursor = System.Windows.Forms.Cursors.Hand; //Cursor.Current = Cursors.Hand; } else { if (x < View.TotalMarginWidth) { if (x < View.GutterMarginWidth) { this.Cursor = System.Windows.Forms.Cursors.Arrow; } else { Assembly assembly = GetType().Assembly; Stream strm = assembly.GetManifestResourceStream("Fireball.FlippedCursor.cur"); this.Cursor = new Cursor(strm); } } else { if (x > View.TextMargin - 8) { if (IsOverSelection(x, y)) this.Cursor = System.Windows.Forms.Cursors.Arrow; else { TextPoint tp = this.Painter.CharFromPixel(x, y); Word w = this.Document.GetWordFromPos(tp); if (w != null && w.Pattern != null && w.Pattern.Category != null) { WordMouseEventArgs e = new WordMouseEventArgs(); e.Pattern = w.Pattern; e.Button = MouseButtons.None; e.Cursor = System.Windows.Forms.Cursors.Hand; e.Word = w; this._CodeEditor.OnWordMouseHover(ref e); this.Cursor = e.Cursor; } else this.Cursor = System.Windows.Forms.Cursors.IBeam; } } else { this.Cursor = System.Windows.Forms.Cursors.Arrow; } } } }
/// <summary> /// Overrides the default OnMouseDown /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { // this.Select(); MouseX = e.X; MouseY = e.Y; MouseButton = e.Button; SetFocus(); base.OnMouseDown(e); TextPoint pos = Painter.CharFromPixel(e.X, e.Y); Row row = null; if (pos.Y >= 0 && pos.Y < this.Document.Count) row = this.Document[pos.Y]; #region RowEvent RowMouseEventArgs rea = new RowMouseEventArgs(); rea.Row = row; rea.Button = e.Button; rea.MouseX = MouseX; rea.MouseY = MouseY; if (e.X >= this.View.TextMargin - 7) { rea.Area = RowArea.TextArea; } else if (e.X < this.View.GutterMarginWidth) { rea.Area = RowArea.GutterArea; } else if (e.X < this.View.LineNumberMarginWidth + this.View.GutterMarginWidth) { rea.Area = RowArea.LineNumberArea; } else if (e.X < this.View.TextMargin - 7) { rea.Area = RowArea.FoldingArea; } this.OnRowMouseDown(rea); #endregion //try //{ Row r2 = Document[pos.Y]; if (r2 != null) { if (e.X >= r2.Expansion_PixelEnd && r2.IsCollapsed) { if (r2.Expansion_StartSegment != null) { if (r2.Expansion_StartSegment.StartRow != null && r2.Expansion_StartSegment.EndRow != null && r2.Expansion_StartSegment.Expanded == false) { if (!IsOverSelection(e.X, e.Y)) { this.Caret.Position.X = pos.X; this.Caret.Position.Y = pos.Y; this.Selection.ClearSelection(); Row r3 = r2.Expansion_EndRow; int x3 = r3.Expansion_StartChar; this.Caret.Position.X = x3; this.Caret.Position.Y = r3.Index; this.Selection.MakeSelection(); this.Redraw(); View.Action = XTextAction.xtSelect; return; } } } } } //} //catch //{ // //this is untested code... //} bool shift = NativeUser32Api.IsKeyPressed(Keys.ShiftKey); if (e.X > View.TotalMarginWidth) { if (e.X > View.TextMargin - 8) { if (!IsOverSelection(e.X, e.Y)) { //selecting if (e.Button == MouseButtons.Left) { if (!shift) { TextPoint tp = pos; Word w = this.Document.GetWordFromPos(tp); if (w != null && w.Pattern != null && w.Pattern.Category != null) { WordMouseEventArgs pe = new WordMouseEventArgs(); pe.Pattern = w.Pattern; pe.Button = e.Button; pe.Cursor = System.Windows.Forms.Cursors.Hand; pe.Word = w; this._CodeEditor.OnWordMouseDown(ref pe); this.Cursor = pe.Cursor; return; } View.Action = XTextAction.xtSelect; Caret.SetPos(pos); Selection.ClearSelection(); Caret.Blink = true; this.Redraw(); } else { View.Action = XTextAction.xtSelect; Caret.SetPos(pos); Selection.MakeSelection(); Caret.Blink = true; this.Redraw(); } } } } else { if (row.Expansion_StartSegment != null) { Caret.SetPos(new TextPoint(0, pos.Y)); Selection.ClearSelection(); this.Document.ToggleRow(row); this.Redraw(); } } } else { if (e.X < View.GutterMarginWidth) { if (_CodeEditor.AllowBreakPoints) { Row r = Document[Painter.CharFromPixel(e.X, e.Y).Y]; r.Breakpoint = !r.Breakpoint; this.Redraw(); } else { Row r = Document[Painter.CharFromPixel(e.X, e.Y).Y]; r.Breakpoint = false; this.Redraw(); } } else { View.Action = XTextAction.xtSelect; Caret.SetPos(Painter.CharFromPixel(0, e.Y)); Selection.ClearSelection(); Caret.MoveDown(true); this.Redraw(); } } SetMouseCursor(e.X, e.Y); }
public void OnWordMouseDown(ref WordMouseEventArgs e) { if (WordMouseDown != null) WordMouseDown(this, ref e); }
public void OnWordMouseHover(ref WordMouseEventArgs e) { if (WordMouseHover != null) WordMouseHover(this, ref e); }
/// <summary> /// 处理取词事件 /// </summary> /// <param name="sender">事件发送者</param> /// <param name="e">事件参数</param> private void luaEditorWordMouseHover(object sender, ref WordMouseEventArgs e) { if (OnWordMouseHover != null) { OnWordMouseHover(sender, ref e); } }