EndUpdate() public method

public EndUpdate ( ) : void
return void
コード例 #1
0
 public void Cut(object sender, EventArgs e)
 {
     if (CopyTextToClipboard(textArea.SelectionManager.SelectedText))
     {
         // Remove text
         textArea.BeginUpdate();
         textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
         textArea.SelectionManager.RemoveSelectedText();
         textArea.EndUpdate();
     }
     else
     {
         // No text was selected, select and cut the entire line
         int         curLineNr        = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
         LineSegment lineWhereCaretIs = textArea.Document.GetLineSegment(curLineNr);
         string      caretLineText    = textArea.Document.GetText(lineWhereCaretIs.Offset, lineWhereCaretIs.TotalLength);
         textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset), textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset + lineWhereCaretIs.TotalLength));
         if (CopyTextToClipboard(caretLineText))
         {
             // remove line
             textArea.BeginUpdate();
             textArea.Caret.Position = textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset);
             textArea.SelectionManager.RemoveSelectedText();
             textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new Point(0, curLineNr)));
             textArea.EndUpdate();
         }
     }
 }
コード例 #2
0
        protected virtual void OnPositionChanged(EventArgs e)
        {
            ArrayList foldings     = textArea.Document.FoldingManager.GetFoldingsFromPosition(line, column);
            bool      shouldUpdate = false;

            foreach (FoldMarker foldMarker in foldings)
            {
                //Console.WriteLine(foldMarker);
                shouldUpdate       |= foldMarker.IsFolded;
                foldMarker.IsFolded = false;
            }

            if (shouldUpdate)
            {
                textArea.BeginUpdate();
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                textArea.EndUpdate();
                textArea.Document.FoldingManager.NotifyFoldingsChanged(EventArgs.Empty);
            }

            if (PositionChanged != null)
            {
                PositionChanged(this, e);
            }
            textArea.ScrollToCaret();
        }
コード例 #3
0
		/// <summary>
		/// Inserts the PInvoke signature at the current cursor position.
		/// </summary>
		/// <param name="textArea">The text editor.</param>
		/// <param name="signature">A PInvoke signature string.</param>
		public void Generate(TextArea textArea, string signature)
		{
			IndentStyle oldIndentStyle = textArea.TextEditorProperties.IndentStyle;
			bool oldEnableEndConstructs = PropertyService.Get("VBBinding.TextEditor.EnableEndConstructs", true);

			try {

				textArea.BeginUpdate();
				textArea.Document.UndoStack.StartUndoGroup();
				textArea.TextEditorProperties.IndentStyle = IndentStyle.Smart;
				PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", false);

				string[] lines = signature.Replace("\r\n", "\n").Split('\n');
				
				for (int i = 0; i < lines.Length; ++i) {
					
					textArea.InsertString(lines[i]);
					
					// Insert new line if not the last line.
					if ( i < (lines.Length - 1))
					{
						Return(textArea);
					}
				}
				
			} finally {
				textArea.Document.UndoStack.EndUndoGroup();
				textArea.TextEditorProperties.IndentStyle = oldIndentStyle;
				PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", oldEnableEndConstructs);
				textArea.EndUpdate();
				textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
				textArea.Document.CommitUpdate();	
			}
		}
コード例 #4
0
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            Point p = _textArea.PointToClient(new Point(e.X, e.Y));

            if (e.Data.GetDataPresent(typeof(string)))
            {
                _textArea.BeginUpdate();
                _textArea.Document.UndoStack.StartUndoGroup();
                try
                {
                    int offset = _textArea.Caret.Offset;
                    if (_textArea.IsReadOnly(offset))
                    {
                        // prevent dragging text into readonly section
                        return;
                    }

                    //TODO2 drag/drop - all this:
                    //if (e.Data.GetDataPresent(typeof(Selection)))
                    //{
                    //    Selection sel = (Selection)e.Data.GetData(typeof(Selection));
                    //    if (sel.ContainsPosition(textArea.Caret.Position))
                    //    {
                    //        return;
                    //    }

                    //    if (GetDragDropEffect(e) == DragDropEffects.Move)
                    //    {
                    //        if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel))
                    //        {
                    //            // prevent dragging text out of readonly section
                    //            return;
                    //        }

                    //        int len = sel.Length;
                    //        textArea.Document.Remove(sel.StartOffset, len);

                    //        if (sel.StartOffset < offset)
                    //        {
                    //            offset -= len;
                    //        }
                    //    }
                    //}

                    _textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    _textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                }
                finally
                {
                    _textArea.Document.UndoStack.EndUndoGroup();
                    _textArea.EndUpdate();
                }
            }
        }
