Search in sources :

Example 6 with ModuleRootListener

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

use of com.intellij.openapi.roots.ModuleRootListener in project intellij-leiningen-plugin by derkork.

the class LeiningenProjectsManagerWatcher method start.

public synchronized void start() {
    final MessageBusConnection myBusConnection = project.getMessageBus().connect(myQueue);
    myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        public void before(List<? extends VFileEvent> vFileEvents) {
        }

        public void after(List<? extends VFileEvent> vFileEvents) {
            for (VFileEvent vFileEvent : vFileEvents) {
                //                    }
                if (vFileEvent instanceof VFileCreateEvent) {
                    if (isRelevant(vFileEvent.getPath())) {
                        manager.importLeiningenProject(vFileEvent.getFileSystem().findFileByPath(vFileEvent.getPath()), project);
                    }
                }
            }
        }

        private boolean isRelevant(String path) {
            return path != null && path.endsWith(LeiningenConstants.PROJECT_CLJ);
        }
    });
    myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {
        }

        public void rootsChanged(ModuleRootEvent moduleRootEvent) {
        }
    });
    myQueue.activate();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 8 with ModuleRootListener

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

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

the class NotIndexedCucumberExtension method getDataObject.

public Object getDataObject(@NotNull final Project project) {
    final DataObject result = new DataObject();
    result.myUpdateQueue.setPassThrough(false);
    PsiManager.getInstance(project).addPsiTreeChangeListener(result.myCucumberPsiTreeListener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(new PsiTreeChangeAdapter() {

        @Override
        public void childAdded(@NotNull PsiTreeChangeEvent event) {
            final PsiElement parent = event.getParent();
            PsiElement child = event.getChild();
            if (isStepLikeFile(child, parent)) {
                final PsiFile file = (PsiFile) child;
                result.myUpdateQueue.queue(new Update(parent) {

                    public void run() {
                        if (file.isValid()) {
                            reloadAbstractStepDefinitions(file);
                            createWatcher(file);
                        }
                    }
                });
            }
        }

        @Override
        public void childRemoved(@NotNull PsiTreeChangeEvent event) {
            final PsiElement parent = event.getParent();
            final PsiElement child = event.getChild();
            if (isStepLikeFile(child, parent)) {
                result.myUpdateQueue.queue(new Update(parent) {

                    public void run() {
                        removeAbstractStepDefinitionsRelatedTo((PsiFile) child);
                    }
                });
            }
        }
    });
    // clear caches after modules roots were changed
    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        final List<VirtualFile> myPreviousStepDefsProviders = new ArrayList<>();

        public void beforeRootsChange(ModuleRootEvent event) {
            myPreviousStepDefsProviders.clear();
            collectAllStepDefsProviders(myPreviousStepDefsProviders, project);
        }

        public void rootsChanged(ModuleRootEvent event) {
            // compare new and previous content roots
            final List<VirtualFile> newStepDefsProviders = new ArrayList<>();
            collectAllStepDefsProviders(newStepDefsProviders, project);
            if (!compareRoots(newStepDefsProviders)) {
                // clear caches on roots changed
                reset(project);
            }
        }

        private boolean compareRoots(final List<VirtualFile> newStepDefsProviders) {
            if (myPreviousStepDefsProviders.size() != newStepDefsProviders.size()) {
                return false;
            }
            for (VirtualFile root : myPreviousStepDefsProviders) {
                if (!newStepDefsProviders.contains(root)) {
                    return false;
                }
            }
            return true;
        }
    });
    Disposer.register(project, connection);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Update(com.intellij.util.ui.update.Update) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent)

Example 10 with ModuleRootListener

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