Skip to content

Commit

Permalink
Include graph folder tree items end now in slashes.
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
Wumpf committed May 30, 2017
1 parent fd41202 commit e372a3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 24 additions & 6 deletions IncludeToolbox/GraphWindow/ViewModel/FolderIncludeTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void GenerateChildItems()
{
leafItems.Sort((x, y) => x.ParentFolder.CompareTo(y.ParentFolder));

var root = new FolderIncludeTreeViewItem_Folder("", "");
var root = new FolderIncludeTreeViewItem_Folder("", 0);
GroupIncludeRecursively(root, leafItems, 0, leafItems.Count, 0);
rootChildren.AddRange(root.ChildrenList);
}
Expand Down Expand Up @@ -119,7 +119,7 @@ private void GroupIncludeRecursively(FolderIncludeTreeViewItem_Folder parentFold
{
// Find maximal prefix of this group.
string largestPrefix = LargestCommonFolderPrefixInRange(allLeafItems, begin, i, currentPrefix);
var newGroup = new FolderIncludeTreeViewItem_Folder(largestPrefix, largestPrefix.Substring(commonPrefixLength));
var newGroup = new FolderIncludeTreeViewItem_Folder(largestPrefix, commonPrefixLength);
parentFolder.ChildrenList.Add(newGroup);

// If there are any direct children, they will be first due to sorting. Add them to the new group and ignore this part of the range.
Expand Down Expand Up @@ -156,10 +156,28 @@ public class FolderIncludeTreeViewItem_Folder : IncludeTreeViewItem
public override IReadOnlyList<IncludeTreeViewItem> Children => ChildrenList;
public List<IncludeTreeViewItem> ChildrenList { get; private set; } = new List<IncludeTreeViewItem>();

public FolderIncludeTreeViewItem_Folder(string absoluteFolderName, string folderPart)
public const string UnresolvedFolderName = "<unresolved>";

public FolderIncludeTreeViewItem_Folder(string largestPrefix, int commonPrefixLength)
{
Name = folderPart;
AbsoluteFilename = absoluteFolderName;
AbsoluteFilename = largestPrefix;

largestPrefix.Substring(commonPrefixLength);

if (largestPrefix != UnresolvedFolderName)
{
var stringBuilder = new StringBuilder(largestPrefix);
stringBuilder.Remove(0, commonPrefixLength);
stringBuilder.Append(Path.DirectorySeparatorChar);
if (stringBuilder[0] == Path.DirectorySeparatorChar)
stringBuilder.Remove(0, 1);

Name = stringBuilder.ToString();
}
else
{
Name = largestPrefix;
}
}

public override void NavigateToInclude()
Expand Down Expand Up @@ -190,7 +208,7 @@ public FolderIncludeTreeViewItem_Leaf(IncludeGraph.GraphItem item)
AbsoluteFilename = item?.AbsoluteFilename;

if (string.IsNullOrWhiteSpace(AbsoluteFilename) || !Path.IsPathRooted(AbsoluteFilename))
ParentFolder = "<unresolved>";
ParentFolder = FolderIncludeTreeViewItem_Folder.UnresolvedFolderName;
else
ParentFolder = Path.GetDirectoryName(AbsoluteFilename);
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/IncludeGraphTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void IncludeFolderGrouping()
Assert.IsNotNull(unresolvedFolder);
Assert.IsInstanceOfType(unresolvedFolder, typeof(IncludeToolbox.GraphWindow.FolderIncludeTreeViewItem_Folder));

var subdirFolder = children.First(x => x.Name.EndsWith("testdata\\subdir"));
var subdirFolder = children.First(x => x.Name.EndsWith("testdata\\subdir\\"));
Assert.IsTrue(Path.IsPathRooted(subdirFolder.Name));
Assert.IsNotNull(unresolvedFolder);
Assert.IsInstanceOfType(unresolvedFolder, typeof(IncludeToolbox.GraphWindow.FolderIncludeTreeViewItem_Folder));
Expand All @@ -189,7 +189,7 @@ public void IncludeFolderGrouping()
Assert.IsNotNull(inline);
Assert.IsInstanceOfType(inline, typeof(IncludeToolbox.GraphWindow.FolderIncludeTreeViewItem_Leaf));

var subdirsubdirFolder = subdirFolder.Children.First(x => x.Name == "\\subdir");
var subdirsubdirFolder = subdirFolder.Children.First(x => x.Name == "subdir\\");
Assert.IsNotNull(subdirsubdirFolder);
Assert.IsInstanceOfType(subdirsubdirFolder, typeof(IncludeToolbox.GraphWindow.FolderIncludeTreeViewItem_Folder));

Expand Down

0 comments on commit e372a3e

Please sign in to comment.