Example #1
0
        /// <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);
                    }
                }
            }
        }
Example #2
0
		/// <summary>
		/// Converts a Column/Row index position into a char index
		/// </summary>
		/// <param name="pos">TextPoint where x is column and y is row index</param>
		/// <returns>Char index in the document text</returns>
		public int PointToIntPos(TextPoint pos)
		{
			int y = 0;
			int p = 0;
			foreach (Row r in this)
			{
				if (y == pos.Y)
					break;
				p += r.Text.Length + Environment.NewLine.Length;
				y++;
			}

			return p + Math.Min(pos.X, this[pos.Y].Text.Length);
		}
Example #3
0
		/// <summary>
		/// Scrolls a given position in the text into view.
		/// </summary>
		/// <param name="Pos">Position in text</param>
		public void ScrollIntoView(TextPoint Pos)
		{
			TextPoint tmp = this.Caret.Position;
			this.Caret.Position = Pos;
			this.Caret.CurrentRow.EnsureVisible();
			this.ScrollIntoView();
			this.Caret.Position = tmp;
			this.Invalidate();
		}
Example #4
0
		//Returns the segment object at the given position
		/// <summary>
		/// Gets a Segment object form a given column , Row index
		/// (This only applies if the row is fully parsed)
		/// </summary>
		/// <param name="p">Column and Rowindex</param>
		/// <returns>Segment object at the given position</returns>
		public Segment GetSegmentFromPos(TextPoint p)
		{
			Row xtr = this[p.Y];
			int CharNo = 0;

            if (xtr == null) return (null);
			if (xtr.Count == 0)
				return xtr.StartSegment;

			Segment prev = xtr.StartSegment;
            Word w;
            //foreach (Word w in xtr)
            for (int i = 0; i < xtr.Count; i++)
            {
                w = xtr[i];

				if (w.Text.Length + CharNo > p.X)
				{
					if (CharNo == p.X)
						return prev;
					else
						return w.Segment;
				}
				else
				{
					CharNo += w.Text.Length;
					prev = w.Segment;
				}
			}

			return xtr.EndSegment;
		}
Example #5
0
		//the specific word that contains the char in point p
		/// <summary>
		/// Gets a Word object form a given column , Row index
		/// (this only applies if the row is fully parsed)
		/// </summary>
		/// <param name="p">Column and Rowindex</param>
		/// <returns>Word object at the given position</returns>
		public Word GetFormatWordFromPos(TextPoint p)
		{
			Row xtr = this[p.Y];
			int CharNo = 0;
			Word CorrectWord = null;
			//foreach (Word w in xtr.FormattedWords)
            for(int i = 0; i< xtr.FormattedWords.Count;i++)
			{
                Word w = xtr.FormattedWords[i];

				if (CorrectWord != null)
				{
					if (w.Text == "")
						return w;
					else
						return CorrectWord;
				}

				if (w.Text.Length + CharNo > p.X || w == xtr[xtr.Count - 1])
				{
					//return w;
					CorrectWord = w;
				}
				else
				{
					CharNo += w.Text.Length;
				}
			}
			return CorrectWord;
		}
Example #6
0
 public int Contains2(TextPoint tp)
 {
     return this.Contains2(tp.X, tp.Y);
 }
Example #7
0
		/// <summary>
		/// Perform an undo action
		/// </summary>
		/// <returns>The position where the caret should be placed</returns>
		public TextPoint Undo()
		{
			if (UndoStep == 0)
				return new TextPoint(-1, -1);


			UndoBlockCollection ActionGroup = (UndoBlockCollection) this.UndoBuffer[UndoStep - 1];
			UndoBlock undo = (UndoBlock) ActionGroup[0];

			for (int i = ActionGroup.Count - 1; i >= 0; i--)
			{
				undo = (UndoBlock) ActionGroup[i];
				//TextPoint tp=new TextPoint (undo.Position.X,undo.Position.Y);
				switch (undo.Action)
				{
					case UndoAction.DeleteRange:
						InsertText(undo.Text, undo.Position.X, undo.Position.Y, false);
						break;
					case UndoAction.InsertRange:
						{
							TextRange r = GetRangeFromText(undo.Text, undo.Position.X, undo.Position.Y);
							DeleteRange(r, false);
						}
						break;
					default:
						break;
				}
			}

			UndoStep--;
			this.ResetVisibleRows();

			//no undo steps left , the document is not dirty
			if (UndoStep == 0)
				Modified = false;

			TextPoint tp = new TextPoint(undo.Position.X, undo.Position.Y);
			OnUndoBufferChanged();
			return tp;

		}
