Search in sources :

Example 11 with ModuleRootEvent

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

the class DirectoryIndexImpl method subscribeToFileChanges.

protected void subscribeToFileChanges() {
    myConnection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {

        @Override
        public void fileTypesChanged(@NotNull FileTypeEvent event) {
            myRootIndex = null;
        }
    });
    myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myRootIndex = null;
        }
    });
    myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            RootIndex rootIndex = myRootIndex;
            if (rootIndex != null && rootIndex.resetOnEvents(events)) {
                myRootIndex = null;
            }
        }
    });
}
Also used : FileTypeListener(com.intellij.openapi.fileTypes.FileTypeListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) FileTypeEvent(com.intellij.openapi.fileTypes.FileTypeEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 12 with ModuleRootEvent

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

the class MiscImportingTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myProject.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void beforeRootsChange(ModuleRootEvent event) {
            beforeRootsChangedCount++;
        }

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

Example 13 with ModuleRootEvent

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

the class NdkFacet method initFacet.

@Override
public void initFacet() {
    MessageBusConnection connection = getModule().getMessageBus().connect(this);
    connection.subscribe(ProjectTopics.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)

Example 14 with ModuleRootEvent

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

the class GradleFacet method initFacet.

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

        @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) ModuleRootAdapter(com.intellij.openapi.roots.ModuleRootAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent)

Example 15 with ModuleRootEvent

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

the class LibraryManager method registerModule.

@NotNull
public ProjectComponentReferenceCounter registerModule(@NotNull final Module module, ProblemsHolder problemsHolder, boolean collectLocalStyleHolders) throws InitException {
    final Project project = module.getProject();
    final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter(16384);
    stringWriter.startChange();
    final AssetCounter assetCounter = new AssetCounter();
    final LibraryCollector libraryCollector = new LibraryCollector(this, new LibraryStyleInfoCollector(assetCounter, problemsHolder, module, stringWriter), module);
    final Client client;
    try {
        final AccessToken token = ReadAction.start();
        try {
            libraryCollector.collect(module);
        } finally {
            token.finish();
        }
        client = Client.getInstance();
        if (stringWriter.hasChanges()) {
            client.updateStringRegistry(stringWriter);
        } else {
            stringWriter.commit();
        }
    } catch (Throwable e) {
        stringWriter.rollback();
        throw new InitException(e, "error.collect.libraries");
    }
    assert !libraryCollector.sdkLibraries.isEmpty();
    final FlexLibrarySet flexLibrarySet = getOrCreateFlexLibrarySet(libraryCollector, assetCounter);
    final InfoMap<Project, ProjectInfo> registeredProjects = client.getRegisteredProjects();
    ProjectInfo info = registeredProjects.getNullableInfo(project);
    if (info == null) {
        info = new ProjectInfo(project);
        registeredProjects.add(info);
        client.openProject(project);
        DesignerApplicationManager.getInstance().projectRegistered(project);
    }
    LibrarySet librarySet;
    if (libraryCollector.externalLibraries.isEmpty()) {
        librarySet = null;
    } else {
        final String key = createKey(libraryCollector.externalLibraries, false);
        librarySet = librarySets.get(key);
        if (librarySet == null) {
            final SortResult sortResult = sortLibraries(new LibrarySorter(), libraryCollector, flexLibrarySet.contains, key, false);
            librarySet = new LibrarySet(sortResult.id, flexLibrarySet, sortResult.libraries);
            registerLibrarySet(key, librarySet);
        }
    }
    final ModuleInfo moduleInfo = new ModuleInfo(module, librarySet == null ? flexLibrarySet : librarySet, ModuleInfoUtil.isApp(module));
    final ProjectComponentReferenceCounter projectComponentReferenceCounter = new ProjectComponentReferenceCounter();
    if (collectLocalStyleHolders) {
        // client.registerModule finalize it
        stringWriter.startChange();
        try {
            moduleInfo.setLocalStyleHolders(ModuleInfoUtil.collectLocalStyle(moduleInfo, libraryCollector.getFlexSdkVersion(), stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
        } catch (Throwable e) {
            stringWriter.rollback();
            throw new InitException(e, "error.collect.local.style.holders");
        }
    }
    client.registerModule(project, moduleInfo, stringWriter);
    client.fillAssetClassPoolIfNeed(flexLibrarySet);
    module.getMessageBus().connect(moduleInfo).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            new Notification(FlashUIDesignerBundle.message("plugin.name"), FlashUIDesignerBundle.message("plugin.name"), "Please reopen your project to update on library changes.", NotificationType.WARNING).notify(project);
        }
    });
    return projectComponentReferenceCounter;
}
Also used : ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) Notification(com.intellij.notification.Notification) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) SortResult(com.intellij.flex.uiDesigner.libraries.LibrarySorter.SortResult) NotNull(org.jetbrains.annotations.NotNull)

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