From 4597caaf3707a2dc69d6073c4a5990ede276dd6a Mon Sep 17 00:00:00 2001 From: Alexandr Suhinin Date: Thu, 28 May 2020 13:30:52 +0300 Subject: [PATCH] move inlay settings presentation to util GitOrigin-RevId: b1ce6a0a6d17114f78fe9357189f4ac2cd7af892 --- .../newImpl/InplaceMethodExtractor.kt | 32 ++--------------- .../rename/inplace/TemplateInlayUtil.kt | 36 +++++++++++++++++-- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/InplaceMethodExtractor.kt b/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/InplaceMethodExtractor.kt index de7897d64992..de85bc162a80 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/InplaceMethodExtractor.kt +++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/InplaceMethodExtractor.kt @@ -1,11 +1,8 @@ // 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. package com.intellij.refactoring.extractMethod.newImpl -import com.intellij.codeInsight.hints.InlayPresentationFactory -import com.intellij.codeInsight.hints.presentation.PresentationFactory import com.intellij.codeInsight.hints.presentation.PresentationRenderer import com.intellij.codeInsight.template.impl.TemplateManagerImpl -import com.intellij.icons.AllIcons import com.intellij.openapi.Disposable import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Inlay @@ -16,7 +13,6 @@ import com.intellij.openapi.util.Pair import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.refactoring.rename.inplace.* -import com.intellij.ui.JBColor import com.intellij.ui.layout.* import java.util.concurrent.atomic.AtomicReference @@ -40,35 +36,11 @@ class InplaceMethodExtractor(val project: Project, val editor: Editor) : Inplace private val inlayReference = AtomicReference>() - private fun getInlayPresentation(): SelectableInlayPresentation? { - val editor = myEditor as? EditorImpl ?: return null - val factory = PresentationFactory(editor) - - val roundedCorners = InlayPresentationFactory.RoundedCorners(6, 6) - val padding = InlayPresentationFactory.Padding(4, 4, 4, 4) - - val inactiveIcon = factory.container( - presentation = factory.icon(AllIcons.Actions.InlayGear), - padding = padding, - roundedCorners = roundedCorners, - background = JBColor.LIGHT_GRAY - ) - val activeIcon = factory.container( - presentation = factory.icon(AllIcons.Actions.InlayGear), - padding = padding, - roundedCorners = roundedCorners, - background = JBColor.DARK_GRAY - ) - val inactivePadded = factory.container(inactiveIcon, padding = InlayPresentationFactory.Padding(3, 6, 0, 0)) - val activePadded = factory.container(activeIcon, padding = InlayPresentationFactory.Padding(3, 6, 0, 0)) - - return SelectableInlayButton(editor, inactivePadded, activePadded, activePadded, inlayReference) - } - override fun afterTemplateStart() { super.afterTemplateStart() val templateState = TemplateManagerImpl.getTemplateState(myEditor) ?: return - val presentation = getInlayPresentation() ?: return + val editor = templateState.editor as? EditorImpl ?: return + val presentation = TemplateInlayUtil.createSettingsPresentation(editor, inlayReference) val offset = templateState.currentVariableRange?.endOffset ?: return val inlay = TemplateInlayUtil.createNavigatableButtonWithPopup(templateState, offset, presentation, popupPanel) ?: return inlayReference.set(inlay) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/TemplateInlayUtil.kt b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/TemplateInlayUtil.kt index a6960a000012..8f4b7b92108b 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/TemplateInlayUtil.kt +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/TemplateInlayUtil.kt @@ -1,14 +1,20 @@ // 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. package com.intellij.refactoring.rename.inplace +import com.intellij.codeInsight.hints.InlayPresentationFactory +import com.intellij.codeInsight.hints.presentation.PresentationFactory import com.intellij.codeInsight.hints.presentation.PresentationRenderer import com.intellij.codeInsight.template.impl.TemplateState +import com.intellij.icons.AllIcons import com.intellij.openapi.editor.Inlay +import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.ui.popup.JBPopupListener import com.intellij.openapi.ui.popup.LightweightWindowEvent import com.intellij.openapi.util.Disposer +import com.intellij.ui.JBColor import com.intellij.ui.popup.PopupFactoryImpl +import java.util.concurrent.atomic.AtomicReference import javax.swing.JComponent object TemplateInlayUtil { @@ -35,7 +41,7 @@ object TemplateInlayUtil { panel: JComponent): Inlay? { val editor = templateState.editor val inlay = createNavigatableButton(templateState, inEditorOffset, presentation) ?: return null - fun showPopup(){ + fun showPopup() { try { editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, inlay.visualPosition) val popup = JBPopupFactory.getInstance() @@ -48,7 +54,8 @@ object TemplateInlayUtil { }) .createPopup() popup.showInBestPositionFor(editor) - } finally { + } + finally { editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null) } } @@ -59,4 +66,29 @@ object TemplateInlayUtil { }) return inlay } + + @JvmStatic + fun createSettingsPresentation(editor: EditorImpl, inlayToUpdate: AtomicReference>): SelectableInlayPresentation { + val factory = PresentationFactory(editor) + + val roundedCorners = InlayPresentationFactory.RoundedCorners(6, 6) + val padding = InlayPresentationFactory.Padding(4, 4, 4, 4) + + val inactiveIcon = factory.container( + presentation = factory.icon(AllIcons.Actions.InlayGear), + padding = padding, + roundedCorners = roundedCorners, + background = JBColor.LIGHT_GRAY + ) + val activeIcon = factory.container( + presentation = factory.icon(AllIcons.Actions.InlayGear), + padding = padding, + roundedCorners = roundedCorners, + background = JBColor.DARK_GRAY + ) + val inactivePadded = factory.container(inactiveIcon, padding = InlayPresentationFactory.Padding(3, 6, 0, 0)) + val activePadded = factory.container(activeIcon, padding = InlayPresentationFactory.Padding(3, 6, 0, 0)) + + return SelectableInlayButton(editor, inactivePadded, activePadded, activePadded, inlayToUpdate) + } } \ No newline at end of file