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
.codeInsight
.folding
.impl
;
18 import com
.intellij
.codeInsight
.CodeInsightActionHandler
;
19 import com
.intellij
.codeInsight
.folding
.CodeFoldingManager
;
20 import com
.intellij
.openapi
.editor
.Editor
;
21 import com
.intellij
.openapi
.editor
.FoldRegion
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.psi
.PsiDocumentManager
;
24 import com
.intellij
.psi
.PsiElement
;
25 import com
.intellij
.psi
.PsiFile
;
26 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
27 import org
.jetbrains
.annotations
.NotNull
;
29 public class CollapseExpandJavadocsHandler
implements CodeInsightActionHandler
{
30 private final boolean myExpand
;
32 public CollapseExpandJavadocsHandler(boolean isExpand
) {
36 public void invoke(@NotNull Project project
, @NotNull final Editor editor
, @NotNull PsiFile file
){
37 PsiDocumentManager
.getInstance(project
).commitAllDocuments();
39 CodeFoldingManager foldingManager
= CodeFoldingManager
.getInstance(project
);
40 foldingManager
.updateFoldRegions(editor
);
41 final FoldRegion
[] allFoldRegions
= editor
.getFoldingModel().getAllFoldRegions();
42 Runnable processor
= new Runnable() {
44 for (FoldRegion region
: allFoldRegions
) {
45 PsiElement element
= EditorFoldingInfo
.get(editor
).getPsiElement(region
);
46 if (element
instanceof PsiDocComment
) {
47 region
.setExpanded(myExpand
);
52 editor
.getFoldingModel().runBatchFoldingOperation(processor
);
55 public boolean startInWriteAction() {