5 // Michael Hutchinson <mhutchinson@novell.com>
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System
.Collections
.Generic
;
32 using System
.Globalization
;
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.");
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 ()) {
89 GetPageAttributeValues (list
, attribute
, clrVersion
);
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
102 switch (directiveName
.ToLower ()) {
104 ExclusiveAdd (list
, existingAtts
, page11Attributes
);
106 ExclusiveAdd (list
, existingAtts
, page20Attributes
);
108 ExclusiveAdd (list
, existingAtts
, pageVBAttributes
);
109 MutexAdd (list
, existingAtts
, page11MutexAttributes
);
113 ExclusiveAdd (list
, existingAtts
, userControlAttributes
);
115 ExclusiveAdd (list
, existingAtts
, pageVBAttributes
);
119 ExclusiveAdd (list
, existingAtts
, userControlAttributes
);
120 ExclusiveAdd (list
, existingAtts
, masterControlAttributes
);
122 ExclusiveAdd (list
, existingAtts
, pageVBAttributes
);
126 MutexAdd (list
, existingAtts
, mastertypeAttributes
);
130 //the two assembly directive attributes are mutually exclusive
131 MutexAdd (list
, existingAtts
, assemblyAttributes
);
135 ExclusiveAdd (list
, existingAtts
, importAttributes
);
139 MutexAdd (list
, existingAtts
, referenceAttributes
);
143 foreach (string s
in registerAssemblyAttributes
)
144 if (existingAtts
.ContainsKey (s
))
147 ExclusiveAdd (list
, existingAtts
, registerAttributes
);
151 ExclusiveAdd (list
, existingAtts
, outputcacheAttributes
);
154 case "previouspagetype":
155 MutexAdd (list
, existingAtts
, previousPageTypeAttributes
);
159 ExclusiveAdd (list
, existingAtts
, implementsAttributes
);
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
))
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
))
178 foreach (string s
in mutexValues
)
182 static void GetPageAttributeValues (CompletionDataList list
, string attribute
, ClrVersion clrVersion
)
184 switch (attribute
.ToLower ()) {
187 //boolean, default to false
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
197 SimpleList
.AddBoolean (list
, false);
201 //boolean, default to true
203 case "autoeventwireup":
205 case "enableeventvalidation":
206 case "enablesessionstate":
207 case "enabletheming":
208 case "enableviewstate":
209 case "enableviewstatemac":
210 case "validaterequest": //enabled in machine.config
212 SimpleList
.AddBoolean (list
, true);
216 //specialised hard value list completions
219 list
.AddRange (from e
in Encoding
.GetEncodings () select e
.CodePage
.ToString ());
220 list
.DefaultCompletionString
= Encoding
.UTF8
.CodePage
.ToString ();
223 case "compilationmode":
224 SimpleList
.AddEnum (list
, System
.Web
.UI
.CompilationMode
.Always
);
228 list
.AddRange (from c
in CultureInfo
.GetCultures (CultureTypes
.AllCultures
) select c
.Name
);
229 list
.DefaultCompletionString
= CultureInfo
.CurrentCulture
.Name
;
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 ();
239 case "responseencoding":
240 list
.AddRange (from e
in Encoding
.GetEncodings () select e
.Name
);
241 list
.DefaultCompletionString
= Encoding
.UTF8
.EncodingName
;
245 list
.Add ("SortByTime");
246 list
.Add ("SortByCategory");
247 list
.DefaultCompletionString
= "SortByTime";
251 list
.Add ("Disabled");
252 list
.Add ("NotSupported");
253 list
.Add ("Required");
254 list
.Add ("RequiresNew");
255 list
.DefaultCompletionString
= "Disabled";
258 case "viewstateencryptionmode":
259 SimpleList
.AddEnum (list
, ViewStateEncryptionMode
.Auto
);
263 list
.AddRange (new string[] {"0", "1", "2", "3", "4"}
);
264 list
.DefaultCompletionString
= "0";
268 //we can probably complete these using info from the project, but not yet
272 //source file to compile for codebehind on server
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
281 // IType : Page. defaults to namespace from ClassName
283 // string, any available .NET langauge
284 case "MasterPageFile":
287 // string, extra source code for page
288 case "StyleSheetTheme":
289 // theme ID, can be overridden by controls
291 // theme identifier, overrides controls' themes
293 // string, valid UI culture
297 //we're not likely to suggest anything for these:
301 // int in seconds, default 45
303 //string, .NET name, default namespace ASP
307 //valid but IGNORE. VS-only
308 case "CompilerOptions":
309 //string, list of compiler switches
313 // schema to validate page content. IGNORED, so rather pointless
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[] {
335 static string[] page20Attributes
= new string[] {
336 "EnableEventValidation", "MaintainScrollPositionOnPostback"
339 static string[] pageVBAttributes
= new string[] {
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[] {
353 "Name", //assembly name to link
354 "Src" //source file name to compile and link
357 static string[] importAttributes
= new string[] {
361 static string[] referenceAttributes
= new string[] {
368 static string[] registerAttributes
= new string[] {
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[] {
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[] {