mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-153710 Fixed relative paths between tree nodes calculation (while displaying changes)
Used when grouping by directory is enabled
This commit is contained in:
+13
-10
@@ -16,14 +16,15 @@
|
||||
|
||||
package com.intellij.openapi.vcs.changes.ui;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfoRt;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangesUtil;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
|
||||
import java.io.File;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.util.FontUtil.spaceAndThinSpace;
|
||||
|
||||
@@ -78,6 +79,7 @@ public class ChangesBrowserFilePathNode extends ChangesBrowserNode<FilePath> {
|
||||
return FileUtil.toSystemDependentName(getUserObject().getPath());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FilePath safeCastToFilePath(Object o) {
|
||||
if (o instanceof FilePath) return (FilePath)o;
|
||||
if (o instanceof Change) {
|
||||
@@ -86,14 +88,15 @@ public class ChangesBrowserFilePathNode extends ChangesBrowserNode<FilePath> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getRelativePath(FilePath parent, FilePath child) {
|
||||
final String systemDependentChild = child.getPath().replace('/', File.separatorChar);
|
||||
final String systemDependentParent = parent == null ? null : parent.getPath().replace('/', File.separatorChar);
|
||||
if (systemDependentParent == null || ! systemDependentChild.startsWith(systemDependentParent)) {
|
||||
return systemDependentChild;
|
||||
}
|
||||
final int beginOffset = (systemDependentParent.length() == 1 && '/' == systemDependentParent.charAt(0)) ? 0 : 1; // IDEADEV-35767
|
||||
return systemDependentChild.substring(systemDependentParent.length() + beginOffset).replace('/', File.separatorChar);
|
||||
@NotNull
|
||||
public static String getRelativePath(@Nullable FilePath parent, @NotNull FilePath child) {
|
||||
boolean isLocal = !child.isNonLocal();
|
||||
boolean caseSensitive = isLocal && SystemInfoRt.isFileSystemCaseSensitive;
|
||||
String result = parent != null ? FileUtil.getRelativePath(parent.getPath(), child.getPath(), '/', caseSensitive) : null;
|
||||
|
||||
result = result == null ? child.getPath() : result;
|
||||
|
||||
return isLocal ? FileUtil.toSystemDependentName(result) : result;
|
||||
}
|
||||
|
||||
public int getSortWeight() {
|
||||
|
||||
Reference in New Issue
Block a user