~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/StyledSourceEditorOptions.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// StyledSourceEditorOptions.cs
 
3
// 
 
4
// Author:
 
5
//       Michael Hutchinson <mhutchinson@novell.com>
 
6
//
 
7
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using MonoDevelop.Projects;
 
29
using MonoDevelop.Ide.Gui.Content;
 
30
 
 
31
namespace MonoDevelop.SourceEditor
 
32
{
 
33
        
 
34
        internal class StyledSourceEditorOptions : ISourceEditorOptions
 
35
        {
 
36
                TextStylePolicy currentPolicy;
 
37
                Project styleParent;
 
38
                EventHandler changed;
 
39
                
 
40
                public StyledSourceEditorOptions (Project styleParent)
 
41
                {
 
42
                        UpdateStyleParent (styleParent);
 
43
                }
 
44
                
 
45
                public void UpdateStyleParent (Project styleParent)
 
46
                {
 
47
                        if (this.styleParent != null)
 
48
                                this.styleParent.Policies.PolicyChanged -= HandlePolicyChanged;
 
49
                        
 
50
                        this.styleParent = styleParent;
 
51
                        
 
52
                        if (styleParent != null) {
 
53
                                currentPolicy = styleParent.Policies.Get<TextStylePolicy> ();
 
54
                                styleParent.Policies.PolicyChanged += HandlePolicyChanged;
 
55
                        } else {
 
56
                                currentPolicy = null;
 
57
                        }
 
58
                }
 
59
 
 
60
                void HandlePolicyChanged (object sender, MonoDevelop.Projects.Policies.PolicyChangedEventArgs args)
 
61
                {
 
62
                        TextStylePolicy newPolicy = args.Policy as TextStylePolicy;
 
63
                        if (newPolicy != null) {
 
64
                                currentPolicy = newPolicy;
 
65
                                this.changed (this, EventArgs.Empty);
 
66
                        }
 
67
                }
 
68
                
 
69
                public int RulerColumn {
 
70
                        get {
 
71
                                return currentPolicy != null
 
72
                                        ? currentPolicy.FileWidth
 
73
                                        : DefaultSourceEditorOptions.Instance.RulerColumn;
 
74
                        }
 
75
                }
 
76
 
 
77
                public int TabSize {
 
78
                        get {
 
79
                                return currentPolicy != null
 
80
                                        ? currentPolicy.TabWidth
 
81
                                        : DefaultSourceEditorOptions.Instance.TabSize;
 
82
                        }
 
83
                }
 
84
                
 
85
                public bool TabsToSpaces {
 
86
                        get {
 
87
                                return currentPolicy != null
 
88
                                        ? currentPolicy.TabsToSpaces
 
89
                                        : DefaultSourceEditorOptions.Instance.TabsToSpaces;
 
90
                        }
 
91
                }
 
92
                
 
93
                public bool RemoveTrailingWhitespaces {
 
94
                        get {
 
95
                                return currentPolicy != null
 
96
                                        ? currentPolicy.RemoveTrailingWhitespace
 
97
                                        : DefaultSourceEditorOptions.Instance.RemoveTrailingWhitespaces;
 
98
                        }
 
99
                }
 
100
                
 
101
                public bool AllowTabsAfterNonTabs {
 
102
                        get {
 
103
                                return currentPolicy != null
 
104
                                        ? !currentPolicy.NoTabsAfterNonTabs
 
105
                                        : DefaultSourceEditorOptions.Instance.AllowTabsAfterNonTabs;
 
106
                        }
 
107
                }
 
108
                
 
109
                public int IndentationSize {
 
110
                        get { return TabSize; }
 
111
                }
 
112
                
 
113
                public string IndentationString {
 
114
                        get {
 
115
                                return this.TabsToSpaces ? new string (' ', this.TabSize) : "\t";
 
116
                        }
 
117
                }
 
118
                
 
119
                #region ITextEditorOptions implementation 
 
120
                
 
121
                public bool AutoIndent {
 
122
                        get { return DefaultSourceEditorOptions.Instance.AutoIndent; }
 
123
                }
 
124
                
 
125
                public bool CanResetZoom {
 
126
                        get { return DefaultSourceEditorOptions.Instance.CanResetZoom; }
 
127
                }
 
128
                
 
129
                public bool CanZoomIn {
 
130
                        get { return DefaultSourceEditorOptions.Instance.CanZoomIn; }
 
131
                }
 
132
                
 
133
                public bool CanZoomOut {
 
134
                        get { return DefaultSourceEditorOptions.Instance.CanZoomOut; }
 
135
                }
 
136
                
 
137
                public event EventHandler Changed {
 
138
                        add {
 
139
                                changed += value;
 
140
                                if (changed != null)
 
141
                                        DefaultSourceEditorOptions.Instance.Changed += HandleDefaultsChanged;
 
142
                        }
 
143
                        remove {
 
144
                                changed -= value;
 
145
                                if (changed == null)
 
146
                                        DefaultSourceEditorOptions.Instance.Changed -= HandleDefaultsChanged;
 
147
                        }
 
148
                }
 
149
 
 
150
                void HandleDefaultsChanged (object sender, EventArgs e)
 
151
                {
 
152
                        changed (this, EventArgs.Empty);
 
153
                }
 
154
                
 
155
                public string ColorScheme {
 
156
                        get { return DefaultSourceEditorOptions.Instance.ColorScheme; }
 
157
                }
 
158
                
 
159
                public bool EnableSyntaxHighlighting {
 
160
                        get { return DefaultSourceEditorOptions.Instance.EnableSyntaxHighlighting; }
 
161
                }
 
162
                
 
163
                public Pango.FontDescription Font {
 
164
                        get { return DefaultSourceEditorOptions.Instance.Font; }
 
165
                }
 
166
                
 
167
                public string FontName {
 
168
                        get { return DefaultSourceEditorOptions.Instance.FontName; }
 
169
                }
 
170
                
 
171
                public Mono.TextEditor.Highlighting.Style GetColorStyle (Gtk.Widget widget)
 
172
                {
 
173
                        return DefaultSourceEditorOptions.Instance.GetColorStyle (widget);
 
174
                }
 
175
                
 
176
                public bool HighlightCaretLine {
 
177
                        get { return DefaultSourceEditorOptions.Instance.HighlightCaretLine; }
 
178
                }
 
179
                
 
180
                public bool HighlightMatchingBracket {
 
181
                        get { return DefaultSourceEditorOptions.Instance.HighlightMatchingBracket; }
 
182
                }
 
183
                
 
184
                public bool ShowEolMarkers {
 
185
                        get { return DefaultSourceEditorOptions.Instance.ShowEolMarkers; }
 
186
                }
 
187
                
 
188
                public bool ShowFoldMargin {
 
189
                        get { return DefaultSourceEditorOptions.Instance.ShowFoldMargin; }
 
190
                }
 
191
                
 
192
                public bool ShowIconMargin {
 
193
                        get { return DefaultSourceEditorOptions.Instance.ShowIconMargin; }
 
194
                }
 
195
                
 
196
                public bool ShowInvalidLines {
 
197
                        get { return DefaultSourceEditorOptions.Instance.ShowInvalidLines; }
 
198
                }
 
199
                
 
200
                public bool ShowLineNumberMargin {
 
201
                        get { return DefaultSourceEditorOptions.Instance.ShowLineNumberMargin; }
 
202
                }
 
203
                
 
204
                public bool ShowRuler {
 
205
                        get { return DefaultSourceEditorOptions.Instance.ShowRuler; }
 
206
                }
 
207
                
 
208
                public bool ShowSpaces {
 
209
                        get { return DefaultSourceEditorOptions.Instance.ShowSpaces; }
 
210
                }
 
211
                
 
212
                public bool ShowTabs {
 
213
                        get { return DefaultSourceEditorOptions.Instance.ShowTabs; }
 
214
                }
 
215
                
 
216
                public Mono.TextEditor.IWordFindStrategy WordFindStrategy {
 
217
                        get { return DefaultSourceEditorOptions.Instance.WordFindStrategy; }
 
218
                }
 
219
                
 
220
                public double Zoom {
 
221
                        get { return DefaultSourceEditorOptions.Instance.Zoom; }
 
222
                }
 
223
                
 
224
                public void ZoomIn ()
 
225
                {
 
226
                        DefaultSourceEditorOptions.Instance.ZoomIn ();
 
227
                }
 
228
                
 
229
                public void ZoomOut ()
 
230
                {
 
231
                        DefaultSourceEditorOptions.Instance.ZoomOut ();
 
232
                }
 
233
                
 
234
                public void ZoomReset ()
 
235
                {
 
236
                        DefaultSourceEditorOptions.Instance.ZoomReset ();
 
237
                }
 
238
                
 
239
                #endregion 
 
240
                
 
241
 
 
242
                #region ISourceEditorOptions implementation 
 
243
                
 
244
                public bool AutoInsertMatchingBracket {
 
245
                        get { return DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket; }
 
246
                }
 
247
                
 
248
                public bool DefaultCommentFolding {
 
249
                        get { return DefaultSourceEditorOptions.Instance.DefaultCommentFolding; }
 
250
                }
 
251
                
 
252
                public bool DefaultRegionsFolding {
 
253
                        get { return DefaultSourceEditorOptions.Instance.DefaultRegionsFolding; }
 
254
                }
 
255
                
 
256
                public EditorFontType EditorFontType {
 
257
                        get { return DefaultSourceEditorOptions.Instance.EditorFontType; }
 
258
                }
 
259
                
 
260
                public bool EnableAutoCodeCompletion {
 
261
                        get { return DefaultSourceEditorOptions.Instance.EnableAutoCodeCompletion; }
 
262
                }
 
263
                
 
264
                public bool EnableCodeCompletion {
 
265
                        get { return DefaultSourceEditorOptions.Instance.EnableCodeCompletion; }
 
266
                }
 
267
                
 
268
                public bool EnableQuickFinder {
 
269
                        get { return DefaultSourceEditorOptions.Instance.EnableQuickFinder; }
 
270
                }
 
271
                
 
272
                public bool EnableSemanticHighlighting {
 
273
                        get { return DefaultSourceEditorOptions.Instance.EnableSemanticHighlighting; }
 
274
                }
 
275
                
 
276
                public IndentStyle IndentStyle {
 
277
                        get { return DefaultSourceEditorOptions.Instance.IndentStyle; }
 
278
                }
 
279
                
 
280
                public bool TabIsReindent {
 
281
                        get { return DefaultSourceEditorOptions.Instance.TabIsReindent; }
 
282
                }
 
283
                
 
284
                public bool UnderlineErrors {
 
285
                        get { return DefaultSourceEditorOptions.Instance.UnderlineErrors; }
 
286
                }
 
287
                
 
288
                public bool UseViModes {
 
289
                        get { return DefaultSourceEditorOptions.Instance.UseViModes; }
 
290
                }
 
291
                
 
292
                #endregion 
 
293
                
 
294
                public void Dispose ()
 
295
                {
 
296
                        UpdateStyleParent (null);
 
297
                        if (changed != null) {
 
298
                                DefaultSourceEditorOptions.Instance.Changed -= HandleDefaultsChanged;
 
299
                                changed = null;
 
300
                        }
 
301
                }
 
302
        }
 
303
}