* Makefile.am:
[monodevelop.git] / main / src / addins / AspNetAddIn / MonoDevelop.AspNet.Parser / Directive.cs
blob73aea4c730cd0c8fc7bccdb8d47f4fbbed2522ae
1 //
2 // Directive.cs
3 //
4 // Author:
5 // Michael Hutchinson <mhutchinson@novell.com>
6 //
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.Linq;
31 using System.Collections.Generic;
32 using System.Globalization;
33 using System.Text;
34 using System.Web.UI;
36 using MonoDevelop.Core;
37 using MonoDevelop.Ide.Gui.Content;
38 using MonoDevelop.Projects;
39 using MonoDevelop.Projects.Gui.Completion;
41 using MonoDevelop.AspNet.Completion;
43 namespace MonoDevelop.AspNet.Parser
45 static class DirectiveCompletion
48 // NOTE: MS' documentation for directives is at http://msdn.microsoft.com/en-us/library/t8syafc7.aspx
50 // FIXME: gettextise this
51 public static ICompletionDataList GetDirectives (WebSubtype type)
53 CompletionDataList list = new CompletionDataList ();
55 if (type == WebSubtype.WebForm) {
56 list.Add ("Implements", null, "Declare that this page implements an interface.");
57 list.Add ("Page", null, "Define properties of this page.");
58 list.Add ("PreviousPageType", null, "Strongly type the page's PreviousPage property.");
59 list.Add ("MasterType", null, "Strongly type the page's Master property.");
60 } else if (type == WebSubtype.MasterPage) {
61 list.Add ("Implements", null, "Declare that this master page implements an interface.");
62 list.Add ("Master", null, "Define properties of this master page.");
63 list.Add ("MasterType", null, "Strongly type the page's Master property.");
64 } else if (type == WebSubtype.WebControl) {
65 list.Add ("Control", null, "Define properties of this user control.");
66 list.Add ("Implements", null, "Declare that this control implements an interface.");
67 } else {
68 return null;
71 list.Add ("Assembly", null, "Reference an assembly.");
72 list.Add ("Import", null, "Import a namespace.");
74 if (type != WebSubtype.MasterPage) {
75 list.Add ("OutputCache", null, "Set output caching behaviour.");
78 list.Add ("Reference", null, "Reference a page or user control.");
79 list.Add ("Register", null, "Register a user control or custom web controls.");
81 return list.Count > 0? list : null;
85 public static void GetAttributeValues (CompletionDataList list, string directiveName, string attribute, ClrVersion clrVersion)
87 switch (directiveName.ToLower ()) {
88 case "page":
89 GetPageAttributeValues (list, attribute, clrVersion);
90 break;
94 public static void GetAttributes (CompletionDataList list, string directiveName,
95 ClrVersion clrVersion, Dictionary<string, string> existingAtts)
97 bool net20 = clrVersion != ClrVersion.Net_1_1;
99 //FIXME: detect whether the page is VB
100 bool vb = false;
102 switch (directiveName.ToLower ()) {
103 case "page":
104 ExclusiveAdd (list, existingAtts, page11Attributes);
105 if (net20)
106 ExclusiveAdd (list, existingAtts, page20Attributes);
107 if (vb)
108 ExclusiveAdd (list, existingAtts, pageVBAttributes);
109 MutexAdd (list, existingAtts, page11MutexAttributes);
110 break;
112 case "control":
113 ExclusiveAdd (list, existingAtts, userControlAttributes);
114 if (vb)
115 ExclusiveAdd (list, existingAtts, pageVBAttributes);
116 break;
118 case "master":
119 ExclusiveAdd (list, existingAtts, userControlAttributes);
120 ExclusiveAdd (list, existingAtts, masterControlAttributes);
121 if (vb)
122 ExclusiveAdd (list, existingAtts, pageVBAttributes);
123 break;
125 case "mastertype":
126 MutexAdd (list, existingAtts, mastertypeAttributes);
127 break;
129 case "assembly":
130 //the two assembly directive attributes are mutually exclusive
131 MutexAdd (list, existingAtts, assemblyAttributes);
132 break;
134 case "import":
135 ExclusiveAdd (list, existingAtts, importAttributes);
136 break;
138 case "reference":
139 MutexAdd (list, existingAtts, referenceAttributes);
140 break;
142 case "register":
143 foreach (string s in registerAssemblyAttributes)
144 if (existingAtts.ContainsKey (s))
147 ExclusiveAdd (list, existingAtts, registerAttributes);
148 break;
150 case "outputcache":
151 ExclusiveAdd (list, existingAtts, outputcacheAttributes);
152 break;
154 case "previouspagetype":
155 MutexAdd (list, existingAtts, previousPageTypeAttributes);
156 break;
158 case "implements":
159 ExclusiveAdd (list, existingAtts, implementsAttributes);
160 break;
164 static void ExclusiveAdd (CompletionDataList list, Dictionary<string, string> existingAtts,
165 IEnumerable<string> values)
167 foreach (string s in values)
168 if (!existingAtts.ContainsKey (s))
169 list.Add (s);
172 static void MutexAdd (CompletionDataList list, Dictionary<string, string> existingAtts,
173 IEnumerable<string> mutexValues)
175 foreach (string s in mutexValues)
176 if (existingAtts.ContainsKey (s))
177 return;
178 foreach (string s in mutexValues)
179 list.Add (s);
182 static void GetPageAttributeValues (CompletionDataList list, string attribute, ClrVersion clrVersion)
184 switch (attribute.ToLower ()) {
187 //boolean, default to false
189 case "async":
190 case "aspcompat":
191 case "explicit": // useful for VB only. set to true in machine.config
192 case "maintainscrollpositiononpostback":
193 case "linepragmas": //actually not sure if this defaults true or false
194 case "smartnavigation":
195 case "strict": //VB ONLY
196 case "trace":
197 SimpleList.AddBoolean (list, false);
198 return;
201 //boolean, default to true
203 case "autoeventwireup":
204 case "buffer":
205 case "enableeventvalidation":
206 case "enablesessionstate":
207 case "enabletheming":
208 case "enableviewstate":
209 case "enableviewstatemac":
210 case "validaterequest": //enabled in machine.config
211 case "debug":
212 SimpleList.AddBoolean (list, true);
213 return;
216 //specialised hard value list completions
218 case "codepage":
219 list.AddRange (from e in Encoding.GetEncodings () select e.CodePage.ToString ());
220 list.DefaultCompletionString = Encoding.UTF8.CodePage.ToString ();
221 return;
223 case "compilationmode":
224 SimpleList.AddEnum (list, System.Web.UI.CompilationMode.Always);
225 return;
227 case "culture":
228 list.AddRange (from c in CultureInfo.GetCultures (CultureTypes.AllCultures) select c.Name);
229 list.DefaultCompletionString = CultureInfo.CurrentCulture.Name;
230 return;
232 case "lcid":
233 // locale ID, MUTUALLY EXCLUSIVE with Culture
234 list.AddRange (from c in CultureInfo.GetCultures (CultureTypes.AllCultures)
235 select c.LCID.ToString ());
236 list.DefaultCompletionString = CultureInfo.CurrentCulture.LCID.ToString ();
237 return;
239 case "responseencoding":
240 list.AddRange (from e in Encoding.GetEncodings () select e.Name);
241 list.DefaultCompletionString = Encoding.UTF8.EncodingName;
242 return;
244 case "tracemode":
245 list.Add ("SortByTime");
246 list.Add ("SortByCategory");
247 list.DefaultCompletionString = "SortByTime";
248 return;
250 case "transaction":
251 list.Add ("Disabled");
252 list.Add ("NotSupported");
253 list.Add ("Required");
254 list.Add ("RequiresNew");
255 list.DefaultCompletionString = "Disabled";
256 return;
258 case "viewstateencryptionmode":
259 SimpleList.AddEnum (list, ViewStateEncryptionMode.Auto);
260 return;
262 case "warninglevel":
263 list.AddRange (new string[] {"0", "1", "2", "3", "4"});
264 list.DefaultCompletionString = "0";
265 return;
268 //we can probably complete these using info from the project, but not yet
271 case "CodeFile":
272 //source file to compile for codebehind on server
273 case "ContentType":
274 //string, HTTP MIME content-type
275 case "CodeFileBaseClass":
276 // known base class for the partial classes, so code generator knows not
277 //to redefine fields to ignore members in partial class
278 case "ErrorPage":
279 // string, URL
280 case "Inherits":
281 // IType : Page. defaults to namespace from ClassName
282 case "Language":
283 // string, any available .NET langauge
284 case "MasterPageFile":
285 // master page path
286 case "Src":
287 // string, extra source code for page
288 case "StyleSheetTheme":
289 // theme ID, can be overridden by controls
290 case "Theme":
291 // theme identifier, overrides controls' themes
292 case "UICulture":
293 // string, valid UI culture
297 //we're not likely to suggest anything for these:
300 case "AsyncTimeOut":
301 // int in seconds, default 45
302 case "ClassName":
303 //string, .NET name, default namespace ASP
304 case "ClientTarget":
305 //string, user agent
306 case "CodeBehind":
307 //valid but IGNORE. VS-only
308 case "CompilerOptions":
309 //string, list of compiler switches
310 case "Description":
311 // string, pointless
312 case "TargetSchema":
313 // schema to validate page content. IGNORED, so rather pointless
314 case "Title":
315 // string for <title>
320 #region Attribute lists
322 static string[] page11Attributes = new string[] {
323 "Async", "AspCompat", "AsyncTimeOut","Buffer", "ClientTarget", "CodeBehind", "CompilerOptions",
324 "CodeFile", "CodePage", "CompilationMode", "ContentType", "CodeFileBaseClass",
325 "Debug", "Description", "EnableSessionState", "EnableTheming", "EnableViewState", "EnableViewStateMac",
326 "ErrorPage", "Inherits", "Language", "LinePragmas", "MasterPageFile", "ResponseEncoding",
327 "SmartNavigation", "Src", "StyleSheetTheme", "Theme", "TargetSchema", "Title", "Trace", "TraceMode",
328 "Transaction", "UICulture", "ValidateRequest", "ViewStateEncryptionMode", "WarningLevel"
331 static string[] page11MutexAttributes = new string[] {
332 "LCID", "Culture"
335 static string[] page20Attributes = new string[] {
336 "EnableEventValidation", "MaintainScrollPositionOnPostback"
339 static string[] pageVBAttributes = new string[] {
340 "Explicit", "Strict"
343 static string[] userControlAttributes = new string[] {
344 "AutoEventWireup", "ClassName", "CodeBehind", "CodeFile", "CodeFileBaseClass", "CompilationMode",
345 "CompilerOptions", "Debug", "Description", "EnableTheming", "EnableViewState", "Inherits", "Language",
346 "LinePragmas", "Src", "TargetSchema", "WarningLevel"
349 static string[] masterControlAttributes = new string[] { "MasterPageFile" };
351 static string[] assemblyAttributes = new string[] {
352 //mutually exclusive
353 "Name", //assembly name to link
354 "Src" //source file name to compile and link
357 static string[] importAttributes = new string[] {
358 "Namespace",
361 static string[] referenceAttributes = new string[] {
362 //one of:
363 "Page",
364 "Control",
365 "VirtualPath"
368 static string[] registerAttributes = new string[] {
369 "TagPrefix"
372 static string[] registerAssemblyAttributes = new string[] {
373 "Assembly", //assembly name from bin directory
374 "Namespace", //if no assembly, assumes App_Code
377 static string[] registerUserControlAttributes = new string[] {
378 "Src", //user controls only. Start with ~ for app root
379 "TagName" //user controls only
382 static string[] outputcacheAttributes = new string[] {
383 "Duration", //seconds, required
384 "Location", //OutputCacheLocation enum, default "Any". aspx-only
385 "CacheProfile", // arbitrary string from config outputCacheSettings/outputCacheProfiles. aspx-only
386 "NoStore", // bool. aspx-only
387 "Shared", //bool, default true. ascx-only
388 "SqlDependency", //string of tables and stuff, or "CommandNotification on aspx
389 "VaryByCustom", // custom requirement. "browser" varies by user agent. Other strings should be handled in GetVaryByCustomString Globl.asax
390 "VaryByHeader", // HTTP headers in a semicolon-separated list. Each combination is cached. aspx-only
391 "VaryByParam", // none or *, or semicolon-separated list of GET/POST parameters. Required or VaryByControl.
392 "VaryByControl", // IDs of server controls, in a semicolon-separated list. Required or VaryByParam.
393 "VaryByContentEncodings" //list of Accept-Encoding encodings
396 static string[] mastertypeAttributes = new string[] {
397 //only one allowed
398 "TypeName", //name of type
399 "VirtualPath" //path to strong type
402 static string[] previousPageTypeAttributes = new string[] {
403 "TypeName", "VirtualPath"
406 static string[] implementsAttributes = new string[] {
407 "Interface"
410 #endregion