Ejemplo n.º 1
0
		/// <remarks>
		/// Executes this edit action
		/// </remarks>
		/// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
		public override void Execute(TextArea textArea)
		{
			if (textArea.SelectionManager.SelectionIsReadonly) {
				return;
			}
			textArea.Document.UndoStack.StartUndoGroup();
			if (textArea.SelectionManager.HasSomethingSelected) {
				foreach (ISelection selection in textArea.SelectionManager.SelectionCollection) {
					int startLine = selection.StartPosition.Y;
					int endLine   = selection.EndPosition.Y;
					if (startLine != endLine) {
						textArea.BeginUpdate();
						InsertTabs(textArea.Document, selection, startLine, endLine);
						textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, startLine, endLine));
						textArea.EndUpdate();
					} else {
						InsertTabAtCaretPosition(textArea);
						break;
					}
				}
				textArea.Document.CommitUpdate();
				textArea.AutoClearSelection = false;
			} else {
				InsertTabAtCaretPosition(textArea);
			}
			textArea.Document.UndoStack.EndUndoGroup();
		}
Ejemplo n.º 2
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected) {
                Delete.DeleteSelection(textArea);
            } else {
                if (textArea.Caret.Offset > 0 && !textArea.IsReadOnly(textArea.Caret.Offset - 1)) {
                    textArea.BeginUpdate();
                    int curLineNr     = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                    int curLineOffset = textArea.Document.GetLineSegment(curLineNr).Offset;

                    if (curLineOffset == textArea.Caret.Offset) {
                        LineSegment line = textArea.Document.GetLineSegment(curLineNr - 1);
                        int lineEndOffset = line.Offset + line.Length;
                        int lineLength = line.Length;
                        textArea.Document.Remove(lineEndOffset, curLineOffset - lineEndOffset);
                        textArea.Caret.Position = new TextLocation(lineLength, curLineNr - 1);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr - 1)));
                    } else {
                        int caretOffset = textArea.Caret.Offset - 1;
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(caretOffset);
                        textArea.Document.Remove(caretOffset, 1);

                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new TextLocation(textArea.Caret.Offset - textArea.Document.GetLineSegment(curLineNr).Offset, curLineNr)));
                    }
                    textArea.EndUpdate();
                }
            }
        }
Ejemplo n.º 3
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly) {
                return;
            }
            if (textArea.SelectionManager.HasSomethingSelected) {
                textArea.BeginUpdate();
                textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
                textArea.SelectionManager.RemoveSelectedText();
                textArea.ScrollToCaret();
                textArea.EndUpdate();
            } else {

                if (textArea.Caret.Offset < textArea.Document.TextLength) {
                    textArea.BeginUpdate();
                    int curLineNr   = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                    LineSegment curLine = textArea.Document.GetLineSegment(curLineNr);

                    if (curLine.Offset + curLine.Length == textArea.Caret.Offset) {
                        if (curLineNr + 1 < textArea.Document.TotalNumberOfLines) {
                            LineSegment nextLine = textArea.Document.GetLineSegment(curLineNr + 1);

                            textArea.Document.Remove(textArea.Caret.Offset, nextLine.Offset - textArea.Caret.Offset);
                            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, curLineNr)));
                        }
                    } else {
                        textArea.Document.Remove(textArea.Caret.Offset, 1);
            //						textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new Point(textArea.Caret.Offset - textArea.Document.GetLineSegment(curLineNr).Offset, curLineNr)));
                    }
                    textArea.UpdateMatchingBracket();
                    textArea.EndUpdate();
                }
            }
        }
Ejemplo n.º 4
0
 internal static void DeleteSelection(TextArea textArea)
 {
     if (textArea.SelectionManager.SelectionIsReadonly)
     {
         return;
     }
     textArea.BeginUpdate();
     textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
     textArea.SelectionManager.RemoveSelectedText();
     textArea.ScrollToCaret();
     textArea.EndUpdate();
 }
 internal static void DeleteSelection(TextArea textArea)
 {
     //Debug.Assert(textArea.SelectionManager.HasSomethingSelected);
     if (!textArea.ReadOnly)
     {
         textArea.BeginUpdate();
         textArea.Caret.Position = textArea.SelectionManager.StartPosition;
         textArea.SelectionManager.RemoveSelectedText();
         textArea.ScrollToCaret();
         textArea.EndUpdate();
     }
 }
        /// <summary>
        /// Executes the action on a certain <see cref="TextArea"/>.
        /// </summary>
        /// <param name="textArea">The text area on which to execute the action.</param>
        public override void Execute(TextArea textArea)
        {
            // if anything is selected we will just delete it first
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                Delete.DeleteSelection(textArea);
                return;
            }
            textArea.BeginUpdate();
            // now delete from the caret to the beginning of the word
            LineSegment line =
                textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);

            // if we are not at the beginning of a line
            if (textArea.Caret.Offset > line.Offset)
            {
                int prevWordStart = TextHelper.FindPrevWordStart(textArea.Document,
                                                                 textArea.Caret.Offset);
                if (prevWordStart < textArea.Caret.Offset)
                {
                    if (!textArea.IsReadOnly(prevWordStart, textArea.Caret.Offset - prevWordStart))
                    {
                        textArea.Document.Remove(prevWordStart,
                                                 textArea.Caret.Offset - prevWordStart);
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(prevWordStart);
                    }
                }
            }
            // if we are now at the beginning of a line
            if (textArea.Caret.Offset == line.Offset)
            {
                // if we are not on the first line
                int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                if (curLineNr > 0)
                {
                    // move to the end of the line above
                    LineSegment lineAbove      = textArea.Document.GetLineSegment(curLineNr - 1);
                    int         endOfLineAbove = lineAbove.Offset + lineAbove.Length;
                    int         charsToDelete  = textArea.Caret.Offset - endOfLineAbove;
                    if (!textArea.IsReadOnly(endOfLineAbove, charsToDelete))
                    {
                        textArea.Document.Remove(endOfLineAbove, charsToDelete);
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(endOfLineAbove);
                    }
                }
            }
            textArea.SetDesiredColumn();
            textArea.EndUpdate();
            // if there are now less lines, we need this or there are redraw problems
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset))));
            textArea.Document.CommitUpdate();
        }
