|  | 
|  | 1 | +using System; | 
|  | 2 | +using System.Collections.Generic; | 
|  | 3 | +using System.Linq; | 
|  | 4 | +using System.Windows.Media.Imaging; | 
|  | 5 | +using Rubberduck.Parsing.Symbols; | 
|  | 6 | + | 
|  | 7 | +namespace Rubberduck.Common | 
|  | 8 | +{ | 
|  | 9 | +    public class DeclarationIconCache | 
|  | 10 | +    { | 
|  | 11 | +        private static readonly IDictionary<Tuple<DeclarationType, Accessibility>, BitmapImage> Images; | 
|  | 12 | + | 
|  | 13 | +        static DeclarationIconCache() | 
|  | 14 | +        { | 
|  | 15 | +            var types = Enum.GetValues(typeof (DeclarationType)).Cast<DeclarationType>(); | 
|  | 16 | +            var accessibilities = Enum.GetValues(typeof (Accessibility)).Cast<Accessibility>(); | 
|  | 17 | + | 
|  | 18 | +            Images = types.SelectMany(t => accessibilities.Select(a => Tuple.Create(t, a))) | 
|  | 19 | +                .ToDictionary(key => key, key => new BitmapImage(GetIconUri(key.Item1, key.Item2))); | 
|  | 20 | +        } | 
|  | 21 | + | 
|  | 22 | +        public BitmapImage this[Declaration declaration] | 
|  | 23 | +        { | 
|  | 24 | +            get | 
|  | 25 | +            { | 
|  | 26 | +                var key = Tuple.Create(declaration.DeclarationType, declaration.Accessibility); | 
|  | 27 | +                return Images[key]; | 
|  | 28 | +            } | 
|  | 29 | +        } | 
|  | 30 | + | 
|  | 31 | +        private static Uri GetIconUri(DeclarationType declarationType, Accessibility accessibility) | 
|  | 32 | +        { | 
|  | 33 | +            const string baseUri = @"../Rubberduck.Resources/Icons/Fugue/"; | 
|  | 34 | + | 
|  | 35 | +            string path; | 
|  | 36 | +            switch (declarationType) | 
|  | 37 | +            { | 
|  | 38 | +                case DeclarationType.ProceduralModule: | 
|  | 39 | +                    path = "ObjectModule.png"; | 
|  | 40 | +                    break; | 
|  | 41 | + | 
|  | 42 | +                case DeclarationType.Document | DeclarationType.ClassModule:  | 
|  | 43 | +                    path = "Document.png"; | 
|  | 44 | +                    break; | 
|  | 45 | +                 | 
|  | 46 | +                case DeclarationType.UserForm | DeclarationType.ClassModule | DeclarationType.Control: | 
|  | 47 | +                    path = "ProjectForm.png"; | 
|  | 48 | +                    break; | 
|  | 49 | + | 
|  | 50 | +                case DeclarationType.ClassModule | DeclarationType.ProceduralModule: | 
|  | 51 | +                    path = "ObjectClass.png"; | 
|  | 52 | +                    break; | 
|  | 53 | + | 
|  | 54 | +                case DeclarationType.Procedure | DeclarationType.Member: | 
|  | 55 | +                case DeclarationType.Function | DeclarationType.Member: | 
|  | 56 | +                    if (accessibility == Accessibility.Private) | 
|  | 57 | +                    { | 
|  | 58 | +                        path = "ObjectMethodPrivate.png"; | 
|  | 59 | +                        break; | 
|  | 60 | +                    } | 
|  | 61 | +                    if (accessibility == Accessibility.Friend) | 
|  | 62 | +                    { | 
|  | 63 | +                        path = "ObjectMethodFriend.png"; | 
|  | 64 | +                        break; | 
|  | 65 | +                    } | 
|  | 66 | + | 
|  | 67 | +                    path = "ObjectMethod.png"; | 
|  | 68 | +                    break; | 
|  | 69 | + | 
|  | 70 | +                case DeclarationType.PropertyGet | DeclarationType.Property | DeclarationType.Function: | 
|  | 71 | +                case DeclarationType.PropertyLet | DeclarationType.Property | DeclarationType.Procedure: | 
|  | 72 | +                case DeclarationType.PropertySet | DeclarationType.Property | DeclarationType.Procedure: | 
|  | 73 | +                    if (accessibility == Accessibility.Private) | 
|  | 74 | +                    { | 
|  | 75 | +                        path = "ObjectPropertiesPrivate.png"; | 
|  | 76 | +                        break; | 
|  | 77 | +                    } | 
|  | 78 | +                    if (accessibility == Accessibility.Friend) | 
|  | 79 | +                    { | 
|  | 80 | +                        path = "ObjectPropertiesFriend.png"; | 
|  | 81 | +                        break; | 
|  | 82 | +                    } | 
|  | 83 | + | 
|  | 84 | +                    path = "ObjectProperties.png"; | 
|  | 85 | +                    break; | 
|  | 86 | + | 
|  | 87 | +                case DeclarationType.Parameter: | 
|  | 88 | +                    path = "ObjectFieldShortcut.png"; | 
|  | 89 | +                    break; | 
|  | 90 | + | 
|  | 91 | +                case DeclarationType.Variable: | 
|  | 92 | +                    if (accessibility == Accessibility.Private) | 
|  | 93 | +                    { | 
|  | 94 | +                        path = "ObjectFieldPrivate.png"; | 
|  | 95 | +                        break; | 
|  | 96 | +                    } | 
|  | 97 | +                    if (accessibility == Accessibility.Friend) | 
|  | 98 | +                    { | 
|  | 99 | +                        path = "ObjectFieldFriend.png"; | 
|  | 100 | +                        break; | 
|  | 101 | +                    } | 
|  | 102 | + | 
|  | 103 | +                    path = "ObjectField.png"; | 
|  | 104 | +                    break; | 
|  | 105 | + | 
|  | 106 | +                case DeclarationType.Constant: | 
|  | 107 | +                    if (accessibility == Accessibility.Private) | 
|  | 108 | +                    { | 
|  | 109 | +                        path = "ObjectConstantPrivate.png"; | 
|  | 110 | +                        break; | 
|  | 111 | +                    } | 
|  | 112 | +                    if (accessibility == Accessibility.Friend) | 
|  | 113 | +                    { | 
|  | 114 | +                        path = "ObjectConstantFriend.png"; | 
|  | 115 | +                        break; | 
|  | 116 | +                    } | 
|  | 117 | + | 
|  | 118 | +                    path = "ObjectConstant.png"; | 
|  | 119 | +                    break; | 
|  | 120 | + | 
|  | 121 | +                case DeclarationType.Enumeration: | 
|  | 122 | +                    if (accessibility == Accessibility.Private) | 
|  | 123 | +                    { | 
|  | 124 | +                        path = "ObjectEnumPrivate.png"; | 
|  | 125 | +                        break; | 
|  | 126 | +                    } | 
|  | 127 | +                    if (accessibility == Accessibility.Friend) | 
|  | 128 | +                    { | 
|  | 129 | +                        path = "ObjectEnumFriend.png"; | 
|  | 130 | +                        break; | 
|  | 131 | +                    } | 
|  | 132 | + | 
|  | 133 | +                    path = "ObjectEnum.png"; | 
|  | 134 | +                    break; | 
|  | 135 | + | 
|  | 136 | +                case DeclarationType.EnumerationMember: | 
|  | 137 | +                    path = "ObjectEnumItem.png"; | 
|  | 138 | +                    break; | 
|  | 139 | + | 
|  | 140 | +                case DeclarationType.Event: | 
|  | 141 | +                    if (accessibility == Accessibility.Private) | 
|  | 142 | +                    { | 
|  | 143 | +                        path = "ObjectEventPrivate.png"; | 
|  | 144 | +                        break; | 
|  | 145 | +                    } | 
|  | 146 | +                    if (accessibility == Accessibility.Friend) | 
|  | 147 | +                    { | 
|  | 148 | +                        path = "ObjectEventFriend.png"; | 
|  | 149 | +                        break; | 
|  | 150 | +                    } | 
|  | 151 | + | 
|  | 152 | +                    path = "ObjectEvent.png"; | 
|  | 153 | +                    break; | 
|  | 154 | + | 
|  | 155 | +                case DeclarationType.UserDefinedType: | 
|  | 156 | +                    if (accessibility == Accessibility.Private) | 
|  | 157 | +                    { | 
|  | 158 | +                        path = "ObjectValueTypePrivate.png"; | 
|  | 159 | +                        break; | 
|  | 160 | +                    } | 
|  | 161 | +                    if (accessibility == Accessibility.Friend) | 
|  | 162 | +                    { | 
|  | 163 | +                        path = "ObjectValueTypeFriend.png"; | 
|  | 164 | +                        break; | 
|  | 165 | +                    } | 
|  | 166 | + | 
|  | 167 | +                    path = "ObjectValueType.png"; | 
|  | 168 | +                    break; | 
|  | 169 | + | 
|  | 170 | +                case DeclarationType.UserDefinedTypeMember: | 
|  | 171 | +                    path = "ObjectField.png"; | 
|  | 172 | +                    break; | 
|  | 173 | + | 
|  | 174 | +                case DeclarationType.LibraryProcedure | DeclarationType.Procedure: | 
|  | 175 | +                case DeclarationType.LibraryFunction | DeclarationType.Function: | 
|  | 176 | +                    path = "ObjectMethodShortcut.png"; | 
|  | 177 | +                    break; | 
|  | 178 | + | 
|  | 179 | +                case DeclarationType.LineLabel: | 
|  | 180 | +                    path = "ObjectConstantShortcut.png"; | 
|  | 181 | +                    break; | 
|  | 182 | + | 
|  | 183 | +                case DeclarationType.Project: | 
|  | 184 | +                    path = "ObjectLibrary.png"; | 
|  | 185 | +                    break; | 
|  | 186 | + | 
|  | 187 | +                default: | 
|  | 188 | +                    path = "ObjectStructure.png"; | 
|  | 189 | +                    break; | 
|  | 190 | +            } | 
|  | 191 | + | 
|  | 192 | +            return new Uri(baseUri + path, UriKind.Relative); | 
|  | 193 | +        } | 
|  | 194 | + | 
|  | 195 | +    } | 
|  | 196 | +} | 
0 commit comments