1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
- using GitHub . Unity ;
5
4
6
- static class TreeBuilder
5
+ namespace GitHub . Unity
7
6
{
8
- internal static void BuildChildNode ( FileTreeNode parent , FileTreeNode node , List < string > foldedTreeEntries1 , Action < FileTreeNode > stateChangeCallback1 )
7
+ static class TreeBuilder
9
8
{
10
- if ( String . IsNullOrEmpty ( node . Label ) )
9
+ internal static void BuildChildNode ( FileTreeNode parent , FileTreeNode node , List < string > foldedTreeEntries1 , Action < FileTreeNode > stateChangeCallback1 )
11
10
{
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
+ }
15
16
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 ) ;
18
19
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 )
30
23
{
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 )
33
31
{
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
+ }
37
39
}
38
- }
39
40
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
+ }
45
47
}
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" )
52
49
{
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 )
55
53
{
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 ) ;
59
65
}
60
66
}
61
- if ( ! found )
67
+ // Not inside a folder - just add this node right here
68
+ else
62
69
{
63
70
parent . Add ( node ) ;
64
71
}
65
72
}
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" ) ;
76
73
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 )
79
75
{
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" ) ;
90
77
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 ; )
95
80
{
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
+ }
97
90
}
98
- else
91
+
92
+ // Remove folding state of nuked items
93
+ for ( var index = 0 ; index < foldedTreeEntries . Count ; )
99
94
{
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
+ }
101
103
}
102
- }
103
104
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 )
109
107
{
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
+ }
112
114
}
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
118
115
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
121
119
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 ;
127
122
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 ++ )
130
124
{
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 ) ;
132
136
}
133
137
134
- TreeBuilder . BuildChildNode ( tree , node , foldedTreeEntries , stateChangeCallback ) ;
138
+ return tree ;
135
139
}
136
-
137
- return tree ;
138
140
}
139
141
}
0 commit comments