From 8065bc4338331760c8fef7e961752841736196b8 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 25 Feb 2013 18:42:15 +0400 Subject: [PATCH] Make "copy to" dialog has default folder selected --- .../framework/JSLibraryDescription.java | 13 +++-- .../JavaRuntimeLibraryDescription.java | 14 +++--- ...dSupportForSingleFrameworkDialogFixed.java | 1 + .../plugin/framework/ui/ChoosePathDialog.java | 22 +++++++-- .../jet/plugin/framework/ui/FileUIUtils.java | 48 +++++++++---------- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java index 02e290ff617..972c32cf2e2 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java @@ -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); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java index d53ac7f2c4f..5bc917a2c9e 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java @@ -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); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/AddSupportForSingleFrameworkDialogFixed.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/AddSupportForSingleFrameworkDialogFixed.java index b5e15e7117b..75eac40c52c 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/AddSupportForSingleFrameworkDialogFixed.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/AddSupportForSingleFrameworkDialogFixed.java @@ -168,6 +168,7 @@ public class AddSupportForSingleFrameworkDialogFixed extends DialogWrapper { return false; } } + return true; } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChoosePathDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChoosePathDialog.java index aebcfa40950..3f006d21979 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChoosePathDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChoosePathDialog.java @@ -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 diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java index c0ed020fc1d..80738d81763 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java @@ -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; } }