1
// TextEditorOptions.cs
4
// Mike Krüger <mkrueger@novell.com>
6
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
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:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
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
28
using System.Diagnostics;
29
using Mono.TextEditor.Highlighting;
31
namespace Mono.TextEditor
33
public class TextEditorOptions : ITextEditorOptions
35
public const string DEFAULT_FONT = "Mono 10";
36
static TextEditorOptions options = new TextEditorOptions ();
38
public static TextEditorOptions DefaultOptions {
44
int indentationSize = 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;
54
bool showRuler = false;
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;
69
IWordFindStrategy wordFindStrategy = new EmacsWordFindStrategy (true);
78
OnChanged (EventArgs.Empty);
81
public bool CanZoomIn {
86
public bool CanZoomOut {
91
public bool CanResetZoom {
99
Zoom = System.Math.Min (8.0, System.Math.Max (0.7, zoom));
102
public void ZoomOut ()
105
Zoom = System.Math.Min (8.0, System.Math.Max (0.7, zoom));
108
public void ZoomReset ()
113
public string IndentationString {
115
return this.tabsToSpaces ? new string (' ', this.TabSize) : "\t";
119
public virtual IWordFindStrategy WordFindStrategy {
121
return wordFindStrategy;
124
wordFindStrategy = value;
128
public virtual bool AllowTabsAfterNonTabs {
130
return allowTabsAfterNonTabs;
133
allowTabsAfterNonTabs = value;
137
public virtual bool HighlightMatchingBracket {
139
return highlightMatchingBracket;
142
if (value != HighlightMatchingBracket) {
143
highlightMatchingBracket = value;
144
OnChanged (EventArgs.Empty);
149
public virtual bool RemoveTrailingWhitespaces {
151
return removeTrailingWhitespaces;
154
removeTrailingWhitespaces = value;
158
public virtual bool TabsToSpaces {
163
tabsToSpaces = value;
164
OnChanged (EventArgs.Empty);
168
public virtual int IndentationSize {
170
return indentationSize;
173
indentationSize = value;
174
OnChanged (EventArgs.Empty);
178
public virtual int TabSize {
184
OnChanged (EventArgs.Empty);
188
public virtual bool ShowIconMargin {
190
return showIconMargin;
193
showIconMargin = value;
194
OnChanged (EventArgs.Empty);
198
public virtual bool ShowLineNumberMargin {
200
return showLineNumberMargin;
203
showLineNumberMargin = value;
204
OnChanged (EventArgs.Empty);
208
public virtual bool ShowFoldMargin {
210
return showFoldMargin;
213
showFoldMargin = value;
214
OnChanged (EventArgs.Empty);
218
public virtual bool ShowInvalidLines {
220
return showInvalidLines;
223
showInvalidLines = value;
224
OnChanged (EventArgs.Empty);
228
public virtual bool ShowTabs {
234
OnChanged (EventArgs.Empty);
238
public virtual bool ShowEolMarkers {
240
return showEolMarkers;
243
showEolMarkers = value;
244
OnChanged (EventArgs.Empty);
248
public virtual bool HighlightCaretLine {
250
return highlightCaretLine;
253
highlightCaretLine = value;
254
OnChanged (EventArgs.Empty);
258
public virtual bool ShowSpaces {
264
OnChanged (EventArgs.Empty);
268
public virtual int RulerColumn {
274
OnChanged (EventArgs.Empty);
278
public virtual bool ShowRuler {
284
OnChanged (EventArgs.Empty);
288
public virtual bool AutoIndent {
294
OnChanged (EventArgs.Empty);
298
public virtual string FontName {
303
if (fontName != value) {
305
fontName = !String.IsNullOrEmpty (value) ? value : DEFAULT_FONT;
306
OnChanged (EventArgs.Empty);
311
public virtual bool EnableSyntaxHighlighting {
313
return enableSyntaxHighlighting;
316
if (value != EnableSyntaxHighlighting) {
317
enableSyntaxHighlighting = value;
318
OnChanged (EventArgs.Empty);
323
public Pango.FontDescription Font {
327
font = Pango.FontDescription.FromString (FontName);
329
Console.WriteLine ("Could not load font: {0}", FontName);
331
if (font == null || String.IsNullOrEmpty (font.Family))
332
font = Pango.FontDescription.FromString (DEFAULT_FONT);
334
font.Size = (int)(font.Size * Zoom);
340
public virtual string ColorScheme {
346
OnChanged (EventArgs.Empty);
349
public virtual Style GetColorStyle (Gtk.Widget widget)
351
return SyntaxModeService.GetColorStyle (widget, ColorScheme);
354
public virtual void CopyFrom (TextEditorOptions other)
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;
377
public virtual void Dispose ()
380
protected void OnChanged (EventArgs args)
383
Changed (null, args);
386
public event EventHandler Changed;