Ejemplo n.º 7
0
 internal static void DeleteSelection(TextArea textArea)
 {
     Debug.Assert(textArea.SelectionManager.HasSomethingSelected);
     if (textArea.SelectionManager.SelectionIsReadonly)
     {
         return;
     }
     textArea.BeginUpdate();
     textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[index : 0].StartPosition;
     textArea.SelectionManager.RemoveSelectedText();
     textArea.ScrollToCaret();
     textArea.EndUpdate();
 }
Ejemplo n.º 8
0
 public override void Execute(TextArea textArea)
 {
     if (textArea.Document.ReadOnly)
     {
         return;
     }
     if (textArea.SelectionManager.HasSomethingSelected)
     {
         textArea.BeginUpdate();
         textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
         textArea.SelectionManager.RemoveSelectedText();
         textArea.ScrollToCaret();
         textArea.EndUpdate();
         return;
     }
     if (textArea.Caret.Offset > 0)
     {
         textArea.BeginUpdate();
         int lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
         int offset = textArea.Document.GetLineSegment(lineNumberForOffset).Offset;
         if (offset == textArea.Caret.Offset)
         {
             LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumberForOffset - 1);
             int         arg_C2_0    = textArea.Document.TotalNumberOfLines;
             int         num         = lineSegment.Offset + lineSegment.Length;
             int         length      = lineSegment.Length;
             textArea.Document.Remove(num, offset - num);
             textArea.Caret.Position = new Point(length, lineNumberForOffset - 1);
             textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, lineNumberForOffset - 1)));
             textArea.EndUpdate();
             return;
         }
         int offset2 = textArea.Caret.Offset - 1;
         textArea.Caret.Position = textArea.Document.OffsetToPosition(offset2);
         textArea.Document.Remove(offset2, 1);
         textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new Point(textArea.Caret.Offset - textArea.Document.GetLineSegment(lineNumberForOffset).Offset, lineNumberForOffset)));
         textArea.EndUpdate();
     }
 }
 public override void Execute(TextArea textArea)
 {
     textArea.BeginUpdate();
     if (textArea.SelectionManager.HasSomethingSelected) {
         foreach (ISelection selection in textArea.SelectionManager.SelectionCollection) {
             Convert(textArea.Document, selection.StartPosition.Y, selection.EndPosition.Y);
         }
     } else {
         Convert(textArea.Document, 0, textArea.Document.TotalNumberOfLines - 1);
     }
     textArea.Caret.ValidateCaretPos();
     textArea.EndUpdate();
     //textArea.Refresh();
 }
Ejemplo n.º 10
0
 public override void Execute(TextArea textArea)
 {
     textArea.BeginUpdate();
     if (textArea.SelectionManager.HasSomethingSelected) {
         foreach (ISelection selection in textArea.SelectionManager.SelectionCollection) {
             Convert(textArea.Document, selection.Offset, selection.Length);
         }
     } else {
         Convert(textArea.Document, 0, textArea.Document.TextLength);
     }
     textArea.Caret.ValidateCaretPos();
     textArea.EndUpdate();
     //textArea.Refresh();
 }
Ejemplo n.º 11
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly) {
                return;
            }
            if (textArea.SelectionManager.HasSomethingSelected) {
                textArea.BeginUpdate();
                textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
                textArea.SelectionManager.RemoveSelectedText();
                textArea.ScrollToCaret();
                textArea.EndUpdate();
            } else {
                if (textArea.Caret.Offset > 0) {
                    textArea.BeginUpdate();
                    int curLineNr     = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                    int curLineOffset = textArea.Document.GetLineSegment(curLineNr).Offset;

                    if (curLineOffset == textArea.Caret.Offset) {
                        LineSegment line = textArea.Document.GetLineSegment(curLineNr - 1);
                        bool lastLine = curLineNr == textArea.Document.TotalNumberOfLines;
                        int lineEndOffset = line.Offset + line.Length;
                        int lineLength = line.Length;
                        textArea.Document.Remove(lineEndOffset, curLineOffset - lineEndOffset);
                        textArea.Caret.Position = new Point(lineLength, curLineNr - 1);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, curLineNr - 1)));
                        textArea.EndUpdate();
                    } else {
                        int caretOffset = textArea.Caret.Offset - 1;
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(caretOffset);
                        textArea.Document.Remove(caretOffset, 1);

            //						textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new Point(textArea.Caret.Offset - textArea.Document.GetLineSegment(curLineNr).Offset, curLineNr)));
                        textArea.EndUpdate();
                    }
                }
            }
        }
Ejemplo n.º 12
0
 public override void Execute(TextArea textArea)
 {
     if (textArea.Document.ReadOnly)
     {
         return;
     }
     if (textArea.SelectionManager.HasSomethingSelected)
     {
         textArea.BeginUpdate();
         textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
         textArea.SelectionManager.RemoveSelectedText();
         textArea.ScrollToCaret();
         textArea.EndUpdate();
         return;
     }
     if (textArea.Caret.Offset < textArea.Document.TextLength)
     {
         textArea.BeginUpdate();
         int         lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
         LineSegment lineSegment         = textArea.Document.GetLineSegment(lineNumberForOffset);
         if (lineSegment.Offset + lineSegment.Length == textArea.Caret.Offset)
         {
             if (lineNumberForOffset + 1 < textArea.Document.TotalNumberOfLines)
             {
                 LineSegment lineSegment2 = textArea.Document.GetLineSegment(lineNumberForOffset + 1);
                 textArea.Document.Remove(textArea.Caret.Offset, lineSegment2.Offset - textArea.Caret.Offset);
                 textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, lineNumberForOffset)));
             }
         }
         else
         {
             textArea.Document.Remove(textArea.Caret.Offset, 1);
         }
         textArea.UpdateMatchingBracket();
         textArea.EndUpdate();
     }
 }
