mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
artifact editor: create directtory/archive with parents
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.CompositePackagingElementType;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.impl.ui.properties.ArchiveElementPropertiesPanel;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.PackagingElementPropertiesPanel;
|
||||
import com.intellij.util.Icons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ArchiveElementType extends CompositePackagingElementType<ArchivePackagingElement> {
|
||||
ArchiveElementType() {
|
||||
super("archive", CompilerBundle.message("element.type.name.archive"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return Icons.JAR_ICON;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArchivePackagingElement createEmpty(@NotNull Project project) {
|
||||
return new ArchivePackagingElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull ArchivePackagingElement element,
|
||||
@NotNull ArtifactEditorContext context) {
|
||||
final String name = element.getArchiveFileName();
|
||||
if (name.length() >= 4 && name.charAt(name.length() - 4) == '.' && StringUtil.endsWithIgnoreCase(name, "ar")) {
|
||||
return new ArchiveElementPropertiesPanel(element, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PackagingElement<?> createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement<?> parent) {
|
||||
final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, "archive", ".jar");
|
||||
final String path = Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, new FilePathValidator());
|
||||
if (path == null) return null;
|
||||
return PackagingElementFactoryImpl.createDirectoryOrArchiveWithParents(path, true);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDialog;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementType;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class DirectoryCopyElementType extends PackagingElementType<DirectoryCopyPackagingElement> {
|
||||
public static final Icon COPY_OF_FOLDER_ICON = IconLoader.getIcon("/nodes/copyOfFolder.png");
|
||||
|
||||
DirectoryCopyElementType() {
|
||||
super("dir-copy", "Directory Content");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return COPY_OF_FOLDER_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends DirectoryCopyPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, true);
|
||||
final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject());
|
||||
final VirtualFile[] files = chooser.choose(null, context.getProject());
|
||||
final List<DirectoryCopyPackagingElement> list = new ArrayList<DirectoryCopyPackagingElement>();
|
||||
for (VirtualFile file : files) {
|
||||
list.add(new DirectoryCopyPackagingElement(file.getPath()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DirectoryCopyPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new DirectoryCopyPackagingElement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.CompositePackagingElementType;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
|
||||
import com.intellij.packaging.impl.ui.properties.DirectoryElementPropertiesPanel;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.PackagingElementPropertiesPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class DirectoryElementType extends CompositePackagingElementType<DirectoryPackagingElement> {
|
||||
private static final Icon ICON = IconLoader.getIcon("/actions/newFolder.png");
|
||||
|
||||
DirectoryElementType() {
|
||||
super("directory", CompilerBundle.message("element.type.name.directory"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return ICON;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DirectoryPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new DirectoryPackagingElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull DirectoryPackagingElement element,
|
||||
@NotNull ArtifactEditorContext context) {
|
||||
if (ArtifactUtil.isArchiveName(element.getDirectoryName())) {
|
||||
return new DirectoryElementPropertiesPanel(element, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PackagingElement<?> createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement<?> parent) {
|
||||
final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, "folder", "");
|
||||
String path = Messages.showInputDialog(context.getProject(), "Enter directory name: ", "New Directory", null, initialValue, new FilePathValidator());
|
||||
if (path == null) return null;
|
||||
return PackagingElementFactoryImpl.createDirectoryOrArchiveWithParents(path, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDialog;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementType;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class FileCopyElementType extends PackagingElementType<FileCopyPackagingElement> {
|
||||
public static final Icon ICON = IconLoader.getIcon("/fileTypes/text.png");
|
||||
|
||||
FileCopyElementType() {
|
||||
super("file-copy", "File");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends FileCopyPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, true);
|
||||
final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject());
|
||||
final VirtualFile[] files = chooser.choose(null, context.getProject());
|
||||
final List<FileCopyPackagingElement> list = new ArrayList<FileCopyPackagingElement>();
|
||||
for (VirtualFile file : files) {
|
||||
list.add(new FileCopyPackagingElement(file.getPath()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FileCopyPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new FileCopyPackagingElement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.ui.InputValidator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class FilePathValidator implements InputValidator {
|
||||
public boolean checkInput(String inputString) {
|
||||
final List<String> fileNames = StringUtil.split(FileUtil.toSystemIndependentName(inputString), "/");
|
||||
if (fileNames.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (String fileName : fileNames) {
|
||||
if (!PathUtil.isValidFileName(fileName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canClose(String inputString) {
|
||||
return checkInput(inputString);
|
||||
}
|
||||
}
|
||||
+7
-151
@@ -15,11 +15,7 @@
|
||||
*/
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDialog;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
@@ -27,27 +23,19 @@ import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactPointerManager;
|
||||
import com.intellij.packaging.elements.*;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
|
||||
import com.intellij.packaging.impl.ui.properties.ArchiveElementPropertiesPanel;
|
||||
import com.intellij.packaging.impl.ui.properties.DirectoryElementPropertiesPanel;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.PackagingElementPropertiesPanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -229,7 +217,7 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String suggestFileName(@NotNull CompositePackagingElement<?> parent, @NonNls @NotNull String prefix, @NonNls @NotNull String suffix) {
|
||||
public static String suggestFileName(@NotNull CompositePackagingElement<?> parent, @NonNls @NotNull String prefix, @NonNls @NotNull String suffix) {
|
||||
String name = prefix + suffix;
|
||||
int i = 2;
|
||||
while (findArchiveOrDirectoryByName(parent, name) != null) {
|
||||
@@ -282,144 +270,12 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
|
||||
return Collections.singletonList(root);
|
||||
}
|
||||
|
||||
private static class DirectoryElementType extends CompositePackagingElementType<DirectoryPackagingElement> {
|
||||
private static final Icon ICON = IconLoader.getIcon("/actions/newFolder.png");
|
||||
|
||||
private DirectoryElementType() {
|
||||
super("directory", CompilerBundle.message("element.type.name.directory"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return ICON;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DirectoryPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new DirectoryPackagingElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull DirectoryPackagingElement element,
|
||||
@NotNull ArtifactEditorContext context) {
|
||||
if (ArtifactUtil.isArchiveName(element.getDirectoryName())) {
|
||||
return new DirectoryElementPropertiesPanel(element, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DirectoryPackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement<?> parent) {
|
||||
final String initialValue = suggestFileName(parent, "folder", "");
|
||||
final String name = Messages.showInputDialog(context.getProject(), "Enter directory name: ", "New Directory", null, initialValue, null);
|
||||
if (name == null) return null;
|
||||
return new DirectoryPackagingElement(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ArchiveElementType extends CompositePackagingElementType<ArchivePackagingElement> {
|
||||
private ArchiveElementType() {
|
||||
super("archive", CompilerBundle.message("element.type.name.archive"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return Icons.JAR_ICON;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArchivePackagingElement createEmpty(@NotNull Project project) {
|
||||
return new ArchivePackagingElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull ArchivePackagingElement element,
|
||||
@NotNull ArtifactEditorContext context) {
|
||||
final String name = element.getArchiveFileName();
|
||||
if (name.length() >= 4 && name.charAt(name.length() - 4) == '.' && StringUtil.endsWithIgnoreCase(name, "ar")) {
|
||||
return new ArchiveElementPropertiesPanel(element, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArchivePackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement<?> parent) {
|
||||
final String initialValue = suggestFileName(parent, "archive", ".jar");
|
||||
final String name = Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, null);
|
||||
if (name == null) return null;
|
||||
return new ArchivePackagingElement(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FileCopyElementType extends PackagingElementType<FileCopyPackagingElement> {
|
||||
public static final Icon ICON = IconLoader.getIcon("/fileTypes/text.png");
|
||||
|
||||
private FileCopyElementType() {
|
||||
super("file-copy", "File");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends FileCopyPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, true);
|
||||
final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject());
|
||||
final VirtualFile[] files = chooser.choose(null, context.getProject());
|
||||
final List<FileCopyPackagingElement> list = new ArrayList<FileCopyPackagingElement>();
|
||||
for (VirtualFile file : files) {
|
||||
list.add(new FileCopyPackagingElement(file.getPath()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FileCopyPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new FileCopyPackagingElement();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DirectoryCopyElementType extends PackagingElementType<DirectoryCopyPackagingElement> {
|
||||
public static final Icon COPY_OF_FOLDER_ICON = IconLoader.getIcon("/nodes/copyOfFolder.png");
|
||||
|
||||
private DirectoryCopyElementType() {
|
||||
super("dir-copy", "Directory Content");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return COPY_OF_FOLDER_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends DirectoryCopyPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, true);
|
||||
final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject());
|
||||
final VirtualFile[] files = chooser.choose(null, context.getProject());
|
||||
final List<DirectoryCopyPackagingElement> list = new ArrayList<DirectoryCopyPackagingElement>();
|
||||
for (VirtualFile file : files) {
|
||||
list.add(new DirectoryCopyPackagingElement(file.getPath()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DirectoryCopyPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new DirectoryCopyPackagingElement();
|
||||
}
|
||||
public static PackagingElement<?> createDirectoryOrArchiveWithParents(@NotNull String path, final boolean archive) {
|
||||
path = FileUtil.toSystemIndependentName(path);
|
||||
final String parentPath = PathUtil.getParentPath(path);
|
||||
final String fileName = PathUtil.getFileName(path);
|
||||
final PackagingElement<?> element = archive ? new ArchivePackagingElement(fileName) : new DirectoryPackagingElement(fileName);
|
||||
return getInstance().createParentDirectories(parentPath, element);
|
||||
}
|
||||
|
||||
private static class ArtifactRootElementType extends PackagingElementType<ArtifactRootElement<?>> {
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl;
|
||||
import com.intellij.packaging.impl.elements.DirectoryCopyElementType;
|
||||
import com.intellij.packaging.ui.PackagingElementPresentation;
|
||||
import com.intellij.packaging.ui.PackagingElementWeights;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
@@ -56,7 +56,7 @@ public class DirectoryCopyPresentation extends PackagingElementPresentation {
|
||||
}
|
||||
|
||||
public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
|
||||
presentationData.setIcons(PackagingElementFactoryImpl.DirectoryCopyElementType.COPY_OF_FOLDER_ICON);
|
||||
presentationData.setIcons(DirectoryCopyElementType.COPY_OF_FOLDER_ICON);
|
||||
if (myFile == null || !myFile.isDirectory()) {
|
||||
mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
|
||||
final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath));
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl;
|
||||
import com.intellij.packaging.impl.elements.FileCopyElementType;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.PackagingElementPresentation;
|
||||
import com.intellij.packaging.ui.PackagingElementWeights;
|
||||
@@ -65,12 +65,12 @@ public class FileCopyPresentation extends PackagingElementPresentation {
|
||||
|
||||
public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
|
||||
if (myFile != null && !myFile.isDirectory() || myContext.isManifestFile(mySourcePath)) {
|
||||
presentationData.setIcons(myFile != null ? myFile.getIcon() : PackagingElementFactoryImpl.FileCopyElementType.ICON);
|
||||
presentationData.setIcons(myFile != null ? myFile.getIcon() : FileCopyElementType.ICON);
|
||||
presentationData.addText(myOutputFileName, mainAttributes);
|
||||
presentationData.addText(" (" + mySourcePath + ")", commentAttributes);
|
||||
}
|
||||
else {
|
||||
presentationData.setIcons(PackagingElementFactoryImpl.FileCopyElementType.ICON);
|
||||
presentationData.setIcons(FileCopyElementType.ICON);
|
||||
presentationData.addText(myOutputFileName, SimpleTextAttributes.ERROR_ATTRIBUTES);
|
||||
final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath));
|
||||
presentationData.addText("(" + mySourcePath + ")",
|
||||
|
||||
+3
-3
@@ -39,11 +39,11 @@ public abstract class CompositePackagingElementType<E extends CompositePackaging
|
||||
|
||||
|
||||
@Nullable
|
||||
public abstract E createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement<?> parent);
|
||||
protected abstract PackagingElement<?> createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement<?> parent);
|
||||
|
||||
@NotNull
|
||||
public List<? extends E> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
|
||||
final E composite = createComposite(context, parent);
|
||||
public List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
|
||||
final PackagingElement<?> composite = createComposite(context, parent);
|
||||
return composite != null ? Collections.singletonList(composite) : Collections.<E>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ public abstract class PackagingElementType<E extends PackagingElement<?>> {
|
||||
public abstract boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact);
|
||||
|
||||
@NotNull
|
||||
public abstract List<? extends E> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent);
|
||||
public abstract List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent);
|
||||
|
||||
@NotNull
|
||||
public abstract E createEmpty(@NotNull Project project);
|
||||
|
||||
@@ -29,6 +29,8 @@ import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class PathUtil {
|
||||
private PathUtil() {
|
||||
}
|
||||
|
||||
public static String getLocalPath(VirtualFile file) {
|
||||
if (file == null || !file.isValid()) {
|
||||
@@ -125,17 +127,30 @@ public class PathUtil {
|
||||
}
|
||||
|
||||
public static String suggestFileName(final String text) {
|
||||
return text.replace(' ', '_')
|
||||
.replace('.', '_')
|
||||
.replace(File.separatorChar, '_')
|
||||
.replace('\t', '_')
|
||||
.replace('\n', '_')
|
||||
.replace(':', '_')
|
||||
.replace('*', '_')
|
||||
.replace('?', '_')
|
||||
.replace('<', '_')
|
||||
.replace('>', '_')
|
||||
.replace('/', '_')
|
||||
.replace('"', '_');
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if (!isValidFileNameChar(c) || c == '.' || Character.isWhitespace(c)) {
|
||||
result.append('_');
|
||||
}
|
||||
else {
|
||||
result.append(c);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static boolean isValidFileName(@NotNull String fileName) {
|
||||
for (int i = 0; i < fileName.length(); i++) {
|
||||
if (!isValidFileNameChar(fileName.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isValidFileNameChar(char c) {
|
||||
return c != '/' && c != '\\' && c != '\t' && c != '\n' && c != '\r' && c != ':' && c != ';' && c != '*' && c != '?'
|
||||
&& c != '"' && c != '\'' && c != '<' && c != '>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user