From dbb6ff2b569db52bd788b87539f574e41a05837b Mon Sep 17 00:00:00 2001 From: "Roman.Ivanov" Date: Fri, 30 Mar 2018 09:54:17 +0700 Subject: [PATCH] MethodChainHintsAction: convert to AnAction --- java/java-impl/src/META-INF/JavaPlugin.xml | 4 -- .../hints/MethodChainHintTurningAction.kt | 38 ++++--------------- .../codeInsight/hints/MethodChainHintsPass.kt | 4 +- .../codeInsight/hints/MethodChainPass.kt | 2 - .../description.html | 5 --- resources/src/idea/JavaActions.xml | 8 ++++ 6 files changed, 19 insertions(+), 42 deletions(-) delete mode 100644 java/java-impl/src/com/intellij/codeInsight/hints/MethodChainPass.kt delete mode 100644 java/java-impl/src/intentionDescriptions/MethodChainHintTurningAction/description.html diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml index d49d07530568..7bec87e04209 100644 --- a/java/java-impl/src/META-INF/JavaPlugin.xml +++ b/java/java-impl/src/META-INF/JavaPlugin.xml @@ -1160,9 +1160,5 @@ com.intellij.codeInsight.intention.impl.SplitFilterAction Java/Streams - - com.intellij.codeInsight.hints.MethodChainHintTurningAction - Other - \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintTurningAction.kt b/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintTurningAction.kt index 26a4817f4725..dc9915ff0c51 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintTurningAction.kt +++ b/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintTurningAction.kt @@ -2,39 +2,17 @@ package com.intellij.codeInsight.hints import com.intellij.codeInsight.CodeInsightSettings -import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction -import com.intellij.openapi.application.ApplicationBundle -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiMethodCallExpression -import com.intellij.psi.PsiWhiteSpace -import com.intellij.psi.util.PsiTreeUtil +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.ToggleAction -class MethodChainHintTurningAction : PsiElementBaseIntentionAction() { - override fun getFamilyName() = "Turn method chain hints" +class MethodChainHintTurningAction : ToggleAction() { + override fun isSelected(e: AnActionEvent?): Boolean { + return CodeInsightSettings.getInstance().SHOW_METHOD_CHAIN_TYPES_INLINE + } - override fun invoke(project: Project, editor: Editor?, element: PsiElement) { - CodeInsightSettings.getInstance().SHOW_METHOD_CHAIN_TYPES_INLINE = !CodeInsightSettings.getInstance().SHOW_METHOD_CHAIN_TYPES_INLINE + override fun setSelected(e: AnActionEvent?, state: Boolean) { + CodeInsightSettings.getInstance().SHOW_METHOD_CHAIN_TYPES_INLINE = state AnnotationHintsPassFactory.forceHintsUpdateOnNextPass() } - override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean { - val origin = if (element is PsiWhiteSpace) { - PsiTreeUtil.skipWhitespacesBackward(element) ?: return false - } else { - element - } - val parent = PsiTreeUtil.getParentOfType(origin, PsiMethodCallExpression::class.java) - if (parent !is PsiMethodCallExpression) return false - val available = (parent.nextSibling as? PsiWhiteSpace)?.textContains('\n') ?: false - text = if (CodeInsightSettings.getInstance().SHOW_METHOD_CHAIN_TYPES_INLINE) { - ApplicationBundle.message("editor.appearance.show.chain.call.type.hints.toggle.off") - } - else { - ApplicationBundle.message("editor.appearance.show.chain.call.type.hints.toggle.on") - } - return available - } - } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintsPass.kt b/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintsPass.kt index e293e3bd37e3..3e1e41edfbb1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintsPass.kt +++ b/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainHintsPass.kt @@ -104,5 +104,7 @@ class MethodChainHintsPass(private val rootElement: PsiElement, editor: Editor) private val METHOD_CHAIN_INLAY_KEY = Key.create("METHOD_CHAIN_INLAY_KEY") } - private class MethodChainHintRenderer(text: String) : HintRenderer(text) + private class MethodChainHintRenderer(text: String) : HintRenderer(text) { + override fun getContextMenuGroupId() = "MethodChainHintsContextMenu" + } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainPass.kt b/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainPass.kt deleted file mode 100644 index 8b19a18e2be6..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/hints/MethodChainPass.kt +++ /dev/null @@ -1,2 +0,0 @@ -package com.intellij.codeInsight.hints - diff --git a/java/java-impl/src/intentionDescriptions/MethodChainHintTurningAction/description.html b/java/java-impl/src/intentionDescriptions/MethodChainHintTurningAction/description.html deleted file mode 100644 index 8dd65c429c19..000000000000 --- a/java/java-impl/src/intentionDescriptions/MethodChainHintTurningAction/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Turns on/off method chain type hints - - diff --git a/resources/src/idea/JavaActions.xml b/resources/src/idea/JavaActions.xml index fef8783b87cd..b7bf436ea187 100644 --- a/resources/src/idea/JavaActions.xml +++ b/resources/src/idea/JavaActions.xml @@ -493,6 +493,14 @@ + + + + + +