Search in sources :

Example 11 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class FoldingModelWindow method getGroupedRegions.

@NotNull
@Override
public List<FoldRegion> getGroupedRegions(FoldingGroup group) {
    List<FoldRegion> hostRegions = myDelegate.getGroupedRegions(group);
    List<FoldRegion> result = new ArrayList<>();
    for (FoldRegion hostRegion : hostRegions) {
        FoldingRegionWindow window = getWindowRegion(hostRegion);
        if (window != null)
            result.add(window);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) FoldRegion(com.intellij.openapi.editor.FoldRegion) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class CopyPasteFoldingProcessor method processTransferableData.

@Override
public void processTransferableData(final Project project, final Editor editor, final RangeMarker bounds, int caretOffset, Ref<Boolean> indented, final List<FoldingTransferableData> values) {
    assert values.size() == 1;
    final FoldingTransferableData value = values.get(0);
    if (value.getData().length == 0)
        return;
    final CodeFoldingManagerImpl foldingManager = (CodeFoldingManagerImpl) CodeFoldingManager.getInstance(project);
    foldingManager.updateFoldRegions(editor, true);
    Runnable operation = () -> {
        for (FoldingData data : value.getData()) {
            FoldRegion region = foldingManager.findFoldRegion(editor, data.startOffset + bounds.getStartOffset(), data.endOffset + bounds.getStartOffset());
            if (region != null) {
                region.setExpanded(data.isExpanded);
            }
        }
    };
    editor.getFoldingModel().runBatchFoldingOperation(operation);
}
Also used : FoldRegion(com.intellij.openapi.editor.FoldRegion) CodeFoldingManagerImpl(com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl)

Example 13 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class FoldingModelSupport method expandAll.

//
// Synchronized toggling of ranges
//
public void expandAll(final boolean expanded) {
    if (myDuringSynchronize)
        return;
    myDuringSynchronize = true;
    try {
        for (int i = 0; i < myCount; i++) {
            final int index = i;
            final FoldingModelEx model = myEditors[index].getFoldingModel();
            model.runBatchFoldingOperation(() -> {
                for (FoldedBlock folding : getFoldedBlocks()) {
                    FoldRegion region = folding.getRegion(index);
                    if (region != null)
                        region.setExpanded(expanded);
                }
            });
        }
    } finally {
        myDuringSynchronize = false;
    }
}
Also used : FoldRegion(com.intellij.openapi.editor.FoldRegion) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx)

Example 14 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class FoldingModelSupport method getFoldedRanges.

@NotNull
private List<FoldedRangeState> getFoldedRanges(int index, @NotNull Settings settings) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    List<FoldedRangeState> ranges = new ArrayList<>();
    DocumentEx document = myEditors[index].getDocument();
    for (FoldedBlock[] blocks : myFoldings) {
        LineRange expanded = null;
        LineRange collapsed = null;
        for (FoldedBlock folding : blocks) {
            FoldRegion region = folding.getRegion(index);
            if (region == null || !region.isValid())
                continue;
            if (region.isExpanded()) {
                if (expanded == null) {
                    int line1 = document.getLineNumber(region.getStartOffset());
                    int line2 = document.getLineNumber(region.getEndOffset()) + 1;
                    expanded = new LineRange(line1, line2);
                }
            } else {
                int line1 = document.getLineNumber(region.getStartOffset());
                int line2 = document.getLineNumber(region.getEndOffset()) + 1;
                collapsed = new LineRange(line1, line2);
                break;
            }
        }
        if (expanded != null || collapsed != null) {
            ranges.add(new FoldedRangeState(expanded, collapsed));
        }
    }
    return ranges;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) ArrayList(java.util.ArrayList) FoldRegion(com.intellij.openapi.editor.FoldRegion) LineRange(com.intellij.diff.util.LineRange) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with FoldRegion

use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.

the class FoldingAnchorsOverlayStrategyTest method collapseFoldingRegion.

private void collapseFoldingRegion(int n) {
    FoldingModel foldingModel = myFixture.getEditor().getFoldingModel();
    final FoldRegion foldRegion = foldingModel.getAllFoldRegions()[n];
    foldingModel.runBatchFoldingOperation(() -> foldRegion.setExpanded(false));
}
Also used : FoldingModel(com.intellij.openapi.editor.FoldingModel) FoldRegion(com.intellij.openapi.editor.FoldRegion)

Aggregations

FoldRegion (com.intellij.openapi.editor.FoldRegion)47 TextRange (com.intellij.openapi.util.TextRange)7 ArrayList (java.util.ArrayList)7 FoldingModel (com.intellij.openapi.editor.FoldingModel)6 NotNull (org.jetbrains.annotations.NotNull)6 FoldingGroup (com.intellij.openapi.editor.FoldingGroup)5 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)5 PsiElement (com.intellij.psi.PsiElement)5 CodeFoldingManager (com.intellij.codeInsight.folding.CodeFoldingManager)3 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)3 Document (com.intellij.openapi.editor.Document)3 Editor (com.intellij.openapi.editor.Editor)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)2 RangeMarker (com.intellij.openapi.editor.RangeMarker)2 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2