2 * Copyright 2000-2009 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.
16 package com
.intellij
.ide
.actions
;
18 import com
.intellij
.ide
.IdeBundle
;
19 import com
.intellij
.ide
.highlighter
.ProjectFileType
;
20 import com
.intellij
.ide
.impl
.ProjectUtil
;
21 import com
.intellij
.openapi
.actionSystem
.AnAction
;
22 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
23 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
24 import com
.intellij
.openapi
.extensions
.Extensions
;
25 import com
.intellij
.openapi
.fileChooser
.FileChooser
;
26 import com
.intellij
.openapi
.fileChooser
.FileChooserDescriptor
;
27 import com
.intellij
.openapi
.project
.Project
;
28 import com
.intellij
.openapi
.project
.DumbAware
;
29 import com
.intellij
.openapi
.util
.text
.StringUtil
;
30 import com
.intellij
.openapi
.vfs
.VirtualFile
;
31 import com
.intellij
.projectImport
.ProjectOpenProcessor
;
32 import com
.intellij
.projectImport
.ProjectOpenProcessorBase
;
33 import com
.intellij
.util
.ArrayUtil
;
35 public class OpenProjectAction
extends AnAction
implements DumbAware
{
36 public void actionPerformed(AnActionEvent e
) {
37 Project project
= PlatformDataKeys
.PROJECT
.getData(e
.getDataContext());
39 final FileChooserDescriptor descriptor
= new OpenProjectFileChooserDescriptor(true);
40 descriptor
.setTitle(IdeBundle
.message("title.open.project"));
41 String
[] extensions
= new String
[]{ProjectFileType
.DOT_DEFAULT_EXTENSION
};
42 final ProjectOpenProcessor
[] openProcessors
= Extensions
.getExtensions(ProjectOpenProcessorBase
.EXTENSION_POINT_NAME
);
43 for (ProjectOpenProcessor openProcessor
: openProcessors
) {
44 final String
[] supportedExtensions
= ((ProjectOpenProcessorBase
)openProcessor
).getSupportedExtensions();
45 if (supportedExtensions
!= null) {
46 extensions
= ArrayUtil
.mergeArrays(extensions
, supportedExtensions
, String
.class);
49 descriptor
.setDescription(IdeBundle
.message("filter.project.files", StringUtil
.join(extensions
, ", ")));
50 final VirtualFile
[] files
= FileChooser
.chooseFiles(project
, descriptor
);
52 if (files
.length
== 0 || files
[0] == null) return;
54 ProjectUtil
.openOrImport(files
[0].getPath(), project
, false);