mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert TargetPopupPresentation to Kotlin
GitOrigin-RevId: 1993d8df0f3d58672f3debe46b0fbe7eba4cf01b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
56c9714e22
commit
90fbe7953d
@@ -1,56 +1,55 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.navigation;
|
||||
package com.intellij.navigation
|
||||
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import org.jetbrains.annotations.ApiStatus.Experimental;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.Nls
|
||||
import java.awt.Color
|
||||
import javax.swing.Icon
|
||||
|
||||
/**
|
||||
* Represents presentation in target popup as follows:<br/>
|
||||
* <code>| $icon $presentable_text (in $location_text) spacer $right_text $right_icon |</code><br/>
|
||||
* Represents presentation in target popup as follows:
|
||||
* ```
|
||||
* | $icon $presentable_text (in $location_text) spacer $right_text $right_icon |
|
||||
* ```
|
||||
* Elements before spacer are aligned to the left, right text and right icon are aligned to the right.
|
||||
*/
|
||||
@Experimental
|
||||
public interface TargetPopupPresentation {
|
||||
@ApiStatus.Experimental
|
||||
interface TargetPopupPresentation {
|
||||
|
||||
default @Nullable Color getBackgroundColor() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val backgroundColor: Color?
|
||||
get() = null
|
||||
|
||||
default @Nullable Icon getIcon() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val icon: Icon?
|
||||
get() = null
|
||||
|
||||
@Nls @NotNull String getPresentableText();
|
||||
val presentableText: @Nls String
|
||||
|
||||
/**
|
||||
* @return attributes to highlight {@link #getPresentableText()}
|
||||
* Attributes to highlight [presentableText]
|
||||
*/
|
||||
default @Nullable TextAttributes getPresentableAttributes() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val presentableAttributes: TextAttributes?
|
||||
get() = null
|
||||
|
||||
default @Nls @Nullable String getLocationText() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val locationText: @Nls String?
|
||||
get() = null
|
||||
|
||||
/**
|
||||
* @return attributes to highlight {@link #getLocationText()}
|
||||
* Attributes to highlight [locationText]
|
||||
*/
|
||||
default @Nullable TextAttributes getLocationAttributes() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val locationAttributes: TextAttributes?
|
||||
get() = null
|
||||
|
||||
default @Nls @Nullable String getRightText() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val rightText: @Nls String?
|
||||
get() = null
|
||||
|
||||
default @Nullable Icon getRightIcon() {
|
||||
return null;
|
||||
}
|
||||
@JvmDefault
|
||||
val rightIcon: Icon?
|
||||
get() = null
|
||||
}
|
||||
|
||||
+32
-29
@@ -38,36 +38,39 @@ class PsiElementTargetPopupPresentation(private val myElement: PsiElement) : Tar
|
||||
}
|
||||
}
|
||||
|
||||
override fun getBackgroundColor(): Color? {
|
||||
val virtualFile = myVirtualFile ?: return null
|
||||
return EditorTabPresentationUtil.getFileBackgroundColor(myProject, virtualFile)
|
||||
}
|
||||
|
||||
override fun getIcon(): Icon? = myElement.getIcon(Iconable.ICON_FLAG_VISIBILITY or Iconable.ICON_FLAG_READ_STATUS)
|
||||
|
||||
override fun getPresentableText(): String {
|
||||
return myItemPresentation?.presentableText
|
||||
?: (myElement as? PsiNamedElement)?.name
|
||||
?: myElement.text
|
||||
}
|
||||
|
||||
override fun getPresentableAttributes(): TextAttributes? = myItemPresentation?.getColoredAttributes()
|
||||
|
||||
override fun getLocationText(): String? = myItemPresentation?.getLocationText()
|
||||
|
||||
override fun getLocationAttributes(): TextAttributes? {
|
||||
val virtualFile = myVirtualFile ?: return null
|
||||
val locationColor = FileStatusManager.getInstance(myProject).getStatus(virtualFile)?.color
|
||||
val hasProblem = WolfTheProblemSolver.getInstance(myProject).isProblemFile(virtualFile)
|
||||
return when {
|
||||
hasProblem -> TextAttributes(locationColor, null, JBColor.red, EffectType.WAVE_UNDERSCORE, Font.PLAIN)
|
||||
locationColor != null -> TextAttributes(locationColor, null, null, null, Font.PLAIN)
|
||||
else -> null
|
||||
override val backgroundColor: Color?
|
||||
get() {
|
||||
val virtualFile = myVirtualFile ?: return null
|
||||
return EditorTabPresentationUtil.getFileBackgroundColor(myProject, virtualFile)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("HardCodedStringLiteral") // inspection doesn't support type annotations in Kotlin
|
||||
override fun getRightText(): String? = myModuleRendererData?.first
|
||||
override val icon: Icon?
|
||||
get() = myElement.getIcon(Iconable.ICON_FLAG_VISIBILITY or Iconable.ICON_FLAG_READ_STATUS)
|
||||
|
||||
override fun getRightIcon(): Icon? = myModuleRendererData?.second
|
||||
override val presentableText: String
|
||||
get() = myItemPresentation?.presentableText
|
||||
?: (myElement as? PsiNamedElement)?.name
|
||||
?: myElement.text
|
||||
|
||||
override val presentableAttributes: TextAttributes?
|
||||
get() = myItemPresentation?.getColoredAttributes()
|
||||
|
||||
override val locationText: String?
|
||||
get() = myItemPresentation?.getLocationText()
|
||||
|
||||
override val locationAttributes: TextAttributes?
|
||||
get() {
|
||||
val virtualFile = myVirtualFile ?: return null
|
||||
val locationColor = FileStatusManager.getInstance(myProject).getStatus(virtualFile)?.color
|
||||
val hasProblem = WolfTheProblemSolver.getInstance(myProject).isProblemFile(virtualFile)
|
||||
return when {
|
||||
hasProblem -> TextAttributes(locationColor, null, JBColor.red, EffectType.WAVE_UNDERSCORE, Font.PLAIN)
|
||||
locationColor != null -> TextAttributes(locationColor, null, null, null, Font.PLAIN)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override val rightText: String? get() = myModuleRendererData?.first
|
||||
|
||||
override val rightIcon: Icon? get() = myModuleRendererData?.second
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.find.actions
|
||||
|
||||
import com.intellij.codeInsight.navigation.getColoredAttributes
|
||||
@@ -10,11 +10,11 @@ import javax.swing.Icon
|
||||
|
||||
internal class Item2TargetPresentation(private val itemPresentation: ItemPresentation) : TargetPopupPresentation {
|
||||
|
||||
override fun getIcon(): Icon? = itemPresentation.getIcon(false)
|
||||
override val icon: Icon? get() = itemPresentation.getIcon(false)
|
||||
|
||||
override fun getPresentableText(): String = itemPresentation.presentableText ?: ""
|
||||
override val presentableText: String get() = itemPresentation.presentableText ?: ""
|
||||
|
||||
override fun getPresentableAttributes(): TextAttributes? = itemPresentation.getColoredAttributes()
|
||||
override val presentableAttributes: TextAttributes? get() = itemPresentation.getColoredAttributes()
|
||||
|
||||
override fun getLocationText(): String? = itemPresentation.getLocationText()
|
||||
override val locationText: String? get() = itemPresentation.getLocationText()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.gradle.service.resolve
|
||||
|
||||
import com.intellij.codeInsight.navigation.PsiElementNavigationTarget
|
||||
@@ -57,8 +57,8 @@ abstract class GradleProjectSymbol(
|
||||
get() {
|
||||
val presentation = symbolPresentation
|
||||
return object : TargetPopupPresentation {
|
||||
override fun getIcon(): Icon? = presentation.icon
|
||||
override fun getPresentableText(): String = presentation.longDescription
|
||||
override val icon: Icon? get() = presentation.icon
|
||||
override val presentableText: String get() = presentation.longDescription
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user