Example #1
0
		/// <summary>
		/// Remove a row at specified row index
		/// </summary>
		/// <param name="index">index of the row that should be removed</param>
		/// <param name="StoreUndo">true if and undo action should be added to the undo stack</param>
		public void Remove(int index, bool StoreUndo, bool RaiseChanged)
		{
			Row r = this[index];

			if (StoreUndo)
			{
				TextRange ra = new TextRange();

				if (index != this.Count - 1)
				{
					ra.FirstColumn = 0;
					ra.FirstRow = index;
					ra.LastRow = index + 1;
					ra.LastColumn = 0;
				}
				else
				{
					ra.FirstColumn = r.PrevRow.Text.Length;
					ra.FirstRow = index - 1;
					ra.LastRow = index;
					ra.LastColumn = r.Text.Length;
				}
				PushUndoBlock(UndoAction.DeleteRange, GetRange(ra), ra.FirstColumn, ra.FirstRow);

			}


			mDocument.RemoveAt(index);
			if (r.InKeywordQueue)
				this.KeywordQueue.Remove(r);

			if (r.InQueue)
				this.ParseQueue.Remove(r);

			//this.ResetVisibleRows ();
			OnRowDeleted(r);
			if (RaiseChanged)
				OnChange();
		}
Example #2
0
		/// <summary>
		/// Get a range of text
		/// </summary>
		/// <param name="Range">The range to get</param>
		/// <returns>string containing the text inside the given range</returns>
		public string GetRange(TextRange Range)
		{
			if (Range.FirstRow >= this.Count)
				Range.FirstRow = this.Count;

			if (Range.LastRow >= this.Count)
				Range.LastRow = this.Count;

			if (Range.FirstRow != Range.LastRow)
			{
				//note:error has been tracked here
				Row r1 = this[Range.FirstRow];
				int mx = Math.Min(r1.Text.Length, Range.FirstColumn);
				string s1 = r1.Text.Substring(mx) + Environment.NewLine;

				//if (Range.LastRow >= this.Count)
				//	Range.LastRow=this.Count -1;

				Row r2 = this[Range.LastRow];
				if (r2 == null)
					return "";

				int Max = Math.Min(r2.Text.Length, Range.LastColumn);
				string s2 = r2.Text.Substring(0, Max);

				string s3 = "";
				StringBuilder sb = new StringBuilder();
				for (int i = Range.FirstRow + 1; i <= Range.LastRow - 1; i++)
				{
					Row r3 = this[i];

					sb.Append(r3.Text + Environment.NewLine);
				}

				s3 = sb.ToString();
				return s1 + s3 + s2;
			}
			else
			{
				Row r = this[Range.FirstRow];
				int Max = Math.Min(r.Text.Length, Range.LastColumn);
				int Length = Max - Range.FirstColumn;
				if (Length <= 0)
					return "";
				string s = r.Text.Substring(Range.FirstColumn, Max - Range.FirstColumn);
				return s;
			}

		}
Example #3
0
		/// <summary>
		/// Gets a Range from a given text
		/// </summary>
		/// <param name="text"></param>
		/// <param name="xPos"></param>
		/// <param name="yPos"></param>
		/// <returns></returns>
		public TextRange GetRangeFromText(string text, int xPos, int yPos)
		{
			string t = text.Replace(Environment.NewLine, "\n");
			string[] lines = t.Split("\n".ToCharArray());
			TextRange r = new TextRange();
			r.FirstColumn = xPos;
			r.FirstRow = yPos;
			r.LastRow = lines.Length - 1 + yPos;
			r.LastColumn = lines[lines.Length - 1].Length;
			if (r.FirstRow == r.LastRow)
				r.LastColumn += r.FirstColumn;

			return r;
		}
Example #4
0
		public FormatRange(TextRange Bounds, Color WaveColor)
		{
			this.WaveColor = WaveColor;
			this.Bounds = Bounds;
			this.Bounds.Change += new EventHandler(this.BoundsChanged);
		}