Ejemplo n.º 13
0
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }
            textArea.BeginUpdate();
            textArea.InsertString(Environment.NewLine);
            int line = textArea.Caret.Line;

            textArea.Caret.Column = textArea.Document.FormattingStrategy.FormatLine(textArea, line, textArea.Caret.Offset, '\n');
            textArea.SetDesiredColumn();
            textArea.Document.UpdateQueue.Clear();
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, line - 1)));
            textArea.EndUpdate();
        }
        public override void Execute(TextArea textArea)
        {
            if (!textArea.ReadOnly)
            {
                if (textArea.SelectionManager.HasSomethingSelected)
                {
                    Clipboard.SetText(textArea.SelectionManager.SelectedText);

                    // Remove text
                    textArea.BeginUpdate();
                    textArea.Caret.Position = textArea.SelectionManager.StartPosition;
                    textArea.SelectionManager.RemoveSelectedText();
                    textArea.EndUpdate();
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Insert a string of text into the specified text area at the current
        /// cursor location.
        /// </summary>
        /// <param name="textArea">The text area to use</param>
        /// <param name="text">The text to insert</param>
        public static void InsertString(TextArea textArea, string text)
        {
            if (textArea == null)
            {
                throw new ArgumentNullException(nameof(textArea));
            }

            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            int offset = textArea.Caret.Offset;

            textArea.BeginUpdate();

            try
            {
                textArea.Document.UndoStack.StartUndoGroup();

                // If inserted in a selection, replace the selection.
                // Otherwise, clear it.
                if (textArea.SelectionManager.HasSomethingSelected)
                {
                    if (textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset))
                    {
                        offset = textArea.SelectionManager.SelectionCollection[0].Offset;
                        textArea.SelectionManager.RemoveSelectedText();
                    }
                    else
                    {
                        textArea.SelectionManager.ClearSelection();
                    }
                }

                textArea.Document.Insert(offset, text);
                textArea.Caret.Position = textArea.Document.OffsetToPosition(offset + text.Length);
                textArea.Refresh();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
            }
            finally
            {
                textArea.Document.UndoStack.EndUndoGroup();
                textArea.EndUpdate();
            }
        }
Ejemplo n.º 16
0
 public override void Execute(TextArea textArea)
 {
     this.textArea = textArea;
     textArea.BeginUpdate();
     if (textArea.SelectionManager.HasSomethingSelected)
     {
         foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
         {
             Convert(textArea.Document, selection.StartPosition.Y, selection.EndPosition.Y);
         }
     }
     else
     {
         Convert(textArea.Document, 0, textArea.Document.TotalNumberOfLines - 1);
     }
     textArea.Caret.ValidateCaretPos();
     textArea.EndUpdate();
     textArea.Refresh();
 }
Ejemplo n.º 17
0
 public override void Execute(TextArea textArea)
 {
     this.textArea = textArea;
     textArea.BeginUpdate();
     if (textArea.SelectionManager.HasSomethingSelected)
     {
         foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
         {
             Convert(textArea.Document, selection.Offset, selection.Length);
         }
     }
     else
     {
         Convert(textArea.Document, 0, textArea.Document.TextLength);
     }
     textArea.Caret.ValidateCaretPos();
     textArea.EndUpdate();
     textArea.Refresh();
 }
Ejemplo n.º 18
0
		public override void Execute(TextArea textArea)
		{
			if (textArea.SelectionManager.SelectionIsReadonly) {
				return;
			}
			this.textArea = textArea;
			textArea.BeginUpdate();
			textArea.Document.UndoStack.StartUndoGroup();
			if (textArea.SelectionManager.HasSomethingSelected) {
				foreach (ISelection selection in textArea.SelectionManager.SelectionCollection) {
					Convert(textArea.Document, selection.StartPosition.Y, selection.EndPosition.Y);
				}
			} else {
				Convert(textArea.Document, 0, textArea.Document.TotalNumberOfLines - 1);
			}
			textArea.Document.UndoStack.EndUndoGroup();
			textArea.Caret.ValidateCaretPos();
			textArea.EndUpdate();
			textArea.Refresh();
		}
        public void Execute(TextArea textArea)
        {
            if (!textArea.Document.ReadOnly)
            {
                //textArea.ClipboardHandler.Cut(null, null);

                if (textArea.SelectionManager.HasSomethingSelected)
                {
                    Clipboard.SetText(textArea.SelectionManager.SelectedText);
                    if (!textArea.SelectionManager.SelectionIsReadonly)
                    {
                        // Remove text
                        textArea.BeginUpdate();
                        textArea.Caret.Position = textArea.SelectionManager.StartPosition;
                        textArea.SelectionManager.RemoveSelectedText();
                        textArea.EndUpdate();
                    }
                }
            }
        }
Ejemplo n.º 20
0
        /// <remarks>
        ///     Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                DeleteSelection(textArea);
            }
            else
            {
                if (textArea.IsReadOnly(textArea.Caret.Offset))
                {
                    return;
                }

                if (textArea.Caret.Offset < textArea.Document.TextLength)
                {
                    textArea.BeginUpdate();
                    var curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                    var curLine   = textArea.Document.GetLineSegment(curLineNr);

                    if (curLine.Offset + curLine.Length == textArea.Caret.Offset)
                    {
                        if (curLineNr + 1 < textArea.Document.TotalNumberOfLines)
                        {
                            var nextLine = textArea.Document.GetLineSegment(curLineNr + 1);

                            textArea.Document.Remove(textArea.Caret.Offset, nextLine.Offset - textArea.Caret.Offset);
                            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd,
                                                                               new TextLocation(0, curLineNr)));
                        }
                    }
                    else
                    {
                        textArea.Document.Remove(textArea.Caret.Offset, 1);
//						textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new TextLocation(textArea.Caret.Offset - textArea.Document.GetLineSegment(curLineNr).Offset, curLineNr)));
                    }

                    textArea.UpdateMatchingBracket();
                    textArea.EndUpdate();
                }
            }
        }
Ejemplo n.º 21
0
        public void Execute(TextArea textArea)
        {
            if (!textArea.SelectionManager.SelectionIsReadonly)
            {
                _textArea = textArea;
                textArea.BeginUpdate();

                if (textArea.SelectionManager.HasSomethingSelected)
                {
                    Convert(textArea.Document, textArea.SelectionManager.StartOffset, textArea.SelectionManager.Length);
                }
                else
                {
                    Convert(textArea.Document, 0, textArea.Document.TextLength);
                }

                textArea.Caret.ValidateCaretPos();
                textArea.EndUpdate();
                textArea.Refresh();
            }
        }
