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

« back to all changes in this revision

Viewing changes to src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorOptions.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
// TextEditorOptions.cs
 
2
//
 
3
// Author:
 
4
//   Mike Krüger <mkrueger@novell.com>
 
5
//
 
6
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
 
7
//
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to deal
 
10
// in the Software without restriction, including without limitation the rights
 
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
// copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
// THE SOFTWARE.
 
25
//
 
26
 
 
27
using System;
 
28
using System.Diagnostics;
 
29
using Mono.TextEditor.Highlighting;
 
30
 
 
31
namespace Mono.TextEditor
 
32
{
 
33
        public class TextEditorOptions : ITextEditorOptions
 
34
        {
 
35
                public const string DEFAULT_FONT = "Mono 10";
 
36
                static TextEditorOptions options = new TextEditorOptions ();
 
37
                
 
38
                public static TextEditorOptions DefaultOptions {
 
39
                        get {
 
40
                                return options;
 
41
                        }
 
42
                }
 
43
                
 
44
                int indentationSize = 4;
 
45
                int  tabSize = 4;
 
46
                bool tabsToSpaces = false;
 
47
                bool showIconMargin = true;
 
48
                bool showLineNumberMargin = true;
 
49
                bool showFoldMargin = true;
 
50
                bool showInvalidLines = true;
 
51
                bool autoIndent = true;
 
52
 
 
53
                int  rulerColumn = 80;
 
54
                bool showRuler = false;
 
55
                
 
56
                bool showTabs   = false;
 
57
                bool showSpaces = false;
 
58
                bool showEolMarkers = false;
 
59
                bool enableSyntaxHighlighting = true;
 
60
                bool highlightMatchingBracket = true;
 
61
                bool highlightCaretLine = false;
 
62
                bool removeTrailingWhitespaces = true;
 
63
                bool allowTabsAfterNonTabs = true;
 
64
                string fontName = DEFAULT_FONT;
 
65
                string colorStyle = "Default";
 
66
                Pango.FontDescription font;
 
67
                
 
68
                double zoom = 1.0;
 
69
                IWordFindStrategy wordFindStrategy = new EmacsWordFindStrategy (true);
 
70
 
 
71
                public double Zoom {
 
72
                        get {
 
73
                                return zoom;
 
74
                        }
 
75
                        set {
 
76
                                zoom = value;
 
77
                                font = null;
 
78
                                OnChanged (EventArgs.Empty);
 
79
                        }
 
80
                }
 
81
                public bool CanZoomIn {
 
82
                        get {
 
83
                                return zoom < 8.0;
 
84
                        }
 
85
                }
 
86
                public bool CanZoomOut {
 
87
                        get {
 
88
                                return zoom > 0.7;
 
89
                        }
 
90
                }
 
91
                public bool CanResetZoom {
 
92
                        get {
 
93
                                return zoom != 1.0;
 
94
                        }
 
95
                }
 
96
                public void ZoomIn ()
 
97
                {
 
98
                        zoom *= 1.1;
 
99
                        Zoom = System.Math.Min (8.0, System.Math.Max (0.7, zoom));
 
100
                }
 
101
                
 
102
                public void ZoomOut ()
 
103
                {
 
104
                        zoom *= 0.9;
 
105
                        Zoom = System.Math.Min (8.0, System.Math.Max (0.7, zoom));
 
106
                }
 
107
                
 
108
                public void ZoomReset ()
 
109
                {
 
110
                        Zoom = 1.0;
 
111
                }
 
112
                
 
113
                public string IndentationString {
 
114
                        get {
 
115
                                return this.tabsToSpaces ? new string (' ', this.TabSize) : "\t";
 
116
                        }
 
117
                }
 
118
                
 
119
                public virtual IWordFindStrategy WordFindStrategy {
 
120
                        get {
 
121
                                return wordFindStrategy;
 
122
                        }
 
123
                        set {
 
124
                                wordFindStrategy = value;
 
125
                        }
 
126
                }
 
127
                
 
128
                public virtual bool AllowTabsAfterNonTabs {
 
129
                        get {
 
130
                                return allowTabsAfterNonTabs;
 
131
                        }
 
132
                        set {
 
133
                                allowTabsAfterNonTabs = value;
 
134
                        }
 
135
                }
 
136
                
 
137
                public virtual bool HighlightMatchingBracket {
 
138
                        get {
 
139
                                return highlightMatchingBracket;
 
140
                        }
 
141
                        set {
 
142
                                if (value != HighlightMatchingBracket) {
 
143
                                        highlightMatchingBracket = value;
 
144
                                        OnChanged (EventArgs.Empty);
 
145
                                }
 
146
                        }
 
147
                }
 
148
                
 
149
                public virtual bool RemoveTrailingWhitespaces {
 
150
                        get {
 
151
                                return removeTrailingWhitespaces;
 
152
                        }
 
153
                        set {
 
154
                                removeTrailingWhitespaces = value;
 
155
                        }
 
156
                }
 
157
                
 
158
                public virtual bool TabsToSpaces {
 
159
                        get {
 
160
                                return tabsToSpaces;
 
161
                        }
 
162
                        set {
 
163
                                tabsToSpaces = value;
 
164
                                OnChanged (EventArgs.Empty);
 
165
                        }
 
166
                }
 
167
 
 
168
                public virtual int IndentationSize {
 
169
                        get {
 
170
                                return indentationSize;
 
171
                        }
 
172
                        set {
 
173
                                indentationSize = value;
 
174
                                OnChanged (EventArgs.Empty);
 
175
                        }
 
176
                }
 
177
 
 
178
                public virtual int TabSize {
 
179
                        get {
 
180
                                return tabSize;
 
181
                        }
 
182
                        set {
 
183
                                tabSize = value;
 
184
                                OnChanged (EventArgs.Empty);
 
185
                        }
 
186
                }
 
187
 
 
188
                public virtual bool ShowIconMargin {
 
189
                        get {
 
190
                                return showIconMargin;
 
191
                        }
 
192
                        set {
 
193
                                showIconMargin = value;
 
194
                                OnChanged (EventArgs.Empty);
 
195
                        }
 
196
                }
 
197
 
 
198
                public virtual bool ShowLineNumberMargin {
 
199
                        get {
 
200
                                return showLineNumberMargin;
 
201
                        }
 
202
                        set {
 
203
                                showLineNumberMargin = value;
 
204
                                OnChanged (EventArgs.Empty);
 
205
                        }
 
206
                }
 
207
 
 
208
                public virtual bool ShowFoldMargin {
 
209
                        get {
 
210
                                return showFoldMargin;
 
211
                        }
 
212
                        set {
 
213
                                showFoldMargin = value;
 
214
                                OnChanged (EventArgs.Empty);
 
215
                        }
 
216
                }
 
217
 
 
218
                public virtual bool ShowInvalidLines {
 
219
                        get {
 
220
                                return showInvalidLines;
 
221
                        }
 
222
                        set {
 
223
                                showInvalidLines = value;
 
224
                                OnChanged (EventArgs.Empty);
 
225
                        }
 
226
                }
 
227
 
 
228
                public virtual bool ShowTabs {
 
229
                        get {
 
230
                                return showTabs;
 
231
                        }
 
232
                        set {
 
233
                                showTabs = value;
 
234
                                OnChanged (EventArgs.Empty);
 
235
                        }
 
236
                }
 
237
 
 
238
                public virtual bool ShowEolMarkers {
 
239
                        get {
 
240
                                return showEolMarkers;
 
241
                        }
 
242
                        set {
 
243
                                showEolMarkers = value;
 
244
                                OnChanged (EventArgs.Empty);
 
245
                        }
 
246
                }
 
247
 
 
248
                public virtual bool HighlightCaretLine {
 
249
                        get {
 
250
                                return highlightCaretLine;
 
251
                        }
 
252
                        set {
 
253
                                highlightCaretLine = value;
 
254
                                OnChanged (EventArgs.Empty);
 
255
                        }
 
256
                }
 
257
 
 
258
                public virtual bool ShowSpaces {
 
259
                        get {
 
260
                                return showSpaces;
 
261
                        }
 
262
                        set {
 
263
                                showSpaces = value;
 
264
                                OnChanged (EventArgs.Empty);
 
265
                        }
 
266
                }
 
267
 
 
268
                public virtual int RulerColumn {
 
269
                        get {
 
270
                                return rulerColumn;
 
271
                        }
 
272
                        set {
 
273
                                rulerColumn = value;
 
274
                                OnChanged (EventArgs.Empty);
 
275
                        }
 
276
                }
 
277
 
 
278
                public virtual bool ShowRuler {
 
279
                        get {
 
280
                                return showRuler;
 
281
                        }
 
282
                        set {
 
283
                                showRuler = value;
 
284
                                OnChanged (EventArgs.Empty);
 
285
                        }
 
286
                }
 
287
 
 
288
                public virtual bool AutoIndent {
 
289
                        get {
 
290
                                return autoIndent;
 
291
                        }
 
292
                        set {
 
293
                                autoIndent = value;
 
294
                                OnChanged (EventArgs.Empty);
 
295
                        }
 
296
                }
 
297
                
 
298
                public virtual string FontName {
 
299
                        get {
 
300
                                return fontName;
 
301
                        }
 
302
                        set {
 
303
                                if (fontName != value) {
 
304
                                        font = null;
 
305
                                        fontName = !String.IsNullOrEmpty (value) ? value : DEFAULT_FONT;
 
306
                                        OnChanged (EventArgs.Empty);
 
307
                                }
 
308
                        }
 
309
                }
 
310
                
 
311
                public virtual bool EnableSyntaxHighlighting {
 
312
                        get {
 
313
                                return enableSyntaxHighlighting;
 
314
                        }
 
315
                        set {
 
316
                                if (value != EnableSyntaxHighlighting) {
 
317
                                        enableSyntaxHighlighting = value;
 
318
                                        OnChanged (EventArgs.Empty);
 
319
                                }
 
320
                        }
 
321
                }
 
322
                
 
323
                public Pango.FontDescription Font {
 
324
                        get {
 
325
                                if (font == null) {
 
326
                                        try {
 
327
                                                font = Pango.FontDescription.FromString (FontName);
 
328
                                        } catch {
 
329
                                                Console.WriteLine ("Could not load font: {0}", FontName);
 
330
                                        }
 
331
                                        if (font == null || String.IsNullOrEmpty (font.Family))
 
332
                                                font = Pango.FontDescription.FromString (DEFAULT_FONT);
 
333
                                        if (font != null)
 
334
                                                font.Size = (int)(font.Size * Zoom);
 
335
                                }
 
336
                                return font;
 
337
                        }
 
338
                }
 
339
                
 
340
                public virtual string ColorScheme {
 
341
                        get {
 
342
                                return colorStyle;
 
343
                        }
 
344
                        set {
 
345
                                colorStyle = value;
 
346
                                OnChanged (EventArgs.Empty);
 
347
                        }
 
348
                }
 
349
                public virtual Style GetColorStyle (Gtk.Widget widget)
 
350
                {
 
351
                        return SyntaxModeService.GetColorStyle (widget, ColorScheme);
 
352
                }
 
353
                
 
354
                public virtual void CopyFrom (TextEditorOptions other)
 
355
                {
 
356
                        Zoom = other.Zoom;
 
357
                        HighlightMatchingBracket = other.HighlightMatchingBracket;
 
358
                        TabsToSpaces = other.TabsToSpaces;
 
359
                        IndentationSize = other.IndentationSize;
 
360
                        TabSize = other.TabSize;
 
361
                        ShowIconMargin = other.ShowIconMargin;
 
362
                        ShowLineNumberMargin = other.ShowLineNumberMargin;
 
363
                        ShowFoldMargin = other.ShowFoldMargin;
 
364
                        ShowInvalidLines = other.ShowInvalidLines;
 
365
                        ShowTabs = other.ShowTabs;
 
366
                        ShowEolMarkers = other.ShowEolMarkers;
 
367
                        HighlightCaretLine = other.HighlightCaretLine;
 
368
                        ShowSpaces = other.ShowSpaces;
 
369
                        RulerColumn = other.RulerColumn;
 
370
                        ShowRuler = other.ShowRuler;
 
371
                        AutoIndent = other.AutoIndent;
 
372
                        FontName = other.FontName;
 
373
                        EnableSyntaxHighlighting = other.EnableSyntaxHighlighting;
 
374
                        ColorScheme = other.ColorScheme;
 
375
                }
 
376
                
 
377
                public virtual void Dispose ()
 
378
                {
 
379
                }
 
380
                protected void OnChanged (EventArgs args)
 
381
                {
 
382
                        if (Changed != null)
 
383
                                Changed (null, args);
 
384
                }
 
385
                
 
386
                public event EventHandler Changed;
 
387
        }
 
388
}