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.
18 * Created by IntelliJ IDEA.
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com
.intellij
.openapi
.editor
.impl
;
27 import com
.intellij
.openapi
.editor
.Editor
;
28 import com
.intellij
.openapi
.editor
.FoldRegion
;
29 import com
.intellij
.openapi
.editor
.FoldingGroup
;
30 import com
.intellij
.openapi
.editor
.ex
.DocumentEx
;
31 import org
.jetbrains
.annotations
.NotNull
;
32 import org
.jetbrains
.annotations
.Nullable
;
34 public class FoldRegionImpl
extends RangeMarkerImpl
implements FoldRegion
{
35 private boolean myIsExpanded
;
36 private final Editor myEditor
;
37 private final String myPlaceholderText
;
38 private final FoldingGroup myGroup
;
40 public FoldRegionImpl(Editor editor
, int startOffset
, int endOffset
, String placeholder
, FoldingGroup group
) {
41 super((DocumentEx
)editor
.getDocument(), startOffset
, endOffset
);
45 myPlaceholderText
= placeholder
;
48 public boolean isExpanded() {
52 public void setExpanded(boolean expanded
) {
53 FoldingModelImpl foldingModel
= (FoldingModelImpl
)myEditor
.getFoldingModel();
54 if (myGroup
== null) {
55 doSetExpanded(expanded
, foldingModel
, this);
57 for (final FoldRegion region
: foldingModel
.getGroupedRegions(myGroup
)) {
58 doSetExpanded(expanded
, foldingModel
, region
);
63 private static void doSetExpanded(boolean expanded
, FoldingModelImpl foldingModel
, FoldRegion region
) {
65 foldingModel
.expandFoldRegion(region
);
68 foldingModel
.collapseFoldRegion(region
);
72 public boolean isValid() {
73 return super.isValid() && getStartOffset() + 1 < getEndOffset();
76 public void setExpandedInternal(boolean toExpand
) {
77 myIsExpanded
= toExpand
;
81 public String
getPlaceholderText() {
82 return myPlaceholderText
;
85 public Editor
getEditor() {
90 public FoldingGroup
getGroup() {
94 @SuppressWarnings({"HardCodedStringLiteral"})
95 public String
toString() {
96 return "FoldRegion (" + getStartOffset() + ":" + getEndOffset() + ")";