コード例 #5
0
 public void Cut(object sender, EventArgs e)
 {
     if (textArea.TextEditorProperties.UseCustomLine == true)
     {
         if (textArea.SelectionManager.HasSomethingSelected)
         {
             if (textArea.SelectionManager.SelectionIsReadonly)
             {
                 return;
             }
         }
         else if (textArea.Document.CustomLineManager.IsReadOnly(textArea.Caret.Line, false) == true)
         {
             return;
         }
     }
     if (CopyTextToClipboard(textArea.SelectionManager.SelectedText))
     {
         // Remove text
         textArea.BeginUpdate();
         textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
         textArea.SelectionManager.RemoveSelectedText();
         textArea.EndUpdate();
     }
     else if (textArea.Document.TextEditorProperties.CutCopyWholeLine)
     {
         // No text was selected, select and cut the entire line
         int         curLineNr        = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
         LineSegment lineWhereCaretIs = textArea.Document.GetLineSegment(curLineNr);
         string      caretLineText    = textArea.Document.GetText(lineWhereCaretIs.Offset, lineWhereCaretIs.TotalLength);
         textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset), textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset + lineWhereCaretIs.TotalLength));
         if (CopyTextToClipboard(caretLineText, true))
         {
             // remove line
             textArea.BeginUpdate();
             textArea.Caret.Position = textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset);
             textArea.SelectionManager.RemoveSelectedText();
             textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr)));
             textArea.EndUpdate();
         }
     }
 }
コード例 #6
0
 public void Cut(object sender, EventArgs e)
 {
     if (CopyTextToClipboard())
     {
         // remove text
         textArea.BeginUpdate();
         textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
         textArea.SelectionManager.RemoveSelectedText();
         textArea.EndUpdate();
     }
 }
コード例 #7
0
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(string)))
            {
                textArea.BeginUpdate();
                textArea.Document.UndoStack.StartUndoGroup();

                try
                {
                    int offset = textArea.Caret.Offset;

                    if (textArea.IsReadOnly(offset))
                    {
                        // prevent dragging text into readonly section
                        return;
                    }

                    if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                    {
                        ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));

                        if (sel.ContainsPosition(textArea.Caret.Position))
                        {
                            return;
                        }

                        if (GetDragDropEffect(e) == DragDropEffects.Move)
                        {
                            if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel))
                            {
                                // prevent dragging text out of readonly section
                                return;
                            }

                            int len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);

                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                    }
                    textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                }
                finally
                {
                    textArea.Document.UndoStack.EndUndoGroup();
                    textArea.EndUpdate();
                }
            }
        }
コード例 #8
0
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            Point p = textArea.PointToClient(new Point(e.X, e.Y));

            if (e.Data.GetDataPresent(typeof(string)))
            {
                bool two = false;
                textArea.BeginUpdate();
                try {
                    int offset = textArea.Caret.Offset;
                    if (textArea.TextEditorProperties.UseCustomLine &&
                        textArea.Document.CustomLineManager.IsReadOnly(textArea.Caret.Line, false))
                    {
                        // prevent dragging text into readonly section
                        return;
                    }
                    if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                    {
                        ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                        if (sel.ContainsPosition(textArea.Caret.Position))
                        {
                            return;
                        }
                        if (GetDragDropEffect(e) == DragDropEffects.Move)
                        {
                            if (textArea.TextEditorProperties.UseCustomLine &&
                                textArea.Document.CustomLineManager.IsReadOnly(sel, false))
                            {
                                // prevent dragging text out of readonly section
                                return;
                            }
                            int len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);
                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                        two = true;
                    }
                    textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    if (two)
                    {
                        textArea.Document.UndoStack.CombineLast(2);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                } finally {
                    textArea.EndUpdate();
                }
            }
        }
