Search in sources :

Example 1 with VirtualFilePropertyEvent

use of com.intellij.openapi.vfs.VirtualFilePropertyEvent 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)

Aggregations

Document (com.intellij.openapi.editor.Document)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 VirtualFileAdapter (com.intellij.openapi.vfs.VirtualFileAdapter)1 VirtualFilePropertyEvent (com.intellij.openapi.vfs.VirtualFilePropertyEvent)1 BulkVirtualFileListenerAdapter (com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter)1 NotNull (org.jetbrains.annotations.NotNull)1