From a6d5ad415563458b2f65d6843901145fef3a85d6 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 5 Mar 2013 15:05:15 +0400 Subject: [PATCH] Redesign dialogs --- .../framework/JSLibraryDescription.java | 27 ++++---- .../plugin/framework/ui/CopyIntoPanel.java | 21 ++++++- .../framework/ui/CreateJavaLibraryDialog.form | 5 +- .../framework/ui/CreateJavaLibraryDialog.java | 2 +- .../ui/CreateJavaScriptLibraryDialog.form | 39 ++++++------ .../ui/CreateJavaScriptLibraryDialog.java | 44 ++++++++----- .../jet/plugin/framework/ui/FileUIUtils.java | 63 ++++++++++++------- 7 files changed, 127 insertions(+), 74 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java index bf15ddf3188..014e05a7a4e 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java @@ -28,7 +28,6 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.plugin.JetPluginUtil; import org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog; import org.jetbrains.jet.plugin.framework.ui.FileUIUtils; import org.jetbrains.jet.utils.KotlinPaths; @@ -36,10 +35,7 @@ import org.jetbrains.jet.utils.PathUtil; import javax.swing.*; import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public class JSLibraryDescription extends CustomLibraryDescription { public static final LibraryKind KOTLIN_JAVASCRIPT_KIND = LibraryKind.create("kotlin-js-stdlib"); @@ -69,15 +65,24 @@ public class JSLibraryDescription extends CustomLibraryDescription { return null; } - String copyIntoPath = dialog.getCopyIntoPath(); - if (copyIntoPath != null) { - List copyFiles = new ArrayList(); + Map copyToPaths = new HashMap(); + if (dialog.isCopyLibraryFiles()) { + String copyIntoPath = dialog.getCopyLibraryIntoPath(); + assert copyIntoPath != null; - if (dialog.isCopyLibraryFiles()) copyFiles.add(libraryFile); - if (dialog.isCopyECMA3()) copyFiles.add(paths.getJsLibJsPath()); + copyToPaths.put(libraryFile, copyIntoPath); + } + if (dialog.isCopyJS()) { + String copyIntoPath = dialog.getCopyJsIntoPath(); + assert copyIntoPath != null; + + copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath); + } + + if (!copyToPaths.isEmpty()) { Map copiedFiles = - FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyIntoPath, copyFiles); + FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths); if (copiedFiles == null) { return null; } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java index 30ba39c551c..359dacfd374 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.framework.ui; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.DocumentAdapter; import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.NotNull; @@ -38,7 +37,11 @@ public class CopyIntoPanel { private boolean hasErrorsState; - public CopyIntoPanel(@Nullable Project project, @NotNull VirtualFile contextDirectory) { + public CopyIntoPanel(@Nullable Project project, @NotNull String defaultPath) { + this(project, defaultPath, null); + } + + public CopyIntoPanel(@Nullable Project project, @NotNull String defaultPath, @Nullable String labelText) { copyIntoField.addBrowseFolderListener( "Copy Into...", "Choose folder where files will be copied", project, FileChooserDescriptorFactory.createSingleFolderDescriptor()); @@ -49,8 +52,20 @@ public class CopyIntoPanel { } }); + if (labelText != null) { + String text = labelText.replace("&", ""); + int mnemonicIndex = labelText.indexOf("&"); + char mnemonicChar = mnemonicIndex != -1 && (mnemonicIndex + 1) < labelText.length() ? labelText.charAt(mnemonicIndex + 1) : 0; + + copyIntoLabel.setText(text); + copyIntoLabel.setDisplayedMnemonic(mnemonicChar); + copyIntoLabel.setDisplayedMnemonicIndex(mnemonicIndex); + } + copyIntoLabel.setLabelFor(copyIntoField.getTextField()); - copyIntoField.getTextField().setText(FileUIUtils.getDefaultLibraryFolder(project, contextDirectory)); + copyIntoField.getTextField().setText(defaultPath); + + copyIntoField.getTextField().setColumns(40); updateComponents(); } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form index 38dde0bf676..09fc39dced4 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form @@ -14,7 +14,7 @@ - + @@ -26,7 +26,8 @@ - + + diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java index 316420d37e0..05682e39055 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java @@ -45,7 +45,7 @@ public class CreateJavaLibraryDialog extends DialogWrapper { ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel(); compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER, 0); - copyIntoPanel = new CopyIntoPanel(project, contextDirectory); + copyIntoPanel = new CopyIntoPanel(project, FileUIUtils.createRelativePath(project, contextDirectory, "lib")); copyIntoPanel.addValidityListener(new ValidityListener() { @Override public void validityChanged(boolean isValid) { diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form index 110391d2add..4e73c304538 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form @@ -1,6 +1,6 @@
- + @@ -10,13 +10,13 @@ - + - - + + - + @@ -26,21 +26,30 @@ - + + - + - + - + - + - + + + + + + + + + @@ -48,14 +57,6 @@ - - - - - - - - diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java index e5c9d93a200..2b66f3cae17 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java @@ -12,13 +12,15 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class CreateJavaScriptLibraryDialog extends DialogWrapper { - private final CopyIntoPanel copyIntoPanel; + private final CopyIntoPanel copyJSIntoPanel; + private final CopyIntoPanel copyLibraryIntoPanel; private JPanel contentPane; private JCheckBox copyLibraryCheckbox; - private JCheckBox ECMAScript3JavaScriptRuntimeCheckBox; + private JCheckBox copyJSRuntimeCheckbox; private JPanel compilerSourcePanelPlace; - private JPanel copyIntoPanelPlace; + private JPanel copyJSIntoPanelPlace; + private JPanel copyHeadersIntoPanelPlace; public CreateJavaScriptLibraryDialog(@Nullable Project project, @NotNull String title, VirtualFile contextDirectory) { super(project); @@ -30,14 +32,23 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel(); compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER); - copyIntoPanel = new CopyIntoPanel(project, contextDirectory); - copyIntoPanel.addValidityListener(new ValidityListener() { + copyJSIntoPanel = new CopyIntoPanel(project, FileUIUtils.createRelativePath(project, contextDirectory, "script"), "&Script directory:"); + copyJSIntoPanel.addValidityListener(new ValidityListener() { @Override public void validityChanged(boolean isValid) { updateComponents(); } }); - copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER); + copyJSIntoPanelPlace.add(copyJSIntoPanel.getContentPane(), BorderLayout.CENTER); + + copyLibraryIntoPanel = new CopyIntoPanel(project, FileUIUtils.createRelativePath(project, contextDirectory, "lib"), "&Lib directory:"); + copyLibraryIntoPanel.addValidityListener(new ValidityListener() { + @Override + public void validityChanged(boolean isValid) { + updateComponents(); + } + }); + copyHeadersIntoPanelPlace.add(copyLibraryIntoPanel.getContentPane(), BorderLayout.CENTER); ActionListener updateComponentsListener = new ActionListener() { @Override @@ -47,29 +58,34 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { }; copyLibraryCheckbox.addActionListener(updateComponentsListener); - ECMAScript3JavaScriptRuntimeCheckBox.addActionListener(updateComponentsListener); + copyJSRuntimeCheckbox.addActionListener(updateComponentsListener); updateComponents(); } @Nullable - public String getCopyIntoPath() { - return copyIntoPanel.getPath(); + public String getCopyJsIntoPath() { + return copyJSIntoPanel.getPath(); + } + + @Nullable + public String getCopyLibraryIntoPath() { + return copyLibraryIntoPanel.getPath(); } public boolean isCopyLibraryFiles() { return copyLibraryCheckbox.isSelected(); } - public boolean isCopyECMA3() { - return ECMAScript3JavaScriptRuntimeCheckBox.isSelected(); + public boolean isCopyJS() { + return copyJSRuntimeCheckbox.isSelected(); } private void updateComponents() { - copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected() || - ECMAScript3JavaScriptRuntimeCheckBox.isSelected()); + copyLibraryIntoPanel.setEnabled(copyLibraryCheckbox.isSelected()); + copyJSIntoPanel.setEnabled(copyJSRuntimeCheckbox.isSelected()); - setOKActionEnabled(!copyIntoPanel.hasErrors()); + setOKActionEnabled(!(copyJSIntoPanel.hasErrors() || copyLibraryIntoPanel.hasErrors())); } @Nullable 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 3105059e3f8..53a26011b51 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java @@ -16,9 +16,10 @@ package org.jetbrains.jet.plugin.framework.ui; +import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.intellij.ide.util.projectWizard.ProjectWizardUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -35,7 +36,6 @@ import java.awt.*; import java.io.File; import java.io.IOException; import java.util.*; -import java.util.List; public class FileUIUtils { private FileUIUtils() { @@ -47,7 +47,7 @@ public class FileUIUtils { @NotNull String messagesTitle, @NotNull String destinationFolder, @NotNull File file) { - Map copiedFiles = copyWithOverwriteDialog(parent, messagesTitle, destinationFolder, ImmutableList.of(file)); + Map copiedFiles = copyWithOverwriteDialog(parent, messagesTitle, ImmutableMap.of(file, destinationFolder)); if (copiedFiles == null) { return null; } @@ -62,40 +62,49 @@ public class FileUIUtils { public static Map copyWithOverwriteDialog( @NotNull Component parent, @NotNull String messagesTitle, - @NotNull String destinationFolder, - @NotNull List files + @NotNull Map filesWithDestinations ) { - if (!ProjectWizardUtil.createDirectoryIfNotExists("Destination folder", destinationFolder, false)) { - Messages.showErrorDialog(String.format("Error during folder creating '%s'", destinationFolder), messagesTitle + ". Error"); - return null; - } - - File folder = new File(destinationFolder); - Set fileNames = new HashSet(); - Map targetFiles = new LinkedHashMap(files.size()); - for (File file : files) { + Map targetFiles = new LinkedHashMap(filesWithDestinations.size()); + for (Map.Entry sourceToDestination : filesWithDestinations.entrySet()) { + File file = sourceToDestination.getKey(); + String destinationPath = sourceToDestination.getValue(); + String fileName = file.getName(); if (!fileNames.add(fileName)) { throw new IllegalArgumentException("There are several files with the same name: " + fileName); } - targetFiles.put(file, new File(folder, fileName)); + targetFiles.put(file, new File(destinationPath, fileName)); } - Collection existentFiles = Collections2.filter(targetFiles.values(), new Predicate() { + Collection> existentFiles = Collections2.filter(targetFiles.entrySet(), new Predicate>() { @Override - public boolean apply(@Nullable File file) { - assert file != null; - return file.exists(); + public boolean apply(@Nullable Map.Entry sourceToTarget) { + assert sourceToTarget != null; + return sourceToTarget.getValue().exists(); } }); if (!existentFiles.isEmpty()) { - String message = existentFiles.size() == 1 ? - String.format("File \"%s\" is already exist in %s.\nDo you want to overwrite it?", existentFiles.iterator().next().getName(), folder.getAbsolutePath()) : - String.format("Several files are already exist in %s:\n%s\nDo you want to overwrite them?", folder.getAbsolutePath(), StringUtil.join(existentFiles, "\n")); + String message; + + if (existentFiles.size() == 1) { + File conflictingFile = existentFiles.iterator().next().getValue(); + message = String.format("File \"%s\" already exists in %s.\nDo you want to overwrite it?", conflictingFile.getName(), + conflictingFile.getParentFile().getAbsolutePath()); + } + else { + Collection conflictFiles = Collections2.transform(existentFiles, new Function, File>() { + @Override + public File apply(@Nullable Map.Entry pair) { + assert pair != null; + return pair.getValue(); + } + }); + message = String.format("Files already exist:\n%s\nDo you want to overwrite them?", StringUtil.join(conflictFiles, "\n")); + } int replaceIfExist = Messages.showYesNoDialog( null, @@ -112,6 +121,12 @@ public class FileUIUtils { for (Map.Entry sourceToTarget : targetFiles.entrySet()) { try { + String destinationPath = sourceToTarget.getValue().getParentFile().getAbsolutePath(); + if (!ProjectWizardUtil.createDirectoryIfNotExists("Destination folder", destinationPath, false)) { + Messages.showErrorDialog(String.format("Error during folder creating '%s'", destinationPath), messagesTitle + ". Error"); + return null; + } + FileUtil.copy(sourceToTarget.getKey(), sourceToTarget.getValue()); LocalFileSystem.getInstance().refreshAndFindFileByIoFile(sourceToTarget.getValue()); } @@ -125,7 +140,7 @@ public class FileUIUtils { } @NotNull - public static String getDefaultLibraryFolder(@Nullable Project project, @Nullable VirtualFile contextDirectory) { + public static String createRelativePath(@Nullable Project project, @Nullable VirtualFile contextDirectory, String relativePath) { String path = null; if (contextDirectory != null) { path = PathUtil.getLocalPath(contextDirectory); @@ -136,7 +151,7 @@ public class FileUIUtils { } if (path != null) { - path = new File(path, "lib").getAbsolutePath(); + path = new File(path, relativePath).getAbsolutePath(); } else { path = "";