protected override CompletionDataList GetAttributeValueCompletions(IAttributedXObject attributedOb, XAttribute att)
        {
            var list = base.GetAttributeValueCompletions(attributedOb, att) ?? new CompletionDataList();
            var ctx  = document.Compilation;

            GetType(attributedOb, delegate(IType type, ICompilation dom) {
                foreach (IProperty prop in type.GetProperties())
                {
                    if (prop.Name != att.Name.FullName)
                    {
                        continue;
                    }

                    //boolean completion
                    if (prop.ReturnType.Equals(ctx.FindType(typeof(bool))))
                    {
                        list.Add("true", "md-literal");
                        list.Add("false", "md-literal");
                        return;
                    }

                    //color completion
                    if (prop.ReturnType.ReflectionName == "System.Windows.Media.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
                    var 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", enumVal.Documentation);
                            }
                        }
                        return;
                    }
                }
            });
            return(list.Count > 0? list : null);
        }
示例#2
0
        protected override CompletionDataList GetAttributeValueCompletions(IAttributedXObject attributedOb, XAttribute att)
        {
            var list = base.GetAttributeValueCompletions(attributedOb, att) ?? new CompletionDataList();

            GetType(attributedOb, delegate(IType type, ProjectDom dom) {
                foreach (IProperty prop in GetAllProperties(dom, type))
                {
                    if (prop.Name != att.Name.FullName)
                    {
                        continue;
                    }

                    //boolean completion
                    if (prop.ReturnType.FullName == "System.Boolean")
                    {
                        list.Add("true", "md-literal");
                        list.Add("false", "md-literal");
                        return;
                    }

                    //color completion
                    if (prop.ReturnType.FullName == "System.Windows.Media.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
                    MonoDevelop.Projects.Dom.IType retCls = dom.GetType(prop.ReturnType);
                    if (retCls != null && retCls.ClassType == MonoDevelop.Projects.Dom.ClassType.Enum)
                    {
                        foreach (MonoDevelop.Projects.Dom.IField enumVal in retCls.Fields)
                        {
                            if (enumVal.IsPublic && enumVal.IsStatic)
                            {
                                list.Add(enumVal.Name, "md-literal", enumVal.Documentation);
                            }
                        }
                        return;
                    }
                }
            });
            return(list.Count > 0? list : null);
        }
        void AddAspAttributeValueCompletionData(CompletionDataList list, XName tagName, XName attName, string id)
        {
            Debug.Assert(tagName.IsValid && tagName.HasPrefix);
            Debug.Assert(attName.IsValid && !attName.HasPrefix);

            INamedTypeSymbol controlClass = refman.GetControlType(tagName.Prefix, tagName.Name);

            if (controlClass == null)
            {
                return;
            }

            //find the codebehind class
            INamedTypeSymbol codeBehindClass;

            GetCodeBehind(out codeBehindClass);

            //if it's an event, suggest compatible methods
            if (codeBehindClass != null && attName.Name.StartsWith("On", StringComparison.Ordinal))
            {
                string eventName = attName.Name.Substring(2);

                foreach (IEventSymbol ev in controlClass.GetAccessibleMembersInThisAndBaseTypes <IEventSymbol> (controlClass))
                {
                    if (ev.Name == eventName)
                    {
                        var domMethod = BindingService.MDDomToCodeDomMethod(ev);
                        if (domMethod == null)
                        {
                            return;
                        }

                        foreach (IMethodSymbol 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,
                                                               CodeBehind.GetNonDesignerClassLocation(codeBehindClass))
                            );
                        return;
                    }
                }
            }

            //if it's a property and is an enum or bool, suggest valid values
            foreach (IPropertySymbol prop in GetAllMembers <IPropertySymbol> (controlClass))
            {
                if (prop.Name != attName.Name)
                {
                    continue;
                }

                //boolean completion
                if (prop.GetReturnType().Equals(refman.Compilation.GetTypeByMetadataName("System.Boolean")))
                {
                    AddBooleanCompletionData(list);
                    return;
                }
                //color completion
                if (prop.GetReturnType().Equals(refman.Compilation.GetTypeByMetadataName("System.Drawing.Color")))
                {
                    var 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
                var retCls = prop.GetReturnType() as INamedTypeSymbol;
                if (retCls != null && retCls.TypeKind == TypeKind.Enum)
                {
                    foreach (var enumVal in GetAllMembers <IFieldSymbol> (retCls))
                    {
                        if (enumVal.DeclaredAccessibility == Accessibility.Public && enumVal.IsStatic)
                        {
                            list.Add(enumVal.Name, "md-literal", Ambience.GetSummaryMarkup(enumVal));
                        }
                    }
                    return;
                }
            }
        }
示例#4
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;
                }
            }
        }
示例#5
0
        public async Task ChangeRole(params string[] args)
        {
            if (args.Length < 2)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Insufficient Parameters",
                    Description = $"The way to use the command is `{await SqliteClass.PrefixGetter(Context.Guild.Id)}color <@role> <color>`",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }
            var role = GetRole(args[0]);

            if (role == null)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "That role is invalid",
                    Description = $"I couldn't parse `{args[0]}` as a role!",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }
            if (!(Context.User as SocketGuildUser).Roles.Any(rl => rl.Position > role.Position) && Context.Guild.OwnerId != Context.User.Id && Context.User.Id != 701029647760097361 && Context.User.Id != 615873008959225856)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Oops!",
                    Description = "You're below the role you want to edit!",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }
            if (args[1].ToLower() == "none" || args[1].ToLower() == "invisible")
            {
                await role.ModifyAsync(x => x.Color = new Color());
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Done!!",
                    Description = $"The role {role.Name}'s color is removed!",
                    Color       = Blurple
                }.WithCurrentTimestamp());

                return;
            }
            System.Drawing.ColorConverter c   = new System.Drawing.ColorConverter();
            System.Drawing.Color          col = new System.Drawing.Color();
            bool hasC   = false;
            var  hArgs1 = args[1][0] != '#' ? $"#{args[1]}" : args[1];

            if (Regex.IsMatch(hArgs1, "^(#[0-9A-Fa-f]{3})$|^(#[0-9A-Fa-f]{6})$"))
            {
                col  = (System.Drawing.Color)c.ConvertFromString(hArgs1);
                hasC = true;
            }
            else
            {
                System.ComponentModel.TypeConverter.StandardValuesCollection svc = (System.Drawing.ColorConverter.StandardValuesCollection)c.GetStandardValues();
                foreach (System.Drawing.Color o in svc)
                {
                    if (o.Name.Equals(args[1], StringComparison.OrdinalIgnoreCase))
                    {
                        col  = (System.Drawing.Color)c.ConvertFromString(args[1]);
                        hasC = true;
                    }
                }
            }
            if (hasC == false)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "What color??",
                    Description = $"Couldn't parse `{args[1]}` as a color!",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }
            await role.ModifyAsync(x => x.Color = new Color(col.R, col.G, col.B));

            await ReplyAsync("", false, new EmbedBuilder
            {
                Title       = "Done!!",
                Description = $"The role {role.Name} is now set to the color of this embed!",
                Color       = new Color(col.R, col.G, col.B) == new Color(255, 255, 255) ? new Color(254, 254, 254) : new Color(col.R, col.G, col.B)
            }.WithCurrentTimestamp());

            return;
        }