Make "copy to" dialog has default folder selected
This commit is contained in:
@@ -50,10 +50,10 @@ public class JSLibraryDescription extends CustomLibraryDescription {
|
||||
@Nullable
|
||||
@Override
|
||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||
return createFromPlugin(parentComponent, contextDirectory);
|
||||
return createFromPlugin(contextDirectory);
|
||||
}
|
||||
|
||||
private NewLibraryConfiguration createFromPlugin(JComponent parentComponent, VirtualFile contextDirectory) {
|
||||
private NewLibraryConfiguration createFromPlugin(VirtualFile contextDirectory) {
|
||||
File runtimePath = PathUtil.getKotlinPathsForIdeaPlugin().getJsLibJarPath();
|
||||
|
||||
if (!runtimePath.exists()) {
|
||||
@@ -62,17 +62,16 @@ public class JSLibraryDescription extends CustomLibraryDescription {
|
||||
return null;
|
||||
}
|
||||
|
||||
final VirtualFile directory = FileUIUtils.selectCopyToDirectory(
|
||||
"Select folder where Kotlin JavaScript header should be copied",
|
||||
parentComponent, contextDirectory);
|
||||
String directoryPath = FileUIUtils.selectDestinationFolderDialog(
|
||||
null, contextDirectory, "Select folder where Kotlin JavaScript header should be copied");
|
||||
|
||||
if (directory == null) {
|
||||
if (directoryPath == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final File targetFile;
|
||||
try {
|
||||
targetFile = FileUIUtils.copyWithOverwriteDialog(directory, runtimePath);
|
||||
targetFile = FileUIUtils.copyWithOverwriteDialog(directoryPath, runtimePath);
|
||||
}
|
||||
catch (IOException e) {
|
||||
Messages.showErrorDialog("Error during file copy", JAVA_SCRIPT_LIBRARY_CREATION);
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
||||
import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import javax.management.openmbean.InvalidOpenTypeException;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -52,10 +51,10 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription {
|
||||
@Nullable
|
||||
@Override
|
||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||
return createFromPlugin(parentComponent, contextDirectory);
|
||||
return createFromPlugin(contextDirectory);
|
||||
}
|
||||
|
||||
private NewLibraryConfiguration createFromPlugin(JComponent parentComponent, VirtualFile contextDirectory) {
|
||||
private NewLibraryConfiguration createFromPlugin(VirtualFile contextDirectory) {
|
||||
File runtimePath = PathUtil.getKotlinPathsForIdeaPlugin().getRuntimePath();
|
||||
|
||||
if (!runtimePath.exists()) {
|
||||
@@ -64,17 +63,16 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription {
|
||||
return null;
|
||||
}
|
||||
|
||||
final VirtualFile directory = FileUIUtils.selectCopyToDirectory(
|
||||
"Select folder where bundled Kotlin java runtime library should be copied",
|
||||
parentComponent, contextDirectory);
|
||||
String directoryPath = FileUIUtils.selectDestinationFolderDialog(
|
||||
null, contextDirectory, "Select folder where bundled Kotlin java runtime library should be copied");
|
||||
|
||||
if (directory == null) {
|
||||
if (directoryPath == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final File targetFile;
|
||||
try {
|
||||
targetFile = FileUIUtils.copyWithOverwriteDialog(directory, runtimePath);
|
||||
targetFile = FileUIUtils.copyWithOverwriteDialog(directoryPath, runtimePath);
|
||||
}
|
||||
catch (IOException e) {
|
||||
Messages.showErrorDialog("Error during file copy", JAVA_RUNTIME_LIBRARY_CREATION);
|
||||
|
||||
+1
@@ -168,6 +168,7 @@ public class AddSupportForSingleFrameworkDialogFixed extends DialogWrapper {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -24,22 +24,23 @@ import com.intellij.openapi.fileChooser.FileTextField;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import org.jdesktop.swingx.VerticalLayout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
class ChoosePathDialog extends DialogWrapper {
|
||||
private final Project myProject;
|
||||
private final String defaultPath;
|
||||
private final String description;
|
||||
private TextFieldWithBrowseButton myPathField;
|
||||
|
||||
public ChoosePathDialog(
|
||||
Project project,
|
||||
String title,
|
||||
String defaultPath) {
|
||||
public ChoosePathDialog(@Nullable Project project, @NotNull String title, @NotNull String defaultPath, @Nullable String description) {
|
||||
super(project);
|
||||
myProject = project;
|
||||
this.defaultPath = defaultPath;
|
||||
this.description = description;
|
||||
|
||||
setTitle(title);
|
||||
init();
|
||||
@@ -47,6 +48,15 @@ class ChoosePathDialog extends DialogWrapper {
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
VerticalLayout verticalLayout = new VerticalLayout();
|
||||
verticalLayout.setGap(3);
|
||||
|
||||
JPanel panel = new JPanel(verticalLayout);
|
||||
|
||||
if (description != null) {
|
||||
panel.add(new JLabel(description));
|
||||
}
|
||||
|
||||
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
||||
FileTextField field = FileChooserFactory.getInstance().createFileTextField(descriptor, myDisposable);
|
||||
field.getField().setColumns(25);
|
||||
@@ -55,7 +65,9 @@ class ChoosePathDialog extends DialogWrapper {
|
||||
myPathField.addBrowseFolderListener("Choose Destination Folder", "Choose folder", myProject, descriptor);
|
||||
myPathField.setText(defaultPath);
|
||||
|
||||
return myPathField;
|
||||
panel.add(myPathField);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.framework.ui;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -61,33 +60,34 @@ public class FileUIUtils {
|
||||
return targetFile;
|
||||
}
|
||||
|
||||
public static File copyWithOverwriteDialog(@NotNull VirtualFile directory, @NotNull File path) throws IOException {
|
||||
String localPath = PathUtil.getLocalPath(directory);
|
||||
assert localPath != null;
|
||||
|
||||
return copyWithOverwriteDialog(localPath, path);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VirtualFile selectCopyToDirectory(
|
||||
@NotNull String description,
|
||||
@Nullable JComponent parentComponent,
|
||||
@Nullable VirtualFile contextDirectory) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
|
||||
public static String selectDestinationFolderDialog(
|
||||
@Nullable Project project,
|
||||
@Nullable VirtualFile contextDirectory,
|
||||
@Nullable String description) {
|
||||
String path = null;
|
||||
if (contextDirectory != null) {
|
||||
path = PathUtil.getLocalPath(contextDirectory);
|
||||
|
||||
descriptor.setTitle("Select Folder");
|
||||
descriptor.setDescription(description);
|
||||
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(descriptor, parentComponent, null, contextDirectory);
|
||||
if (files.length == 0) {
|
||||
return null;
|
||||
}
|
||||
else if (project != null) {
|
||||
path = PathUtil.getLocalPath(project.getBaseDir());
|
||||
}
|
||||
|
||||
assert files.length == 1: "Only one folder is expected";
|
||||
if (path != null) {
|
||||
path = new File(path, "lib").getAbsolutePath();
|
||||
}
|
||||
else {
|
||||
path = "";
|
||||
}
|
||||
|
||||
final VirtualFile directory = files[0];
|
||||
assert directory.isDirectory();
|
||||
ChoosePathDialog dialog = new ChoosePathDialog(project, "Copy Bundled Library", path, description);
|
||||
dialog.show();
|
||||
|
||||
return directory;
|
||||
if (dialog.isOK()) {
|
||||
return dialog.getPath();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user