Ejemplo n.º 22
0
 /// <remarks>
 /// Executes this edit action
 /// </remarks>
 /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
 public override void Execute(TextArea textArea)
 {
     if (textArea.Document.ReadOnly)
     {
         return;
     }
     textArea.BeginUpdate();
     if (textArea.SelectionManager.HasSomethingSelected)
     {
         foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
         {
             textArea.Document.FormattingStrategy.IndentLines(textArea, selection.StartPosition.Y, selection.EndPosition.Y);
         }
     }
     else
     {
         textArea.Document.FormattingStrategy.IndentLines(textArea, 0, textArea.Document.TotalNumberOfLines - 1);
     }
     textArea.EndUpdate();
     textArea.Refresh();
 }
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.SelectionIsReadonly)
            {
                return;
            }

            textArea.Document.UndoStack.StartUndoGroup();

            if (textArea.SelectionManager.HasSomethingSelected)
            {
                foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
                {
                    int startLine = selection.StartPosition.Y;
                    int endLine   = selection.EndPosition.Y;

                    if (startLine != endLine)
                    {
                        textArea.BeginUpdate();
                        InsertTabs(textArea.Document, selection, startLine, endLine);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, startLine, endLine));
                        textArea.EndUpdate();
                    }
                    else
                    {
                        InsertTabAtCaretPosition(textArea);
                        break;
                    }
                }

                textArea.Document.CommitUpdate();
                textArea.AutoClearSelection = false;
            }
            else
            {
                InsertTabAtCaretPosition(textArea);
            }

            textArea.Document.UndoStack.EndUndoGroup();
        }
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
                {
                    int startLine = selection.StartPosition.Y;
                    int endLine   = selection.EndPosition.Y;
                    textArea.BeginUpdate();
                    RemoveTabs(textArea.Document, selection, startLine, endLine);
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, startLine, endLine));
                    textArea.EndUpdate();
                }

                textArea.AutoClearSelection = false;
            }
            else
            {
                // Pressing Shift-Tab with nothing selected the cursor will move back to the
                // previous tab stop. It will stop at the beginning of the line. Also, the desired
                // column is updated to that column.
                //LineSegment line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
                //string startOfLine = textArea.Document.GetText(line.Offset, textArea.Caret.Offset - line.Offset);
                int tabIndent     = textArea.Document.TextEditorProperties.IndentationSize;
                int currentColumn = textArea.Caret.Column;
                int remainder     = currentColumn % tabIndent;

                if (remainder == 0)
                {
                    textArea.Caret.DesiredColumn = Math.Max(0, currentColumn - tabIndent);
                }
                else
                {
                    textArea.Caret.DesiredColumn = Math.Max(0, currentColumn - remainder);
                }

                textArea.SetCaretToDesiredColumn();
            }
        }
Ejemplo n.º 25
0
        /// <remarks>
        ///     Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                Delete.DeleteSelection(textArea);
            }
            else
            {
                if (textArea.Caret.Offset > 0 && !textArea.IsReadOnly(textArea.Caret.Offset - 1))
                {
                    textArea.BeginUpdate();
                    var curLineNr     = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                    var curLineOffset = textArea.Document.GetLineSegment(curLineNr).Offset;

                    if (curLineOffset == textArea.Caret.Offset)
                    {
                        var line          = textArea.Document.GetLineSegment(curLineNr - 1);
                        var lastLine      = curLineNr == textArea.Document.TotalNumberOfLines;
                        var lineEndOffset = line.Offset + line.Length;
                        var lineLength    = line.Length;
                        textArea.Document.Remove(lineEndOffset, curLineOffset - lineEndOffset);
                        textArea.Caret.Position = new TextLocation(lineLength, curLineNr - 1);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd,
                                                                           new TextLocation(0, curLineNr - 1)));
                    }
                    else
                    {
                        var caretOffset = textArea.Caret.Offset - 1;
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(caretOffset);
                        textArea.Document.Remove(caretOffset, 1);

                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd,
                                                                           new TextLocation(textArea.Caret.Offset - textArea.Document.GetLineSegment(curLineNr).Offset,
                                                                                            curLineNr)));
                    }

                    textArea.EndUpdate();
                }
            }
        }
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                Delete.DeleteSelection(textArea);
                return;
            }
            textArea.BeginUpdate();
            LineSegment lineSegmentForOffset = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);

            if (textArea.Caret.Offset > lineSegmentForOffset.Offset)
            {
                int num = TextUtilities.FindPrevWordStart(textArea.Document, textArea.Caret.Offset);
                if (num < textArea.Caret.Offset && !textArea.IsReadOnly(num, textArea.Caret.Offset - num))
                {
                    textArea.Document.Remove(num, textArea.Caret.Offset - num);
                    textArea.Caret.Position = textArea.Document.OffsetToPosition(num);
                }
            }
            if (textArea.Caret.Offset == lineSegmentForOffset.Offset)
            {
                int lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                if (lineNumberForOffset > 0)
                {
                    LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumberForOffset - 1);
                    int         offset      = lineSegment.Offset + lineSegment.Length;
                    int         offset1     = textArea.Caret.Offset - offset;
                    if (!textArea.IsReadOnly(offset, offset1))
                    {
                        textArea.Document.Remove(offset, offset1);
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(offset);
                    }
                }
            }
            textArea.SetDesiredColumn();
            textArea.EndUpdate();
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset))));
            textArea.Document.CommitUpdate();
        }
 /// <summary>
 /// Executes the action on a certain <see cref="TextArea"/>.
 /// </summary>
 /// <param name="textArea">The text area on which to execute the action.</param>
 public override void Execute(TextArea textArea)
 {
     if (textArea.Document.ReadOnly)
     {
         return;
     }
     textArea.BeginUpdate();
     textArea.Document.UndoStack.StartUndoGroup();
     try
     {
         textArea.InsertString(Environment.NewLine);
         int curLineNr = textArea.Caret.Line;
         textArea.Document.FormattingStrategy.FormatLine(textArea, curLineNr, textArea.Caret.Offset, '\n');
         textArea.SetDesiredColumn();
         textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr - 1)));
     }
     finally
     {
         textArea.Document.UndoStack.EndUndoGroup();
         textArea.EndUpdate();
     }
 }
