|
1 | 1 | using System; |
2 | | -using System.Collections.Generic; |
3 | 2 | using System.Globalization; |
4 | | -using System.Linq; |
5 | 3 | using System.Windows.Data; |
6 | 4 | using System.Windows.Media; |
7 | 5 | using Rubberduck.Navigation.CodeExplorer; |
8 | | -using Rubberduck.Parsing.Annotations.Concrete; |
9 | | -using Rubberduck.Parsing.Symbols; |
10 | 6 | using Rubberduck.Resources.CodeExplorer; |
11 | 7 |
|
12 | 8 | namespace Rubberduck.UI.Converters |
13 | 9 | { |
14 | | - public class DeclarationToIconConverter : ImageSourceConverter |
15 | | - { |
16 | | - private static readonly ImageSource NullIcon = ToImageSource(CodeExplorerUI.status_offline); |
17 | | - private static readonly ImageSource ExceptionIcon = ToImageSource(CodeExplorerUI.exclamation); |
18 | | - private static readonly ImageSource InterfaceIcon = ToImageSource(CodeExplorerUI.ObjectInterface); |
19 | | - private static readonly ImageSource PredeclaredIcon = ToImageSource(CodeExplorerUI.ObjectClassPredeclared); |
20 | | - private static readonly ImageSource TestMethodIcon = ToImageSource(CodeExplorerUI.ObjectTestMethod); |
21 | | - |
22 | | - protected ImageSource NullIconSource => NullIcon; |
23 | | - protected ImageSource ExceptionIconSource => ExceptionIcon; |
24 | | - |
25 | | - private static readonly IDictionary<DeclarationType, ImageSource> DeclarationIcons = new Dictionary<DeclarationType, ImageSource> |
26 | | - { |
27 | | - // Components |
28 | | - { DeclarationType.ClassModule, ToImageSource(CodeExplorerUI.ObjectClass) }, |
29 | | - { DeclarationType.ProceduralModule, ToImageSource(CodeExplorerUI.ObjectModule) }, |
30 | | - { DeclarationType.UserForm, ToImageSource(CodeExplorerUI.ProjectForm) }, |
31 | | - { DeclarationType.Document, ToImageSource(CodeExplorerUI.document_office) }, |
32 | | - { DeclarationType.VbForm, ToImageSource(CodeExplorerUI.ProjectForm)}, |
33 | | - { DeclarationType.MdiForm, ToImageSource(CodeExplorerUI.MdiForm)}, |
34 | | - { DeclarationType.UserControl, ToImageSource(CodeExplorerUI.ui_scroll_pane_form)}, |
35 | | - { DeclarationType.DocObject, ToImageSource(CodeExplorerUI.document_globe)}, |
36 | | - { DeclarationType.PropPage, ToImageSource(CodeExplorerUI.ui_tab_content)}, |
37 | | - { DeclarationType.ActiveXDesigner, ToImageSource(CodeExplorerUI.pencil_ruler)}, |
38 | | - { DeclarationType.ResFile, ToImageSource(CodeExplorerUI.document_block)}, |
39 | | - { DeclarationType.RelatedDocument, ToImageSource(CodeExplorerUI.document_import)}, |
40 | | - // Members |
41 | | - { DeclarationType.Constant, ToImageSource(CodeExplorerUI.ObjectConstant)}, |
42 | | - { DeclarationType.Enumeration, ToImageSource(CodeExplorerUI.ObjectEnum)}, |
43 | | - { DeclarationType.EnumerationMember, ToImageSource(CodeExplorerUI.ObjectEnumItem)}, |
44 | | - { DeclarationType.Event, ToImageSource(CodeExplorerUI.ObjectEvent)}, |
45 | | - { DeclarationType.Function, ToImageSource(CodeExplorerUI.ObjectMethod)}, |
46 | | - { DeclarationType.LibraryFunction, ToImageSource(CodeExplorerUI.ObjectLibraryFunction)}, |
47 | | - { DeclarationType.LibraryProcedure, ToImageSource(CodeExplorerUI.ObjectLibraryFunction)}, |
48 | | - { DeclarationType.Procedure, ToImageSource(CodeExplorerUI.ObjectMethod)}, |
49 | | - { DeclarationType.PropertyGet, ToImageSource(CodeExplorerUI.ObjectPropertyGet)}, |
50 | | - { DeclarationType.PropertyLet, ToImageSource(CodeExplorerUI.ObjectPropertyLet)}, |
51 | | - { DeclarationType.PropertySet, ToImageSource(CodeExplorerUI.ObjectPropertySet)}, |
52 | | - { DeclarationType.UserDefinedType, ToImageSource(CodeExplorerUI.ObjectValueType)}, |
53 | | - { DeclarationType.UserDefinedTypeMember, ToImageSource(CodeExplorerUI.ObjectField)}, |
54 | | - { DeclarationType.Variable, ToImageSource(CodeExplorerUI.ObjectField)}, |
55 | | - { DeclarationType.Parameter, ToImageSource(CodeExplorerUI.ObjectField)}, |
56 | | - }; |
57 | | - |
58 | | - public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
59 | | - { |
60 | | - if (value == null) |
61 | | - { |
62 | | - return NullIcon; |
63 | | - } |
64 | | - |
65 | | - if (value is Declaration declaration) |
66 | | - { |
67 | | - if (declaration is ClassModuleDeclaration classModule) |
68 | | - { |
69 | | - if (classModule.QualifiedModuleName.ComponentType == |
70 | | - VBEditor.SafeComWrappers.ComponentType.Document) |
71 | | - { |
72 | | - return DeclarationIcons[DeclarationType.Document]; |
73 | | - } |
74 | | - |
75 | | - if (classModule.QualifiedModuleName.ComponentType == VBEditor.SafeComWrappers.ComponentType.UserForm) |
76 | | - { |
77 | | - // a form has a predeclared ID, but we want it to have a UserForm icon: |
78 | | - return DeclarationIcons[DeclarationType.UserForm]; |
79 | | - } |
80 | | - |
81 | | - if (classModule.IsInterface || classModule.Annotations.Any(annotation => annotation.Annotation is InterfaceAnnotation)) |
82 | | - { |
83 | | - return InterfaceIcon; |
84 | | - } |
85 | | - |
86 | | - if (classModule.HasPredeclaredId) |
87 | | - { |
88 | | - return PredeclaredIcon; |
89 | | - } |
90 | | - |
91 | | - return DeclarationIcons.ContainsKey(classModule.DeclarationType) |
92 | | - ? DeclarationIcons[classModule.DeclarationType] |
93 | | - : NullIcon; |
94 | | - } |
95 | | - |
96 | | - if (DeclarationIcons.ContainsKey(declaration.DeclarationType)) |
97 | | - { |
98 | | - if (declaration.Annotations.Any(a => a.Annotation is TestMethodAnnotation)) |
99 | | - { |
100 | | - return TestMethodIcon; |
101 | | - } |
102 | | - |
103 | | - return DeclarationIcons[declaration.DeclarationType]; |
104 | | - } |
105 | | - return NullIcon; |
106 | | - } |
107 | | - |
108 | | - return null; |
109 | | - } |
110 | | - } |
111 | | - |
112 | 10 | public class CodeExplorerNodeToIconConverter : DeclarationToIconConverter, IMultiValueConverter |
113 | 11 | { |
114 | 12 | private static readonly ImageSource ProjectIcon = ToImageSource(CodeExplorerUI.ObjectLibrary); |
|
0 commit comments