コード例 #9
0
        private void templateEditor_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));

            ICSharpCode.TextEditor.TextArea textArea = (ICSharpCode.TextEditor.TextArea)sender;
            try
            {
                Hashtable idPack = node.Tag as Hashtable;
                switch (idPack["Type"] as string)
                {
                case "promptgroup":
                    return;

                case "prompt":
                    break;
                }

                //Build the variable to insert here
                Prompt prompt = idPack["Data"] as Prompt;

                Point p = textArea.PointToClient(new Point(e.X, e.Y));
                textArea.BeginUpdate();
                textArea.Document.UndoStack.StartUndoGroup();

                int offset = textArea.Caret.Offset;
                if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                {
                    ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                    if (sel.ContainsPosition(textArea.Caret.Position))
                    {
                        return;
                    }
                    int len = sel.Length;
                    textArea.Document.Remove(sel.Offset, len);
                    if (sel.Offset < offset)
                    {
                        offset -= len;
                    }
                }
                insertIntoTemplateEditor(textArea, offset, prompt.VariableName);
            }
            finally
            {
                textArea.Document.UndoStack.EndUndoGroup();
                textArea.EndUpdate();
            }
        }
コード例 #10
0
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            Point p = textArea.PointToClient(new Point(e.X, e.Y));

            if (textArea.EnableCutOrPaste == false)
            {
                return;
            }
            if (e.Data.GetDataPresent(typeof(string)))
            {
                bool two = false;
                textArea.BeginUpdate();
                try {
                    int offset = textArea.Caret.Offset;
                    if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                    {
                        ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                        if (sel.ContainsPosition(textArea.Caret.Position))
                        {
                            return;
                        }
                        if (GetDragDropEffect(e) == DragDropEffects.Move)
                        {
                            int len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);
                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                        two = true;
                    }
                    textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    if (two)
                    {
                        textArea.Document.UndoStack.UndoLast(2);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                } finally {
                    textArea.EndUpdate();
                }
            }
        }
コード例 #11
0
        public void Cut(object sender, EventArgs e)
        {
            if (textArea.SelectionManager.HasSomethingSelected)
            {
                if (CopyTextToClipboard(textArea.SelectionManager.SelectedText))
                {
                    if (textArea.SelectionManager.SelectionIsReadonly)
                    {
                        return;
                    }

                    // Remove text
                    textArea.BeginUpdate();
                    textArea.Caret.Position = textArea.SelectionManager.StartPosition;
                    textArea.SelectionManager.RemoveSelectedText();
                    textArea.EndUpdate();
                }
            }
        }
コード例 #12
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)
        {
            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();
            }
        }
コード例 #13
0
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            if (!IsSupportedData(e.Data))
            {
                return;
            }

            textArea.BeginUpdate();
            textArea.Document.UndoStack.StartUndoGroup();
            try
            {
                var offset = textArea.Caret.Offset;
                if (textArea.IsReadOnly(offset))
                {
                    return;
                }

                try
                {
                    if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                    {
                        var sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                        if (sel.ContainsPosition(textArea.Caret.Position))
                        {
                            return;
                        }
                        if (GetDragDropEffect(e) == DragDropEffects.Move)
                        {
                            if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel))
                            {
                                return;
                            }
                            var len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);
                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                    }
                }
                catch (System.InvalidCastException)
                {
                    /*
                     *  If GetDataPresent(typeof(DefaultSelection)) threw this
                     *  exception, then it's an interprocess DefaultSelection
                     *  COM object that is not serializable! In general,
                     *  GetDataPresent(typeof(...)) throws InvalidCastException
                     *  for drags and drops from other GitExt processes (maybe
                     *  we need to make the data objects [Serializable]?). We
                     *  can get around this exception by doing
                     *  GetDataPresent(String s) [using the string of the type
                     *  name seems to work fine!] Since it is interprocess
                     *  data, just get the string data from it - special
                     *  handling logic in try {} is only valid for selections
                     *  within the current process's text editor!
                     */
                }

                textArea.SelectionManager.ClearSelection();
                InsertString(offset, (string)e.Data.GetData("System.String"));
                textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
            }
            finally
            {
                textArea.Document.UndoStack.EndUndoGroup();
                textArea.EndUpdate();
            }
        }
