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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects/MonoDevelop.Projects.Dom.Output/OutputSettings.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
// OutputSettings.cs
 
2
//
 
3
// Author:
 
4
//   Mike Krüger <mkrueger@novell.com>
 
5
//
 
6
// Copyright (c) 2008 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.Text;
 
29
 
 
30
namespace MonoDevelop.Projects.Dom.Output
 
31
{
 
32
        public class OutputSettings
 
33
        {
 
34
                public OutputFlags OutputFlags {
 
35
                        get;
 
36
                        set;
 
37
                }
 
38
                
 
39
                public OutputSettings (OutputFlags outputFlags)
 
40
                {
 
41
                        this.OutputFlags = outputFlags;
 
42
                }
 
43
                
 
44
                public string Markup (string text)
 
45
                {
 
46
                        if (MarkupCallback != null)
 
47
                                return MarkupCallback (text);
 
48
                        return IncludeMarkup ? PangoFormat (text) : text;
 
49
                }
 
50
 
 
51
                public string EmitName (IDomVisitable domVisitable, string text)
 
52
                {
 
53
                        if (EmitNameCallback != null) {
 
54
                                EmitNameCallback (domVisitable, ref text);
 
55
                                return text;
 
56
                        }
 
57
                        return text;
 
58
                }
 
59
                
 
60
                public string EmitModifiers (string text)
 
61
                {
 
62
                        if (!IncludeModifiers)
 
63
                                return string.Empty;
 
64
                        if (EmitModifiersCallback != null)
 
65
                                return EmitModifiersCallback (text + " ");
 
66
                        if (IncludeMarkup)
 
67
                                return "<b>" + PangoFormat (text) + "</b> ";
 
68
                        return text + " ";
 
69
                }
 
70
                
 
71
                public string EmitKeyword (string text)
 
72
                {
 
73
                        if (EmitKeywordCallback != null)
 
74
                                return EmitKeywordCallback (text);
 
75
                        if (!IncludeKeywords)
 
76
                                return "";
 
77
                        if (IncludeMarkup)
 
78
                                return "<b>" + PangoFormat (text) + "</b> ";
 
79
                        return text + " ";
 
80
                }
 
81
                
 
82
                public string Highlight (string text)
 
83
                {
 
84
                        if (HighlightCallback != null)
 
85
                                return HighlightCallback (text);
 
86
                        if (IncludeMarkup)
 
87
                                return "<b>" + PangoFormat (text) + "</b> ";
 
88
                        return text;
 
89
                }
 
90
                
 
91
                public void PostProcess (IDomVisitable domVisitable, ref string outString)
 
92
                {
 
93
                        if (PostProcessCallback != null)
 
94
                                PostProcessCallback (domVisitable, ref outString);
 
95
                }
 
96
                
 
97
                static string PangoFormat (string input)
 
98
                {
 
99
                        StringBuilder result = new StringBuilder ();
 
100
                        foreach (char ch in input) {
 
101
                                switch (ch) {
 
102
                                        case '<':
 
103
                                                result.Append ("&lt;");
 
104
                                                break;
 
105
                                        case '>':
 
106
                                                result.Append ("&gt;");
 
107
                                                break;
 
108
                                        case '&':
 
109
                                                result.Append ("&amp;");
 
110
                                                break;
 
111
                                        default:
 
112
                                                result.Append (ch);
 
113
                                                break;
 
114
                                }
 
115
                        }
 
116
                        return result.ToString ();
 
117
                }
 
118
                        
 
119
                public bool IncludeMarkup {
 
120
                        get {
 
121
                                return (OutputFlags & OutputFlags.IncludeMarkup) == OutputFlags.IncludeMarkup;
 
122
                        }
 
123
                }
 
124
                
 
125
                public bool IncludeKeywords  {
 
126
                        get {
 
127
                                return (OutputFlags & OutputFlags.IncludeKeywords) == OutputFlags.IncludeKeywords;
 
128
                        }
 
129
                }
 
130
                
 
131
                public bool IncludeModifiers {
 
132
                        get {
 
133
                                return (OutputFlags & OutputFlags.IncludeModifiers) == OutputFlags.IncludeModifiers;
 
134
                        }
 
135
                }
 
136
 
 
137
                public bool UseFullName {
 
138
                        get {
 
139
                                return (OutputFlags & OutputFlags.UseFullName) == OutputFlags.UseFullName;
 
140
                        }
 
141
                }
 
142
                
 
143
                public bool IncludeParameters {
 
144
                        get {
 
145
                                return (OutputFlags & OutputFlags.IncludeParameters) == OutputFlags.IncludeParameters;
 
146
                        }
 
147
                }
 
148
 
 
149
                public bool IncludeReturnType {
 
150
                        get {
 
151
                                return (OutputFlags & OutputFlags.IncludeReturnType) == OutputFlags.IncludeReturnType;
 
152
                        }
 
153
                }
 
154
                
 
155
                public bool IncludeParameterName {
 
156
                        get {
 
157
                                return (OutputFlags & OutputFlags.IncludeParameterName) == OutputFlags.IncludeParameterName;
 
158
                        }
 
159
                }
 
160
                
 
161
                public bool IncludeBaseTypes {
 
162
                        get {
 
163
                                return (OutputFlags & OutputFlags.IncludeBaseTypes) == OutputFlags.IncludeBaseTypes;
 
164
                        }
 
165
                }
 
166
                
 
167
                public bool IncludeGenerics {
 
168
                        get {
 
169
                                return (OutputFlags & OutputFlags.IncludeGenerics) == OutputFlags.IncludeGenerics;
 
170
                        }
 
171
                }
 
172
                
 
173
                public bool HighlightName {
 
174
                        get {
 
175
                                return (OutputFlags & OutputFlags.HighlightName) == OutputFlags.HighlightName;
 
176
                        }
 
177
                }
 
178
                
 
179
                public bool HideExtensionsParameter {
 
180
                        get {
 
181
                                return (OutputFlags & OutputFlags.HideExtensionsParameter) == OutputFlags.HideExtensionsParameter;
 
182
                        }
 
183
                }
 
184
                
 
185
                public MarkupText EmitModifiersCallback;
 
186
                public MarkupText EmitKeywordCallback;
 
187
                public MarkupText MarkupCallback;
 
188
                public MarkupText HighlightCallback;
 
189
                public ProcessString EmitNameCallback;
 
190
                
 
191
                public delegate string MarkupText (string text);
 
192
                
 
193
                public ProcessString PostProcessCallback;
 
194
                public delegate void ProcessString (IDomVisitable domVisitable, ref string outString);
 
195
        }
 
196
}