diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveModel.kt b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveModel.kt index d5f3135d95a3..fa65f7a0f3c7 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveModel.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveModel.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.k2.refactoring.move.ui import com.intellij.openapi.editor.Editor @@ -50,6 +50,7 @@ sealed class K2MoveModel { } ?: false } if (source.elements.isEmpty()) return false + if (target is K2MoveTargetModel.File && !(target as K2MoveTargetModel.File).fileName.isValidKotlinFile()) return false val files = source.elements.map { it.containingKtFile }.toSet() return files.size != 1 || !files.single().isTargetFile() } diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveTargetModel.kt b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveTargetModel.kt index 0b976ae5cfe5..db20f3f0f86a 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveTargetModel.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/K2MoveTargetModel.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.k2.refactoring.move.ui import com.intellij.ide.util.DirectoryChooser @@ -131,6 +131,11 @@ sealed interface K2MoveTargetModel { fileChooser.addDocumentListener(object : DocumentAdapter() { override fun textChanged(e: DocumentEvent) { fileName = fileChooser.text + if (!fileName.isValidKotlinFile()) { + onError(KotlinBundle.message("refactoring.move.non.kotlin.file"), fileChooser) + } else { + onError(null, fileChooser) + } revalidateButtons() } }) diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/moveUiUtil.kt b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/moveUiUtil.kt new file mode 100644 index 000000000000..39b476f2de9b --- /dev/null +++ b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/ui/moveUiUtil.kt @@ -0,0 +1,8 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.kotlin.idea.k2.refactoring.move.ui + +import org.jetbrains.kotlin.idea.KotlinLanguage + +internal fun String.isValidKotlinFile(): Boolean { + return endsWith(KotlinLanguage.INSTANCE.associatedFileType?.defaultExtension ?: return false) || endsWith(".kts") +} \ No newline at end of file