Search in sources :

Example 1 with MultipleRootsMoveDestination

use of com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination in project intellij-community by JetBrains.

the class CreateClassDialog method doOKAction.

@Override
protected void doOKAction() {
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myPackageComponent.getText());
    final String packageName = getPackageName();
    final String[] errorString = new String[1];
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        try {
            final PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
            final MoveDestination destination = myDestinationCB.selectDirectory(targetPackage, false);
            if (destination == null)
                return;
            myTargetDirectory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {

                @Override
                public PsiDirectory compute() {
                    PsiDirectory baseDir = getBaseDir(packageName);
                    if (baseDir == null && destination instanceof MultipleRootsMoveDestination) {
                        errorString[0] = "Destination not found for package '" + packageName + "'";
                        return null;
                    }
                    return destination.getTargetDirectory(baseDir);
                }
            });
            if (myTargetDirectory == null) {
                return;
            }
            errorString[0] = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
        } catch (IncorrectOperationException e) {
            errorString[0] = e.getMessage();
        }
    }, CodeInsightBundle.message("create.directory.command"), null);
    if (errorString[0] != null) {
        if (errorString[0].length() > 0) {
            Messages.showMessageDialog(myProject, errorString[0], CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        }
        return;
    }
    super.doOKAction();
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) MultipleRootsMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination) MoveDestination(com.intellij.refactoring.MoveDestination) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PackageWrapper(com.intellij.refactoring.PackageWrapper) Computable(com.intellij.openapi.util.Computable) MultipleRootsMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination)

Example 2 with MultipleRootsMoveDestination

use of com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method selectPackageBasedTargetDirAndDestination.

@Nullable
private Pair<VirtualFile, ? extends MoveDestination> selectPackageBasedTargetDirAndDestination(boolean askIfDoesNotExist) {
    String packageName = getTargetPackage();
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
    if (!targetPackage.exists() && askIfDoesNotExist) {
        int ret = Messages.showYesNoDialog(myProject, RefactoringBundle.message("package.does.not.exist", packageName), RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
        if (ret != Messages.YES)
            return null;
    }
    DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) destinationFolderCB.getComboBox().getSelectedItem();
    PsiDirectory selectedPsiDirectory = selectedItem != null ? selectedItem.getDirectory() : null;
    if (selectedPsiDirectory == null) {
        if (initialTargetDirectory != null) {
            selectedPsiDirectory = initialTargetDirectory;
        } else {
            return Pair.create(null, new MultipleRootsMoveDestination(targetPackage));
        }
    }
    VirtualFile targetDirectory = selectedPsiDirectory.getVirtualFile();
    return Pair.create(targetDirectory, new AutocreatingSingleSourceRootMoveDestination(targetPackage, targetDirectory));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AutocreatingSingleSourceRootMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination) PackageWrapper(com.intellij.refactoring.PackageWrapper) DirectoryChooser(com.intellij.ide.util.DirectoryChooser) MultipleRootsMoveDestination(com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PackageWrapper (com.intellij.refactoring.PackageWrapper)2 MultipleRootsMoveDestination (com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination)2 DirectoryChooser (com.intellij.ide.util.DirectoryChooser)1 Computable (com.intellij.openapi.util.Computable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 MoveDestination (com.intellij.refactoring.MoveDestination)1 AutocreatingSingleSourceRootMoveDestination (com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Nullable (org.jetbrains.annotations.Nullable)1