~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Unused/TextEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
 
5
//     <version value="$version"/>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.IO;
 
10
using System.Collections;
 
11
 
 
12
using MonoDevelop.Core.Gui;
 
13
 
 
14
namespace MonoDevelop.TextEditor.Document
 
15
{
 
16
        public class ProvidedDocumentInformation
 
17
        {
 
18
                IDocument document;
 
19
                ITextBufferStrategy textBuffer;
 
20
                string              fileName;
 
21
                int                 currentOffset;
 
22
                
 
23
                public ITextBufferStrategy TextBuffer {
 
24
                        get {
 
25
                                return textBuffer;
 
26
                        }
 
27
                        set {
 
28
                                textBuffer = value;
 
29
                        }
 
30
                }
 
31
                
 
32
                public string FileName {
 
33
                        get {
 
34
                                return fileName;
 
35
                        }
 
36
                }
 
37
                
 
38
                public int CurrentOffset {
 
39
                        get {
 
40
//                              if (document != null) {
 
41
//                                      return document.Caret.Offset;
 
42
//                              }
 
43
                                return currentOffset;
 
44
                        }
 
45
                        set {
 
46
//                              if (document != null) {
 
47
//                                      document.Caret.Offset = value;
 
48
//                              } else {
 
49
                                        currentOffset = value;
 
50
//                              }
 
51
                        }
 
52
                }
 
53
                
 
54
                public int EndOffset {
 
55
                        get {
 
56
                                if (document != null) {
 
57
                                        return SearchReplaceUtilities.CalcCurrentOffset(document);
 
58
                                }
 
59
                                return currentOffset;
 
60
                        }
 
61
                }
 
62
                
 
63
                public void Replace(int offset, int length, string pattern)
 
64
                {
 
65
                        if (document != null) {
 
66
                                document.Replace(offset, length, pattern);
 
67
                        } else {
 
68
                                textBuffer.Replace(offset, length, pattern);
 
69
                        }
 
70
                        
 
71
                        if (offset <= CurrentOffset) {
 
72
                                CurrentOffset = CurrentOffset - length + pattern.Length;
 
73
                        }
 
74
                }
 
75
                
 
76
                public void SaveBuffer()
 
77
                {
 
78
                        if (document != null) {
 
79
                                
 
80
                        } else {
 
81
                                StreamWriter streamWriter = File.CreateText(this.fileName);
 
82
                                streamWriter.Write(textBuffer.GetText(0, textBuffer.Length));
 
83
                                streamWriter.Close();
 
84
                        }
 
85
                }
 
86
                
 
87
                public IDocument CreateDocument()
 
88
                {
 
89
                        if (document != null) {
 
90
                                return document;
 
91
                        }
 
92
                        return new DocumentFactory().CreateFromFile(fileName);
 
93
                }               
 
94
                
 
95
                public ProvidedDocumentInformation(IDocument document, string fileName)
 
96
                {
 
97
                        this.document   = document;
 
98
                        this.textBuffer = document.TextBufferStrategy;
 
99
                        this.fileName   = fileName;
 
100
//                      this.currentOffset = document.Caret.Offset;
 
101
                }
 
102
                
 
103
                public ProvidedDocumentInformation(ITextBufferStrategy textBuffer, string fileName, int currentOffset)
 
104
                {
 
105
                        this.textBuffer    = textBuffer;
 
106
                        this.fileName      = fileName;
 
107
                        this.currentOffset = currentOffset;
 
108
                }
 
109
        }
 
110
}