예제 #1
0
        void AddAspAttributeCompletionData(CompletionDataList list, S.XName name, Dictionary <string, string> existingAtts)
        {
            Debug.Assert(name.IsValid);
            Debug.Assert(name.HasPrefix);

            var database = TypeSystemService.GetCompilation(project);

            if (database == null)
            {
                LoggingService.LogWarning("Could not obtain project DOM in AddAspAttributeCompletionData");
                return;
            }

            IType controlClass = refman.GetControlType(name.Prefix, name.Name);

            if (controlClass == null)
            {
                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;
                }
            }

            AddControlMembers(list, controlClass, existingAtts);
        }
예제 #2
0
        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;
                }
            }
        }
예제 #3
0
        /*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;
            }
        }
		bool IsServerScriptTag (S.XElement el)
		{
			if (el.Name.FullName == "script") {
				S.XName runat = new S.XName ("runat");
				foreach (S.XAttribute attr in el.Attributes) {
					if ((attr.Name.ToLower () == runat) && (attr.Value.ToLower () == "server"))
						return true;
				}
			}
			return false;
		}