From 26d14a03aa98101f0251bd8a2a8f253751896a52 Mon Sep 17 00:00:00 2001 From: Nasller Date: Mon, 16 Jan 2023 15:44:31 +0800 Subject: [PATCH] optimize --- .../RequestMappingGotoSEContributor.kt | 4 ++-- .../requestmapper/RequestMappingModel.kt | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/viartemev/requestmapper/RequestMappingGotoSEContributor.kt b/src/main/kotlin/com/viartemev/requestmapper/RequestMappingGotoSEContributor.kt index 9b12862..ec876ea 100644 --- a/src/main/kotlin/com/viartemev/requestmapper/RequestMappingGotoSEContributor.kt +++ b/src/main/kotlin/com/viartemev/requestmapper/RequestMappingGotoSEContributor.kt @@ -12,7 +12,7 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.Project import com.intellij.util.text.MatcherHolder -import com.viartemev.requestmapper.RequestMappingModel.Companion.addLocationLabel +import com.viartemev.requestmapper.RequestMappingModel.Companion.addRightModuleComponent import com.viartemev.requestmapper.contributors.RequestMappingContributor import java.awt.BorderLayout import java.awt.Component @@ -60,8 +60,8 @@ class RequestMappingGotoSEContributor(event: AnActionEvent) : AbstractGotoSECont val component = RequestMappingModel.MyLeftRenderer(MatcherHolder.getAssociatedMatcher(list)) .getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) add(component, BorderLayout.WEST) - addLocationLabel(value, list, isSelected) background = component.background + addRightModuleComponent(value, list, isSelected) return this } } diff --git a/src/main/kotlin/com/viartemev/requestmapper/RequestMappingModel.kt b/src/main/kotlin/com/viartemev/requestmapper/RequestMappingModel.kt index 522cbe3..c62fd9f 100644 --- a/src/main/kotlin/com/viartemev/requestmapper/RequestMappingModel.kt +++ b/src/main/kotlin/com/viartemev/requestmapper/RequestMappingModel.kt @@ -3,6 +3,7 @@ package com.viartemev.requestmapper import com.intellij.ide.IdeBundle import com.intellij.ide.util.NavigationItemListCellRenderer import com.intellij.ide.util.PropertiesComponent +import com.intellij.ide.util.PsiElementListCellRenderer import com.intellij.ide.util.gotoByName.FilteringGotoByModel import com.intellij.ide.util.gotoByName.LanguageRef import com.intellij.ide.util.treeView.NodeRenderer @@ -13,7 +14,6 @@ import com.intellij.openapi.editor.markup.EffectType import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project -import com.intellij.openapi.util.Iconable import com.intellij.openapi.vcs.FileStatus import com.intellij.openapi.vfs.newvfs.VfsPresentationUtil import com.intellij.problems.WolfTheProblemSolver @@ -21,6 +21,7 @@ import com.intellij.psi.util.PsiUtilCore import com.intellij.ui.* import com.intellij.ui.speedSearch.SpeedSearchUtil import com.intellij.util.IconUtil +import com.intellij.util.SlowOperations import com.intellij.util.text.Matcher import com.intellij.util.text.MatcherHolder import com.intellij.util.ui.JBUI.Borders @@ -63,9 +64,9 @@ class RequestMappingModel(project: Project, contributors: List, isSelected: Boolean) { - add(JLabel(value.presentation.locationString, value.targetElement.getIcon(Iconable.ICON_FLAG_READ_STATUS), SwingConstants.RIGHT).apply { - horizontalTextPosition = SwingConstants.LEFT - foreground = if (isSelected) list.foreground else UIUtil.getInactiveTextColor() - }, BorderLayout.EAST) + fun JComponent.addRightModuleComponent(value: RequestMappingItem,list: JList<*>, isSelected: Boolean) { + SlowOperations.allowSlowOperations(SlowOperations.RENDERING).use { + PsiElementListCellRenderer.getModuleTextWithIcon(value.targetElement) + }?.let{ + add(JLabel(it.text, it.icon, SwingConstants.RIGHT).apply { + horizontalTextPosition = SwingConstants.LEFT + foreground = if (isSelected) list.foreground else UIUtil.getInactiveTextColor() + }, BorderLayout.EAST) + } } private fun getMethodSimpleTextAttributes(method: String,textAttributes: TextAttributes) : SimpleTextAttributes {