Redesign dialogs
This commit is contained in:
@@ -28,7 +28,6 @@ import com.intellij.openapi.vfs.VfsUtil;
|
|||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.CreateJavaScriptLibraryDialog;
|
||||||
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
||||||
import org.jetbrains.jet.utils.KotlinPaths;
|
import org.jetbrains.jet.utils.KotlinPaths;
|
||||||
@@ -36,10 +35,7 @@ import org.jetbrains.jet.utils.PathUtil;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class JSLibraryDescription extends CustomLibraryDescription {
|
public class JSLibraryDescription extends CustomLibraryDescription {
|
||||||
public static final LibraryKind KOTLIN_JAVASCRIPT_KIND = LibraryKind.create("kotlin-js-stdlib");
|
public static final LibraryKind KOTLIN_JAVASCRIPT_KIND = LibraryKind.create("kotlin-js-stdlib");
|
||||||
@@ -69,15 +65,24 @@ public class JSLibraryDescription extends CustomLibraryDescription {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String copyIntoPath = dialog.getCopyIntoPath();
|
Map<File, String> copyToPaths = new HashMap<File, String>();
|
||||||
if (copyIntoPath != null) {
|
if (dialog.isCopyLibraryFiles()) {
|
||||||
List<File> copyFiles = new ArrayList<File>();
|
String copyIntoPath = dialog.getCopyLibraryIntoPath();
|
||||||
|
assert copyIntoPath != null;
|
||||||
|
|
||||||
if (dialog.isCopyLibraryFiles()) copyFiles.add(libraryFile);
|
copyToPaths.put(libraryFile, copyIntoPath);
|
||||||
if (dialog.isCopyECMA3()) copyFiles.add(paths.getJsLibJsPath());
|
}
|
||||||
|
|
||||||
|
if (dialog.isCopyJS()) {
|
||||||
|
String copyIntoPath = dialog.getCopyJsIntoPath();
|
||||||
|
assert copyIntoPath != null;
|
||||||
|
|
||||||
|
copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!copyToPaths.isEmpty()) {
|
||||||
Map<File,File> copiedFiles =
|
Map<File,File> copiedFiles =
|
||||||
FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyIntoPath, copyFiles);
|
FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths);
|
||||||
if (copiedFiles == null) {
|
if (copiedFiles == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.framework.ui;
|
|||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.ui.DocumentAdapter;
|
import com.intellij.ui.DocumentAdapter;
|
||||||
import com.intellij.util.EventDispatcher;
|
import com.intellij.util.EventDispatcher;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -38,7 +37,11 @@ public class CopyIntoPanel {
|
|||||||
|
|
||||||
private boolean hasErrorsState;
|
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(
|
copyIntoField.addBrowseFolderListener(
|
||||||
"Copy Into...", "Choose folder where files will be copied", project,
|
"Copy Into...", "Choose folder where files will be copied", project,
|
||||||
FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
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());
|
copyIntoLabel.setLabelFor(copyIntoField.getTextField());
|
||||||
copyIntoField.getTextField().setText(FileUIUtils.getDefaultLibraryFolder(project, contextDirectory));
|
copyIntoField.getTextField().setText(defaultPath);
|
||||||
|
|
||||||
|
copyIntoField.getTextField().setColumns(40);
|
||||||
|
|
||||||
updateComponents();
|
updateComponents();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
</constraints>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<grid id="46726" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="46726" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="15" left="0" bottom="0" right="0"/>
|
<margin top="10" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
@@ -26,7 +26,8 @@
|
|||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Make local copy of library (could be stored in VCS) "/>
|
<selected value="true"/>
|
||||||
|
<text value="&Make local copy of library (could be stored in VCS) "/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<grid id="e47d8" binding="copyIntoPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
<grid id="e47d8" binding="copyIntoPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class CreateJavaLibraryDialog extends DialogWrapper {
|
|||||||
ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel();
|
ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel();
|
||||||
compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER, 0);
|
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() {
|
copyIntoPanel.addValidityListener(new ValidityListener() {
|
||||||
@Override
|
@Override
|
||||||
public void validityChanged(boolean isValid) {
|
public void validityChanged(boolean isValid) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog">
|
||||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="48" y="54" width="436" height="297"/>
|
<xy x="48" y="54" width="436" height="297"/>
|
||||||
@@ -10,13 +10,13 @@
|
|||||||
<children>
|
<children>
|
||||||
<vspacer id="bb37c">
|
<vspacer id="bb37c">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<grid id="46726" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="46726" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="10" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@@ -26,21 +26,30 @@
|
|||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="&Library files"/>
|
<selected value="true"/>
|
||||||
|
<text value="&Make local copy of library (could be stored in VCS) "/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="dd25b" class="javax.swing.JCheckBox" binding="ECMAScript3JavaScriptRuntimeCheckBox" default-binding="true">
|
<component id="dd25b" class="javax.swing.JCheckBox" binding="copyJSRuntimeCheckbox" default-binding="true">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<selected value="true"/>
|
<selected value="true"/>
|
||||||
<text value="EC&MAScript 3 JavaScript runtime file"/>
|
<text value="&Get JavaScript runtime files"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<grid id="11e35" binding="copyIntoPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
<grid id="11e35" binding="copyJSIntoPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="3" use-parent-layout="false"/>
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="3" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="2bd15" binding="copyHeadersIntoPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="3" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@@ -48,14 +57,6 @@
|
|||||||
</grid>
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<component id="7c0b3" class="com.intellij.ui.TitledSeparator">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Copy Into Project"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<grid id="d209b" binding="compilerSourcePanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
<grid id="d209b" binding="compilerSourcePanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
|||||||
@@ -12,13 +12,15 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class CreateJavaScriptLibraryDialog extends DialogWrapper {
|
public class CreateJavaScriptLibraryDialog extends DialogWrapper {
|
||||||
private final CopyIntoPanel copyIntoPanel;
|
private final CopyIntoPanel copyJSIntoPanel;
|
||||||
|
private final CopyIntoPanel copyLibraryIntoPanel;
|
||||||
|
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
private JCheckBox copyLibraryCheckbox;
|
private JCheckBox copyLibraryCheckbox;
|
||||||
private JCheckBox ECMAScript3JavaScriptRuntimeCheckBox;
|
private JCheckBox copyJSRuntimeCheckbox;
|
||||||
private JPanel compilerSourcePanelPlace;
|
private JPanel compilerSourcePanelPlace;
|
||||||
private JPanel copyIntoPanelPlace;
|
private JPanel copyJSIntoPanelPlace;
|
||||||
|
private JPanel copyHeadersIntoPanelPlace;
|
||||||
|
|
||||||
public CreateJavaScriptLibraryDialog(@Nullable Project project, @NotNull String title, VirtualFile contextDirectory) {
|
public CreateJavaScriptLibraryDialog(@Nullable Project project, @NotNull String title, VirtualFile contextDirectory) {
|
||||||
super(project);
|
super(project);
|
||||||
@@ -30,14 +32,23 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper {
|
|||||||
ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel();
|
ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel();
|
||||||
compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER);
|
compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER);
|
||||||
|
|
||||||
copyIntoPanel = new CopyIntoPanel(project, contextDirectory);
|
copyJSIntoPanel = new CopyIntoPanel(project, FileUIUtils.createRelativePath(project, contextDirectory, "script"), "&Script directory:");
|
||||||
copyIntoPanel.addValidityListener(new ValidityListener() {
|
copyJSIntoPanel.addValidityListener(new ValidityListener() {
|
||||||
@Override
|
@Override
|
||||||
public void validityChanged(boolean isValid) {
|
public void validityChanged(boolean isValid) {
|
||||||
updateComponents();
|
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() {
|
ActionListener updateComponentsListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -47,29 +58,34 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper {
|
|||||||
};
|
};
|
||||||
|
|
||||||
copyLibraryCheckbox.addActionListener(updateComponentsListener);
|
copyLibraryCheckbox.addActionListener(updateComponentsListener);
|
||||||
ECMAScript3JavaScriptRuntimeCheckBox.addActionListener(updateComponentsListener);
|
copyJSRuntimeCheckbox.addActionListener(updateComponentsListener);
|
||||||
|
|
||||||
updateComponents();
|
updateComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getCopyIntoPath() {
|
public String getCopyJsIntoPath() {
|
||||||
return copyIntoPanel.getPath();
|
return copyJSIntoPanel.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getCopyLibraryIntoPath() {
|
||||||
|
return copyLibraryIntoPanel.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCopyLibraryFiles() {
|
public boolean isCopyLibraryFiles() {
|
||||||
return copyLibraryCheckbox.isSelected();
|
return copyLibraryCheckbox.isSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCopyECMA3() {
|
public boolean isCopyJS() {
|
||||||
return ECMAScript3JavaScriptRuntimeCheckBox.isSelected();
|
return copyJSRuntimeCheckbox.isSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateComponents() {
|
private void updateComponents() {
|
||||||
copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected() ||
|
copyLibraryIntoPanel.setEnabled(copyLibraryCheckbox.isSelected());
|
||||||
ECMAScript3JavaScriptRuntimeCheckBox.isSelected());
|
copyJSIntoPanel.setEnabled(copyJSRuntimeCheckbox.isSelected());
|
||||||
|
|
||||||
setOKActionEnabled(!copyIntoPanel.hasErrors());
|
setOKActionEnabled(!(copyJSIntoPanel.hasErrors() || copyLibraryIntoPanel.hasErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.framework.ui;
|
package org.jetbrains.jet.plugin.framework.ui;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Collections2;
|
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.ide.util.projectWizard.ProjectWizardUtil;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
@@ -35,7 +36,6 @@ import java.awt.*;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FileUIUtils {
|
public class FileUIUtils {
|
||||||
private FileUIUtils() {
|
private FileUIUtils() {
|
||||||
@@ -47,7 +47,7 @@ public class FileUIUtils {
|
|||||||
@NotNull String messagesTitle,
|
@NotNull String messagesTitle,
|
||||||
@NotNull String destinationFolder,
|
@NotNull String destinationFolder,
|
||||||
@NotNull File file) {
|
@NotNull File file) {
|
||||||
Map<File, File> copiedFiles = copyWithOverwriteDialog(parent, messagesTitle, destinationFolder, ImmutableList.of(file));
|
Map<File, File> copiedFiles = copyWithOverwriteDialog(parent, messagesTitle, ImmutableMap.of(file, destinationFolder));
|
||||||
if (copiedFiles == null) {
|
if (copiedFiles == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -62,40 +62,49 @@ public class FileUIUtils {
|
|||||||
public static Map<File, File> copyWithOverwriteDialog(
|
public static Map<File, File> copyWithOverwriteDialog(
|
||||||
@NotNull Component parent,
|
@NotNull Component parent,
|
||||||
@NotNull String messagesTitle,
|
@NotNull String messagesTitle,
|
||||||
@NotNull String destinationFolder,
|
@NotNull Map<File, String> filesWithDestinations
|
||||||
@NotNull List<File> files
|
|
||||||
) {
|
) {
|
||||||
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<String> fileNames = new HashSet<String>();
|
Set<String> fileNames = new HashSet<String>();
|
||||||
Map<File, File> targetFiles = new LinkedHashMap<File, File>(files.size());
|
Map<File, File> targetFiles = new LinkedHashMap<File, File>(filesWithDestinations.size());
|
||||||
for (File file : files) {
|
for (Map.Entry<File, String> sourceToDestination : filesWithDestinations.entrySet()) {
|
||||||
|
File file = sourceToDestination.getKey();
|
||||||
|
String destinationPath = sourceToDestination.getValue();
|
||||||
|
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
|
|
||||||
if (!fileNames.add(fileName)) {
|
if (!fileNames.add(fileName)) {
|
||||||
throw new IllegalArgumentException("There are several files with the same name: " + 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<File> existentFiles = Collections2.filter(targetFiles.values(), new Predicate<File>() {
|
Collection<Map.Entry<File, File>> existentFiles = Collections2.filter(targetFiles.entrySet(), new Predicate<Map.Entry<File, File>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable File file) {
|
public boolean apply(@Nullable Map.Entry<File, File> sourceToTarget) {
|
||||||
assert file != null;
|
assert sourceToTarget != null;
|
||||||
return file.exists();
|
return sourceToTarget.getValue().exists();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existentFiles.isEmpty()) {
|
if (!existentFiles.isEmpty()) {
|
||||||
String message = existentFiles.size() == 1 ?
|
String message;
|
||||||
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"));
|
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<File> conflictFiles = Collections2.transform(existentFiles, new Function<Map.Entry<File, File>, File>() {
|
||||||
|
@Override
|
||||||
|
public File apply(@Nullable Map.Entry<File, File> 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(
|
int replaceIfExist = Messages.showYesNoDialog(
|
||||||
null,
|
null,
|
||||||
@@ -112,6 +121,12 @@ public class FileUIUtils {
|
|||||||
|
|
||||||
for (Map.Entry<File, File> sourceToTarget : targetFiles.entrySet()) {
|
for (Map.Entry<File, File> sourceToTarget : targetFiles.entrySet()) {
|
||||||
try {
|
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());
|
FileUtil.copy(sourceToTarget.getKey(), sourceToTarget.getValue());
|
||||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(sourceToTarget.getValue());
|
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(sourceToTarget.getValue());
|
||||||
}
|
}
|
||||||
@@ -125,7 +140,7 @@ public class FileUIUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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;
|
String path = null;
|
||||||
if (contextDirectory != null) {
|
if (contextDirectory != null) {
|
||||||
path = PathUtil.getLocalPath(contextDirectory);
|
path = PathUtil.getLocalPath(contextDirectory);
|
||||||
@@ -136,7 +151,7 @@ public class FileUIUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
path = new File(path, "lib").getAbsolutePath();
|
path = new File(path, relativePath).getAbsolutePath();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path = "";
|
path = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user