1:   //  UndoableInsert.cs 
2:   //  Copyright (c) 2000 Mike Krueger
3:   //
4:   //  This program is free software; you can redistribute it and/or modify
5:   //  it under the terms of the GNU General Public License as published by
6:   //  the Free Software Foundation; either version 2 of the License, or
7:   //  (at your option) any later version.
8:   //
9:   //  This program is distributed in the hope that it will be useful,
10:   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11:   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12:   //  GNU General Public License for more details.
13:   //
14:   //  You should have received a copy of the GNU General Public License
15:   //  along with this program; if not, write to the Free Software
16:   //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17:  
18:   using System;
19:   using System.Diagnostics;
20:   using System.Drawing;
21:   using SharpDevelop.DefaultEditor.Text;
22:   using SharpDevelop.Internal.Undo;
23:       
24:   namespace SharpDevelop.DefaultEditor.Undo {
25:       
26:       /// <summary>
27:       /// This class is for the undo of Document insert operations
28:       /// </summary>
29:       public class UndoableInsert : IUndoableOperation
30:       {
31:           IDocument document;
32:           int      oldCaretPos;
33:           int      offset;
34:           string   text;
35:           
36:           public UndoableInsert(IDocument documentint offsetstring text)
37:           {
38:               if (document == null) {
39:                   throw new ArgumentNullException("document");
40:               }
41:               if (offset || offset document.TextLength) {
42:                   throw new ArgumentOutOfRangeException("offset");
43:               }
44:               
45:               Debug.Assert(text != null"text can't be null");
46:               oldCaretPos   document.Caret.Offset;
47:               this.document document;
48:               this.offset   offset;
49:               this.text     text;
50:           }
51:           
52:           public void Undo()
53:           {
54:               document.UndoStack.AcceptChanges false;
55:               document.Remove(offsettext.Length);
56:               document.Caret.Offset oldCaretPos;
57:               document.UndoStack.AcceptChanges true;
58:           }
59:           
60:           public void Redo()
61:           {
62:               document.UndoStack.AcceptChanges false;
63:               document.Insert(offsettext);
64:               document.UndoStack.AcceptChanges true;
65:           }
66:       }
67:   }
68:  

This page was automatically generated by SharpDevelop.