Search in sources :

Example 1 with CodeFoldingState

use of com.intellij.openapi.fileEditor.impl.text.CodeFoldingState in project intellij-community by JetBrains.

the class CodeFoldingManagerImpl method buildInitialFoldings.

@Override
public void buildInitialFoldings(@NotNull final Editor editor) {
    final Project project = editor.getProject();
    if (project == null || !project.equals(myProject) || editor.isDisposed())
        return;
    if (!((FoldingModelEx) editor.getFoldingModel()).isFoldingEnabled())
        return;
    if (!FoldingUpdate.supportsDumbModeFolding(editor))
        return;
    Document document = editor.getDocument();
    PsiDocumentManager.getInstance(myProject).commitDocument(document);
    CodeFoldingState foldingState = buildInitialFoldings(document);
    if (foldingState != null) {
        foldingState.setToEditor(editor);
    }
}
Also used : Project(com.intellij.openapi.project.Project) CodeFoldingState(com.intellij.openapi.fileEditor.impl.text.CodeFoldingState)

Example 2 with CodeFoldingState

use of com.intellij.openapi.fileEditor.impl.text.CodeFoldingState in project intellij-community by JetBrains.

the class CodeFoldingManagerImpl method buildInitialFoldings.

@Nullable
@Override
public CodeFoldingState buildInitialFoldings(@NotNull final Document document) {
    if (myProject.isDisposed()) {
        return null;
    }
    ApplicationManager.getApplication().assertReadAccessAllowed();
    PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject);
    if (psiDocumentManager.isUncommited(document)) {
        // skip building foldings for uncommitted document, CodeFoldingPass invoked by daemon will do it later
        return null;
    }
    //Do not save/restore folding for code fragments
    final PsiFile file = psiDocumentManager.getPsiFile(document);
    if (file == null || !file.isValid() || !file.getViewProvider().isPhysical() && !ApplicationManager.getApplication().isUnitTestMode()) {
        return null;
    }
    final FoldingUpdate.FoldingMap foldingMap = FoldingUpdate.getFoldingsFor(file, document, true);
    return editor -> {
        ApplicationManagerEx.getApplicationEx().assertIsDispatchThread();
        if (myProject.isDisposed() || editor.isDisposed())
            return;
        final FoldingModelEx foldingModel = (FoldingModelEx) editor.getFoldingModel();
        if (!foldingModel.isFoldingEnabled())
            return;
        if (isFoldingsInitializedInEditor(editor))
            return;
        if (DumbService.isDumb(myProject) && !FoldingUpdate.supportsDumbModeFolding(editor))
            return;
        foldingModel.runBatchFoldingOperationDoNotCollapseCaret(new UpdateFoldRegionsOperation(myProject, editor, file, foldingMap, UpdateFoldRegionsOperation.ApplyDefaultStateMode.YES, false, false));
        initFolding(editor);
    };
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) EditorMouseMotionAdapter(com.intellij.openapi.editor.event.EditorMouseMotionAdapter) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) com.intellij.openapi.editor(com.intellij.openapi.editor) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) EditorMouseEventArea(com.intellij.openapi.editor.event.EditorMouseEventArea) StartupManager(com.intellij.openapi.startup.StartupManager) CodeFoldingManager(com.intellij.codeInsight.folding.CodeFoldingManager) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) EditorEx(com.intellij.openapi.editor.ex.EditorEx) ProjectComponent(com.intellij.openapi.components.ProjectComponent) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) DumbService(com.intellij.openapi.project.DumbService) WeakList(com.intellij.util.containers.WeakList) MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) CodeFoldingState(com.intellij.openapi.fileEditor.impl.text.CodeFoldingState) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) HintManager(com.intellij.codeInsight.hint.HintManager) NotNull(org.jetbrains.annotations.NotNull) LightweightHint(com.intellij.ui.LightweightHint) Element(org.jdom.Element) EditorFragmentComponent(com.intellij.codeInsight.hint.EditorFragmentComponent) javax.swing(javax.swing) PsiFile(com.intellij.psi.PsiFile) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CodeFoldingState (com.intellij.openapi.fileEditor.impl.text.CodeFoldingState)2 Project (com.intellij.openapi.project.Project)2 CodeFoldingManager (com.intellij.codeInsight.folding.CodeFoldingManager)1 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationManagerEx (com.intellij.openapi.application.ex.ApplicationManagerEx)1 ProjectComponent (com.intellij.openapi.components.ProjectComponent)1 com.intellij.openapi.editor (com.intellij.openapi.editor)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 EditorMouseEventArea (com.intellij.openapi.editor.event.EditorMouseEventArea)1 EditorMouseMotionAdapter (com.intellij.openapi.editor.event.EditorMouseMotionAdapter)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)1 DumbAwareRunnable (com.intellij.openapi.project.DumbAwareRunnable)1 DumbService (com.intellij.openapi.project.DumbService)1 StartupManager (com.intellij.openapi.startup.StartupManager)1 com.intellij.openapi.util (com.intellij.openapi.util)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 PsiElement (com.intellij.psi.PsiElement)1