Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 7a3337d

Browse files
Code cleanup; Restoring funcitonality to load icons optionally
1 parent a78e312 commit 7a3337d

File tree

6 files changed

+108
-110
lines changed

6 files changed

+108
-110
lines changed

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@
221221
<Compile Include="Extensions\UriExtensions.cs" />
222222
<Compile Include="Platform\Platform.cs" />
223223
<Compile Include="Git\GitCredentialManager.cs" />
224-
<Compile Include="UI\CommitState.cs" />
225224
<Compile Include="UI\FileTreeNode.cs" />
226225
<Compile Include="UI\GitCommitTarget.cs" />
227226
<Compile Include="UI\TreeBuilder.cs" />

src/GitHub.Api/UI/CommitState.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/GitHub.Api/UI/FileTreeNode.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
namespace GitHub.Unity
66
{
7+
enum CommitState
8+
{
9+
None,
10+
Some,
11+
All
12+
}
13+
714
class FileTreeNode
815
{
916
private readonly Action<FileTreeNode> stateChangeCallback;

src/GitHub.Api/UI/TreeBuilder.cs

Lines changed: 100 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,141 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using GitHub.Unity;
54

6-
static class TreeBuilder
5+
namespace GitHub.Unity
76
{
8-
internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List<string> foldedTreeEntries1, Action<FileTreeNode> stateChangeCallback1)
7+
static class TreeBuilder
98
{
10-
if (String.IsNullOrEmpty(node.Label))
9+
internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List<string> foldedTreeEntries1, Action<FileTreeNode> stateChangeCallback1)
1110
{
12-
// TODO: We should probably reassign this target onto the parent? Depends on how we want to handle .meta files for folders
13-
return;
14-
}
11+
if (String.IsNullOrEmpty(node.Label))
12+
{
13+
// TODO: We should probably reassign this target onto the parent? Depends on how we want to handle .meta files for folders
14+
return;
15+
}
1516

16-
node.RepositoryPath = parent.RepositoryPath.ToNPath().Combine(node.Label);
17-
parent.Open = !foldedTreeEntries1.Contains(parent.RepositoryPath);
17+
node.RepositoryPath = parent.RepositoryPath.ToNPath().Combine(node.Label);
18+
parent.Open = !foldedTreeEntries1.Contains(parent.RepositoryPath);
1819

19-
// Is this node inside a folder?
20-
var nodePath = node.Label.ToNPath();
21-
if (nodePath.Elements.Count() > 1)
22-
{
23-
// Figure out what the root folder is and chop it from the path
24-
var root = nodePath.Elements.First();
25-
node.Label = new NPath("").Combine(nodePath.Elements.Skip(1).ToArray());
26-
27-
// Look for a branch matching our root in the existing children
28-
var found = false;
29-
foreach (var child in parent.Children)
20+
// Is this node inside a folder?
21+
var nodePath = node.Label.ToNPath();
22+
if (nodePath.Elements.Count() > 1)
3023
{
31-
// If we found the branch, continue building from that branch
32-
if (child.Label.Equals(root))
24+
// Figure out what the root folder is and chop it from the path
25+
var root = nodePath.Elements.First();
26+
node.Label = new NPath("").Combine(nodePath.Elements.Skip(1).ToArray());
27+
28+
// Look for a branch matching our root in the existing children
29+
var found = false;
30+
foreach (var child in parent.Children)
3331
{
34-
found = true;
35-
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
36-
break;
32+
// If we found the branch, continue building from that branch
33+
if (child.Label.Equals(root))
34+
{
35+
found = true;
36+
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
37+
break;
38+
}
3739
}
38-
}
3940

40-
// No existing branch - we will have to add a new one to build from
41-
if (!found)
42-
{
43-
var p = parent.RepositoryPath.ToNPath().Combine(root);
44-
BuildChildNode(parent.Add(new FileTreeNode(root, stateChangeCallback1) { RepositoryPath = p }), node, foldedTreeEntries1, stateChangeCallback1);
41+
// No existing branch - we will have to add a new one to build from
42+
if (!found)
43+
{
44+
var p = parent.RepositoryPath.ToNPath().Combine(root);
45+
BuildChildNode(parent.Add(new FileTreeNode(root, stateChangeCallback1) { RepositoryPath = p }), node, foldedTreeEntries1, stateChangeCallback1);
46+
}
4547
}
46-
}
47-
else if (nodePath.ExtensionWithDot == ".meta")
48-
{
49-
// Look for a branch matching our root in the existing children
50-
var found = false;
51-
foreach (var child in parent.Children)
48+
else if (nodePath.ExtensionWithDot == ".meta")
5249
{
53-
// If we found the branch, continue building from that branch
54-
if (child.Label.Equals(nodePath.Parent.Combine(nodePath.FileNameWithoutExtension)))
50+
// Look for a branch matching our root in the existing children
51+
var found = false;
52+
foreach (var child in parent.Children)
5553
{
56-
found = true;
57-
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
58-
break;
54+
// If we found the branch, continue building from that branch
55+
if (child.Label.Equals(nodePath.Parent.Combine(nodePath.FileNameWithoutExtension)))
56+
{
57+
found = true;
58+
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
59+
break;
60+
}
61+
}
62+
if (!found)
63+
{
64+
parent.Add(node);
5965
}
6066
}
61-
if (!found)
67+
// Not inside a folder - just add this node right here
68+
else
6269
{
6370
parent.Add(node);
6471
}
6572
}
66-
// Not inside a folder - just add this node right here
67-
else
68-
{
69-
parent.Add(node);
70-
}
71-
}
72-
73-
internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, List<GitStatusEntry> gitStatusEntries, List<GitCommitTarget> gitCommitTargets, List<string> foldedTreeEntries, Action<FileTreeNode> stateChangeCallback)
74-
{
75-
Guard.ArgumentNotNullOrEmpty(newEntries, "newEntries");
7673

77-
// Remove what got nuked
78-
for (var index = 0; index < gitStatusEntries.Count;)
74+
internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, List<GitStatusEntry> gitStatusEntries, List<GitCommitTarget> gitCommitTargets, List<string> foldedTreeEntries, Action<FileTreeNode> stateChangeCallback, Func<string, object> iconLoaderFunc = null)
7975
{
80-
if (!newEntries.Contains(gitStatusEntries[index]))
81-
{
82-
gitStatusEntries.RemoveAt(index);
83-
gitCommitTargets.RemoveAt(index);
84-
}
85-
else
86-
{
87-
index++;
88-
}
89-
}
76+
Guard.ArgumentNotNullOrEmpty(newEntries, "newEntries");
9077

