public AndroidProjectTreeBuilder(@NotNull Project project, @NotNull JTree tree, @NotNull DefaultTreeModel treeModel, @Nullable Comparator<NodeDescriptor> comparator, @NotNull ProjectAbstractTreeStructureBase treeStructure) { super(project, tree, treeModel, comparator, treeStructure); MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent e : events) { if (e instanceof VFileDeleteEvent) { removeMapping(e.getFile()); } } } }); }
public void activate() { if (messageBusConnection != null) { return; } messageBusConnection = project.getMessageBus().connect(); messageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (event instanceof VFileDeleteEvent) { synchronized (changedFiles) { changedFiles.remove(event.getFile()); } } } } }); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(listener, project); }
/** * Handler method that is called before IntelliJ executes the file change, stores a lookup of IntelliJ modules for * deleted files because the module can't be determined after the delete is executed * @param vFileEvents List of file events, provided by IntelliJ */ public void before(@NotNull List<? extends VFileEvent> vFileEvents) { // sometimes file events occur before the plugin was initialized, so lets make sure we have a plugin, a project and a configuration if (plugin == null || plugin.getProject() == null || config == null || !config.isOpenCmsPluginEnabled()) { return; } // save all modules for deleted files in a lookup map, because IntelliJ can't find the module after the // deletion of directories (ModuleUtil.findModuleForFile returns null in that case) for (VFileEvent event : vFileEvents) { if (event instanceof VFileDeleteEvent) { VirtualFile ideaVFile = event.getFile(); if (ideaVFile == null) { continue; } Module ideaModule = ModuleUtil.findModuleForFile(ideaVFile, plugin.getProject()); if (ideaModule == null) { continue; } deletedFileModuleLookup.put(ideaVFile, ideaModule); } } }
/** * Internal handler for file delete, move and rename events * @param event IntelliJ's file change event * @throws CmsConnectionException if the connection to OpenCms fails */ private void handleFileEvent(VFileEvent event) throws CmsConnectionException { // File is deleted if (event instanceof VFileDeleteEvent) { handleFileDeleteEvent(event); } // File is moved if (event instanceof VFileMoveEvent) { handleFileMoveEvent(event); } // File is renamed if (event instanceof VFilePropertyChangeEvent) { String propertyName = ((VFilePropertyChangeEvent)event).getPropertyName(); if ("name".equals(propertyName)) { handleFileRenameEvent(event); } } }
private void _after( final List<? extends VFileEvent> events ) { if( _project.isDisposed() ) { return; } for( VFileEvent event : events ) { final VirtualFile file = event.getFile(); if( file != null ) { if( event instanceof VFileCreateEvent ) { fireCreatedEvent( file ); } else if( event instanceof VFileDeleteEvent ) { fireDeletedEvent( file ); } else if( event instanceof VFileCopyEvent ) { processFileCopyEvent( (VFileCopyEvent)event ); } else if( isMoveOrRename( event ) ) { processRenameAfter( event ); } else // modified { ApplicationManager.getApplication().runReadAction( () -> fireModifiedEvent( file ) ); } } } }
public void testFindRoot() throws IOException { VirtualFile root = myFS.findFileByPath("wrong_path"); assertNull(root); VirtualFile root2; if (SystemInfo.isWindows) { root = myFS.findFileByPath("\\\\unit-133"); assertNotNull(root); root2 = myFS.findFileByPath("//UNIT-133"); assertNotNull(root2); assertEquals(String.valueOf(root2), root, root2); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); root = myFS.findFileByIoFile(new File("\\\\unit-133")); assertNotNull(root); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); if (new File("c:").exists()) { root = myFS.findFileByPath("c:"); assertNotNull(root); assertEquals("C:/", root.getPath()); root2 = myFS.findFileByPath("C:\\"); assertSame(String.valueOf(root), root, root2); VirtualFileManager fm = VirtualFileManager.getInstance(); root = fm.findFileByUrl("file://C:/"); assertNotNull(root); root2 = fm.findFileByUrl("file:///c:/"); assertSame(String.valueOf(root), root, root2); } } else if (SystemInfo.isUnix) { root = myFS.findFileByPath("/"); assertNotNull(root); assertEquals("/", root.getPath()); } root = myFS.findFileByPath(""); assertNotNull(root); File jarFile = IoTestUtil.createTestJar(); assertNotNull(getVirtualFile(jarFile)); root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/"); assertNotNull(root); root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/"); assertEquals(String.valueOf(root2), root, root2); if (!SystemInfo.isFileSystemCaseSensitive) { root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/"); assertEquals(String.valueOf(root2), root, root2); } }
public void testFindRoot() throws IOException { VirtualFile root = LocalFileSystem.getInstance().findFileByPath("wrong_path"); assertNull(root); VirtualFile root2; if (SystemInfo.isWindows) { root = LocalFileSystem.getInstance().findFileByPath("\\\\unit-133"); assertNotNull(root); root2 = LocalFileSystem.getInstance().findFileByPath("//UNIT-133"); assertNotNull(root2); assertEquals(String.valueOf(root2), root, root2); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); root = LocalFileSystem.getInstance().findFileByIoFile(new File("\\\\unit-133")); assertNotNull(root); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); if (new File("c:").exists()) { root = LocalFileSystem.getInstance().findFileByPath("c:"); assertNotNull(root); assertEquals("C:/", root.getPath()); root2 = LocalFileSystem.getInstance().findFileByPath("C:\\"); assertEquals(String.valueOf(root2), root, root2); } } else if (SystemInfo.isUnix) { root = LocalFileSystem.getInstance().findFileByPath("/"); assertNotNull(root); assertEquals(root.getPath(), "/"); } root = LocalFileSystem.getInstance().findFileByPath(""); assertNotNull(root); File jarFile = IoTestUtil.createTestJar(); root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/"); assertNotNull(root); root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/"); assertEquals(String.valueOf(root2), root, root2); if (!SystemInfo.isFileSystemCaseSensitive) { root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/"); assertEquals(String.valueOf(root2), root, root2); } }
public void testFindRoot() throws IOException { VirtualFile root = myFS.findFileByPath("wrong_path"); assertNull(root); VirtualFile root2; if (SystemInfo.isWindows) { root = myFS.findFileByPath("\\\\unit-133"); assertNotNull(root); root2 = myFS.findFileByPath("//UNIT-133"); assertNotNull(root2); assertEquals(String.valueOf(root2), root, root2); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); root = myFS.findFileByIoFile(new File("\\\\unit-133")); assertNotNull(root); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); if (new File("c:").exists()) { root = myFS.findFileByPath("c:"); assertNotNull(root); assertEquals("C:/", root.getPath()); root2 = myFS.findFileByPath("C:\\"); assertSame(String.valueOf(root), root, root2); VirtualFileManager fm = VirtualFileManager.getInstance(); root = fm.findFileByUrl("file://C:/"); assertNotNull(root); root2 = fm.findFileByUrl("file:///c:/"); assertSame(String.valueOf(root), root, root2); } } else if (SystemInfo.isUnix) { root = myFS.findFileByPath("/"); assertNotNull(root); assertEquals(root.getPath(), "/"); } root = myFS.findFileByPath(""); assertNotNull(root); File jarFile = IoTestUtil.createTestJar(); root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/"); assertNotNull(root); root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/"); assertEquals(String.valueOf(root2), root, root2); if (!SystemInfo.isFileSystemCaseSensitive) { root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/"); assertEquals(String.valueOf(root2), root, root2); } }