Example #5
0
		/// <summary>
		/// Deletes a range of text
		/// </summary>
		/// <param name="Range">Range to delete</param>
		/// <param name="StoreUndo">true if the actions should be pushed onto the undo stack</param>
		public void DeleteRange(TextRange Range, bool StoreUndo)
		{
			TextRange r = Range;
			Modified = true;
			if (StoreUndo)
			{
				string deltext = GetRange(Range);
				PushUndoBlock(UndoAction.DeleteRange, deltext, r.FirstColumn, r.FirstRow);
			}


			if (r.FirstRow == r.LastRow)
			{
				Row xtr = this[r.FirstRow];
				int max = Math.Min(r.FirstColumn, xtr.Text.Length);
				string left = xtr.Text.Substring(0, max);
				string right = "";
				if (xtr.Text.Length >= r.LastColumn)
					right = xtr.Text.Substring(r.LastColumn);
				xtr.Text = left + right;
			}
			else
			{
				if (r.LastRow > this.Count - 1)
					r.LastRow = this.Count - 1;

				string row1 = "";
				Row xtr = this[r.FirstRow];
				if (r.FirstColumn > xtr.Text.Length)
				{
					int diff = r.FirstColumn - xtr.Text.Length;
					string ws = new string(' ', diff);
					this.InsertText(ws, xtr.Text.Length, r.FirstRow, true);
					//return;
				}

				row1 = xtr.Text.Substring(0, r.FirstColumn);

				string row2 = "";
				Row xtr2 = this[r.LastRow];
				int Max = Math.Min(xtr2.Text.Length, r.LastColumn);
				row2 = xtr2.Text.Substring(Max);

				string tot = row1 + row2;
				//bool fold=this[r.LastRow].IsCollapsed | this[r.FirstRow].IsCollapsed ;

				int start = r.FirstRow;
				int end = r.LastRow;

				for (int i = end - 1; i >= start; i--)
				{
					this.Remove(i, false, false);
				}

				//todo: DeleteRange error						
				//this.Insert ( tot  ,r.FirstRow,false);


				Row row = this[start];
				bool f = row.IsCollapsed;
				row.Expanded = true;
				row.Text = tot;
				row.StartSegments.Clear();
				row.EndSegments.Clear();
				row.StartSegment = null;
				row.EndSegment = null;
				row.Parse();


				//	if (row.CanFold)
				//		row.Expansion_StartSegment.Expanded = !fold;

			}

			//ShirinkFormatRanges
			if (this.FormatRanges != null)
			{
				this.FormatRanges.Shrink(Range);
			}


			ResetVisibleRows();
			OnChange();


		}
		private void DeleteBackwards()
		{
			Caret.CropPosition();
			if (Selection.IsValid)
				Selection.DeleteSelection();
			else
			{
				Row xtr = Caret.CurrentRow;
				if (Caret.Position.X == 0)
				{
					if (Caret.Position.Y > 0)
					{
						Caret.Position.Y --;
						Caret.MoveEnd(false);
						DeleteForward();
						//Caret.CurrentRow.Parse ();
						Document.ResetVisibleRows();
					}
				}
				else
				{
					if (Caret.Position.X >= xtr.Text.Length)
					{
						TextRange r = new TextRange();
						r.FirstColumn = Caret.Position.X - 1;
						r.FirstRow = Caret.Position.Y;
						r.LastRow = r.FirstRow;
						r.LastColumn = r.FirstColumn + 1;
						Document.DeleteRange(r);
						Document.ResetVisibleRows();
						Caret.MoveEnd(false);
						Caret.CurrentRow.Parse();
					}
					else
					{
						TextRange r = new TextRange();
						r.FirstColumn = Caret.Position.X - 1;
						r.FirstRow = Caret.Position.Y;
						r.LastRow = r.FirstRow;
						r.LastColumn = r.FirstColumn + 1;
						Document.DeleteRange(r);
						Document.ResetVisibleRows();
						Caret.MoveLeft(false);
						Caret.CurrentRow.Parse();
					}
				}
			}
		}
