Search in sources :

Example 1 with KotlinFileChooserDialog

use of org.jetbrains.kotlin.idea.refactoring.ui.KotlinFileChooserDialog in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method initFileChooser.

private void initFileChooser(@Nullable KtFile targetFile, @NotNull Set<KtNamedDeclaration> elementsToMove, @NotNull List<KtFile> sourceFiles) {
    final PsiDirectory sourceDir = sourceFiles.get(0).getParent();
    assert sourceDir != null : sourceFiles.get(0).getVirtualFile().getPath();
    fileChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            KotlinFileChooserDialog dialog = new KotlinFileChooserDialog("Choose Containing File", myProject);
            File targetFile = new File(getTargetFilePath());
            PsiFile targetPsiFile = KotlinRefactoringUtilKt.toPsiFile(targetFile, myProject);
            if (targetPsiFile instanceof KtFile) {
                dialog.select((KtFile) targetPsiFile);
            } else {
                PsiDirectory targetDir = KotlinRefactoringUtilKt.toPsiDirectory(targetFile.getParentFile(), myProject);
                if (targetDir == null) {
                    targetDir = sourceDir;
                }
                dialog.selectDirectory(targetDir);
            }
            dialog.showDialog();
            KtFile selectedFile = dialog.isOK() ? dialog.getSelected() : null;
            if (selectedFile != null) {
                fileChooser.setText(selectedFile.getVirtualFile().getPath());
            }
        }
    });
    String initialTargetPath = targetFile != null ? targetFile.getVirtualFile().getPath() : sourceFiles.get(0).getVirtualFile().getParent().getPath() + "/" + MoveUtilsKt.guessNewFileName(elementsToMove);
    fileChooser.setText(initialTargetPath);
}
Also used : KotlinFileChooserDialog(org.jetbrains.kotlin.idea.refactoring.ui.KotlinFileChooserDialog) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) KtFile(org.jetbrains.kotlin.psi.KtFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 KotlinFileChooserDialog (org.jetbrains.kotlin.idea.refactoring.ui.KotlinFileChooserDialog)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1