@NotNull public static String calcRelativeToProjectPath(@NotNull final VirtualFile file, @Nullable final Project project, final boolean includeFilePath, final boolean includeUniqueFilePath, final boolean keepModuleAlwaysOnTheLeft) { if (file instanceof VirtualFilePathWrapper && ((VirtualFilePathWrapper)file).enforcePresentableName()) { return includeFilePath ? ((VirtualFilePathWrapper)file).getPresentablePath() : file.getName(); } String url; if (includeFilePath) { url = file.getPresentableUrl(); } else if (includeUniqueFilePath) { url = UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file); } else { url = file.getName(); } if (project == null) { return url; } return ProjectUtilCore.displayUrlRelativeToProject(file, url, project, includeFilePath, keepModuleAlwaysOnTheLeft); }
@Override public String getFileTitle(@NotNull final Project project, @NotNull final VirtualFile file) { if (SystemInfo.isMac) { return UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file); } if (file instanceof VirtualFilePathWrapper) { return ((VirtualFilePathWrapper)file).getPresentablePath(); } String url = FileUtil.getLocationRelativeToUserHome(file.getPresentableUrl()); if (url == null) url = file.getPresentableUrl(); VirtualFile baseDir = ProjectBaseDirectory.getInstance(project).getBaseDir(); if (baseDir == null) baseDir = project.getBaseDir(); if (baseDir != null) { final String projectHomeUrl = FileUtil.getLocationRelativeToUserHome(baseDir.getPresentableUrl()); if (projectHomeUrl != null && url.startsWith(projectHomeUrl)) { url = "..." + url.substring(projectHomeUrl.length()); } } return url; }
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value instanceof FileInfo) { VirtualFile virtualFile = ((FileInfo)value).getFirst(); String name = virtualFile instanceof VirtualFilePathWrapper ? ((VirtualFilePathWrapper)virtualFile).getPresentablePath() : UISettings.getInstance().SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES ? UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(myProject, virtualFile) : virtualFile.getName(); setIcon(IconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_READ_STATUS, myProject)); FileStatus fileStatus = FileStatusManager.getInstance(myProject).getStatus(virtualFile); open = FileEditorManager.getInstance(myProject).isFileOpen(virtualFile); TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null , null, EffectType.LINE_UNDERSCORE, Font.PLAIN); append(name, SimpleTextAttributes.fromTextAttributes(attributes)); // calc color the same way editor tabs do this, i.e. including extensions Color color = EditorTabbedContainer.calcTabColor(myProject, virtualFile); if (!selected && color != null) { setBackground(color); } } }
@NotNull public static String calcRelativeToProjectPath(@NotNull final VirtualFile file, @Nullable final Project project, final boolean includeFilePath, final boolean includeUniqueFilePath, final boolean keepModuleAlwaysOnTheLeft) { if (file instanceof VirtualFilePathWrapper) { return includeFilePath ? ((VirtualFilePathWrapper)file).getPresentablePath() : file.getName(); } String url; if (includeFilePath) { url = file.getPresentableUrl(); } else if (includeUniqueFilePath) { url = UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file); } else { url = file.getName(); } if (project == null) { return url; } return ProjectUtilCore.displayUrlRelativeToProject(file, url, project, includeFilePath, keepModuleAlwaysOnTheLeft); }
@Override public String getFileTitle(@Nonnull final Project project, @Nonnull final VirtualFile file) { if (SystemInfo.isMac) { return UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file); } if (file instanceof VirtualFilePathWrapper) { return ((VirtualFilePathWrapper)file).getPresentablePath(); } String url = FileUtil.getLocationRelativeToUserHome(file.getPresentableUrl()); if (url == null) url = file.getPresentableUrl(); VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { final String projectHomeUrl = FileUtil.getLocationRelativeToUserHome(baseDir.getPresentableUrl()); if (projectHomeUrl != null && url.startsWith(projectHomeUrl)) { url = "..." + url.substring(projectHomeUrl.length()); } } return url; }
@Override protected String getElementText(Object element) { if (element instanceof ToolWindow) { return ids.get(element); } else if (element instanceof FileInfo) { final VirtualFile file = ((FileInfo)element).getFirst(); return file instanceof VirtualFilePathWrapper ? ((VirtualFilePathWrapper)file).getPresentablePath() : file.getName(); } return ""; }
private static String getUniqueVirtualFilePath(final Project project, VirtualFile file, final boolean skipNonOpenedFiles) { Key<CachedValue<ConcurrentMap<String, UniqueNameBuilder<VirtualFile>>>> key = skipNonOpenedFiles ? ourShortNameOpenedBuilderCacheKey:ourShortNameBuilderCacheKey; CachedValue<ConcurrentMap<String, UniqueNameBuilder<VirtualFile>>> data = project.getUserData(key); if (data == null) { project.putUserData(key, data = CachedValuesManager.getManager(project).createCachedValue( new CachedValueProvider<ConcurrentMap<String, UniqueNameBuilder<VirtualFile>>>() { @Nullable @Override public Result<ConcurrentMap<String, UniqueNameBuilder<VirtualFile>>> compute() { return new Result<ConcurrentMap<String, UniqueNameBuilder<VirtualFile>>>( ContainerUtil.<String, UniqueNameBuilder<VirtualFile>>createConcurrentSoftValueMap(), PsiModificationTracker.MODIFICATION_COUNT, //ProjectRootModificationTracker.getInstance(project), //VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS, FileEditorManagerImpl.OPEN_FILE_SET_MODIFICATION_COUNT ); } }, false)); } final ConcurrentMap<String, UniqueNameBuilder<VirtualFile>> valueMap = data.getValue(); final String fileName = file.getName(); UniqueNameBuilder<VirtualFile> uniqueNameBuilderForShortName = valueMap.get(fileName); if (uniqueNameBuilderForShortName == null) { final UniqueNameBuilder<VirtualFile> builder = filesWithTheSameName( fileName, project, skipNonOpenedFiles, ProjectScope.getProjectScope(project) ); valueMap.put(fileName, builder != null ? builder:ourEmptyBuilder); uniqueNameBuilderForShortName = builder; } else if (uniqueNameBuilderForShortName == ourEmptyBuilder) { uniqueNameBuilderForShortName = null; } if (uniqueNameBuilderForShortName != null && uniqueNameBuilderForShortName.contains(file)) { if (file instanceof VirtualFilePathWrapper) { return ((VirtualFilePathWrapper)file).getPresentablePath(); } return getEditorTabText(file, uniqueNameBuilderForShortName, UISettings.getInstance().HIDE_KNOWN_EXTENSION_IN_TABS); } return file.getPresentableName(); }
@Nonnull public static String calcRelativeToProjectPath(@Nonnull final VirtualFile file, @Nullable final Project project, final boolean includeFilePath, final boolean includeUniqueFilePath, final boolean keepModuleAlwaysOnTheLeft) { if (file instanceof VirtualFilePathWrapper) { return includeFilePath ? ((VirtualFilePathWrapper)file).getPresentablePath() : file.getName(); } String url; if (includeFilePath) { url = file.getPresentableUrl(); } else if (includeUniqueFilePath) { url = UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file); } else { url = file.getName(); } if (project == null) { return url; } else { final VirtualFile baseDir = project.getBaseDir(); if (baseDir != null && includeFilePath) { //noinspection ConstantConditions final String projectHomeUrl = baseDir.getPresentableUrl(); if (url.startsWith(projectHomeUrl)) { url = "..." + url.substring(projectHomeUrl.length()); } } if (SystemInfo.isMac && file.getFileSystem() instanceof ArchiveFileSystem) { final VirtualFile fileForJar = ((ArchiveFileSystem)file.getFileSystem()).getLocalVirtualFileFor(file); if (fileForJar != null) { final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project); if (libraryEntry != null) { if (libraryEntry instanceof ModuleExtensionWithSdkOrderEntry) { url = url + " - [" + ((ModuleExtensionWithSdkOrderEntry)libraryEntry).getSdkName() + "]"; } else { url = url + " - [" + libraryEntry.getPresentableName() + "]"; } } else { url = url + " - [" + fileForJar.getName() + "]"; } } } final Module module = ModuleUtil.findModuleForFile(file, project); if (module == null) return url; return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ? url + " - [" + module.getName() + "]" : "[" + module.getName() + "] - " + url; } }
private static String getUniqueVirtualFilePath(final Project project, VirtualFile file, final boolean skipNonOpenedFiles, GlobalSearchScope scope) { Key<CachedValue<Map<GlobalSearchScope, Map<String, UniqueNameBuilder<VirtualFile>>>>> key = skipNonOpenedFiles ? ourShortNameOpenedBuilderCacheKey:ourShortNameBuilderCacheKey; CachedValue<Map<GlobalSearchScope, Map<String, UniqueNameBuilder<VirtualFile>>>> data = project.getUserData(key); if (data == null) { project.putUserData(key, data = CachedValuesManager.getManager(project).createCachedValue( () -> new CachedValueProvider.Result<Map<GlobalSearchScope, Map<String, UniqueNameBuilder<VirtualFile>>>>( new ConcurrentHashMap<>(2), PsiModificationTracker.MODIFICATION_COUNT, //ProjectRootModificationTracker.getInstance(project), //VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS, FileEditorManagerImpl.OPEN_FILE_SET_MODIFICATION_COUNT ), false)); } ConcurrentMap<GlobalSearchScope, Map<String, UniqueNameBuilder<VirtualFile>>> scope2ValueMap = (ConcurrentMap<GlobalSearchScope, Map<String,UniqueNameBuilder<VirtualFile>>>)data.getValue(); Map<String, UniqueNameBuilder<VirtualFile>> valueMap = scope2ValueMap.get(scope); if (valueMap == null) { valueMap = ConcurrencyUtil.cacheOrGet(scope2ValueMap, scope, ContainerUtil.createConcurrentSoftValueMap()); } final String fileName = file.getName(); UniqueNameBuilder<VirtualFile> uniqueNameBuilderForShortName = valueMap.get(fileName); if (uniqueNameBuilderForShortName == null) { final UniqueNameBuilder<VirtualFile> builder = filesWithTheSameName( fileName, project, skipNonOpenedFiles, scope ); valueMap.put(fileName, builder != null ? builder:ourEmptyBuilder); uniqueNameBuilderForShortName = builder; } else if (uniqueNameBuilderForShortName == ourEmptyBuilder) { uniqueNameBuilderForShortName = null; } if (uniqueNameBuilderForShortName != null && uniqueNameBuilderForShortName.contains(file)) { if (file instanceof VirtualFilePathWrapper) { return ((VirtualFilePathWrapper)file).getPresentablePath(); } return uniqueNameBuilderForShortName.getShortPath(file); } return file.getName(); }