2 * Copyright 2000-2010 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.openapi.fileChooser;
19 import com.intellij.openapi.vfs.VirtualFile;
20 import com.intellij.util.ArrayUtil;
21 import org.jetbrains.annotations.NotNull;
23 import java.util.Arrays;
24 import java.util.List;
27 * Defines save dialog behaviour
29 * @author Konstantin Bulenkov
30 * @see FileSaverDialog
31 * @see FileChooserDescriptor
34 public class FileSaverDescriptor extends FileChooserDescriptor implements Cloneable {
35 private final List<String> extensions;
38 * Constructs save dialog properties
40 * @param title save dialog text title (not window title)
41 * @param description description
42 * @param extensions accepted file extensions: "txt", "jpg", etc. Accepts all if empty
44 public FileSaverDescriptor(@NotNull String title, @NotNull String description, String... extensions) {
45 super(true, true, true, true, false, false);
47 setDescription(description);
48 this.extensions = Arrays.asList(extensions);
52 public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
53 return extensions.isEmpty() || file.isDirectory() ?
54 super.isFileVisible(file, showHiddenFiles)
56 extensions.contains(file.getExtension());
60 * Returns accepted file extensions
62 * @return accepted file extensions
64 public String[] getFileExtensions() {
65 return ArrayUtil.toStringArray(extensions);