Ejemplo n.º 28
0
        /// <remarks>
        ///     Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                DeleteSelection(textArea);
                return;
            }

            // if anything is selected we will just delete it first
            textArea.BeginUpdate();
            // now delete from the caret to the beginning of the word
            var line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);

            if (textArea.Caret.Offset == line.Offset + line.Length)
            {
                // if we are at the end of a line
                base.Execute(textArea);
            }
            else
            {
                var nextWordStart = TextUtilities.FindNextWordStart(textArea.Document,
                                                                    textArea.Caret.Offset);
                if (nextWordStart > textArea.Caret.Offset)
                {
                    if (!textArea.IsReadOnly(textArea.Caret.Offset, nextWordStart - textArea.Caret.Offset))
                    {
                        textArea.Document.Remove(textArea.Caret.Offset, nextWordStart - textArea.Caret.Offset);
                    }
                }
                // cursor never moves with this command
            }

            textArea.UpdateMatchingBracket();
            textArea.EndUpdate();
            // if there are now less lines, we need this or there are redraw problems
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd,
                                                               new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset))));
            textArea.Document.CommitUpdate();
        }
Ejemplo n.º 29
0
        public void Execute(TextArea textArea)
        {
            if (!textArea.SelectionManager.SelectionIsReadonly)
            {
                _textArea = textArea;
                textArea.BeginUpdate();
                textArea.Document.UndoStack.StartUndoGroup();

                if (textArea.SelectionManager.HasSomethingSelected)
                {
                    Convert(textArea.Document, textArea.SelectionManager.StartPosition.Y, textArea.SelectionManager.EndPosition.Y);
                }
                else
                {
                    Convert(textArea.Document, 0, textArea.Document.TotalNumberOfLines - 1);
                }

                textArea.Document.UndoStack.EndUndoGroup();
                textArea.Caret.ValidateCaretPos();
                textArea.EndUpdate();
                textArea.Refresh();
            }
        }
Ejemplo n.º 30
0
            public void NewEventHandlerPreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
            {
                if (e.KeyCode == Keys.Tab ||
                    e.KeyCode == Keys.Enter ||
                    e.KeyCode == Keys.Return)
                {
                    textArea.BeginUpdate();
                    textArea.Document.UndoStack.StartUndoGroup();

                    textArea.SelectionManager.ClearSelection();

                    // is there a better way to calculate the optimal insertion point?
                    DomRegion region = resolveResult.CallingMember.BodyRegion;
                    textArea.Caret.Line   = region.EndLine - 1;
                    textArea.Caret.Column = region.EndColumn;

                    textArea.InsertString(this.newHandlerCode);

                    textArea.Document.FormattingStrategy.IndentLines(textArea, region.EndLine, textArea.Caret.Line);

                    textArea.Caret.Line -= 1;

                    LineSegment segment = textArea.Document.GetLineSegment(textArea.Caret.Line);

                    textArea.SelectionManager.SetSelection(
                        textArea.Document.OffsetToPosition(TextUtilities.GetFirstNonWSChar(textArea.Document, segment.Offset)),
                        textArea.Document.OffsetToPosition(segment.Offset + segment.Length));

                    textArea.Document.UndoStack.EndUndoGroup();
                    textArea.EndUpdate();

                    textArea.DoProcessDialogKey += new DialogKeyProcessor(IgnoreNextDialogKey);
                }

                // detatch our keydown filter to return to the normal processing state
                this.textArea.PreviewKeyDown -= new PreviewKeyDownEventHandler(NewEventHandlerPreviewKeyDown);
            }
