Esempio n. 1
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);
		}
Esempio n. 2
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;
		}
Esempio n. 3
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;
		}
Esempio n. 4
0
		public int Contains2(TextPoint tp)
		{
			return this.Contains2(tp.X, tp.Y);
		}
Esempio n. 5
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;
                    case UndoAction.ReplaceRange:
                        {
                            TextRange r = GetRangeFromText(undo.ReplacedText, undo.Position.X, undo.Position.Y);
                            DeleteRange(r, false);
                            InsertText(undo.Text, undo.Position.X, undo.Position.Y, 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;

		}
        private Point GetTextPointPixelPos(TextPoint tp)
        {
            Row xtr = Control.Document[tp.Y];
            if (xtr == null) return new Point();
            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);
        }
 /// <summary>
 /// Implementation of the IPainter GetDrawingPos method
 /// </summary>
 /// <param name="tp">Input TextPoint</param>
 /// <returns>Drawing corrdinates in Point</returns>
 /// 
 public Point GetDrawingPos(TextPoint tp)
 {
     return GetTextPointPixelPos(tp);
 }
        public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch)
        {
            
            if (InsightWindowVisible)
            {
                CloseInsightWindow(null, null);
            }
            ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(this.FileName, this, ch);
            if (completionData == null || completionData.Length == 0) {
                this.AutoListVisible = false;
				return ;
			}
      //      this.Caret.CurrentRow.AddToParseQueue();
            
            Word curWord = this.Caret.CurrentWord;
            TextPoint tp = null;
            if (ch == '\0')
            {

                if (curWord != null)
                {
                    // control space with some word already typed
                    tp = this.Caret.Position;
                    startOffset = new TextPoint(curWord.Column, tp.Y);
                }
                else
                {
                    tp = new TextPoint(this.Caret.Position.X + 1, this.Caret.Position.Y);
                    startOffset = new TextPoint(this.Caret.Position.X + 1, this.Caret.Position.Y);
                }
            }
            else
            {
                tp = new TextPoint(this.Caret.Position.X + 1, this.Caret.Position.Y);
                startOffset = new TextPoint(this.Caret.Position.X + 1, this.Caret.Position.Y);
            }
            this._AutoListStartPos = tp;
            
            // Set Caret correct Position before TryAutoCompletion;
            if (ch == '\0')
                if(TryAutoCompletion(completionData))
                    return ;

            this._AutoList.BeginLoad();
            this._AutoList.Clear();
            foreach (ICompletionData data in completionData)
            {
                this._AutoList.Add(data, data.ImageIndex);
            }
           
            this._AutoList.EndLoad();
            this.AutoListVisible = true;
            if (completionDataProvider != null && completionDataProvider.DefaultIndex >= 0)
            {
                this._AutoList.SelectItemByIndex(completionDataProvider.DefaultIndex);
            }
            else
            {
                this._AutoList.SelectItemByIndex(0);
            }
        }
Esempio n. 9
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();
		}
        private void SelectAutolistWord()
        {
            string s = Caret.CurrentRow.Text;
            //try
            //{
            if (_AutoListStartPos == null)
            {
                Word w = Caret.CurrentWord;

                if (w.Text == ".")
                    _AutoListStartPos = new TextPoint(w.Column + 1, Caret.Position.Y);
                else
                    _AutoListStartPos = new TextPoint(w.Column, Caret.Position.Y);
            }
            _CodeEditor.AutoListPosition = new TextPoint(Caret.Position.X + 2, Caret.Position.Y);
            if (Caret.Position.X - _AutoListStartPos.X >= 0 && _AutoListStartPos.X > 0)
            {
                s = s.Substring(_AutoListStartPos.X-1, Caret.Position.X - _AutoListStartPos.X+1);
                if(Caret.CurrentWord.Text.Length>0)
                    s = Caret.CurrentWord.Text;
                s = s.Replace('.', ' ').Trim();

                AutoList.SelectItem(s);
            }
        }
		/// <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;
            if (this.Caret.CurrentRow != null) this.Caret.CurrentRow.EnsureVisible();
			this.ScrollIntoView();
			this.Caret.Position = tmp;
			this.Invalidate();
		}
 public Point GetDrawingPos(TextPoint tp)
 {
     return this.Painter.GetDrawingPos(tp);
 }
Esempio n. 13
0
		/// <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();
		}
		/// <summary>
		/// Scrolls the active view to a specific position.
		/// </summary>
		/// <param name="Pos"></param>
		public void ScrollIntoView(TextPoint Pos)
		{
			_ActiveView.ScrollIntoView(Pos);
		}