Example #7
0
		public FormatRange(TextRange Bounds, Color ForeColor, Color BackColor)
		{
			this.BackColor = BackColor;
			this.ForeColor = ForeColor;
			this.Bounds = Bounds;
			this.Bounds.Change += new EventHandler(this.BoundsChanged);
		}
        private void OutdentEndRow()
        {
            //try
            //{
            if (this.Indent == IndentStyle.Scope)
            {
                Row xtr = Caret.CurrentRow;
                string ct = xtr.Text.Substring(0, xtr.GetLeadingWhitespace().Length);
                string indent1 = new String('\t', Caret.CurrentRow.Depth);
                TextRange tr = new TextRange();
                tr.FirstColumn = 0;
                tr.LastColumn = xtr.GetLeadingWhitespace().Length;
                tr.FirstRow = xtr.Index;
                tr.LastRow = xtr.Index;
                this.Document.DeleteRange(tr);
                this.Document.InsertText(indent1, 0, xtr.Index, true);

                int diff = indent1.Length - tr.LastColumn;
                Caret.Position.X += diff;
                Caret.SetPos(Caret.Position);
                Caret.CropPosition();
                Selection.ClearSelection();
                //BOO Caret.CurrentRow.Parse(false);
                Caret.CurrentRow.Parse(true);

            }
            else if (this.Indent == IndentStyle.Smart)
            {
                Row xtr = Caret.CurrentRow;

                if (xtr.FirstNonWsWord == xtr.Expansion_EndSegment.EndWord)
                {
                    string ct = xtr.Text.Substring(0, xtr.GetLeadingWhitespace().Length);
                    //int j=xtr.Expansion_StartRow.StartWordIndex;
                    string indent1 = xtr.StartSegment.StartWord.Row.GetVirtualLeadingWhitespace();
                    TextRange tr = new TextRange();
                    tr.FirstColumn = 0;
                    tr.LastColumn = xtr.GetLeadingWhitespace().Length;
                    tr.FirstRow = xtr.Index;
                    tr.LastRow = xtr.Index;
                    this.Document.DeleteRange(tr);
                    string ts = "\t" + new String(' ', this.TabSize);
                    while (indent1.IndexOf(ts) >= 0)
                    {
                        indent1 = indent1.Replace(ts, "\t\t");
                    }
                    this.Document.InsertText(indent1, 0, xtr.Index, true);

                    int diff = indent1.Length - tr.LastColumn;
                    Caret.Position.X += diff;
                    Caret.SetPos(Caret.Position);
                    Caret.CropPosition();
                    Selection.ClearSelection();
                    //BOO   Caret.CurrentRow.Parse(false);
                    Caret.CurrentRow.Parse(true);
                }
            }
            //}
            //catch
            //{
            //}
        }
		private void DeleteForward()
		{
			Caret.CropPosition();
			if (Selection.IsValid)
				Selection.DeleteSelection();
			else
			{
				Row xtr = Caret.CurrentRow;
				if (Caret.Position.X == xtr.Text.Length)
				{
					if (Caret.Position.Y <= Document.Count - 2)
					{
						TextRange r = new TextRange();
						r.FirstColumn = Caret.Position.X;
						r.FirstRow = Caret.Position.Y;
						r.LastRow = r.FirstRow + 1;
						r.LastColumn = 0;

						Document.DeleteRange(r);
						Document.ResetVisibleRows();

					}
				}
				else
				{
					TextRange r = new TextRange();
					r.FirstColumn = Caret.Position.X;
					r.FirstRow = Caret.Position.Y;
					r.LastRow = r.FirstRow;
					r.LastColumn = r.FirstColumn + 1;
					Document.DeleteRange(r);
					Document.ResetVisibleRows();
					//BOO Caret.CurrentRow.Parse(false);
					Caret.CurrentRow.Parse(true);
				}
			}
		}
        private bool TryAutoCompletion(ICompletionData[] completionData)
        {
            if (this.Caret.CurrentWord == null) return false;
            string SearchWord = this.Caret.CurrentWord.Text;
            string FinalWord = "";
            
            
            ArrayList list = new ArrayList();
            foreach (ICompletionData c in completionData)
            {
                list.Add(c.Text);
            }
            
            
            FinalWord = FindMatchedWord(list, SearchWord);
            if (FinalWord.Length > 0)
            {
                TextRange tr = new TextRange();
                tr.FirstRow = Caret.Position.Y;
                tr.LastRow = Caret.Position.Y;
                
                tr.FirstColumn = Math.Min(_AutoListStartPos.X, startOffset.X);
                tr.LastColumn = Math.Max(Caret.Position.X, Caret.CurrentWord.Column + Caret.CurrentWord.Text.Length);

                Document.DeleteRange(tr, true);
                Caret.Position.X = _AutoListStartPos.X;
                this.InsertText(FinalWord);
                SetFocus();
                return true;
            }
            return false;
        }
		public void InsertText(string text)
		{
			Caret.CropPosition();
			if (Selection.IsValid)
			{
				Selection.DeleteSelection();
				InsertText(text);
			}
			else
			{
				if (!_OverWrite || text.Length > 1)
				{
					Row xtr = Caret.CurrentRow;
					TextPoint p = Document.InsertText(text, Caret.Position.X, Caret.Position.Y);
					Caret.CurrentRow.Parse(true);
					if (text.Length == 1)
					{
						Caret.SetPos(p);
						Caret.CaretMoved(false);

					}
					else
					{
						//Document.i = true;

						Document.ResetVisibleRows();
						Caret.SetPos(p);
						Caret.CaretMoved(false);
					}
				}
				else
				{
					TextRange r = new TextRange();
					r.FirstColumn = Caret.Position.X;
					r.FirstRow = Caret.Position.Y;
					r.LastColumn = Caret.Position.X + 1;
					r.LastRow = Caret.Position.Y;
					UndoBlockCollection ag = new UndoBlockCollection();
					UndoBlock b;
					b = new UndoBlock();
					b.Action = UndoAction.DeleteRange;
					b.Text = Document.GetRange(r);
					b.Position = Caret.Position;
					ag.Add(b);
					Document.DeleteRange(r, false);
					b = new UndoBlock();
					b.Action = UndoAction.InsertRange;
					string NewChar = text;
					b.Text = NewChar;
					b.Position = Caret.Position;
					ag.Add(b);
					Document.AddToUndoList(ag);
					Document.InsertText(NewChar, Caret.Position.X, Caret.Position.Y, false);
					Caret.CurrentRow.Parse(true);

					Caret.MoveRight(false);
				}
			}
			//	this.ScrollIntoView ();

		}
        //public bool ReplaceSelection(string text)
        //{
        //    if (!Selection.IsValid)
        //        return false;

        //    int x = Selection.LogicalBounds.FirstColumn;
        //    int y = Selection.LogicalBounds.FirstRow;

        //    this.Selection.DeleteSelection();

        //    Caret.Position.X = x;
        //    Caret.Position.Y = y;

        //    InsertText(text);


        //    Selection.Bounds.FirstRow = y;
        //    Selection.Bounds.FirstColumn = x + text.Length;

        //    Selection.Bounds.LastRow = y;
        //    Selection.Bounds.LastColumn = x + text.Length;

        //    Caret.Position.X = x + text.Length;
        //    Caret.Position.Y = y;
        //    return true;
        //}

        public bool ReplaceSelection(string text)
        {
            if (!Selection.IsValid)
                return false;

            int x = Selection.LogicalBounds.FirstColumn;
            int y = Selection.LogicalBounds.FirstRow;

            TextRange t = new TextRange(Selection.Bounds.FirstColumn, Selection.Bounds.FirstRow, Selection.Bounds.LastColumn, Selection.Bounds.LastRow);


            TextRange newRange =  this.Document.ReplaceRange(t, text, true);
            Selection.Bounds = newRange;
            Caret.Position.X = newRange.LastColumn;
            Caret.Position.Y = newRange.LastRow;
            return true;
        }
		public void InsertAutolistText()
		{
			TextRange tr = new TextRange();
			tr.FirstRow = Caret.Position.Y;
			tr.LastRow = Caret.Position.Y;
            
            tr.FirstColumn = Math.Min(_AutoListStartPos.X, startOffset.X);
            tr.LastColumn = Math.Max(Caret.Position.X,Caret.CurrentWord.Column + Caret.CurrentWord.Text.Length) ;
            //this.Selection.Bounds = tr;
			Document.DeleteRange(tr, true);
			Caret.Position.X = _AutoListStartPos.X;
            ICompletionData i = AutoList.SelectedListItem.CodeCompletionData;
            if(i == null)
                this.InsertText(AutoList.SelectedText);
            else
                i.InsertAction(this, '\0');
			//this.InsertText(AutoList.SelectedText);
            
			SetFocus();
		}
		private void TextDraw(TextDrawDirectionType Direction)
		{
			TextRange r = new TextRange();
			r.FirstColumn = Caret.Position.X;
			r.FirstRow = Caret.Position.Y;
			r.LastColumn = Caret.Position.X + 1;
			r.LastRow = Caret.Position.Y;

			int Style = (int) this.TextDrawStyle;
			string OldChar = Document.GetRange(r);
			string BorderString = TextBorderStyles[Style];
			//TextBorderChars OldCharType=0;

			if (OldChar == "")
				OldChar = " ";


			UndoBlockCollection ag = new UndoBlockCollection();
			UndoBlock b;
			b = new UndoBlock();
			b.Action = UndoAction.DeleteRange;
			b.Text = Document.GetRange(r);
			b.Position = Caret.Position;
			ag.Add(b);
			Document.DeleteRange(r, false);

			b = new UndoBlock();
			b.Action = UndoAction.InsertRange;


			string NewChar = "*";


			b.Text = NewChar;
			b.Position = Caret.Position;
			ag.Add(b);
			Document.AddToUndoList(ag);
			Document.InsertText(NewChar, Caret.Position.X, Caret.Position.Y, false);
		}
