0:   //  BufferOptions.cs
1:   //  Copyright (c) 2001 Mike Krueger
2:   //
3:   //  This program is free software; you can redistribute it and/or modify
4:   //  it under the terms of the GNU General Public License as published by
5:   //  the Free Software Foundation; either version 2 of the License, or
6:   //  (at your option) any later version.
7:   //
8:   //  This program is distributed in the hope that it will be useful,
9:   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10:   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11:   //  GNU General Public License for more details.
12:   //
13:   //  You should have received a copy of the GNU General Public License
14:   //  along with this program; if not, write to the Free Software
15:   //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16:  
17:   using System;
18:   using System.Drawing;
19:   using System.Reflection;
20:   using System.Xml;
21:  
22:   using SharpDevelop.Tool.Data;
23:  
24:   namespace SharpDevelop.Internal.Text {
25:       
26:       /// <summary>
27:       /// Specifies the style of an additional line viewer in the textarea.
28:       /// </summary>
29:       public enum LineViewerStyle {
30:           None,
31:           FullRow
32:       }
33:           
34:       public enum IndentStyle {
35:           None
36:           Auto
37:           Smart
38:       };
39:            
40:       public enum BracketHighlightingStyle {
41:           None,
42:           OnBracket
43:           AfterBracket
44:       };
45:       
46:       /// <summary>
47:       /// This class contains all options for the textarea/buffer classes.
48:       /// </summary>
49:       public class BufferOptions : ICloneableIXmlConvertable
50:       {
51:           bool autoinsertcurlybracket true;
52:           bool showeolmarkers   false;
53:           bool showlinenumbers  true;
54:           bool showinvalidlines true;
55:           
56:           bool showbrackethighlight true;
57:           
58:           bool showtabs         false;
59:           bool showspaces       false;
60:           
61:           bool mousewheeldown   true;
62:           
63:           bool showvruler       false;
64:           bool showhruler       false;
65:           int  hrulerrow        80;
66:           
67:           int  tabindent        4;
68:           int  indentationSize  4;
69:           bool tabstospaces     false;
70:           
71:           bool hidemousecursor  false;
72:           
73:           bool cursorbehindeol  false;
74:           
75:           bool useantialiasfont false;
76:           bool showerrors       true;
77:           
78:           bool doublebuffer        true;
79:           bool autoinserttemplates true;
80:           
81:           bool enableCodeCompletion true;
82:           bool enableFolding true;
83:           
84:           LineViewerStyle lineviewerstyle;
85:           IndentStyle     indent    IndentStyle.Smart;
86:           
87:           public event EventHandler OptionChanged;
88:           
89:           public bool EnableFolding {
90:               get {
91:                   return enableFolding;
92:               }
93:               set {
94:                   enableFolding value;
95:               }
96:           }
97:           
98:           public bool EnableCodeCompletion {
99:               get {
100:                   return enableCodeCompletion;
101:               }
102:               set {
103:                   enableCodeCompletion value;
104:               }
105:           }
106:           
107:           public bool DoubleBuffer {
108:               get {
109:                   return doublebuffer;
110:               }
111:               set {
112:                   doublebuffer value;
113:               }
114:           }
115:           
116:           public bool ShowBracketHighlight {
117:               get {
118:                   return showbrackethighlight;
119:               }
120:               set {
121:                   showbrackethighlight value;
122:               }
123:           }
124:           
125:           public bool AutoInsertCurlyBracket {
126:               get {
127:                   return autoinsertcurlybracket;
128:               }
129:               set {
130:                   autoinsertcurlybracket value;
131:                   OnChanged();
132:               }
133:           }
134:           
135:           public bool AutoInsertTemplates {
136:               get {
137:                   return autoinserttemplates;
138:               }
139:               set {
140:                   autoinserttemplates value;
141:                   OnChanged();
142:               }
143:           }
144:           
145:           public Font DefaultFont {
146:               get {
147:                   return FontContainer.DefaultFont;
148:               }
149:               set {
150:                   FontContainer.DefaultFont value;
151:                   OnChanged();
152:               }
153:           }
154:           
155:           public bool ShowErrors {
156:               get {
157:                   return showerrors;
158:               }
159:               set {
160:                   showerrors value;
161:                   OnChanged();
162:               }
163:           }
164:               
165:           public bool UseAntiAliasFont {
166:               get {
167:                   return useantialiasfont;
168:               }
169:               set {
170:                   useantialiasfont value;
171:                   OnChanged();
172:               }
173:           }
174:  
175:           public bool ShowVRuler {
176:               get {
177:                   return showvruler;
178:               }
179:               set {
180:                   showvruler value;
181:                   OnChanged();
182:               }
183:           }
184:           
185:           public LineViewerStyle LineViewerStyle {
186:               get {
187:                   return lineviewerstyle;
188:               }
189:               set {
190:                   lineviewerstyle value;
191:                   OnChanged();
192:               }
193:           }
194:           
195:           public bool CursorBehindEOL {
196:               get {
197:                   return cursorbehindeol;
198:               }
199:               set {
200:                   cursorbehindeol value;
201:                   OnChanged();
202:               }
203:           }
204:           
205:           public bool HideMouseCursor {
206:               get {
207:                   return hidemousecursor;
208:               }
209:               set {
210:                   hidemousecursor value;
211:                   OnChanged();
212:               }
213:           }
214:           
215:           public bool TabsToSpaces {
216:               get {
217:                   return tabstospaces;
218:               }
219:               set {
220:                   tabstospaces value;
221:                   OnChanged();
222:               }
223:           }
224:           
225:           public bool MouseWheelScrollDown {
226:               get {
227:                   return mousewheeldown;
228:               }
229:               set {
230:                   mousewheeldown value;
231:               }
232:           }
233:           
234:           public int IndentationSize {
235:               get {
236:                   return indentationSize;
237:               }
238:               set {
239:                   indentationSize value;
240:               }
241:           }
242:           
243:           public int TabIndent {
244:               get {
245:                   return tabindent;
246:               }
247:               set {
248:                   tabindent value;
249:                   OnChanged();
250:               }
251:           }
252:           
253:           public int HRulerRow {
254:               get {
255:                   return hrulerrow;
256:               }
257:               set {
258:                   hrulerrow value;
259:                   OnChanged();
260:               }
261:           }
262:           
263:           public bool ShowHRuler {
264:               get {
265:                   return showhruler;
266:               }
267:               set {
268:                   showhruler value;
269:                   OnChanged();
270:               }
271:           }
272:           
273:           public IndentStyle IndentStyle {
274:               get {
275:                   return indent;
276:               }
277:               set {
278:                   indent value;
279:                   OnChanged();
280:               }
281:           }
282:           
283:           public bool ShowSpaces {
284:               get {
285:                   return showspaces;
286:               }
287:               set {
288:                   showspaces value;
289:                   OnChanged();
290:               }
291:           }
292:           
293:           public bool ShowTabs {
294:               get {
295:                   return showtabs;
296:               }
297:               set {
298:                   showtabs value;
299:                   OnChanged();
300:               }
301:           }
302:           
303:           public bool ShowEOLMarkers {
304:               get {
305:                   return showeolmarkers;
306:               }
307:               set {
308:                   showeolmarkers value;
309:                   OnChanged();
310:               }
311:           }
312:           
313:           public bool ShowInvalidLines {
314:               get {
315:                   return showinvalidlines;
316:               }
317:               set {
318:                   showinvalidlines value;
319:                   OnChanged();
320:               }
321:           }
322:           
323:           public bool ShowLineNumbers {
324:               get {
325:                   return showlinenumbers;
326:               }
327:               set {
328:                   showlinenumbers value;
329:                   OnChanged();
330:               }
331:           }
332:           
333:           public BufferOptions()
334:           {
335:           }
336:           
337:           public BufferOptions(XmlElement element)
338:           {
339:               if (element == null) {
340:                   throw new ArgumentNullException("element can't be null");
341:               }
342:               PropertyInfo[] properties typeof(BufferOptions).GetProperties();
343:               
344:               foreach (PropertyInfo property in properties) {
345:                   XmlElement el element[property.Name];
346:                   if (el == null)
347:                       continue;
348:                   object     obj null;
349:                   if (property.PropertyType == typeof(bool))
350:                       obj Boolean.Parse(el.InnerText);
351:                   else
352:                   if (property.PropertyType == typeof(int))
353:                       obj Int32.Parse(el.InnerText);
354:                   else
355:                   if (property.PropertyType == typeof(LineViewerStyle))
356:                       obj Enum.Parse(typeof(LineViewerStyle), el.InnerText);
357:                   else
358:                   if (property.PropertyType == typeof(IndentStyle))
359:                       obj Enum.Parse(typeof(IndentStyle), el.InnerText);
360:                   else
361:                   if (property.PropertyType == typeof(Font)) {
362:                       // TODO : font reading
363:                       string txt el.InnerText.Substring(30); // hack to read courier font size
364:                       string nr  "";
365:                       for (int 0< txt.Length;++i)
366:                           if (Char.IsDigit(txt[i]))
367:                               nr += txt[i];
368:                           else
369:                               break;
370:                       DefaultFont new Font("Courier New"Int32.Parse(nr));
371:                       continue;
372:                   }
373:                   else
374:                       throw new ApplicationException("Unknown type in BufferOptions!");
375:                   property.SetValue(thisobjnull);
376:               }
377:           }
378:           
379:           void OnChanged()
380:           {
381:               if (OptionChanged != null)
382:                   OptionChanged(thisnull);
383:           }
384:           
385:           /// <summary>
386:           /// Creates a new object that is a copy of the current instance.
387:           /// </summary>
388:           /// <returns>
389:           /// A new object that is a copy of this instance.
390:           /// </returns>
391:           public object Clone()
392:           {
393:               return MemberwiseClone();
394:           }
395:           
396:           /// <summary>
397:           /// Creates a new object instance of the data from element.
398:           /// </summary>
399:           /// <param name="element">
400:           /// An XmlElement which holds a valid representation of an object state
401:           /// of this class type.
402:           /// </param>
403:           /// <returns>
404:           /// A new object of this type with the state from element.
405:           /// </returns>
406:           public object     FromXmlElement(XmlElement element)
407:           {
408:               return new BufferOptions(element);
409:           }
410:           
411:           /// <summary>
412:           /// This method converts the object state to xml.
413:           /// </summary>
414:           /// <returns>
415:           /// An XmlElement which represents the state of this object.
416:           /// </returns>
417:           public XmlElement ToXmlElement(XmlDocument doc)
418:           {
419:               XmlElement el doc.CreateElement("BufferOptions");
420:               
421:               PropertyInfo[] properties typeof(BufferOptions).GetProperties();
422:               foreach (PropertyInfo property in properties) {
423:                   XmlElement child doc.CreateElement(property.Name);
424:                   child.InnerText property.GetValue(thisnull).ToString();
425:                   el.AppendChild(child);
426:               }
427:               return el;
428:           }
429:       }
430:   }

This page was automatically generated by SharpDevelop.