@Nullable public static Reader getReaderByUrl(final String surl, final HttpConfigurable httpConfigurable, final ProgressIndicator pi) throws IOException { if (surl.startsWith(JAR_PROTOCOL)) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(BrowserUtil.getDocURL(surl)); if (file == null) { return null; } return new StringReader(VfsUtil.loadText(file)); } URL url = BrowserUtil.getURL(surl); if (url == null) { return null; } httpConfigurable.prepareURL(url.toString()); final URLConnection urlConnection = url.openConnection(); final String contentEncoding = urlConnection.getContentEncoding(); final InputStream inputStream = pi != null ? UrlConnectionUtil.getConnectionInputStreamWithException(urlConnection, pi) : urlConnection.getInputStream(); //noinspection IOResourceOpenedButNotSafelyClosed return contentEncoding != null ? new InputStreamReader(inputStream, contentEncoding) : new InputStreamReader(inputStream); }
public void actionPerformed(AnActionEvent e) { VcsContext context = CvsContextWrapper.createCachedInstance(e); final VirtualFile[] selectedFiles = context.getSelectedFiles(); ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { public void run() { ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); for (int i = 0; i < selectedFiles.length; i++) { File file = CvsVfsUtil.getFileFor(selectedFiles[i]); if (progressIndicator != null){ progressIndicator.setFraction((double)i/(double)selectedFiles.length); progressIndicator.setText(file.getAbsolutePath()); } CvsUtil.removeEntryFor(file); } } }, CvsBundle.message("operation.name.undo.add"), true, context.getProject()); VirtualFileManager.getInstance().asyncRefresh(null); }
private <B extends XBreakpoint<?>> XLineBreakpoint createXLineBreakpoint(Class<? extends XBreakpointType<B, ?>> typeCls, Element breakpointNode) throws InvalidDataException { final String url = breakpointNode.getAttributeValue("url"); VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url); if (vFile == null) { throw new InvalidDataException(DebuggerBundle.message("error.breakpoint.file.not.found", url)); } final Document doc = FileDocumentManager.getInstance().getDocument(vFile); if (doc == null) { throw new InvalidDataException(DebuggerBundle.message("error.cannot.load.breakpoint.file", url)); } final int line; try { //noinspection HardCodedStringLiteral line = Integer.parseInt(breakpointNode.getAttributeValue("line")); } catch (Exception e) { throw new InvalidDataException("Line number is invalid for breakpoint"); } return addXLineBreakpoint(typeCls, doc, line); }
private void restoreSources() { Runnable runnable = new Runnable() { @Override public void run() { try { FileUtil.copyDir(new File(JavaTestUtil.getJavaTestDataPath() + "/psi/arrayIndexOutOfBounds/src"), VfsUtilCore.virtualToIoFile(myProjectRoot)); } catch (IOException e) { LOG.error(e); } VirtualFileManager.getInstance().syncRefresh(); } }; CommandProcessor.getInstance().executeCommand(myProject, runnable, "", null); }
private void deleteNewPackage() { Runnable runnable = new Runnable() { @Override public void run() { final PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("anotherBla"); assertNotNull("Package anotherBla not found", aPackage); WriteCommandAction.runWriteCommandAction(null, new Runnable() { @Override public void run() { aPackage.getDirectories()[0].delete(); } }); VirtualFileManager.getInstance().syncRefresh(); } }; CommandProcessor.getInstance().executeCommand(myProject, runnable, "", null); }
private Set<VirtualFile> getNotExcludedRoots() { Set<VirtualFile> roots = new LinkedHashSet<VirtualFile>(); String[] excludedRootUrls = getLibraryEditor().getExcludedRootUrls(); Set<VirtualFile> excludedRoots = new HashSet<VirtualFile>(); for (String url : excludedRootUrls) { ContainerUtil.addIfNotNull(excludedRoots, VirtualFileManager.getInstance().findFileByUrl(url)); } for (PersistentOrderRootType type : OrderRootType.getAllPersistentTypes()) { VirtualFile[] files = getLibraryEditor().getFiles(type); for (VirtualFile file : files) { if (!VfsUtilCore.isUnder(file, excludedRoots)) { roots.add(PathUtil.getLocalFile(file)); } } } return roots; }
public static String[] getOutputPaths(Module[] modules) { final Set<String> outputPaths = new OrderedSet<String>(); for (Module module : modules) { final CompilerModuleExtension compilerModuleExtension = !module.isDisposed()? CompilerModuleExtension.getInstance(module) : null; if (compilerModuleExtension == null) { continue; } String outputPathUrl = compilerModuleExtension.getCompilerOutputUrl(); if (outputPathUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar)); } String outputPathForTestsUrl = compilerModuleExtension.getCompilerOutputUrlForTests(); if (outputPathForTestsUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathForTestsUrl).replace('/', File.separatorChar)); } } return ArrayUtil.toStringArray(outputPaths); }
@Nullable public static String getAnnotationProcessorsGenerationPath(Module module) { final AnnotationProcessingConfiguration config = CompilerConfiguration.getInstance(module.getProject()).getAnnotationProcessingConfiguration(module); final String sourceDirName = config.getGeneratedSourcesDirectoryName(false); if (config.isOutputRelativeToContentRoot()) { final String[] roots = ModuleRootManager.getInstance(module).getContentRootUrls(); if (roots.length == 0) { return null; } if (roots.length > 1) { Arrays.sort(roots, URLS_COMPARATOR); } return StringUtil.isEmpty(sourceDirName)? VirtualFileManager.extractPath(roots[0]): VirtualFileManager.extractPath(roots[0]) + "/" + sourceDirName; } final String path = getModuleOutputPath(module, false); if (path == null) { return null; } return StringUtil.isEmpty(sourceDirName)? path : path + "/" + sourceDirName; }
@Nullable public CustomResourceBundleState removeNonExistentFiles(final VirtualFileManager virtualFileManager) { final List<String> existentFiles = ContainerUtil.filter(myFileUrls, new Condition<String>() { @Override public boolean value(String url) { return virtualFileManager.findFileByUrl(url) != null; } }); if (existentFiles.isEmpty()) { return null; } final CustomResourceBundleState customResourceBundleState = new CustomResourceBundleState(); customResourceBundleState.myFileUrls.addAll(existentFiles); customResourceBundleState.myBaseName = myBaseName; return customResourceBundleState; }
public void saveCredentials() { if (myGetPassword == null) return; // if checkbox is selected, save on disk. Otherwise in memory. Don't read password safe settings. final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance(); final String url = VirtualFileManager.extractPath(myGetPassword.getURL()); final String key = keyForUrlAndLogin(url, myGetPassword.getUserName()); try { if (myGetPassword.isRememberPassword()) { PasswordSafe.getInstance().storePassword(myProject, HgCommandAuthenticator.class, key, myGetPassword.getPassword()); } else if (passwordSafe.getSettings().getProviderType() != PasswordSafeSettings.ProviderType.DO_NOT_STORE) { passwordSafe.getMemoryProvider().storePassword(myProject, HgCommandAuthenticator.class, key, myGetPassword.getPassword()); } final HgVcs vcs = HgVcs.getInstance(myProject); if (vcs != null) { vcs.getGlobalSettings().addRememberedUrl(url, myGetPassword.getUserName()); } } catch (PasswordSafeException e) { LOG.info("Couldn't store the password for key [" + key + "]", e); } }
public static void attachJdkAnnotations(@NotNull SdkModificator modificator) { String homePath = FileUtil.toSystemIndependentName(PathManager.getHomePath()); VirtualFileManager fileManager = VirtualFileManager.getInstance(); // release build? String releaseLocation = homePath + "/plugins/android/lib/androidAnnotations.jar"; VirtualFile root = fileManager.findFileByUrl("jar://" + releaseLocation + "!/"); for (String relativePath : DEVELOPMENT_ANNOTATIONS_PATHS) { if (root != null) break; String developmentLocation = homePath + relativePath; root = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(developmentLocation)); } if (root == null) { // error message tailored for release build file layout LOG.error("jdk annotations not found in: " + releaseLocation); return; } OrderRootType annoType = AnnotationOrderRootType.getInstance(); modificator.removeRoot(root, annoType); modificator.addRoot(root, annoType); }
@Override public void disposeComponent() { if (!isInitialized.getAndSet(false)) return; long period = Registry.intValue("localHistory.daysToKeep") * 1000L * 60L * 60L * 24L; VirtualFileManager fm = VirtualFileManager.getInstance(); fm.removeVirtualFileListener(myEventDispatcher); fm.removeVirtualFileManagerListener(myEventDispatcher); CommandProcessor.getInstance().removeCommandListener(myEventDispatcher); validateStorage(); LocalHistoryLog.LOG.debug("Purging local history..."); myChangeList.purgeObsolete(period); validateStorage(); myChangeList.close(); LocalHistoryLog.LOG.debug("Local history storage successfully closed."); ShutDownTracker.getInstance().unregisterShutdownTask(myShutdownTask); }
@Nullable @Override public RefEntity getReference(final String type, final String fqName) { for (RefManagerExtension extension : myExtensions.values()) { final RefEntity refEntity = extension.getReference(type, fqName); if (refEntity != null) return refEntity; } if (SmartRefElementPointer.FILE.equals(type)) { return RefFileImpl.fileFromExternalName(this, fqName); } if (SmartRefElementPointer.MODULE.equals(type)) { return RefModuleImpl.moduleFromName(this, fqName); } if (SmartRefElementPointer.PROJECT.equals(type)) { return getRefProject(); } if (SmartRefElementPointer.DIR.equals(type)) { String url = VfsUtilCore.pathToUrl(PathMacroManager.getInstance(getProject()).expandPath(fqName)); VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url); if (vFile != null) { final PsiDirectory dir = PsiManager.getInstance(getProject()).findDirectory(vFile); return getReference(dir); } } return null; }
/** * Forces a reparse of the specified collection of files. * * @param files the files to reparse. */ public static void reparseFiles(@NotNull final Collection<VirtualFile> files) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { // files must be processed under one write action to prevent firing event for invalid files. final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>(); for (VirtualFile file : files) { saveOrReload(file, events); } BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES); List<VFileEvent> eventList = new ArrayList<VFileEvent>(events); publisher.before(eventList); publisher.after(eventList); } }); }
protected Location getLocation(@NotNull Project project, @NotNull GlobalSearchScope searchScope, String locationUrl) { if (locationUrl != null && myLocator != null) { String protocolId = VirtualFileManager.extractProtocol(locationUrl); if (protocolId != null) { String path = VirtualFileManager.extractPath(locationUrl); if (!DumbService.isDumb(project) || DumbService.isDumbAware(myLocator)) { List<Location> locations = myLocator.getLocation(protocolId, path, project, searchScope); if (!locations.isEmpty()) { return locations.get(0); } } } } return null; }
protected void fireEventsInWriteAction() { final VirtualFileManagerEx manager = (VirtualFileManagerEx)VirtualFileManager.getInstance(); manager.fireBeforeRefreshStart(myIsAsync); try { while (!myWorkQueue.isEmpty() || !myEvents.isEmpty()) { PersistentFS.getInstance().processEvents(mergeEventsAndReset()); scan(); } } finally { try { manager.fireAfterRefreshFinish(myIsAsync); } finally { if (myFinishRunnable != null) { myFinishRunnable.run(); } } } }
public DefaultHtmlDoctypeInitialConfigurator(ProjectManager projectManager, PropertiesComponent propertiesComponent) { if (!propertiesComponent.getBoolean("DefaultHtmlDoctype.MigrateToHtml5")) { propertiesComponent.setValue("DefaultHtmlDoctype.MigrateToHtml5", true); ExternalResourceManagerEx.getInstanceEx() .setDefaultHtmlDoctype(Html5SchemaProvider.getHtml5SchemaLocation(), projectManager.getDefaultProject()); } // sometimes VFS fails to pick up updated schema contents and we need to force refresh if (StringUtilRt.parseInt(propertiesComponent.getValue("DefaultHtmlDoctype.Refreshed"), 0) < VERSION) { propertiesComponent.setValue("DefaultHtmlDoctype.Refreshed", Integer.toString(VERSION)); final String schemaUrl = VfsUtilCore.pathToUrl(Html5SchemaProvider.getHtml5SchemaLocation()); final VirtualFile schemaFile = VirtualFileManager.getInstance().findFileByUrl(schemaUrl); if (schemaFile != null) { schemaFile.getParent().refresh(false, true); } } }
private static void addOutputModuleRoots(@Nullable ExternalSourceSet externalSourceSet, @NotNull ExternalSystemSourceType sourceType, @NotNull Collection<String> result) { if (externalSourceSet == null) return; final ExternalSourceDirectorySet directorySet = externalSourceSet.getSources().get(sourceType); if (directorySet == null) return; if (directorySet.isCompilerOutputPathInherited()) return; final String path = directorySet.getOutputDir().getAbsolutePath(); VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(path); if (virtualFile == null) { if(!directorySet.getOutputDir().exists()){ FileUtil.createDirectory(directorySet.getOutputDir()); } ApplicationEx app = (ApplicationEx)ApplicationManager.getApplication(); if (app.isDispatchThread() || !app.holdsReadLock()) { LocalFileSystem.getInstance().refreshAndFindFileByIoFile(directorySet.getOutputDir()); } } result.add(VfsUtilCore.pathToUrl(path)); }
public void scheduleInitialVfsRefresh() { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; markContentRootsForRefresh(); Application app = ApplicationManager.getApplication(); if (!app.isHeadlessEnvironment()) { final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null); final MessageBusConnection connection = app.getMessageBus().connect(); connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener.Adapter() { @Override public void afterProjectClosed(@NotNull Project project) { RefreshQueue.getInstance().cancelSession(sessionId); connection.disconnect(); } }); } else { VirtualFileManager.getInstance().syncRefresh(); } } }); }
protected static String pathToUrl(File path) { String name = path.getName(); boolean isJarFile = FileUtilRt.extensionEquals(name, "jar") || FileUtilRt.extensionEquals(name, "zip"); // .jar files require an URL with "jar" protocol. String protocol = isJarFile ? StandardFileSystems.JAR_PROTOCOL : VirtualFileSystemProvider.getInstance().getSystem().getProtocol(); String filePath = FileUtil.toSystemIndependentName(path.getPath()); String url = VirtualFileManager.constructUrl(protocol, filePath); if (isJarFile) { url += URLUtil.JAR_SEPARATOR; } return url; }
@Nullable public static ResourceBundle createByUrl(final @NotNull String url, final @NotNull Project project) { final int idx = url.lastIndexOf('/'); if (idx == -1) return null; final String baseDirectoryName = url.substring(0, idx); final String baseName = url.substring(idx + 1); final VirtualFile baseDirectoryVirtualFile = VirtualFileManager.getInstance().findFileByUrl(baseDirectoryName); if (baseDirectoryVirtualFile == null) { return null; } final PsiDirectory baseDirectory = PsiManager.getInstance(project).findDirectory(baseDirectoryVirtualFile); if (baseDirectory == null) { return null; } return getResourceBundle(baseName, baseDirectory); }
public AntBuildTarget findTarget(Project project, String fileUrl, String targetName) { if (fileUrl == null || targetName == null || project == null) { return null; } final VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileUrl); if (vFile == null) { return null; } final AntConfigurationImpl antConfiguration = (AntConfigurationImpl)AntConfiguration.getInstance(project); for (AntBuildFile buildFile : antConfiguration.getBuildFiles()) { if (vFile.equals(buildFile.getVirtualFile())) { final AntBuildTarget target = buildFile.getModel().findTarget(targetName); if (target != null) { return target; } for (AntBuildTarget metaTarget : antConfiguration.getMetaTargets(buildFile)) { if (targetName.equals(metaTarget.getName())) { return metaTarget; } } return null; } } return null; }
@Nullable public static List<String> getHttpRoots(@NotNull String[] roots, String relPath) { List<String> result = new SmartList<String>(); for (String root : roots) { VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(root); if (virtualFile != null) { if (virtualFile.getFileSystem() instanceof HttpFileSystem) { String url = virtualFile.getUrl(); if (!url.endsWith("/")) { url += "/"; } result.add(url + relPath); } else { VirtualFile file = virtualFile.findFileByRelativePath(relPath); if (file != null) { result.add(file.getUrl()); } } } } return result.isEmpty() ? null : result; }
public ResourceBundleManagerState removeNonExistentFiles() { final ResourceBundleManagerState newState = new ResourceBundleManagerState(); final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance(); for (final String dissociatedFileUrl : myDissociatedFiles) { if (virtualFileManager.findFileByUrl(dissociatedFileUrl) != null) { newState.myDissociatedFiles.add(dissociatedFileUrl); } } for (CustomResourceBundleState customResourceBundle : myCustomResourceBundles) { final CustomResourceBundleState updatedCustomResourceBundle = customResourceBundle.removeNonExistentFiles(virtualFileManager); if (updatedCustomResourceBundle != null) { newState.myCustomResourceBundles.add(updatedCustomResourceBundle); } } return newState; }
private static List<VirtualFile> getBundledGdslFiles() { final List<VirtualFile> result = ContainerUtil.newArrayList(); for (File file : getBundledScriptFolders()) { if (file.exists()) { File[] children = file.listFiles(); if (children != null) { for (File child : children) { final String fileName = child.getName(); if (fileName.endsWith(".gdsl")) { String path = FileUtil.toSystemIndependentName(child.getPath()); String url = VirtualFileManager.constructUrl(URLUtil.FILE_PROTOCOL, path); ContainerUtil.addIfNotNull(result, VirtualFileManager.getInstance().refreshAndFindFileByUrl(url)); } } } } } return result; }
public static void selectConfigurationDirectory(@NotNull String path, @NotNull final Consumer<String> dirConsumer, final Project project, @Nullable final Component component) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor() .withTitle(SvnBundle.message("dialog.title.select.configuration.directory")) .withDescription(SvnBundle.message("dialog.description.select.configuration.directory")) .withShowFileSystemRoots(true) .withHideIgnored(false) .withShowHiddenFiles(true); path = "file://" + path.replace(File.separatorChar, '/'); VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(path); VirtualFile file = FileChooser.chooseFile(descriptor, component, project, root); if (file == null) { return; } final String resultPath = file.getPath().replace('/', File.separatorChar); dirConsumer.consume(resultPath); }
@Override public void loadState(Element state) { myDisabledHintsFiles.clear(); Element element = state.getChild(DISABLE_HINTS_TAG); if (element != null) { for (Element e : element.getChildren(FILE_TAG)) { String url = e.getAttributeValue(URL_ATT); if (url != null) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file != null) { myDisabledHintsFiles.add(file); } } } } }
@Override public void loadState(Element element) { List children = element.getChildren(SETTING_TAG); for (final Object aChildren : children) { final Element child = (Element)aChildren; final String url = child.getAttributeValue(FILE_ATT); if (url == null) continue; final VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(url); if (fileByUrl != null) { final List<FileHighlightingSetting> settings = new ArrayList<FileHighlightingSetting>(); int index = 0; while (child.getAttributeValue(ROOT_ATT_PREFIX + index) != null) { final String attributeValue = child.getAttributeValue(ROOT_ATT_PREFIX + index++); settings.add(Enum.valueOf(FileHighlightingSetting.class, attributeValue)); } myHighlightSettings.put(fileByUrl, settings.toArray(new FileHighlightingSetting[settings.size()])); } } }
@Override public void loadState(Element state) { final VirtualFileManager vfManager = VirtualFileManager.getInstance(); for (Object child : state.getChildren(FILE_ELEMENT)) { if (child instanceof Element) { final Element fileElement = (Element)child; final Attribute filePathAttr = fileElement.getAttribute(PATH_ATTR); if (filePathAttr != null) { final String filePath = filePathAttr.getValue(); VirtualFile vf = vfManager.findFileByUrl(filePath); if (vf != null) { myFiles.add(vf); } } } } }
@Override public void setError(String filePath, BsbError error) { VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl("file://" + filePath); if (fileByUrl != null) { m_errorsByFile.putValue(fileByUrl.getCanonicalPath(), error); } }
@Override public void projectOpened() { m_documentListener = new RmlDocumentListener(myProject); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(m_documentListener); m_messageBusConnection = myProject.getMessageBus().connect(); m_messageBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new RmlFileEditorListener(myProject)); m_vfListener = new VirtualFileListener(myProject); VirtualFileManager.getInstance().addVirtualFileListener(m_vfListener); }
@Override public void projectClosed() { EditorFactory.getInstance().getEventMulticaster().removeDocumentListener(m_documentListener); VirtualFileManager.getInstance().removeVirtualFileListener(m_vfListener); m_documentListener.projectClosed(); m_messageBusConnection.disconnect(); }
@Override public void actionPerformed(AnActionEvent e) { try { com.intellij.openapi.actionSystem.DataContext dataContext = e.getDataContext(); PsiJavaFile javaFile = (PsiJavaFile) ((PsiFile) DataKeys.PSI_FILE.getData(dataContext)).getContainingFile(); String sourceName = javaFile.getName(); Module module = (Module) DataKeys.MODULE.getData(dataContext); String compileRoot = CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath(); getVirtualFile(sourceName, CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getChildren(), compileRoot); VirtualFileManager.getInstance().syncRefresh(); } catch (Exception ex) { ex.printStackTrace(); Messages.showErrorDialog("Please build your module or project!!!", "error"); } }
public NpmScanManager(Project project) { super(project); npmDriver = new NpmDriver(); try { Path installationPath = Paths.get(getProjectBasePath(project), INSTALLATION_DIR); Files.createDirectories(installationPath); } catch (IOException e) { Utils.notify(logger, "Failed to create installation directory", e, NotificationType.ERROR); } FileChangeListener.Callback asyncScanCbk = getFileListenerCbk(); VirtualFileManager.getInstance().addVirtualFileListener(new FileChangeListener(Arrays.asList(NPM_FILES), asyncScanCbk)); }
@Nullable @Override public BpGraphNode resolveElementByFQN(final String s, final Project project) { final VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(s); final BpGraphService bpGraphService = ServiceManager.getService(BpGraphService.class); try { return null == virtualFile ? null : bpGraphService.buildGraphFromXmlFile(virtualFile); } catch (UnmarshalException e) { LOG.error("Can not build Business Process graph from the file: " + virtualFile.getName(), e); return null; } }
/** * Maintain watch on gitHeadFile via {@link VirtualFileManager#addVirtualFileListener(VirtualFileListener)}. */ private void registerFileChangedListener(final String gitHeadFilePath) { if (!gitHeadFileWatchSet.contains(gitHeadFilePath)) { gitHeadFileWatchSet.add(gitHeadFilePath); VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() { @Override public void contentsChanged(@NotNull VirtualFileEvent event) { if (gitHeadFilePath.equals(event.getFile().getCanonicalPath())) { final String branchName = determineBranchName(event.getFile()); updateFrameTitle(getProjectForFile(event.getFile()), branchName); } } }); } }
public void createAndAddListener() { if (listener == null) { listener = getVirtualFileListener(); VirtualFileManager.getInstance().addVirtualFileListener(listener); } else { VirtualFileManager.getInstance().removeVirtualFileListener(listener); listener = getVirtualFileListener(); VirtualFileManager.getInstance().addVirtualFileListener(listener); } this.projectPath = project.getBasePath(); }
private void trackDeletedFile(@NotNull ProgressEvent event) { @NonNls final String filePath = "file://" + event.getFile().getAbsolutePath().replace(File.separatorChar, '/'); VirtualFile virtualFile = ApplicationManager.getApplication().runReadAction(new Computable<VirtualFile>() { @Nullable public VirtualFile compute() { return VirtualFileManager.getInstance().findFileByUrl(filePath); } }); if (virtualFile != null) { myDeletedFiles.add(virtualFile); } }
private void notifyModified() { boolean modified = undoHandler.getCommandPosition() != undoHandler.getSyncPoint(); if (modified != this.modified) { this.modified = modified; // TODO: Trying to force "modified behavior" Document document = FileDocumentManager.getInstance().getDocument(virtualFile); if (document instanceof DocumentEx) { ((DocumentEx) document).setModificationStamp(LocalTimeCounter.currentTime()); } propertyChangeSupport.firePropertyChange(FileEditor.PROP_MODIFIED, !modified, modified); VirtualFileManager.getInstance().notifyPropertyChanged(virtualFile, FileEditor.PROP_MODIFIED, !modified, modified); } saveFileButton.setEnabled(modified); }
public NonClasspathClassFinder(Project project, String... fileExtensions) { myProject = project; myManager = PsiManager.getInstance(myProject); myFileExtensions = ArrayUtil.append(fileExtensions, "class"); final MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { clearCache(); } }); }