Search in sources :

Example 1 with RelativePathCalculator

use of com.intellij.openapi.vcs.changes.patch.RelativePathCalculator in project intellij-community by JetBrains.

the class ModuleVcsPathPresenter method getPresentableRelativePath.

@Override
public String getPresentableRelativePath(@NotNull final ContentRevision fromRevision, @NotNull final ContentRevision toRevision) {
    final FilePath fromPath = fromRevision.getFile();
    final FilePath toPath = toRevision.getFile();
    // need to use parent path because the old file is already not there
    final VirtualFile fromParent = getParentFile(fromPath);
    final VirtualFile toParent = getParentFile(toPath);
    if (fromParent != null && toParent != null) {
        String moduleResult = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

            @Override
            public String compute() {
                final boolean hideExcludedFiles = Registry.is("ide.hide.excluded.files");
                ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
                Module fromModule = fileIndex.getModuleForFile(fromParent, hideExcludedFiles);
                Module toModule = fileIndex.getModuleForFile(toParent, hideExcludedFiles);
                if (fromModule == null || toModule == null || fromModule.equals(toModule))
                    return null;
                VirtualFile fromContentRoot = fileIndex.getContentRootForFile(fromParent, hideExcludedFiles);
                if (fromContentRoot == null)
                    return null;
                String relativePath = VfsUtilCore.getRelativePath(fromParent, fromContentRoot, File.separatorChar);
                assert relativePath != null;
                relativePath += File.separatorChar;
                if (!fromPath.getName().equals(toPath.getName())) {
                    relativePath += fromPath.getName();
                }
                return getPresentableRelativePathFor(fromModule, fromContentRoot, relativePath);
            }
        });
        if (moduleResult != null)
            return moduleResult;
    }
    final RelativePathCalculator calculator = new RelativePathCalculator(toPath.getPath(), fromPath.getPath());
    calculator.execute();
    final String result = calculator.getResult();
    return result != null ? result.replace("/", File.separator) : null;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) RelativePathCalculator(com.intellij.openapi.vcs.changes.patch.RelativePathCalculator) Module(com.intellij.openapi.module.Module)

Example 2 with RelativePathCalculator

use of com.intellij.openapi.vcs.changes.patch.RelativePathCalculator in project intellij-community by JetBrains.

the class PlatformVcsPathPresenter method getPresentableRelativePath.

public String getPresentableRelativePath(final ContentRevision fromRevision, final ContentRevision toRevision) {
    RelativePathCalculator calculator = new RelativePathCalculator(toRevision.getFile().getPath(), fromRevision.getFile().getPath());
    calculator.execute();
    final String result = calculator.getResult();
    return (result == null) ? null : result.replace("/", File.separator);
}
Also used : RelativePathCalculator(com.intellij.openapi.vcs.changes.patch.RelativePathCalculator)

Aggregations

RelativePathCalculator (com.intellij.openapi.vcs.changes.patch.RelativePathCalculator)2 Module (com.intellij.openapi.module.Module)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1