Ejemplo n.º 31
0
        public override void Execute(TextArea textArea)
        {
            textArea.BeginUpdate();
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                textArea.SelectionManager.RemoveSelectedText();
                textArea.ScrollToCaret();
            }
            LineSegment lineSegmentForOffset = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);

            if (textArea.Caret.Offset > lineSegmentForOffset.Offset)
            {
                int num = TextUtilities.FindPrevWordStart(textArea.Document, textArea.Caret.Offset);
                if (num < textArea.Caret.Offset)
                {
                    textArea.Document.Remove(num, textArea.Caret.Offset - num);
                    textArea.Caret.Position = textArea.Document.OffsetToPosition(num);
                }
            }
            if (textArea.Caret.Offset == lineSegmentForOffset.Offset)
            {
                int lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                if (lineNumberForOffset > 0)
                {
                    LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumberForOffset - 1);
                    int         num2        = lineSegment.Offset + lineSegment.Length;
                    int         length      = textArea.Caret.Offset - num2;
                    textArea.Document.Remove(num2, length);
                    textArea.Caret.Position = textArea.Document.OffsetToPosition(num2);
                }
            }
            textArea.SetDesiredColumn();
            textArea.EndUpdate();
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset))));
            textArea.Document.CommitUpdate();
        }
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="TextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }
            textArea.BeginUpdate();
            textArea.Document.UndoStack.StartUndoGroup();
            try
            {
                if (textArea.HandleKeyPress('\n'))
                    return;

                textArea.InsertString(Environment.NewLine);

                int curLineNr = textArea.Caret.Line;
                textArea.Document.FormattingStrategy.FormatLine(textArea, curLineNr, textArea.Caret.Offset, '\n');
                textArea.SetDesiredColumn();

                textArea.Document.UpdateQueue.Clear();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr - 1)));
            }
            finally
            {
                textArea.Document.UndoStack.EndUndoGroup();
                textArea.EndUpdate();
            }
        }
 internal static void DeleteSelection(TextArea textArea)
 {
     Debug.Assert(textArea.SelectionManager.HasSomethingSelected);
     if (textArea.SelectionManager.SelectionIsReadonly)
         return;
     textArea.BeginUpdate();
     textArea.Caret.Position = textArea.SelectionManager.StartPosition;
     textArea.SelectionManager.RemoveSelectedText();
     textArea.ScrollToCaret();
     textArea.EndUpdate();
 }
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }

            string comment = null;
            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("LineComment"))
            {
                comment = textArea.Document.HighlightingStrategy.Properties["LineComment"].ToString();
            }

            if (comment == null || comment.Length == 0)
            {
                return;
            }

            textArea.Document.UndoStack.StartUndoGroup();
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                bool shouldComment = true;
                if (!ShouldComment(textArea.Document, comment, textArea.SelectionManager, textArea.SelectionManager.StartPosition.Y, textArea.SelectionManager.EndPosition.Y))
                {
                    shouldComment = false;
                }

                textArea.BeginUpdate();
                if (shouldComment)
                {
                    SetCommentAt(textArea.Document, comment, textArea.SelectionManager, textArea.SelectionManager.StartPosition.Y, textArea.SelectionManager.EndPosition.Y);
                }
                else
                {
                    RemoveCommentAt(textArea.Document, comment, textArea.SelectionManager, textArea.SelectionManager.StartPosition.Y, textArea.SelectionManager.EndPosition.Y);
                }

                textArea.Document.UpdateQueue.Clear();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, firstLine, lastLine));
                textArea.EndUpdate();
                textArea.Document.CommitUpdate();
                textArea.AutoClearSelection = false;
            }
            else
            {
                textArea.BeginUpdate();
                int caretLine = textArea.Caret.Line;
                if (ShouldComment(textArea.Document, comment, null, caretLine, caretLine))
                {
                    SetCommentAt(textArea.Document, comment, null, caretLine, caretLine);
                }
                else
                {
                    RemoveCommentAt(textArea.Document, comment, null, caretLine, caretLine);
                }

                textArea.Document.UpdateQueue.Clear();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, caretLine));
                textArea.EndUpdate();
            }
            textArea.Document.UndoStack.EndUndoGroup();
        }
 /// <remarks>
 /// Executes this edit action
 /// </remarks>
 /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
 public override void Execute(TextArea textArea)
 {
     if (textArea.SelectionManager.HasSomethingSelected)
     {
         int startLine = textArea.SelectionManager.StartPosition.Y;
         int endLine = textArea.SelectionManager.EndPosition.Y;
         textArea.BeginUpdate();
         RemoveTabs(textArea.Document, textArea.SelectionManager, startLine, endLine);
         textArea.Document.UpdateQueue.Clear();
         textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, startLine, endLine));
         textArea.EndUpdate();
         textArea.AutoClearSelection = false;
     }
     else
     {
         // Pressing Shift-Tab with nothing selected the cursor will move back to the
         // previous tab stop. It will stop at the beginning of the line. Also, the desired
         // column is updated to that column.
         LineSegment line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
         string startOfLine = textArea.Document.GetText(line.Offset,textArea.Caret.Offset - line.Offset);
         int tabIndent = textArea.Document.TextEditorProperties.IndentationSize;
         int currentColumn = textArea.Caret.Column;
         int remainder = currentColumn % tabIndent;
         if (remainder == 0)
         {
             textArea.Caret.DesiredColumn = Math.Max(0, currentColumn - tabIndent);
         }
         else
         {
             textArea.Caret.DesiredColumn = Math.Max(0, currentColumn - remainder);
         }
         textArea.SetCaretToDesiredColumn();
     }
 }
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }
            string str = null;

            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("LineComment"))
            {
                str = textArea.Document.HighlightingStrategy.Properties["LineComment"].ToString();
            }
            if (str == null || str.Length == 0)
            {
                return;
            }
            textArea.Document.UndoStack.StartUndoGroup();
            if (!textArea.SelectionManager.HasSomethingSelected)
            {
                textArea.BeginUpdate();
                int line = textArea.Caret.Line;
                if (!this.ShouldComment(textArea.Document, str, null, line, line))
                {
                    this.RemoveCommentAt(textArea.Document, str, null, line, line);
                }
                else
                {
                    this.SetCommentAt(textArea.Document, str, null, line, line);
                }
                textArea.Document.UpdateQueue.Clear();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, line));
                textArea.EndUpdate();
            }
            else
            {
                bool flag = true;
                foreach (ISelection selectionCollection in textArea.SelectionManager.SelectionCollection)
                {
                    if (this.ShouldComment(textArea.Document, str, selectionCollection, selectionCollection.StartPosition.Y, selectionCollection.EndPosition.Y))
                    {
                        continue;
                    }
                    flag = false;
                    break;
                }
                foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
                {
                    textArea.BeginUpdate();
                    if (!flag)
                    {
                        IDocument    document    = textArea.Document;
                        int          y           = selection.StartPosition.Y;
                        TextLocation endPosition = selection.EndPosition;
                        this.RemoveCommentAt(document, str, selection, y, endPosition.Y);
                    }
                    else
                    {
                        IDocument    document1    = textArea.Document;
                        int          num          = selection.StartPosition.Y;
                        TextLocation textLocation = selection.EndPosition;
                        this.SetCommentAt(document1, str, selection, num, textLocation.Y);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, this.firstLine, this.lastLine));
                    textArea.EndUpdate();
                }
                textArea.Document.CommitUpdate();
                textArea.AutoClearSelection = false;
            }
            textArea.Document.UndoStack.EndUndoGroup();
        }
Ejemplo n.º 37
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }

            string comment = null;

            if (textArea.Document.HighlightingStrategy.Properties["LineComment"] != null)
            {
                comment = textArea.Document.HighlightingStrategy.Properties["LineComment"].ToString();
            }

            if (comment == null || comment.Length == 0)
            {
                return;
            }

            if (textArea.SelectionManager.HasSomethingSelected)
            {
                bool shouldComment = true;
                foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
                {
                    if (!ShouldComment(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y))
                    {
                        shouldComment = false;
                        break;
                    }
                }

                foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
                {
                    textArea.BeginUpdate();
                    if (shouldComment)
                    {
                        SetCommentAt(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y);
                    }
                    else
                    {
                        RemoveCommentAt(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, firstLine, lastLine));
                    textArea.EndUpdate();
                }
                textArea.Document.OnUpdateCommited();
                textArea.AutoClearSelection = false;
            }
            else
            {
                textArea.BeginUpdate();
                int caretLine = textArea.Caret.Line;
                if (ShouldComment(textArea.Document, comment, null, caretLine, caretLine))
                {
                    SetCommentAt(textArea.Document, comment, null, caretLine, caretLine);
                }
                else
                {
                    RemoveCommentAt(textArea.Document, comment, null, caretLine, caretLine);
                }
                textArea.Document.UpdateQueue.Clear();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, caretLine));
                textArea.EndUpdate();
            }
        }
