[extract method] setup settings change listener one time for all templates

GitOrigin-RevId: 545a61d305fae24e52a8d754f21ac2d162523688
This commit is contained in:
Alexandr Suhinin
2024-08-12 09:29:26 +00:00
committed by intellij-monorepo-bot
parent 61a69b3efb
commit 6efb57a0f7
2 changed files with 5 additions and 8 deletions
@@ -9,7 +9,6 @@ import com.intellij.java.refactoring.JavaRefactoringBundle
import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.application.readAction
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.command.writeCommandAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
@@ -185,6 +184,7 @@ class MethodExtractor {
private suspend fun runInplaceExtract(editor: Editor, extractor: DuplicatesMethodExtractor, methodNames: List<String>){
val popupSettings = readAction { createInplaceSettingsPopup(extractor.extractOptions) }
val suggestedNames = methodNames.takeIf { it.size > 1 }.orEmpty()
setupRestartOnSettingsChange(editor, popupSettings, extractor)
val inplaceExtractor = readAction { InplaceMethodExtractor(editor, popupSettings, extractor) }
inplaceExtractor.extractAndRunTemplate(suggestedNames)
}
@@ -223,10 +223,6 @@ class MethodExtractor {
)
}
fun executeRefactoringCommand(project: Project, command: () -> Unit) {
CommandProcessor.getInstance().executeCommand(project, command, ExtractMethodHandler.getRefactoringName(), null)
}
fun extractMethod(extractOptions: ExtractOptions): ExtractedElements {
val preparedElements = prepareRefactoringElements(extractOptions)
return WriteAction.compute<ExtractedElements, Throwable> {
@@ -148,7 +148,6 @@ internal class InplaceMethodExtractor(
private fun afterTemplateStart(templateState: TemplateState) {
setActiveExtractor(editor, this)
setupRestartOnSettingsChange(templateState, popupProvider, defaultExtractor)
addInlaySettingsElement(templateState, popupProvider)?.also { inlay ->
Disposer.register(templateState, inlay)
}
@@ -156,8 +155,8 @@ internal class InplaceMethodExtractor(
}
private fun setupRestartOnSettingsChange(templateState: TemplateState, popupProvider: ExtractMethodPopupProvider, defaultExtractor: DuplicatesMethodExtractor){
val project = templateState.editor.project ?: return
fun setupRestartOnSettingsChange(editor: Editor, popupProvider: ExtractMethodPopupProvider, defaultExtractor: DuplicatesMethodExtractor){
val project = editor.project ?: return
popupProvider.setChangeListener {
val shouldAnnotate = popupProvider.annotate
if (shouldAnnotate != null) {
@@ -168,10 +167,12 @@ private fun setupRestartOnSettingsChange(templateState: TemplateState, popupProv
JavaRefactoringSettings.getInstance().EXTRACT_STATIC_METHOD = makeStatic
}
ExtractMethodService.getInstance(project).scope.launch {
val templateState = TemplateManagerImpl.getTemplateState(editor) ?: return@launch
MethodExtractor().restartInplace(templateState, defaultExtractor, popupProvider)
}
}
popupProvider.setShowDialogAction { actionEvent ->
val templateState = TemplateManagerImpl.getTemplateState(editor) ?:return@setShowDialogAction
val extractor = createExtractor(defaultExtractor, popupProvider)
MethodExtractor().restartInDialog(templateState, extractor, actionEvent == null)
}