From f5eeccef6ab006a1bb9c75bbff12a5167b738026 Mon Sep 17 00:00:00 2001 From: irengrig Date: Thu, 26 Jul 2012 12:54:14 +0400 Subject: [PATCH] IDEA-89289 Commit changes presentation: when treeview is used with added subtree and missing [changed] folder in the middle --- .../changes/ui/ChangesBrowserFilePathNode.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java index 9ba8a0d7e750..bc5fd836721a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java @@ -18,6 +18,8 @@ package com.intellij.openapi.vcs.changes.ui; 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; @@ -76,14 +78,20 @@ public class ChangesBrowserFilePathNode extends ChangesBrowserNode { public static FilePath safeCastToFilePath(Object o) { if (o instanceof FilePath) return (FilePath)o; + if (o instanceof Change) { + return ChangesUtil.getAfterPath((Change)o); + } return null; } public static String getRelativePath(FilePath parent, FilePath child) { - if (parent == null || ! child.getPath().startsWith(parent.getPath())) return child.getPath().replace('/', File.separatorChar); - final String parentPath = parent.getPath(); - final int beginOffset = (parentPath.length() == 1 && '/' == parentPath.charAt(0)) ? 0 : 1; // IDEADEV-35767 - return child.getPath().substring(parent.getPath().length() + beginOffset).replace('/', File.separatorChar); + 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); } public int getSortWeight() {