Search in sources :

Example 1 with ModuleRootListener

use of com.intellij.openapi.roots.ModuleRootListener in project intellij-community by JetBrains.

the class MavenMergingUpdateQueue method makeUserAware.

public void makeUserAware(final Project project) {
    AccessToken accessToken = ReadAction.start();
    try {
        EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
        multicaster.addCaretListener(new CaretAdapter() {

            @Override
            public void caretPositionChanged(CaretEvent e) {
                MavenMergingUpdateQueue.this.restartTimer();
            }
        }, this);
        multicaster.addDocumentListener(new DocumentAdapter() {

            @Override
            public void documentChanged(DocumentEvent event) {
                MavenMergingUpdateQueue.this.restartTimer();
            }
        }, this);
        project.getMessageBus().connect(this).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

            int beforeCalled;

            @Override
            public void beforeRootsChange(ModuleRootEvent event) {
                if (beforeCalled++ == 0) {
                    suspend();
                }
            }

            @Override
            public void rootsChanged(ModuleRootEvent event) {
                if (beforeCalled == 0)
                    // This may occur if listener has been added between beforeRootsChange() and rootsChanged() calls.
                    return;
                if (--beforeCalled == 0) {
                    resume();
                    MavenMergingUpdateQueue.this.restartTimer();
                }
            }
        });
    } finally {
        accessToken.finish();
    }
}
Also used : ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 2 with ModuleRootListener

use of com.intellij.openapi.roots.ModuleRootListener in project intellij-community by JetBrains.

the class ExternalSystemProjectsWatcher method makeUserAware.

private static void makeUserAware(final MergingUpdateQueue mergingUpdateQueue, final Project project) {
    AccessToken accessToken = ReadAction.start();
    try {
        EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
        multicaster.addCaretListener(new CaretAdapter() {

            @Override
            public void caretPositionChanged(CaretEvent e) {
                mergingUpdateQueue.restartTimer();
            }
        }, mergingUpdateQueue);
        multicaster.addDocumentListener(new DocumentAdapter() {

            @Override
            public void documentChanged(DocumentEvent event) {
                mergingUpdateQueue.restartTimer();
            }
        }, mergingUpdateQueue);
        project.getMessageBus().connect(mergingUpdateQueue).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

            int beforeCalled;

            @Override
            public void beforeRootsChange(ModuleRootEvent event) {
                if (beforeCalled++ == 0) {
                    mergingUpdateQueue.suspend();
                }
            }

            @Override
            public void rootsChanged(ModuleRootEvent event) {
                if (beforeCalled == 0) {
                    // This may occur if listener has been added between beforeRootsChange() and rootsChanged() calls.
                    return;
                }
                if (--beforeCalled == 0) {
                    mergingUpdateQueue.resume();
                    mergingUpdateQueue.restartTimer();
                }
            }
        });
    } finally {
        accessToken.finish();
    }
}
Also used : ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 3 with ModuleRootListener

use of com.intellij.openapi.roots.ModuleRootListener in project intellij-community by JetBrains.

the class LibraryDependentToolWindowManager method projectOpened.

@Override
public void projectOpened() {
    final ModuleRootListener rootListener = new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            if (!myProject.isDisposed()) {
                checkToolWindowStatuses(myProject);
            }
        }
    };
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
        if (!myProject.isDisposed()) {
            checkToolWindowStatuses(myProject);
            final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
            connection.subscribe(ProjectTopics.PROJECT_ROOTS, rootListener);
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 4 with ModuleRootListener

use of com.intellij.openapi.roots.ModuleRootListener in project intellij-plugins by JetBrains.

the class DartServerRootsHandler method ensureProjectServed.

public void ensureProjectServed() {
    assert (myIncludedRoots.isEmpty());
    assert (myExcludedRoots.isEmpty());
    ProgressManager.getInstance().executeNonCancelableSection(() -> {
        updateRoots();
        final DartAnalysisServerService das = DartAnalysisServerService.getInstance(myProject);
        das.updateCurrentFile();
        das.updateVisibleFiles();
    });
    myProject.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(final ModuleRootEvent event) {
            updateRoots();
        }
    });
}
Also used : ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 5 with ModuleRootListener

use of com.intellij.openapi.roots.ModuleRootListener in project android by JetBrains.

the class JavaFacet method initFacet.

@Override
public void initFacet() {
    MessageBusConnection connection = getModule().getMessageBus().connect(this);
    connection.subscribe(PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (!isDisposed()) {
                    PsiDocumentManager.getInstance(getModule().getProject()).commitAllDocuments();
                    updateConfiguration();
                }
            });
        }
    });
    updateConfiguration();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Aggregations

ModuleRootEvent (com.intellij.openapi.roots.ModuleRootEvent)13 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)13 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)2 Update (com.intellij.util.ui.update.Update)2 StringRegistry (com.intellij.flex.uiDesigner.io.StringRegistry)1 SortResult (com.intellij.flex.uiDesigner.libraries.LibrarySorter.SortResult)1 ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)1 Notification (com.intellij.notification.Notification)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Document (com.intellij.openapi.editor.Document)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)1 FileTypeEvent (com.intellij.openapi.fileTypes.FileTypeEvent)1 FileTypeListener (com.intellij.openapi.fileTypes.FileTypeListener)1 Project (com.intellij.openapi.project.Project)1