Search in sources :

Example 1 with VirtualFileAdapter

use of com.intellij.openapi.vfs.VirtualFileAdapter in project intellij-community by JetBrains.

the class EncodingPanel method install.

@Override
public void install(@NotNull StatusBar statusBar) {
    super.install(statusBar);
    // should update to reflect encoding-from-content
    EncodingManager.getInstance().addPropertyChangeListener(evt -> {
        if (evt.getPropertyName().equals(EncodingManagerImpl.PROP_CACHED_ENCODING_CHANGED)) {
            Document document = evt.getSource() instanceof Document ? (Document) evt.getSource() : null;
            updateForDocument(document);
        }
    }, this);
    ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(new VirtualFileAdapter() {

        @Override
        public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
            if (VirtualFile.PROP_ENCODING.equals(event.getPropertyName())) {
                updateForFile(event.getFile());
            }
        }
    }));
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            Document document = e.getDocument();
            updateForDocument(document);
        }
    }, this);
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) BulkVirtualFileListenerAdapter(com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter) Document(com.intellij.openapi.editor.Document) VirtualFilePropertyEvent(com.intellij.openapi.vfs.VirtualFilePropertyEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) NotNull(org.jetbrains.annotations.NotNull) VirtualFileAdapter(com.intellij.openapi.vfs.VirtualFileAdapter)

Example 2 with VirtualFileAdapter

use of com.intellij.openapi.vfs.VirtualFileAdapter in project intellij-community by JetBrains.

the class MovePackageAsDirectoryTest method testMultipleClassesInOneFile.

public void testMultipleClassesInOneFile() throws Exception {
    final boolean[] fileWasDeleted = new boolean[] { false };
    final VirtualFileAdapter fileAdapter = new VirtualFileAdapter() {

        @Override
        public void fileDeleted(@NotNull VirtualFileEvent event) {
            fileWasDeleted[0] = !event.getFile().isDirectory();
        }
    };
    VirtualFileManager.getInstance().addVirtualFileListener(fileAdapter);
    try {
        doTest(createAction("pack1", "target"));
    } finally {
        VirtualFileManager.getInstance().removeVirtualFileListener(fileAdapter);
    }
    Assert.assertFalse("Deleted instead of moved", fileWasDeleted[0]);
}
Also used : VirtualFileEvent(com.intellij.openapi.vfs.VirtualFileEvent) NotNull(org.jetbrains.annotations.NotNull) VirtualFileAdapter(com.intellij.openapi.vfs.VirtualFileAdapter)

Example 3 with VirtualFileAdapter

use of com.intellij.openapi.vfs.VirtualFileAdapter in project intellij-community by JetBrains.

the class ConfigProjectComponent method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // Register project-level config managers
    final EditorFactory editorFactory = EditorFactory.getInstance();
    MessageBus bus = project.getMessageBus();
    EditorSettingsManager editorSettingsManager = new EditorSettingsManager(project);
    EncodingManager encodingManager = new EncodingManager(project);
    LineEndingsManager lineEndingsManager = new LineEndingsManager(project);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, encodingManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, editorSettingsManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, lineEndingsManager);
    VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {

        @Override
        public void fileCreated(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        @Override
        public void fileDeleted(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        @Override
        public void contentsChanged(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        private void updateOpenEditors(VirtualFileEvent event) {
            final VirtualFile file = event.getFile();
            if (".editorconfig".equals(file.getName())) {
                if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(file) || !Registry.is("editor.config.stop.at.project.root")) {
                    for (Editor editor : editorFactory.getAllEditors()) {
                        if (editor.isDisposed())
                            continue;
                        ;
                        ((EditorEx) editor).reinitSettings();
                    }
                }
            }
        }
    }, project);
}
Also used : EncodingManager(org.editorconfig.configmanagement.EncodingManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorFactory(com.intellij.openapi.editor.EditorFactory) MessageBus(com.intellij.util.messages.MessageBus) EditorSettingsManager(org.editorconfig.configmanagement.EditorSettingsManager) VirtualFileEvent(com.intellij.openapi.vfs.VirtualFileEvent) LineEndingsManager(org.editorconfig.configmanagement.LineEndingsManager) Editor(com.intellij.openapi.editor.Editor) VirtualFileAdapter(com.intellij.openapi.vfs.VirtualFileAdapter)

Aggregations

VirtualFileAdapter (com.intellij.openapi.vfs.VirtualFileAdapter)3 VirtualFileEvent (com.intellij.openapi.vfs.VirtualFileEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFilePropertyEvent (com.intellij.openapi.vfs.VirtualFilePropertyEvent)1 BulkVirtualFileListenerAdapter (com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter)1 MessageBus (com.intellij.util.messages.MessageBus)1 EditorSettingsManager (org.editorconfig.configmanagement.EditorSettingsManager)1 EncodingManager (org.editorconfig.configmanagement.EncodingManager)1 LineEndingsManager (org.editorconfig.configmanagement.LineEndingsManager)1