コード例 #14
0
        public static void Highlight(TextArea textArea)
        {
            try
            {

                int beg_off = -1;
                int end_off = -1;
                List<TextMarker> marks = markers[textArea] as List<TextMarker>;
                if (marks == null)
                {
                    marks = new List<TextMarker>();
                    markers[textArea] = marks;
                }
                RemoveMarkers(textArea);
                string word = GetWordAtOffset(textArea, out beg_off, out end_off);
                if (string.Compare(word, "begin", true) == 0 || highlighted_keywords[word] != null)
                {
                    TmpPos end_pos = GetPositionOfEnd(textArea, end_off);
                    if (end_pos != null)
                    {
                        TextLocation Beg = textArea.Document.OffsetToPosition(beg_off);
                        TextLocation End = textArea.Document.OffsetToPosition(end_off);
                        TextMarker marker = new TextMarker(beg_off, word.Length, TextMarkerType.SolidBlock, System.Drawing.Color.FromArgb(219, 224, 204));
                        marker.WholeLine = false;
                        textArea.Document.MarkerStrategy.AddMarker(marker);
                        marks.Add(marker);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, textArea.Document.GetLineNumberForOffset(beg_off)));
                        textArea.EndUpdate();
                        Beg = textArea.Document.OffsetToPosition(end_pos.start_pos);
                        End = textArea.Document.OffsetToPosition(end_pos.start_pos + end_pos.len);
                        marker = new TextMarker(end_pos.start_pos, end_pos.len, TextMarkerType.SolidBlock, System.Drawing.Color.FromArgb(219, 224, 204));
                        marker.WholeLine = false;
                        textArea.Document.MarkerStrategy.AddMarker(marker);
                        marks.Add(marker);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, textArea.Document.GetLineNumberForOffset(end_pos.start_pos)));
                        textArea.EndUpdate();
                        textArea.Document.CommitUpdate();
                    }
                }
                else if (string.Compare(word, "end", true) == 0)
                {
                    TmpPos beg_pos = GetPositionOfBegin(textArea, beg_off);
                    if (beg_pos != null)
                    {
                        TextLocation Beg = textArea.Document.OffsetToPosition(beg_off);
                        TextLocation End = textArea.Document.OffsetToPosition(end_off);
                        TextMarker marker = new TextMarker(beg_off, 3, TextMarkerType.SolidBlock, System.Drawing.Color.FromArgb(219, 224, 204));
                        marker.WholeLine = false;
                        textArea.Document.MarkerStrategy.AddMarker(marker);
                        marks.Add(marker);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, textArea.Document.GetLineNumberForOffset(beg_off)));
                        textArea.EndUpdate();
                        Beg = textArea.Document.OffsetToPosition(beg_pos.start_pos);
                        End = textArea.Document.OffsetToPosition(beg_pos.start_pos + beg_pos.len);
                        marker = new TextMarker(beg_pos.start_pos, beg_pos.len, TextMarkerType.SolidBlock, System.Drawing.Color.FromArgb(219, 224, 204));
                        marker.WholeLine = false;
                        textArea.Document.MarkerStrategy.AddMarker(marker);
                        marks.Add(marker);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, textArea.Document.GetLineNumberForOffset(beg_pos.start_pos)));
                        textArea.EndUpdate();
                        textArea.Document.CommitUpdate();
                    }
                }
            }
            catch (Exception e)
            {

            }
        }
コード例 #15
0
        private static void RemoveMarkers(TextArea textArea)
        {
            //textArea.Document.MarkerStrategy.RemoveAll(remove_pred);
            List<TextMarker> marks = markers[textArea] as List<TextMarker>;
            if (marks != null)
            {
                foreach (TextMarker marker in marks)
                {
                    try
                    {
                        textArea.Document.MarkerStrategy.RemoveMarker(marker);
                        textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, textArea.Document.GetLineNumberForOffset(marker.Offset)));
                        textArea.EndUpdate();
                    }
                    catch
                    {

                    }
                }
                marks.Clear();
            }
            textArea.Document.CommitUpdate();
        }