Ejemplo n.º 38
0
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }
            string text = null;

            if (textArea.Document.HighlightingStrategy.Properties["LineComment"] != null)
            {
                text = textArea.Document.HighlightingStrategy.Properties["LineComment"].ToString();
            }
            if (text == null || text.Length == 0)
            {
                return;
            }
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                bool flag = true;
                foreach (ISelection current in textArea.SelectionManager.SelectionCollection)
                {
                    if (!this.ShouldComment(textArea.Document, text, current, current.StartPosition.Y, current.EndPosition.Y))
                    {
                        flag = false;
                        break;
                    }
                }
                foreach (ISelection current2 in textArea.SelectionManager.SelectionCollection)
                {
                    textArea.BeginUpdate();
                    if (flag)
                    {
                        this.SetCommentAt(textArea.Document, text, current2, current2.StartPosition.Y, current2.EndPosition.Y);
                    }
                    else
                    {
                        this.RemoveCommentAt(textArea.Document, text, current2, current2.StartPosition.Y, current2.EndPosition.Y);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, this.firstLine, this.lastLine));
                    textArea.EndUpdate();
                }
                textArea.Document.CommitUpdate();
                textArea.AutoClearSelection = false;
                return;
            }
            textArea.BeginUpdate();
            int line = textArea.Caret.Line;

            if (this.ShouldComment(textArea.Document, text, null, line, line))
            {
                this.SetCommentAt(textArea.Document, text, null, line, line);
            }
            else
            {
                this.RemoveCommentAt(textArea.Document, text, null, line, line);
            }
            textArea.Document.UpdateQueue.Clear();
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, line));
            textArea.EndUpdate();
        }
Ejemplo n.º 39
0
		/// <remarks>
		/// Executes this edit action
		/// </remarks>
		/// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
		public override void Execute(TextArea textArea)
		{
			if (textArea.Document.ReadOnly) {
				return;
			}
			textArea.BeginUpdate();
			
			textArea.InsertString(Environment.NewLine); 
			
			int curLineNr = textArea.Caret.Line;
			textArea.Caret.Column = textArea.Document.FormattingStrategy.FormatLine(textArea, curLineNr, textArea.Caret.Offset, '\n');
			textArea.SetDesiredColumn();
			
			textArea.Document.UpdateQueue.Clear();
			textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, curLineNr - 1)));
			textArea.EndUpdate();
		}
Ejemplo n.º 40
0
        /// <summary>
        /// Executes the action on a certain <see cref="TextArea"/>.
        /// </summary>
        /// <param name="textArea">The text area on which to execute the action.</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
              {
            DeleteSelection(textArea);
              }
              else
              {
            if (textArea.IsReadOnly(textArea.Caret.Offset))
              return;

            if (textArea.Caret.Offset < textArea.Document.TextLength)
            {
              textArea.BeginUpdate();
              int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
              LineSegment curLine = textArea.Document.GetLineSegment(curLineNr);

              if (curLine.Offset + curLine.Length == textArea.Caret.Offset)
              {
            if (curLineNr + 1 < textArea.Document.TotalNumberOfLines)
            {
              LineSegment nextLine = textArea.Document.GetLineSegment(curLineNr + 1);

              textArea.Document.Remove(textArea.Caret.Offset, nextLine.Offset - textArea.Caret.Offset);
              textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr)));
            }
              }
              else
              {
            textArea.Document.Remove(textArea.Caret.Offset, 1);
              }
              textArea.UpdateMatchingBracket();
              textArea.EndUpdate();
            }
              }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Executes the action on a certain <see cref="TextArea"/>.
        /// </summary>
        /// <param name="textArea">The text area on which to execute the action.</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            return;

              string comment = null;
              if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("LineComment"))
            comment = textArea.Document.HighlightingStrategy.Properties["LineComment"];

              if (String.IsNullOrEmpty(comment))
            return;

              textArea.Document.UndoStack.StartUndoGroup();

              if (textArea.SelectionManager.HasSomethingSelected)
              {
            bool shouldComment = true;
            foreach (ISelection selection in textArea.SelectionManager.Selections)
            {
              if (!ShouldComment(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y))
              {
            shouldComment = false;
            break;
              }
            }

            foreach (ISelection selection in textArea.SelectionManager.Selections)
            {
              textArea.BeginUpdate();
              if (shouldComment)
            SetCommentAt(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y);
              else
            RemoveCommentAt(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y);

              textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, firstLine, lastLine));
              textArea.EndUpdate();
            }
            textArea.Document.CommitUpdate();
            textArea.AutoClearSelection = false;
              }
              else
              {
            textArea.BeginUpdate();
            int caretLine = textArea.Caret.Line;
            if (ShouldComment(textArea.Document, comment, null, caretLine, caretLine))
              SetCommentAt(textArea.Document, comment, null, caretLine, caretLine);
            else
              RemoveCommentAt(textArea.Document, comment, null, caretLine, caretLine);

            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, caretLine));
            textArea.EndUpdate();
              }
              textArea.Document.UndoStack.EndUndoGroup();
        }
    /// <summary>
    /// Executes the action on a given <see cref="TextArea"/>.
    /// </summary>
    /// <param name="textArea">The text area on which to execute the action.</param>
    public override void Execute(TextArea textArea)
    {
      if (textArea.SelectionManager.SelectionIsReadonly)
        return;

      _textArea = textArea;
      textArea.BeginUpdate();
      textArea.Document.UndoStack.StartUndoGroup();
      if (textArea.SelectionManager.HasSomethingSelected)
      {
        foreach (ISelection selection in textArea.SelectionManager.Selections)
          Convert(textArea.Document, selection.Offset, selection.Length);
      }
      else
      {
        Convert(textArea.Document, 0, textArea.Document.TextLength);
      }
      textArea.Document.UndoStack.EndUndoGroup();
      textArea.EndUpdate();
      textArea.Refresh();
    }
