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.
17 package com
.intellij
.ide
.favoritesTreeView
.actions
;
19 import com
.intellij
.ide
.favoritesTreeView
.FavoritesManager
;
20 import com
.intellij
.openapi
.actionSystem
.AnAction
;
21 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
22 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
23 import com
.intellij
.openapi
.fileEditor
.FileEditorManager
;
24 import com
.intellij
.openapi
.project
.Project
;
25 import com
.intellij
.openapi
.vfs
.VirtualFile
;
26 import com
.intellij
.psi
.PsiFile
;
27 import com
.intellij
.psi
.PsiManager
;
29 import java
.util
.ArrayList
;
35 public class AddAllOpenFilesToFavorites
extends AnAction
{
36 private final String myFavoritesName
;
37 public AddAllOpenFilesToFavorites(String choosenList
) {
39 myFavoritesName
= choosenList
;
42 public void actionPerformed(AnActionEvent e
) {
43 final Project project
= PlatformDataKeys
.PROJECT
.getData(e
.getDataContext());
48 final FavoritesManager favoritesManager
= FavoritesManager
.getInstance(project
);
50 final ArrayList
<PsiFile
> filesToAdd
= getFilesToAdd(project
);
51 for (PsiFile file
: filesToAdd
) {
52 favoritesManager
.addRoots(myFavoritesName
, null, file
);
56 static ArrayList
<PsiFile
> getFilesToAdd (Project project
) {
57 ArrayList
<PsiFile
> result
= new ArrayList
<PsiFile
>();
58 final FileEditorManager editorManager
= FileEditorManager
.getInstance(project
);
59 final PsiManager psiManager
= PsiManager
.getInstance(project
);
60 final VirtualFile
[] openFiles
= editorManager
.getOpenFiles();
61 for (VirtualFile openFile
: openFiles
) {
62 final PsiFile psiFile
= psiManager
.findFile(openFile
);
63 if (psiFile
!= null) {
70 public void update(AnActionEvent e
) {
71 final Project project
= PlatformDataKeys
.PROJECT
.getData(e
.getDataContext());
73 e
.getPresentation().setEnabled(false);
76 e
.getPresentation().setEnabled(!getFilesToAdd(project
).isEmpty());