From 2bd21b0f3711da9f7f8e35705ba800d74664c6b6 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 13 May 2015 16:08:11 +0300 Subject: [PATCH] Move: Allow moving several files represented by their top-level declarations in the Project View (provided there is only one declaration per file) --- .../MoveKotlinTopLevelDeclarationsHandler.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsHandler.kt index fd2aa9bf5d0..418681c1f17 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsHandler.kt @@ -69,8 +69,18 @@ public class MoveKotlinTopLevelDeclarationsHandler : MoveHandlerDelegate() { [suppress("UNCHECKED_CAST")] val elementsToSearch = elements.toSet() as Set - val sourceFile = elementsToSearch.mapTo(LinkedHashSet()) { it.getContainingJetFile() }.singleOrNull() + val sourceFiles = elementsToSearch.mapTo(LinkedHashSet()) { it.getContainingJetFile() } + val sourceFile = sourceFiles.singleOrNull() if (sourceFile == null) { + if (sourceFiles.all { it.getDeclarations().size() == 1 }) { + MoveFilesOrDirectoriesUtil.doMove(project, + sourceFiles.toTypedArray(), + arrayOf(targetContainer), + null) + + return true + } + CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("move.title"), "All declarations must belong to the same file", null, project) return false }