mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Forbid moving to non-Kotlin files
#KTIJ-28296 Fixed GitOrigin-RevId: 859f2e869aa5b7de4e6882f5f9345b1052a1724b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c5bc52d9fd
commit
776ab56b2e
+2
-1
@@ -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()
|
||||
}
|
||||
|
||||
+6
-1
@@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
+8
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user