Example #15
0
		/// <summary>
		/// Deletes a range of text
		/// </summary>
		/// <param name="Range">the range that should be deleted</param>
		public void DeleteRange(TextRange Range)
		{
			DeleteRange(Range, true);
		}
Example #16
0
		public void Shrink(TextRange Range)
		{
			string Text = this.Document.GetRange(Range);
			string tmp = Text.Replace(Environment.NewLine, "\n");
			int l = tmp.Length;
			string[] tmplines = tmp.Split('\n');

			foreach (FormatRange fr in this)
			{
				int res = fr.Contains(Range.FirstColumn, Range.FirstRow);
				int res2 = fr.Contains(Range.LastColumn, Range.LastRow);

				int rows = Range.LastRow - Range.FirstRow;
				if (res == -1 && res2 == -1)
				{
					fr.Bounds.FirstRow -= rows;
					fr.Bounds.LastRow -= rows;
					if (fr.Bounds.FirstRow == Range.FirstRow + tmplines.Length - 1)
					{
						if (tmplines.Length > 1)
							fr.Bounds.FirstColumn -= Range.FirstColumn;

						fr.Bounds.FirstColumn -= tmplines[tmplines.Length - 1].Length;
					}
					else if (fr.Bounds.FirstRow == Range.FirstRow)
					{
						if (tmplines.Length > 1)
							fr.Bounds.FirstColumn += Range.FirstColumn;

						fr.Bounds.FirstColumn -= tmplines[tmplines.Length - 1].Length;
					}
				}
				if (res == -1 && res2 == 0)
				{
					fr.Bounds.FirstRow -= rows;
					fr.Bounds.LastRow -= rows;
					fr.Bounds.FirstColumn = Range.FirstColumn;
				}
				if (res == 0 && res2 == 0)
				{
					fr.Bounds.LastRow -= rows;
					if (fr.Bounds.LastRow == Range.FirstRow)
					{
						if (rows == 0)
							fr.Bounds.LastColumn -= tmplines[tmplines.Length - 1].Length;
						else
							fr.Bounds.LastColumn = Range.FirstColumn + fr.Bounds.LastColumn;
					}
				}
				if (res == 0 && res2 == 1)
				{
					//delete end of range
					fr.Bounds.LastColumn = Range.FirstColumn - 1;
					fr.Bounds.LastRow = Range.FirstRow;
				}

				if (res == -1 && res2 == 1)
				{
					//delete this range
					fr.Bounds.SetBounds(-1, -1, -1, -1);
				}


				if (res == 1)
				{
					//ignore
				}
			}
		}