Example #8
0
        private Point GetTextPointPixelPos(TextPoint tp)
        {
            Row xtr = Control.Document[tp.Y];
            if (xtr.RowState == RowState.SegmentParsed)
                this.Control.Document.Parser.ParseLine(xtr.Index, true);

            Row r = null;

            if (xtr.IsCollapsedEndPart)
                r = xtr.Expansion_StartRow;
            else
                r = xtr;

            int index = r.VisibleIndex;
            int yPos = (index - Control.View.FirstVisibleRow);
            if (yPos < 0 || yPos > Control.View.VisibleRowCount)
                return new Point(-1, -1);

            yPos *= Control.View.RowHeight;

            bool Collapsed = false;
            Collapsed = (xtr.IsCollapsedEndPart);
            int pos = MeasureRow(xtr, tp.X, xtr.Expansion_PixelStart).Width + 1;

            if (Collapsed)
            {
                pos += xtr.Expansion_PixelStart;
                pos -= MeasureRow(xtr, xtr.Expansion_StartChar,
                                  xtr.Expansion_PixelStart).Width;
            }

            int xPos = pos + Control.View.TextMargin - Control.View.ClientAreaStart;

            if (xPos < Control.View.TextMargin || xPos > Control.View.ClientAreaWidth
                + Control.View.TextMargin)
                return new Point(-1, -1);

            return new Point(xPos, yPos);
        }
Example #9
0
File: Row.cs Project: viticm/pap2
		/// <summary>
		/// Assigns a new text to the row.
		/// </summary>
		/// <param name="Text"></param>
		public void SetText(string Text)
		{
			this.Document.StartUndoCapture();
			TextPoint tp = new TextPoint(0, this.Index);
			TextRange tr = new TextRange();
			tr.FirstColumn = 0;
			tr.FirstRow = tp.Y;
			tr.LastColumn = this.Text.Length;
			tr.LastRow = tp.Y;

			this.Document.StartUndoCapture();
			//delete the current line
			this.Document.PushUndoBlock(UndoAction.DeleteRange, this.Document.GetRange(tr), tr.FirstColumn, tr.FirstRow);
			//alter the text
			this.Document.PushUndoBlock(UndoAction.InsertRange, Text, tp.X, tp.Y);
			this.Text = Text;
			this.Document.EndUndoCapture();
			this.Document.InvokeChange();
		}
Example #10
0
		/// <summary>
		/// Sets the position of the caret
		/// </summary>
		/// <param name="pos">Point containing the new x and y positions</param>
		public void SetPos(TextPoint pos)
		{
			this.Position = pos;
			RememberXPos();
		}
Example #11
0
		/// <summary>
		/// Scrolls the active view to a specific position.
		/// </summary>
		/// <param name="Pos"></param>
		public void ScrollIntoView(TextPoint Pos)
		{
			_ActiveView.ScrollIntoView(Pos);
		}
Example #12
0
		//the specific word that contains the char in point p
		/// <summary>
		/// Gets a Word object form a given column , Row index
		/// (this only applies if the row is fully parsed)
		/// </summary>
		/// <param name="p">Column and Rowindex</param>
		/// <returns>Word object at the given position</returns>
		public Word GetWordFromPos(TextPoint p, bool useLeft)
		{
			Row xtr = this[p.Y];
			int CharNo = 0;
			Word CorrectWord = null;

            Word w;
			//foreach (Word w in xtr)
            for(int i = 0; i< xtr.Count;++i)
			{
                w = xtr[i];

				if (CorrectWord != null)
				{
					if (w.Text == "")
						return w;
					else
						return CorrectWord;
				}

                if ((w.Text.Length + CharNo > p.X && !useLeft) ||
                    (w.Text.Length + CharNo >= p.X && useLeft) ||
                    w == xtr[xtr.Count - 1])
				{
					return w;
				}
				else
				{
					CharNo += w.Text.Length;
				}
			}
			return CorrectWord;
		}
Example #13
0
        //the specific word that contains the char in point p
		/// <summary>
		/// Gets a Word object form a given column , Row index
		/// (this only applies if the row is fully parsed)
		/// </summary>
		/// <param name="p">Column and Rowindex</param>
		/// <returns>Word object at the given position</returns>
        public Word GetWordFromPos(TextPoint p)
        {
            return GetWordFromPos(p, false);
        }
Example #14
0
 /// <summary>
 /// 设置提示文本
 /// </summary>
 /// <param name="tipText">文本内容</param>
 /// <param name="location">位置</param>
 public void SetTipText(string tipText, TextPoint location)
 {
     codeEditorControl.InfoTipPosition = location;
     codeEditorControl.InfoTipCount = 1;
     codeEditorControl.InfoTipSelectedIndex = 0;
     codeEditorControl.InfoTipText = tipText;
     codeEditorControl.InfoTipVisible = true;
 }