Search in sources :

Example 1 with ModuleRootEvent

use of com.intellij.openapi.roots.ModuleRootEvent 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 ModuleRootEvent

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

the class GeneratedSourceFileChangeTrackerImpl method projectOpened.

@Override
public void projectOpened() {
    final Update check = new Update("check for changes in generated files") {

        @Override
        public void run() {
            checkFiles();
        }
    };
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            VirtualFile file = myDocumentManager.getFile(e.getDocument());
            if (file != null) {
                myFilesToCheck.add(file);
                myCheckingQueue.queue(check);
            }
        }
    }, myProject);
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
            myFilesToCheck.remove(file);
            if (myEditedGeneratedFiles.remove(file)) {
                myEditorNotifications.updateNotifications(file);
            }
        }
    });
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            myEditedGeneratedFiles.remove(file);
        }
    });
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myFilesToCheck.addAll(myEditedGeneratedFiles);
            myEditedGeneratedFiles.clear();
            myCheckingQueue.queue(check);
        }
    });
    myCheckingQueue.activate();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Update(com.intellij.util.ui.update.Update) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 3 with ModuleRootEvent

use of com.intellij.openapi.roots.ModuleRootEvent 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 4 with ModuleRootEvent

use of com.intellij.openapi.roots.ModuleRootEvent 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 5 with ModuleRootEvent

use of com.intellij.openapi.roots.ModuleRootEvent 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)16 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)13 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)10 ModuleRootAdapter (com.intellij.openapi.roots.ModuleRootAdapter)3 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