public IEnumerable <CompletionData> GetControlCompletionData(IType baseType) { bool isSWC = baseType.FullName == "System.Web.UI.Control"; string aspPrefix = "asp:"; foreach (IType cls in WebTypeContext.ListSystemControlClasses(baseType, Project)) { yield return(new AspTagCompletionData(aspPrefix, cls)); } foreach (var rd in RegisteredTags) { if (!rd.IsValid()) { continue; } var ard = rd as AssemblyRegisterDirective; if (ard != null) { var dom = TypeCtx.ResolveAssembly(ard.Assembly); if (dom == null) { continue; } string prefix = ard.TagPrefix + ":"; foreach (IType cls in WebTypeContext.ListControlClasses(baseType, dom, ard.Namespace)) { yield return(new AspTagCompletionData(prefix, cls)); } continue; } if (!isSWC) { continue; } ControlRegisterDirective cd = rd as ControlRegisterDirective; if (cd != null) { yield return(new CompletionData(string.Concat(cd.TagPrefix, ":", cd.TagName), Gtk.Stock.GoForward)); } } //return controls from web.config foreach (var cd in TypeCtx.GetRegisteredTypeCompletionData(DirectoryPath, baseType)) { yield return(cd); } }
public string GetTypeName(string tagPrefix, string tagName, string htmlTypeAttribute) { if (tagPrefix == null || tagPrefix.Length < 1) { return(WebTypeContext.HtmlControlLookup(tagName, htmlTypeAttribute)); } if (0 == string.Compare(tagPrefix, "asp", StringComparison.OrdinalIgnoreCase)) { string systemType = TypeCtx.SystemTypeNameLookup(tagName); if (!string.IsNullOrEmpty(systemType)) { return(systemType); } } foreach (var rd in RegisteredTags) { if (string.Compare(rd.TagPrefix, tagPrefix, StringComparison.OrdinalIgnoreCase) != 0) { continue; } var ard = rd as AssemblyRegisterDirective; if (ard != null) { var dom = TypeCtx.ResolveAssembly(ard.Assembly); if (dom == null) { continue; } string fullName = WebTypeContext.AssemblyTypeNameLookup(dom, ard.Namespace, tagName); if (fullName != null) { return(fullName); } } var crd = rd as ControlRegisterDirective; if (crd != null && string.Compare(crd.TagName, tagName, StringComparison.OrdinalIgnoreCase) == 0) { string fullName = TypeCtx.GetUserControlTypeName(crd.Src, Doc.FileName); if (fullName != null) { return(fullName); } } } //returns null if type not found return(TypeCtx.GetRegisteredTypeName(DirectoryPath, tagPrefix, tagName)); }
public IType GetControlType(string tagPrefix, string tagName) { if (String.IsNullOrEmpty(tagPrefix)) { return(null); } IType type = null; if (0 == string.Compare(tagPrefix, "asp", StringComparison.OrdinalIgnoreCase)) { type = TypeCtx.SystemTypeLookup(tagName); if (type != null) { return(type); } } foreach (var rd in RegisteredTags) { if (string.Compare(rd.TagPrefix, tagPrefix, StringComparison.OrdinalIgnoreCase) != 0) { continue; } AssemblyRegisterDirective ard = rd as AssemblyRegisterDirective; if (ard != null) { string assembly = ard.Assembly; var dom = TypeCtx.ResolveAssembly(ard.Assembly); if (dom == null) { continue; } type = WebTypeContext.AssemblyTypeLookup(dom, ard.Namespace, tagName); if (type != null) { return(type); } continue; } var crd = rd as ControlRegisterDirective; if (crd != null && string.Compare(crd.TagName, tagName, StringComparison.OrdinalIgnoreCase) == 0) { return(TypeCtx.GetUserControlType(crd.Src, Doc.FileName)); } } //returns null if type not found return(TypeCtx.GetRegisteredType(DirectoryPath, tagPrefix, tagName)); }
public DocumentReferenceManager(AspNetAppProject project) { this.Project = project; TypeCtx = new WebTypeContext(project); }
void AddAspAttributeValueCompletionData(CompletionDataList list, S.XName tagName, S.XName attName, string id) { Debug.Assert(tagName.IsValid && tagName.HasPrefix); Debug.Assert(attName.IsValid && !attName.HasPrefix); IType controlClass = HasDoc ? refman.GetControlType(tagName.Prefix, tagName.Name) : null; if (controlClass == null) { LoggingService.LogWarning("Could not obtain IType for {0}", tagName.FullName); var database = WebTypeContext.GetSystemWebDom(project); controlClass = ReflectionHelper.ParseReflectionName("System.Web.UI.WebControls.WebControl").Resolve(database); if (controlClass == null) { LoggingService.LogWarning("Could not obtain IType for System.Web.UI.WebControls.WebControl"); return; } } //find the codebehind class IType codeBehindClass; ICompilation projectDatabase; GetCodeBehind(out codeBehindClass, out projectDatabase); //if it's an event, suggest compatible methods if (codeBehindClass != null && attName.Name.StartsWith("On")) { string eventName = attName.Name.Substring(2); foreach (IEvent ev in controlClass.GetEvents()) { if (ev.Name == eventName) { var domMethod = BindingService.MDDomToCodeDomMethod(ev); if (domMethod == null) { return; } foreach (IMethod meth in BindingService.GetCompatibleMethodsInClass(codeBehindClass, ev)) { list.Add(meth.Name, "md-method", GettextCatalog.GetString("A compatible method in the CodeBehind class")); } string suggestedIdentifier = ev.Name; if (id != null) { suggestedIdentifier = id + "_" + suggestedIdentifier; } else { suggestedIdentifier = tagName.Name + "_" + suggestedIdentifier; } domMethod.Name = BindingService.GenerateIdentifierUniqueInClass (codeBehindClass, suggestedIdentifier); domMethod.Attributes = (domMethod.Attributes & ~System.CodeDom.MemberAttributes.AccessMask) | System.CodeDom.MemberAttributes.Family; list.Add( new SuggestedHandlerCompletionData(project, domMethod, codeBehindClass, MonoDevelop.DesignerSupport.CodeBehind.GetNonDesignerClass(codeBehindClass)) ); return; } } } if (projectDatabase == null) { projectDatabase = WebTypeContext.GetSystemWebDom(project); if (projectDatabase == null) { LoggingService.LogWarning("Could not obtain type database in AddAspAttributeCompletionData"); return; } } //if it's a property and is an enum or bool, suggest valid values foreach (IProperty prop in controlClass.GetProperties()) { if (prop.Name != attName.Name) { continue; } //boolean completion if (prop.ReturnType.Equals(projectDatabase.FindType(KnownTypeCode.Boolean))) { AddBooleanCompletionData(list); return; } //color completion if (prop.ReturnType.Equals(projectDatabase.FindType(typeof(System.Drawing.Color)))) { System.Drawing.ColorConverter conv = new System.Drawing.ColorConverter(); foreach (System.Drawing.Color c in conv.GetStandardValues(null)) { if (c.IsSystemColor) { continue; } string hexcol = string.Format("#{0:x2}{1:x2}{2:x2}", c.R, c.G, c.B); list.Add(c.Name, hexcol); } return; } //enum completion IType retCls = prop.ReturnType; if (retCls != null && retCls.Kind == TypeKind.Enum) { foreach (var enumVal in retCls.GetFields()) { if (enumVal.IsPublic && enumVal.IsStatic) { list.Add(enumVal.Name, "md-literal", AmbienceService.GetSummaryMarkup(enumVal)); } } return; } } }
/*public override void RunParameterCompletionCommand () * { * if (localDocumentInfo == null) { * base.RunParameterCompletionCommand (); * return; * } * var doc = document; * document = localDocumentInfo.HiddenDocument; * var cw = CompletionWidget; * CompletionWidget = documentBuilder.CreateCompletionWidget (localDocumentInfo); * try { * base.RunParameterCompletionCommand (); * } finally { * document = doc; * CompletionWidget = cw; * } * }*/ protected override void GetElementCompletions(CompletionDataList list) { S.XName parentName = GetParentElementName(0); //fallback if (!HasDoc) { AddAspBeginExpressions(list); string aspPrefix = "asp:"; var type = ReflectionHelper.ParseReflectionName("System.Web.UI.Control").Resolve(TypeSystemService.GetCompilation(project)); foreach (var cls in WebTypeContext.ListSystemControlClasses(type, project)) { list.Add(new AspTagCompletionData(aspPrefix, cls)); } base.GetElementCompletions(list); return; } IType controlClass = null; if (parentName.HasPrefix) { controlClass = refman.GetControlType(parentName.Prefix, parentName.Name); } else { S.XName grandparentName = GetParentElementName(1); if (grandparentName.IsValid && grandparentName.HasPrefix) { controlClass = refman.GetControlType(grandparentName.Prefix, grandparentName.Name); } } //we're just in HTML if (controlClass == null) { //root element? if (!parentName.IsValid) { if (aspDoc.Info.Subtype == WebSubtype.WebControl) { AddHtmlTagCompletionData(list, Schema, new S.XName("div")); AddAspBeginExpressions(list); list.AddRange(refman.GetControlCompletionData()); AddMiscBeginTags(list); } else if (!string.IsNullOrEmpty(aspDoc.Info.MasterPageFile)) { //FIXME: add the actual region names list.Add(new CompletionData("asp:Content")); } } else { AddAspBeginExpressions(list); list.AddRange(refman.GetControlCompletionData()); base.GetElementCompletions(list); } return; } string defaultProp; bool childrenAsProperties = AreChildrenAsProperties(controlClass, out defaultProp); if (defaultProp != null && defaultProp.Length == 0) { defaultProp = null; } //parent permits child controls directly if (!childrenAsProperties) { AddAspBeginExpressions(list); list.AddRange(refman.GetControlCompletionData()); AddMiscBeginTags(list); //TODO: get correct parent for Content tags AddHtmlTagCompletionData(list, Schema, new S.XName("body")); return; } //children of properties if (childrenAsProperties && (!parentName.HasPrefix || defaultProp != null)) { if (controlClass.GetProjectContent() == null) { LoggingService.LogWarning("IType {0} does not have a SourceProjectDom", controlClass); return; } string propName = defaultProp ?? parentName.Name; IProperty property = controlClass.GetProperties() .Where(x => string.Compare(propName, x.Name, StringComparison.OrdinalIgnoreCase) == 0) .FirstOrDefault(); if (property == null) { return; } //sanity checks on attributes switch (GetPersistenceMode(property)) { case System.Web.UI.PersistenceMode.Attribute: case System.Web.UI.PersistenceMode.EncodedInnerDefaultProperty: return; case System.Web.UI.PersistenceMode.InnerDefaultProperty: if (!parentName.HasPrefix) { return; } break; case System.Web.UI.PersistenceMode.InnerProperty: if (parentName.HasPrefix) { return; } break; } //check if allows freeform ASP/HTML content if (property.ReturnType.ToString() == "System.Web.UI.ITemplate") { AddAspBeginExpressions(list); AddMiscBeginTags(list); AddHtmlTagCompletionData(list, Schema, new S.XName("body")); list.AddRange(refman.GetControlCompletionData()); return; } //FIXME:unfortunately ASP.NET doesn't seem to have enough type information / attributes //to be able to resolve the correct child types here //so we assume it's a list and have a quick hack to find arguments of strongly typed ILists IType collectionType = property.ReturnType; if (collectionType == null) { list.AddRange(refman.GetControlCompletionData()); return; } string addStr = "Add"; IMethod meth = collectionType.GetMethods() .Where(m => m.Parameters.Count == 1 && m.Name == addStr).FirstOrDefault(); if (meth != null) { IType argType = meth.Parameters [0].Type; var type = ReflectionHelper.ParseReflectionName("System.Web.UI.Control").Resolve(argType.GetDefinition().Compilation); if (argType != null && argType.IsBaseType(type)) { list.AddRange(refman.GetControlCompletionData(argType)); return; } } list.AddRange(refman.GetControlCompletionData()); return; } //properties as children of controls if (parentName.HasPrefix && childrenAsProperties) { if (controlClass.GetProjectContent() == null) { LoggingService.LogWarning("IType {0} does not have a SourceProjectDom", controlClass); } foreach (IProperty prop in GetUniqueMembers <IProperty> (controlClass.GetProperties())) { if (GetPersistenceMode(prop) != System.Web.UI.PersistenceMode.Attribute) { list.Add(prop.Name, prop.GetStockIcon(), AmbienceService.GetSummaryMarkup(prop)); } } return; } }
public DocumentReferenceManager (AspNetAppProject project) { this.Project = project; TypeCtx = new WebTypeContext (project); }