Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
		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();
					}
				}
			}
		}
Exemplo n.º 3
0
		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();
					Caret.CurrentRow.Parse(false);
					Caret.CurrentRow.Parse(true);
				}
			}
		}
Exemplo n.º 4
0
        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();
                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();
                    Caret.CurrentRow.Parse(false);
                    Caret.CurrentRow.Parse(true);
                }
            }
            //}
            //catch
            //{
            //}
        }
Exemplo n.º 5
0
		private 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 ();

		}
Exemplo n.º 6
0
		public void InsertAutolistText()
		{
			TextRange tr = new TextRange();
			tr.FirstRow = Caret.Position.Y;
			tr.LastRow = Caret.Position.Y;
			tr.FirstColumn = AutoListStartPos.X;
			tr.LastColumn = Caret.Position.X;

			Document.DeleteRange(tr, true);
			Caret.Position.X = AutoListStartPos.X;
			this.InsertText(AutoList.SelectedText);
			SetFocus();
		}
Exemplo n.º 7
0
		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);
		}
Exemplo n.º 8
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;
			}

		}
Exemplo n.º 9
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();


		}
Exemplo n.º 10
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);
		}
Exemplo n.º 11
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();
		}
Exemplo n.º 12
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;
		}
Exemplo n.º 13
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
                }
            }
        }
Exemplo n.º 14
0
 public FormatRange(TextRange Bounds, Color WaveColor)
 {
     this.WaveColor = WaveColor;
     this.Bounds = Bounds;
     this.Bounds.Change += new EventHandler(this.BoundsChanged);
 }
Exemplo n.º 15
0
Arquivo: Row.cs Projeto: 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();
		}