91-
// Remove folding state of nuked items
92-
for (var index = 0; index < foldedTreeEntries.Count;)
93-
{
94-
if (!newEntries.Any(e => e.Path.IndexOf(foldedTreeEntries[index]) == 0))
78+
// Remove what got nuked
79+
for (var index = 0; index < gitStatusEntries.Count;)
9580
{
96-
foldedTreeEntries.RemoveAt(index);
81+
if (!newEntries.Contains(gitStatusEntries[index]))
82+
{
83+
gitStatusEntries.RemoveAt(index);
84+
gitCommitTargets.RemoveAt(index);
85+
}
86+
else
87+
{
88+
index++;
89+
}
9790
}
98-
else
91+
92+
// Remove folding state of nuked items
93+
for (var index = 0; index < foldedTreeEntries.Count;)
9994
{
100-
index++;
95+
if (!newEntries.Any(e => e.Path.IndexOf(foldedTreeEntries[index]) == 0))
96+
{
97+
foldedTreeEntries.RemoveAt(index);
98+
}
99+
else
100+
{
101+
index++;
102+
}
101103
}
102-
}
103104

104-
// Add new stuff
105-
for (var index = 0; index < newEntries.Count; ++index)
106-
{
107-
var entry = newEntries[index];
108-
if (!gitStatusEntries.Contains(entry))
105+
// Add new stuff
106+
for (var index = 0; index < newEntries.Count; ++index)
109107
{
110-
gitStatusEntries.Add(entry);
111-
gitCommitTargets.Add(new GitCommitTarget());
108+
var entry = newEntries[index];
109+
if (!gitStatusEntries.Contains(entry))
110+
{
111+
gitStatusEntries.Add(entry);
112+
gitCommitTargets.Add(new GitCommitTarget());
113+
}
112114
}
113-
}
114-
115-
// TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting
116-
// TODO: In stead of completely rebuilding the tree structure, figure out a way to migrate open/closed states from the old tree to the new
117-
// Build tree structure
118115

119-
var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path)), stateChangeCallback);
120-
tree.RepositoryPath = tree.Path;
116+
// TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting
117+
// TODO: In stead of completely rebuilding the tree structure, figure out a way to migrate open/closed states from the old tree to the new
118+
// Build tree structure
121119

122-
for (var index1 = 0; index1 < gitStatusEntries.Count; index1++)
123-
{
124-
GitStatusEntry gitStatusEntry = gitStatusEntries[index1];
125-
var entryPath = gitStatusEntry.Path.ToNPath();
126-
if (entryPath.IsChildOf(tree.Path)) entryPath = entryPath.RelativeTo(tree.Path.ToNPath());
120+
var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path)), stateChangeCallback);
121+
tree.RepositoryPath = tree.Path;
127122

128-
var node = new FileTreeNode(entryPath, stateChangeCallback) { Target = gitCommitTargets[index1] };
129-
if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath))
123+
for (var index1 = 0; index1 < gitStatusEntries.Count; index1++)
130124
{
131-
//node.Icon = AssetDatabase.GetCachedIcon(gitStatusEntry.ProjectPath);
125+
GitStatusEntry gitStatusEntry = gitStatusEntries[index1];
126+
var entryPath = gitStatusEntry.Path.ToNPath();
127+
if (entryPath.IsChildOf(tree.Path)) entryPath = entryPath.RelativeTo(tree.Path.ToNPath());
128+
129+
var node = new FileTreeNode(entryPath, stateChangeCallback) { Target = gitCommitTargets[index1] };
130+
if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath))
131+
{
132+
node.Icon = iconLoaderFunc.Invoke(gitStatusEntry.ProjectPath);
133+
}
134+
135+
TreeBuilder.BuildChildNode(tree, node, foldedTreeEntries, stateChangeCallback);
132136
}
133137

134-
TreeBuilder.BuildChildNode(tree, node, foldedTreeEntries, stateChangeCallback);
138+
return tree;
135139
}
136-
137-
return tree;
138140
}
139141
}

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@
230230
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
231231
</None>
232232
</ItemGroup>
233-
<ItemGroup />
234233
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
235234
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
236235
Other similar extension points exist, see Microsoft.Common.targets.

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesetTreeView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void UpdateEntries(IList<GitStatusEntry> newEntries)
109109
return;
110110
}
111111

112-
tree = TreeBuilder.BuildTreeRoot(newEntries, entries, entryCommitTargets, foldedTreeEntries, stateChangeCallback);
112+
tree = TreeBuilder.BuildTreeRoot(newEntries, entries, entryCommitTargets, foldedTreeEntries, stateChangeCallback, AssetDatabase.GetCachedIcon);
113113

114114
OnCommitTreeChange();
115115
}

0 commit comments

Comments
 (0)