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