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);
}
Aggregations