Java Code Examples for com.intellij.openapi.util.io.FileUtil#getLocationRelativeToUserHome()
The following examples show how to use
com.intellij.openapi.util.io.FileUtil#getLocationRelativeToUserHome() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformFrameTitleBuilder.java From consulo with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: PsiPackageHelperImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public String getQualifiedName(@Nonnull final PsiDirectory directory, final boolean presentable) { if (presentable) { return FileUtil.getLocationRelativeToUserHome(directory.getVirtualFile().getPresentableUrl()); } return ""; }
Example 3
Source File: PlatformFrameTitleBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Override public String getProjectTitle(@Nonnull final Project project) { final String basePath = project.getBasePath(); if (basePath == null) return project.getName(); if (basePath.equals(project.getName())) { return "[" + FileUtil.getLocationRelativeToUserHome(basePath) + "]"; } else { return project.getName() + " - [" + FileUtil.getLocationRelativeToUserHome(basePath) + "]"; } }
Example 4
Source File: FileEditorManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public String getFileTooltipText(@Nonnull VirtualFile file) { List<EditorTabTitleProvider> availableProviders = DumbService.getDumbAwareExtensions(myProject, EditorTabTitleProvider.EP_NAME); for (EditorTabTitleProvider provider : availableProviders) { String text = provider.getEditorTabTooltipText(myProject, file); if (text != null) { return text; } } return FileUtil.getLocationRelativeToUserHome(file.getPresentableUrl()); }
Example 5
Source File: VagrantCredentialsHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public String getPresentableDetails(String interpreterPath) { VagrantBasedCredentialsHolder cred = getCredentials(); String pathRelativeToHome = FileUtil.getLocationRelativeToUserHome(cred.getVagrantFolder()); return "Vagrant VM " + (StringUtil.isNotEmpty(cred.getMachineName()) ? "'" + cred.getMachineName() + "' " : "") + "at " + (pathRelativeToHome.length() < cred.getVagrantFolder().length() ? pathRelativeToHome : cred.getVagrantFolder()) + " (" + interpreterPath + ")"; }
Example 6
Source File: ReopenProjectAction.java From consulo with Apache License 2.0 | 5 votes |
public ReopenProjectAction(final String projectPath, final String projectName, final String displayName, @Nonnull List<String> extensions) { myProjectPath = projectPath; myProjectName = projectName; myExtensions = extensions; final Presentation presentation = getTemplatePresentation(); String text = projectPath.equals(displayName) ? FileUtil.getLocationRelativeToUserHome(projectPath) : displayName; presentation.setText(text, false); presentation.setDescription(projectPath); }
Example 7
Source File: PsiFileNode.java From consulo with Apache License 2.0 | 5 votes |
@Override public String getTitle() { VirtualFile file = getVirtualFile(); if (file != null) { return FileUtil.getLocationRelativeToUserHome(file.getPresentableUrl()); } return super.getTitle(); }
Example 8
Source File: RecentProjectPanel.java From consulo with Apache License 2.0 | 5 votes |
protected String getTitle2Text(String fullText, JComponent pathLabel, int leftOffset) { if (StringUtil.isEmpty(fullText)) return " "; fullText = FileUtil.getLocationRelativeToUserHome(fullText, false); try { FontMetrics fm = pathLabel.getFontMetrics(pathLabel.getFont()); int maxWidth = myRootPanel.getWidth() - leftOffset; if (maxWidth > 0 && fm.stringWidth(fullText) > maxWidth) { int left = 1; int right = 1; int center = fullText.length() / 2; String s = fullText.substring(0, center - left) + "..." + fullText.substring(center + right); while (fm.stringWidth(s) > maxWidth) { if (left == right) { left++; } else { right++; } if (center - left < 0 || center + right >= fullText.length()) { return ""; } s = fullText.substring(0, center - left) + "..." + fullText.substring(center + right); } return s; } } catch (Exception e) { LOG.error("Path label font: " + pathLabel.getFont()); LOG.error("Panel width: " + myRootPanel.getWidth()); LOG.error(e); } return fullText; }
Example 9
Source File: ProjectUtil.java From consulo with Apache License 2.0 | 4 votes |
@Nullable public static String getProjectLocationString(@Nonnull final Project project) { return FileUtil.getLocationRelativeToUserHome(project.getBasePath()); }
Example 10
Source File: RunAnythingContext.java From consulo with Apache License 2.0 | 4 votes |
public RecentDirectoryContext(@Nonnull String path) { super(FileUtil.getLocationRelativeToUserHome(path), "", AllIcons.Nodes.Folder); myPath = path; }
Example 11
Source File: PsiDirectoryNode.java From consulo with Apache License 2.0 | 4 votes |
@Override protected void updateImpl(PresentationData data) { final Project project = getProject(); final PsiDirectory psiDirectory = getValue(); final VirtualFile directoryFile = psiDirectory.getVirtualFile(); final Object parentValue = getParentValue(); if (ProjectRootsUtil.isModuleContentRoot(directoryFile, project)) { ProjectFileIndex fi = ProjectRootManager.getInstance(project).getFileIndex(); Module module = fi.getModuleForFile(directoryFile); data.setPresentableText(directoryFile.getName()); if (module != null) { if (!(parentValue instanceof Module)) { if (Comparing.equal(module.getName(), directoryFile.getName())) { data.addText(directoryFile.getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } else { data.addText(directoryFile.getName() + " ", SimpleTextAttributes.REGULAR_ATTRIBUTES); data.addText("[" + module.getName() + "]", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } } else { data.addText(directoryFile.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } if (parentValue instanceof Module || parentValue instanceof Project) { final String location = FileUtil.getLocationRelativeToUserHome(directoryFile.getPresentableUrl()); data.addText(" (" + location + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES); } else if (ProjectRootsUtil.isSourceOrTestRoot(directoryFile, project)) { if (ProjectRootsUtil.isInTestSource(directoryFile, project)) { data.addText(" (test source root)", SimpleTextAttributes.GRAY_ATTRIBUTES); } else { data.addText(" (source root)", SimpleTextAttributes.GRAY_ATTRIBUTES); } } setupIcon(data, psiDirectory); return; } } final String name = parentValue instanceof Project ? psiDirectory.getVirtualFile().getPresentableUrl() : BaseProjectViewDirectoryHelper.getNodeName(getSettings(), parentValue, psiDirectory); if (name == null) { setValue(null); return; } data.setPresentableText(name); if (ProjectRootsUtil.isLibraryRoot(directoryFile, project)) { data.setLocationString("library home"); } else { data.setLocationString(BaseProjectViewDirectoryHelper.getLocationString(psiDirectory)); } setupIcon(data, psiDirectory); }