|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - |
17 | 16 | package com.jetbrains.python.impl; |
18 | 17 |
|
19 | 18 | import com.jetbrains.python.PyNames; |
20 | 19 | import com.jetbrains.python.psi.Property; |
21 | 20 | import com.jetbrains.python.psi.PyClass; |
22 | 21 | import com.jetbrains.python.psi.PyFunction; |
| 22 | +import consulo.annotation.access.RequiredReadAction; |
23 | 23 | import consulo.annotation.component.ExtensionImpl; |
24 | | -import consulo.application.AllIcons; |
25 | 24 | import consulo.language.icon.IconDescriptor; |
26 | 25 | import consulo.language.icon.IconDescriptorUpdater; |
27 | 26 | import consulo.language.psi.PsiDirectory; |
28 | 27 | import consulo.language.psi.PsiElement; |
29 | 28 | import consulo.module.content.ProjectRootManager; |
| 29 | +import consulo.platform.base.icon.PlatformIconGroup; |
| 30 | +import consulo.python.impl.icon.PythonImplIconGroup; |
30 | 31 | import consulo.ui.image.Image; |
31 | | -import consulo.util.lang.Comparing; |
32 | 32 | import consulo.virtualFileSystem.VirtualFile; |
33 | | - |
34 | 33 | import jakarta.annotation.Nonnull; |
35 | 34 |
|
| 35 | +import java.util.Objects; |
| 36 | + |
36 | 37 | /** |
37 | 38 | * @author yole |
38 | 39 | */ |
39 | 40 | @ExtensionImpl |
40 | 41 | public class PyIconDescriptorUpdater implements IconDescriptorUpdater { |
41 | | - @Override |
42 | | - public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int i) { |
43 | | - if (element instanceof PsiDirectory) { |
44 | | - final PsiDirectory directory = (PsiDirectory)element; |
45 | | - if (directory.findFile(PyNames.INIT_DOT_PY) != null) { |
46 | | - final VirtualFile vFile = directory.getVirtualFile(); |
47 | | - final VirtualFile root = ProjectRootManager.getInstance(directory.getProject()).getFileIndex().getSourceRootForFile(vFile); |
48 | | - if (!Comparing.equal(root, vFile)) { |
49 | | - iconDescriptor.setMainIcon(AllIcons.Nodes.Package); |
50 | | - } |
51 | | - } |
52 | | - } |
53 | | - else if (element instanceof PyClass) { |
54 | | - iconDescriptor.setMainIcon(AllIcons.Nodes.Class); |
55 | | - } |
56 | | - else if (element instanceof PyFunction) { |
57 | | - Image icon = null; |
58 | | - final Property property = ((PyFunction)element).getProperty(); |
59 | | - if (property != null) { |
60 | | - if (property.getGetter().valueOrNull() == this) { |
61 | | - icon = PythonIcons.Python.PropertyGetter; |
62 | | - } |
63 | | - else if (property.getSetter().valueOrNull() == this) { |
64 | | - icon = PythonIcons.Python.PropertySetter; |
| 42 | + @Override |
| 43 | + @RequiredReadAction |
| 44 | + public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int i) { |
| 45 | + if (element instanceof PsiDirectory directory) { |
| 46 | + if (directory.findFile(PyNames.INIT_DOT_PY) != null) { |
| 47 | + VirtualFile vFile = directory.getVirtualFile(); |
| 48 | + VirtualFile root = ProjectRootManager.getInstance(directory.getProject()).getFileIndex().getSourceRootForFile(vFile); |
| 49 | + if (!Objects.equals(root, vFile)) { |
| 50 | + iconDescriptor.setMainIcon(PlatformIconGroup.nodesPackage()); |
| 51 | + } |
| 52 | + } |
65 | 53 | } |
66 | | - else if (property.getDeleter().valueOrNull() == this) { |
67 | | - icon = PythonIcons.Python.PropertyDeleter; |
| 54 | + else if (element instanceof PyClass) { |
| 55 | + iconDescriptor.setMainIcon(PlatformIconGroup.nodesClass()); |
68 | 56 | } |
69 | | - else { |
70 | | - icon = AllIcons.Nodes.Property; |
| 57 | + else if (element instanceof PyFunction function) { |
| 58 | + Image icon = null; |
| 59 | + Property property = function.getProperty(); |
| 60 | + if (property != null) { |
| 61 | + if (property.getGetter().valueOrNull() == this) { |
| 62 | + icon = PythonImplIconGroup.pythonPropertygetter(); |
| 63 | + } |
| 64 | + else if (property.getSetter().valueOrNull() == this) { |
| 65 | + icon = PythonImplIconGroup.pythonPropertysetter(); |
| 66 | + } |
| 67 | + else if (property.getDeleter().valueOrNull() == this) { |
| 68 | + icon = PythonImplIconGroup.pythonPropertydeleter(); |
| 69 | + } |
| 70 | + else { |
| 71 | + icon = PlatformIconGroup.nodesProperty(); |
| 72 | + } |
| 73 | + } |
| 74 | + if (icon != null) { |
| 75 | + iconDescriptor.setMainIcon(icon); |
| 76 | + } |
| 77 | + else { |
| 78 | + iconDescriptor.setMainIcon(PlatformIconGroup.nodesMethod()); |
| 79 | + } |
71 | 80 | } |
72 | | - } |
73 | | - if (icon != null) { |
74 | | - iconDescriptor.setMainIcon(icon); |
75 | | - } |
76 | | - else { |
77 | | - iconDescriptor.setMainIcon(AllIcons.Nodes.Method); |
78 | | - } |
79 | 81 | } |
80 | | - } |
81 | 82 | } |
0 commit comments