~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor/Selection.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
namespace Mono.TextEditor
5
5
{
6
 
        public class Selection
 
6
        public struct Selection
7
7
        {
8
 
                DocumentLocation anchor;
 
8
                public static readonly Selection Empty = new Selection (true);
 
9
 
 
10
                public bool IsEmpty {
 
11
                        get {
 
12
                                return anchor.IsEmpty;
 
13
                        }
 
14
                }
 
15
 
 
16
                readonly DocumentLocation anchor;
9
17
                public DocumentLocation Anchor {
10
18
                        get {
11
19
                                return anchor;
12
20
                        }
13
 
                        set {
14
 
                                if (anchor != value) {
15
 
                                        anchor = value;
16
 
                                        OnChanged ();
17
 
                                }
18
 
                        }
19
21
                }
20
22
                
21
 
                DocumentLocation lead;
 
23
                readonly DocumentLocation lead;
22
24
                public DocumentLocation Lead {
23
25
                        get {
24
26
                                return lead;
25
27
                        }
26
 
                        set {
27
 
                                if (lead != value) {
28
 
                                        lead = value;
29
 
                                        OnChanged ();
30
 
                                }
31
 
                        }
32
28
                }
33
 
                
 
29
 
 
30
 
34
31
                public int MinLine {
35
32
                        get {
36
33
                                return System.Math.Min (Anchor.Line, Lead.Line);
55
52
                        }
56
53
                }
57
54
                
 
55
                readonly SelectionMode selectionMode;
58
56
                public SelectionMode SelectionMode {
59
 
                        get;
60
 
                        set;
 
57
                        get {
 
58
                                return selectionMode;
 
59
                        }
61
60
                }
62
61
                
63
62
                public bool Contains (DocumentLocation loc)
64
63
                {
65
64
                        return anchor <= loc && loc <= lead || lead <= loc && loc <= anchor;
66
65
                }
67
 
                
68
 
                public Selection ()
69
 
                {
70
 
                        SelectionMode = SelectionMode.Normal;
71
 
                }
72
 
                
73
 
                public static Selection Clone (Selection selection)
74
 
                {
75
 
                        if (selection == null)
76
 
                                return null;
77
 
                        return new Selection (selection.Anchor, selection.Lead, selection.SelectionMode);
78
 
                }
79
 
                
 
66
 
 
67
                Selection(bool empty)
 
68
                {
 
69
                        anchor = lead = DocumentLocation.Empty;
 
70
                        selectionMode = SelectionMode.Normal;
 
71
                }
 
72
 
80
73
                public Selection (int anchorLine, int anchorColumn, int leadLine, int leadColumn, SelectionMode mode = SelectionMode.Normal) : this(new DocumentLocation (anchorLine, anchorColumn), new DocumentLocation (leadLine, leadColumn), mode)
81
74
                {
82
75
                }
87
80
                                throw new ArgumentOutOfRangeException ("anchor", anchor + " is out of range.");
88
81
                        if (lead.Line < DocumentLocation.MinLine || lead.Column < DocumentLocation.MinColumn)
89
82
                                throw new ArgumentOutOfRangeException ("lead", lead + " is out of range.");
90
 
                        this.Anchor        = anchor;
91
 
                        this.Lead          = lead;
92
 
                        this.SelectionMode = selectionMode;
93
 
                }
94
 
                
 
83
                        this.anchor        = anchor;
 
84
                        this.lead          = lead;
 
85
                        this.selectionMode = selectionMode;
 
86
                }
 
87
 
 
88
                public Selection WithLead (DocumentLocation newLead)
 
89
                {
 
90
                        return new Selection (Anchor, newLead, SelectionMode);
 
91
                }
 
92
 
 
93
                public Selection WithAnchor (DocumentLocation newAnchor)
 
94
                {
 
95
                        return new Selection (newAnchor, Lead, SelectionMode);
 
96
                }
 
97
 
 
98
                public Selection WithRange (DocumentLocation newAnchor, DocumentLocation newLead)
 
99
                {
 
100
                        return new Selection (newAnchor, newLead, SelectionMode);
 
101
                }
 
102
 
 
103
                public Selection WithSelectionMode (SelectionMode newSelectionMode)
 
104
                {
 
105
                        return new Selection (Anchor, Lead, newSelectionMode);
 
106
                }
 
107
 
95
108
                public TextSegment GetSelectionRange (TextEditorData data)
96
109
                {
97
110
                        int anchorOffset = GetAnchorOffset (data);
130
143
                {
131
144
                        if (obj == null)
132
145
                                return false;
133
 
                        if (ReferenceEquals (this, obj))
134
 
                                return true;
135
146
                        if (obj.GetType () != typeof(Selection))
136
147
                                return false;
137
148
                        Mono.TextEditor.Selection other = (Mono.TextEditor.Selection)obj;
138
 
                        return Anchor == other.Anchor && Lead == other.Lead;
 
149
                        return Anchor == other.Anchor && Lead == other.Lead && SelectionMode == other.SelectionMode;
139
150
                }
140
151
                
141
152
                public bool IsSelected (DocumentLocation loc)
169
180
                {
170
181
                        return string.Format("[Selection: Anchor={0}, Lead={1}, MinLine={2}, MaxLine={3}, SelectionMode={4}]", Anchor, Lead, MinLine, MaxLine, SelectionMode);
171
182
                }
172
 
                
173
 
                protected virtual void OnChanged ()
174
 
                {
175
 
                        if (Changed != null)
176
 
                                Changed (this, EventArgs.Empty);
177
 
                }
178
 
                
179
 
                public event EventHandler Changed;
180
183
        }
181
184
}