Example #17
0
        public TextRange ReplaceRange(TextRange Range, string ReplacedText, bool StoreUndo)
        {
            TextRange r = Range;
            Modified = true;
            string deltext = "";
            int i;
            Row xtr;
            if(StoreUndo)
                deltext = GetRange(Range);
            if (r.FirstRow == r.LastRow)
            {
                xtr = this[r.FirstRow];
                int max = Math.Min(r.FirstColumn, xtr.Text.Length);
                string left = xtr.Text.Substring(0, max);
                string right = "";
                if (xtr.Text.Length >= r.LastColumn)
                    right = xtr.Text.Substring(r.LastColumn);
                xtr.Text = left + right;
            }
            else
            {
                if (r.LastRow > this.Count - 1)
                    r.LastRow = this.Count - 1;

                string row1 = "";
                xtr = this[r.FirstRow];
                if (r.FirstColumn > xtr.Text.Length)
                {
                    int diff = r.FirstColumn - xtr.Text.Length;
                    string ws = new string(' ', diff);
                    this.InsertText(ws, xtr.Text.Length, r.FirstRow, true);
                    //return;
                }

                row1 = xtr.Text.Substring(0, r.FirstColumn);

                string row2 = "";
                Row xtr2 = this[r.LastRow];
                int Max = Math.Min(xtr2.Text.Length, r.LastColumn);
                row2 = xtr2.Text.Substring(Max);

                string tot = row1 + row2;
                //bool fold=this[r.LastRow].IsCollapsed | this[r.FirstRow].IsCollapsed ;

                int start = r.FirstRow;
                int end = r.LastRow;

                for (i = end - 1; i >= start; i--)
                {
                    this.Remove(i, false, false);
                }

                //todo: DeleteRange error						
                //this.Insert ( tot  ,r.FirstRow,false);


                Row row = this[start];
                bool f = row.IsCollapsed;
                row.Expanded = true;
                row.Text = tot;
                row.StartSegments.Clear();
                row.EndSegments.Clear();
                row.StartSegment = null;
                row.EndSegment = null;
                row.Parse();


                //	if (row.CanFold)
                //		row.Expansion_StartSegment.Expanded = !fold;

            }

            //ShirinkFormatRanges
            if (this.FormatRanges != null)
            {
                this.FormatRanges.Shrink(Range);
            }


          
            //------------------------Insert Text

            string text = ReplacedText ;
            int xPos = r.FirstColumn ;
            int yPos = r.FirstRow;
            Modified = true;
            xtr = this[yPos];
            string lft, rgt;

            if (xPos > xtr.Text.Length)
            {
                //virtualwhitespace fix
                int Padd = xPos - xtr.Text.Length;
                string PaddStr = new string(' ', Padd);
                text = PaddStr + text;
                xPos -= Padd;
            }
            lft = xtr.Text.Substring(0, xPos);
            rgt = xtr.Text.Substring(xPos);
            string NewText = lft + text + rgt;


            string t = NewText.Replace(Environment.NewLine, "\n");
            string[] lines = t.Split('\n');
            xtr.Text = lines[0];

            Row lastrow = xtr;

            //this.Parser.ParsePreviewLine(xtr);	
            xtr.Parse();
            if (!xtr.InQueue)
                this.ParseQueue.Add(xtr);
            xtr.InQueue = true;

            i = IndexOf(xtr);


            for (int j = 1; j < lines.Length; j++)
            {
                lastrow = Insert(lines[j], j + i, false);
            }

            if (StoreUndo)
            {
                PushUndoBlock(UndoAction.ReplaceRange, deltext,text, r.FirstColumn, r.FirstRow);
            }

            //ExpandFormatRanges
            if (this.FormatRanges != null)
            {
                this.FormatRanges.Expand(xPos, yPos, text);

            }


            this.ResetVisibleRows();
            OnChange();


            return new TextRange(r.FirstColumn,r.FirstRow, lastrow.Text.Length - rgt.Length, IndexOf(lastrow));


        }
Example #18
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();
		}