From 3c6358dd911c89a922319ba0bfc7fb5b554d8d1d Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Mon, 27 Mar 2017 16:43:36 +0300 Subject: [PATCH] Move: Fix file preview presentation #KT-8930 Fixed --- .../MoveFilesWithDeclarationsProcessor.kt | 5 ++ ...MoveFilesWithDeclarationsViewDescriptor.kt | 58 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsViewDescriptor.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsProcessor.kt index c3b70beb0d9..b3fa85b7c11 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsProcessor.kt @@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement import com.intellij.refactoring.move.MoveCallback import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor import com.intellij.usageView.UsageInfo +import com.intellij.usageView.UsageViewDescriptor import com.intellij.usageView.UsageViewUtil import com.intellij.util.containers.MultiMap import com.intellij.util.text.UniqueNameGenerator @@ -49,6 +50,10 @@ class MoveFilesWithDeclarationsProcessor( return if (targetFileName != null) "Move " + sourceFiles.single().name else "Move" } + override fun createUsageViewDescriptor(usages: Array): UsageViewDescriptor { + return MoveFilesWithDeclarationsViewDescriptor(sourceFiles.toTypedArray(), targetDirectory) + } + override fun preprocessUsages(refUsages: Ref>): Boolean { val usages = refUsages.get() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsViewDescriptor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsViewDescriptor.kt new file mode 100644 index 00000000000..53348efff02 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveFilesWithDeclarationsViewDescriptor.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations + +import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.PsiDirectory +import com.intellij.psi.PsiElement +import com.intellij.refactoring.RefactoringBundle +import com.intellij.usageView.UsageViewBundle +import com.intellij.usageView.UsageViewDescriptor +import com.intellij.usageView.UsageViewUtil + +internal class MoveFilesWithDeclarationsViewDescriptor( + private val myElementsToMove: Array, + newParent: PsiDirectory +) : UsageViewDescriptor { + private var myProcessedElementsHeader: String? = null + private val myCodeReferencesText: String + + init { + if (myElementsToMove.size == 1) { + myProcessedElementsHeader = RefactoringBundle.message("move.single.element.elements.header", + UsageViewUtil.getType(myElementsToMove[0]), + newParent.virtualFile.presentableUrl).capitalize() + myCodeReferencesText = "References in code to ${UsageViewUtil.getType(myElementsToMove[0])} ${UsageViewUtil.getLongName(myElementsToMove[0])} and its declarations" + } + else { + myProcessedElementsHeader = StringUtil.capitalize(RefactoringBundle.message("move.files.elements.header", newParent.virtualFile.presentableUrl)) + myCodeReferencesText = RefactoringBundle.message("references.found.in.code") + } + } + + override fun getElements() = myElementsToMove + + override fun getProcessedElementsHeader() = myProcessedElementsHeader + + override fun getCodeReferencesText(usagesCount: Int, filesCount: Int): String { + return myCodeReferencesText + UsageViewBundle.getReferencesString(usagesCount, filesCount) + } + + override fun getCommentReferencesText(usagesCount: Int, filesCount: Int): String? { + return RefactoringBundle.message("comments.elements.header", UsageViewBundle.getOccurencesString(usagesCount, filesCount)) + } +} \ No newline at end of file