use of com.intellij.codeInsight.folding.CodeFoldingManager in project intellij-community by JetBrains.
the class RestoreFoldArrangementCallback method afterArrangement.
@Override
public void afterArrangement(@NotNull final List<ArrangementMoveInfo> moveInfos) {
// Restore state for the PSI elements not affected by arrangement.
Project project = myEditor.getProject();
if (project != null) {
final FoldRegion[] regions = myEditor.getFoldingModel().getAllFoldRegions();
final List<FoldRegionInfo> foldRegionsInfo = new ArrayList<>();
for (FoldRegion region : regions) {
final FoldRegionInfo info = new FoldRegionInfo(region.getStartOffset(), region.getEndOffset(), region.isExpanded());
foldRegionsInfo.add(info);
}
final CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project);
foldingManager.updateFoldRegions(myEditor);
myEditor.getFoldingModel().runBatchFoldingOperation(() -> {
for (FoldRegionInfo info : foldRegionsInfo) {
final FoldRegion foldRegion = foldingManager.findFoldRegion(myEditor, info.myStart, info.myEnd);
if (foldRegion != null) {
foldRegion.setExpanded(info.myIsExpanded);
}
}
});
}
}
use of com.intellij.codeInsight.folding.CodeFoldingManager in project intellij-community by JetBrains.
the class CodeFoldingConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
EditorSettingsExternalizable.getInstance().setFoldingOutlineShown(myCbFolding.isSelected());
super.apply();
final List<Pair<Editor, Project>> toUpdate = new ArrayList<>();
for (final Editor editor : EditorFactory.getInstance().getAllEditors()) {
final Project project = editor.getProject();
if (project != null && !project.isDefault()) {
toUpdate.add(Pair.create(editor, project));
}
}
ApplicationManager.getApplication().invokeLater(() -> {
for (Pair<Editor, Project> each : toUpdate) {
if (each.second == null || each.second.isDisposed()) {
continue;
}
final CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(each.second);
if (foldingManager != null) {
foldingManager.buildInitialFoldings(each.first);
}
}
EditorOptionsPanel.reinitAllEditors();
}, ModalityState.NON_MODAL);
}
use of com.intellij.codeInsight.folding.CodeFoldingManager in project intellij-community by JetBrains.
the class CollapseExpandDocCommentsHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project);
foldingManager.updateFoldRegions(editor);
final FoldRegion[] allFoldRegions = editor.getFoldingModel().getAllFoldRegions();
Runnable processor = () -> {
for (FoldRegion region : allFoldRegions) {
PsiElement element = EditorFoldingInfo.get(editor).getPsiElement(region);
if (element instanceof PsiDocCommentBase) {
region.setExpanded(myExpand);
}
}
};
editor.getFoldingModel().runBatchFoldingOperation(processor);
}
use of com.intellij.codeInsight.folding.CodeFoldingManager in project intellij-community by JetBrains.
the class ExpandRegionAction method expandRegionAtOffset.
public static void expandRegionAtOffset(@NotNull Project project, @NotNull final Editor editor, final int offset) {
CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project);
foldingManager.updateFoldRegions(editor);
final int line = editor.getDocument().getLineNumber(offset);
Runnable processor = () -> {
FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, line);
if (region != null && !region.isExpanded()) {
region.setExpanded(true);
} else {
FoldRegion[] regions = FoldingUtil.getFoldRegionsAtOffset(editor, offset);
for (int i = regions.length - 1; i >= 0; i--) {
region = regions[i];
if (!region.isExpanded()) {
region.setExpanded(true);
break;
}
}
}
};
editor.getFoldingModel().runBatchFoldingOperation(processor);
}
Aggregations