Move: Allow changing file package without moving to new directory
#KT-8370 Fixed
This commit is contained in:
+14
-13
@@ -24,6 +24,7 @@ import com.intellij.openapi.fileTypes.FileTypeManager;
|
|||||||
import com.intellij.openapi.options.ConfigurationException;
|
import com.intellij.openapi.options.ConfigurationException;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.JavaProjectRootsUtil;
|
import com.intellij.openapi.roots.JavaProjectRootsUtil;
|
||||||
|
import com.intellij.openapi.ui.DialogWrapper;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
@@ -528,11 +529,6 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
|
|||||||
|
|
||||||
List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDirectory);
|
List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDirectory);
|
||||||
if (!filesExistingInTargetDir.isEmpty()) {
|
if (!filesExistingInTargetDir.isEmpty()) {
|
||||||
if (!CollectionsKt.intersect(sourceFiles, filesExistingInTargetDir).isEmpty()) {
|
|
||||||
setErrorText("Can't move to the original file(s)");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filesExistingInTargetDir.size() > 1) {
|
if (filesExistingInTargetDir.size() > 1) {
|
||||||
String filePathsToReport = StringUtil.join(
|
String filePathsToReport = StringUtil.join(
|
||||||
filesExistingInTargetDir,
|
filesExistingInTargetDir,
|
||||||
@@ -552,13 +548,17 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String question = String.format(
|
PsiFile targetFile = filesExistingInTargetDir.get(0);
|
||||||
"File '%s' already exists. Do you want to move selected declarations to this file?",
|
|
||||||
filesExistingInTargetDir.get(0).getVirtualFile().getPath()
|
if (!sourceFiles.contains(targetFile)) {
|
||||||
);
|
String question = String.format(
|
||||||
int ret =
|
"File '%s' already exists. Do you want to move selected declarations to this file?",
|
||||||
Messages.showYesNoDialog(myProject, question, RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
|
targetFile.getVirtualFile().getPath()
|
||||||
if (ret != Messages.YES) return null;
|
);
|
||||||
|
int ret =
|
||||||
|
Messages.showYesNoDialog(myProject, question, RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
|
||||||
|
if (ret != Messages.YES) return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All source files must be in the same directory
|
// All source files must be in the same directory
|
||||||
@@ -724,7 +724,8 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
|
|||||||
PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
|
PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
|
||||||
String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
|
String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
|
||||||
List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDir);
|
List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDir);
|
||||||
if (filesExistingInTargetDir.isEmpty()) {
|
if (filesExistingInTargetDir.isEmpty()
|
||||||
|
|| (filesExistingInTargetDir.size() == 1 && sourceFiles.contains(filesExistingInTargetDir.get(0)))) {
|
||||||
PsiDirectory targetDirectory = ApplicationUtilsKt.runWriteAction(
|
PsiDirectory targetDirectory = ApplicationUtilsKt.runWriteAction(
|
||||||
new Function0<PsiDirectory>() {
|
new Function0<PsiDirectory>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user