Ejemplo n.º 43
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            IDocument d = textArea.Document;

            if (d.ReadOnly)
                return;

            textArea.BeginUpdate();
            textArea.InsertChar('\n');

            ++textArea.Caret.Line;
            int curLineNr = textArea.Caret.Line;
            textArea.Caret.Column = d.FormattingStrategy.FormatLine (d, curLineNr, textArea.Caret.Offset, '\n');
            textArea.SetDesiredColumn();

            textArea.Document.UpdateQueue.Clear();
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, curLineNr - 1)));
            textArea.EndUpdate();
        }
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            // if anything is selected we will just delete it first
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                Delete.DeleteSelection(textArea);
                return;
            }

            textArea.BeginUpdate();
            // now delete from the caret to the beginning of the word
            LineSegment line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
            // if we are not at the beginning of a line
            if (textArea.Caret.Offset > line.Offset)
            {
                int prevWordStart = TextUtilities.FindPrevWordStart(textArea.Document, textArea.Caret.Offset);
                if (prevWordStart < textArea.Caret.Offset)
                {
                    if (!textArea.IsReadOnly(prevWordStart, textArea.Caret.Offset - prevWordStart))
                    {
                        textArea.Document.Remove(prevWordStart, textArea.Caret.Offset - prevWordStart);
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(prevWordStart);
                    }
                }
            }

            // if we are now at the beginning of a line
            if (textArea.Caret.Offset == line.Offset)
            {
                // if we are not on the first line
                int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
                if (curLineNr > 0)
                {
                    // move to the end of the line above
                    LineSegment lineAbove = textArea.Document.GetLineSegment(curLineNr - 1);
                    int endOfLineAbove = lineAbove.Offset + lineAbove.Length;
                    int charsToDelete = textArea.Caret.Offset - endOfLineAbove;
                    if (!textArea.IsReadOnly(endOfLineAbove, charsToDelete))
                    {
                        textArea.Document.Remove(endOfLineAbove, charsToDelete);
                        textArea.Caret.Position = textArea.Document.OffsetToPosition(endOfLineAbove);
                    }
                }
            }
            textArea.SetDesiredColumn();
            textArea.EndUpdate();
            // if there are now less lines, we need this or there are redraw problems
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset))));
            textArea.Document.CommitUpdate();
        }
        /// <summary>
        /// Executes the action on a certain <see cref="TextArea"/>.
        /// </summary>
        /// <param name="textArea">The text area on which to execute the action.</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }

            string comment = null;

            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("LineComment"))
            {
                comment = textArea.Document.HighlightingStrategy.Properties["LineComment"];
            }

            if (String.IsNullOrEmpty(comment))
            {
                return;
            }

            textArea.Document.UndoStack.StartUndoGroup();

            if (textArea.SelectionManager.HasSomethingSelected)
            {
                bool shouldComment = true;
                foreach (ISelection selection in textArea.SelectionManager.Selections)
                {
                    if (!ShouldComment(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y))
                    {
                        shouldComment = false;
                        break;
                    }
                }

                foreach (ISelection selection in textArea.SelectionManager.Selections)
                {
                    textArea.BeginUpdate();
                    if (shouldComment)
                    {
                        SetCommentAt(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y);
                    }
                    else
                    {
                        RemoveCommentAt(textArea.Document, comment, selection, selection.StartPosition.Y, selection.EndPosition.Y);
                    }

                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, firstLine, lastLine));
                    textArea.EndUpdate();
                }
                textArea.Document.CommitUpdate();
                textArea.AutoClearSelection = false;
            }
            else
            {
                textArea.BeginUpdate();
                int caretLine = textArea.Caret.Line;
                if (ShouldComment(textArea.Document, comment, null, caretLine, caretLine))
                {
                    SetCommentAt(textArea.Document, comment, null, caretLine, caretLine);
                }
                else
                {
                    RemoveCommentAt(textArea.Document, comment, null, caretLine, caretLine);
                }

                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, caretLine));
                textArea.EndUpdate();
            }
            textArea.Document.UndoStack.EndUndoGroup();
        }
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                DeleteSelection(textArea);
                return;
            }

            // if anything is selected we will just delete it first
            textArea.BeginUpdate();
            // now delete from the caret to the beginning of the word
            LineSegment line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
            if(textArea.Caret.Offset == line.Offset + line.Length)
            {
                // if we are at the end of a line
                base.Execute(textArea);
            }
            else
            {
                int nextWordStart = TextUtilities.FindNextWordStart(textArea.Document, textArea.Caret.Offset);
                if(nextWordStart > textArea.Caret.Offset)
                {
                    if (!textArea.IsReadOnly(textArea.Caret.Offset, nextWordStart - textArea.Caret.Offset))
                    {
                        textArea.Document.Remove(textArea.Caret.Offset, nextWordStart - textArea.Caret.Offset);
                        // cursor never moves with this command
                    }
                }
            }

            textArea.UpdateMatchingBracket();
            textArea.EndUpdate();
            // if there are now less lines, we need this or there are redraw problems
            textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset))));
            textArea.Document.CommitUpdate();
        }
Ejemplo n.º 47
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            IDocument d = textArea.Document;

            if (d.ReadOnly)
                return;

            textArea.BeginUpdate();
            if (textArea.SelectionManager.HasSomethingSelected) {
                foreach (ISelection selection in textArea.SelectionManager.SelectionCollection)
                    d.FormattingStrategy.IndentLines (d, selection.StartPosition.Y, selection.EndPosition.Y);
            } else
                d.FormattingStrategy.IndentLines (d, 0, textArea.Document.TotalNumberOfLines - 1);

            textArea.EndUpdate();
            //textArea.Refresh();
        }