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

Commit 2332eeb

Browse files
Moving files to a place where I can write tests against it
1 parent c2c5f2e commit 2332eeb

File tree

8 files changed

+159
-149
lines changed

8 files changed

+159
-149
lines changed

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@
221221
<Compile Include="Extensions\UriExtensions.cs" />
222222
<Compile Include="Platform\Platform.cs" />
223223
<Compile Include="Git\GitCredentialManager.cs" />
224+
<Compile Include="UI\CommitState.cs" />
225+
<Compile Include="UI\FileTreeNode.cs" />
226+
<Compile Include="UI\GitCommitTarget.cs" />
227+
<Compile Include="UI\TreeBuilder.cs" />
224228
</ItemGroup>
225229
<Choose>
226230
<When Condition="$(Buildtype) == 'Internal'">

src/GitHub.Api/GitHub.Api.csproj.DotSettings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platform/@EntryIndexedValue">True</s:Boolean>
1515
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=primitives/@EntryIndexedValue">True</s:Boolean>
1616
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=process/@EntryIndexedValue">True</s:Boolean>
17-
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
17+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks/@EntryIndexedValue">True</s:Boolean>
18+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ui/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/GitHub.Api/UI/CommitState.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GitHub.Unity
2+
{
3+
enum CommitState
4+
{
5+
None,
6+
Some,
7+
All
8+
}
9+
}

src/GitHub.Api/UI/FileTreeNode.cs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace GitHub.Unity
6+
{
7+
class FileTreeNode
8+
{
9+
private readonly Action<FileTreeNode> stateChangeCallback;
10+
private List<FileTreeNode> children;
11+
private string path;
12+
private CommitState state;
13+
14+
public object Icon;
15+
public string Label;
16+
public bool Open = true;
17+
public string RepositoryPath;
18+
public GitCommitTarget Target { get; set; }
19+
20+
public FileTreeNode(Action<FileTreeNode> stateChangeCallback)
21+
{
22+
this.stateChangeCallback = stateChangeCallback;
23+
children = new List<FileTreeNode>();
24+
}
25+
26+
public FileTreeNode(string path, Action<FileTreeNode> stateChangeCallback)
27+
{
28+
this.stateChangeCallback = stateChangeCallback;
29+
this.path = path ?? "";
30+
Label = this.path;
31+
children = new List<FileTreeNode>();
32+
}
33+
34+
public FileTreeNode Add(FileTreeNode child)
35+
{
36+
children.Add(child);
37+
return child;
38+
}
39+
40+
public CommitState State
41+
{
42+
get
43+
{
44+
if (children == null)
45+
return state;
46+
47+
var commitState = CommitState.None;
48+
if (Target != null)
49+
{
50+
commitState = Target.All ? CommitState.All : Target.Any ? CommitState.Some : CommitState.None;
51+
if (!children.Any())
52+
{
53+
state = commitState;
54+
return state;
55+
}
56+
}
57+
58+
var allCount = children.Count(c => c.State == CommitState.All);
59+
60+
if (allCount == children.Count && (commitState == CommitState.All || Target == null))
61+
{
62+
state = CommitState.All;
63+
return state;
64+
}
65+
66+
if (allCount > 0 || commitState == CommitState.Some)
67+
{
68+
state = CommitState.Some;
69+
return state;
70+
}
71+
72+
var someCount = children.Count(c => c.State == CommitState.Some);
73+
if (someCount > 0 || commitState == CommitState.Some)
74+
{
75+
state = CommitState.Some;
76+
return state;
77+
}
78+
state = CommitState.None;
79+
return state;
80+
}
81+
82+
set
83+
{
84+
if (value == state)
85+
{
86+
return;
87+
}
88+
89+
if (Target != null)
90+
{
91+
if (value == CommitState.None)
92+
{
93+
Target.Clear();
94+
}
95+
else if (value == CommitState.All)
96+
{
97+
Target.All = true;
98+
}
99+
}
100+
101+
state = value;
102+
stateChangeCallback?.Invoke(this);
103+
104+
if (children == null)
105+
{
106+
return;
107+
}
108+
109+
for (var index = 0; index < children.Count; ++index)
110+
{
111+
children[index].State = value;
112+
}
113+
}
114+
}
115+
116+
public string Path
117+
{
118+
get { return path; }
119+
}
120+
121+
public IEnumerable<FileTreeNode> Children
122+
{
123+
get {
124+
if (children == null)
125+
children = new List<FileTreeNode>();
126+
return children;
127+
}
128+
}
129+
130+
private ILogging logger;
131+
protected ILogging Logger
132+
{
133+
get
134+
{
135+
if (logger == null)
136+
logger = Logging.GetLogger(GetType());
137+
return logger;
138+
}
139+
}
140+
}
141+
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitCommitTarget.cs renamed to src/GitHub.Api/UI/GitCommitTarget.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
2-
using UnityEngine;
32

43
namespace GitHub.Unity
54
{
65
[Serializable]
76
class GitCommitTarget
87
{
9-
[SerializeField] public bool All = false;
8+
public bool All = false;
109

1110
public void Clear()
1211
{

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeBuilder.cs renamed to src/GitHub.Api/UI/TreeBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using GitHub.Unity;
5-
using UnityEditor;
65

76
static internal class TreeBuilder
87
{
@@ -89,7 +88,7 @@ internal static FileTreeNode BuildTree3(List<GitStatusEntry> gitStatusEntries, A
8988
var node = new FileTreeNode(entryPath, stateChangeCallback1) { Target = entryCommitTargets[index] };
9089
if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath))
9190
{
92-
node.Icon = AssetDatabase.GetCachedIcon(gitStatusEntry.ProjectPath);
91+
//node.Icon = AssetDatabase.GetCachedIcon(gitStatusEntry.ProjectPath);
9392
}
9493

9594
TreeBuilder.BuildTree(tree, node, foldedTreeEntries1, stateChangeCallback1);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@
9797
<Compile Include="UI\BranchesView.cs" />
9898
<Compile Include="UI\ChangesetTreeView.cs" />
9999
<Compile Include="UI\ChangesView.cs" />
100-
<Compile Include="UI\GitCommitTarget.cs" />
101100
<Compile Include="UI\HistoryView.cs" />
102101
<Compile Include="UI\IView.cs" />
103102
<Compile Include="UI\SettingsView.cs" />
104103
<Compile Include="UI\Subview.cs" />
105-
<Compile Include="UI\TreeBuilder.cs" />
106104
<Compile Include="UI\Window.cs" />
107105
</ItemGroup>
108106
<ItemGroup>
@@ -232,6 +230,7 @@
232230
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
233231
</None>
234232
</ItemGroup>
233+
<ItemGroup />
235234
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
236235
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
237236
Other similar extension points exist, see Microsoft.Common.targets.

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

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -288,146 +288,4 @@ public IList<GitCommitTarget> CommitTargets
288288
get { return entryCommitTargets; }
289289
}
290290
}
291-
292-
class FileTreeNode
293-
{
294-
private readonly Action<FileTreeNode> stateChangeCallback;
295-
private List<FileTreeNode> children;
296-
private string path;
297-
private CommitState state;
298-
299-
public object Icon;
300-
public string Label;
301-
public bool Open = true;
302-
public string RepositoryPath;
303-
public GitCommitTarget Target { get; set; }
304-
305-
public FileTreeNode(Action<FileTreeNode> stateChangeCallback)
306-
{
307-
this.stateChangeCallback = stateChangeCallback;
308-
children = new List<FileTreeNode>();
309-
}
310-
311-
public FileTreeNode(string path, Action<FileTreeNode> stateChangeCallback)
312-
{
313-
this.stateChangeCallback = stateChangeCallback;
314-
this.path = path ?? "";
315-
Label = this.path;
316-
children = new List<FileTreeNode>();
317-
}
318-
319-
public FileTreeNode Add(FileTreeNode child)
320-
{
321-
children.Add(child);
322-
return child;
323-
}
324-
325-
public CommitState State
326-
{
327-
get
328-
{
329-
if (children == null)
330-
return state;
331-
332-
var commitState = CommitState.None;
333-
if (Target != null)
334-
{
335-
commitState = Target.All ? CommitState.All : Target.Any ? CommitState.Some : CommitState.None;
336-
if (!children.Any())
337-
{
338-
state = commitState;
339-
return state;
340-
}
341-
}
342-
343-
var allCount = children.Count(c => c.State == CommitState.All);
344-
345-
if (allCount == children.Count && (commitState == CommitState.All || Target == null))
346-
{
347-
state = CommitState.All;
348-
return state;
349-
}
350-
351-
if (allCount > 0 || commitState == CommitState.Some)
352-
{
353-
state = CommitState.Some;
354-
return state;
355-
}
356-
357-
var someCount = children.Count(c => c.State == CommitState.Some);
358-
if (someCount > 0 || commitState == CommitState.Some)
359-
{
360-
state = CommitState.Some;
361-
return state;
362-
}
363-
state = CommitState.None;
364-
return state;
365-
}
366-
367-
set
368-
{
369-
if (value == state)
370-
{
371-
return;
372-
}
373-
374-
if (Target != null)
375-
{
376-
if (value == CommitState.None)
377-
{
378-
Target.Clear();
379-
}
380-
else if (value == CommitState.All)
381-
{
382-
Target.All = true;
383-
}
384-
}
385-
386-
state = value;
387-
stateChangeCallback.SafeInvoke(this);
388-
389-
if (children == null)
390-
{
391-
return;
392-
}
393-
394-
for (var index = 0; index < children.Count; ++index)
395-
{
396-
children[index].State = value;
397-
}
398-
}
399-
}
400-
401-
public string Path
402-
{
403-
get { return path; }
404-
}
405-
406-
public IEnumerable<FileTreeNode> Children
407-
{
408-
get {
409-
if (children == null)
410-
children = new List<FileTreeNode>();
411-
return children;
412-
}
413-
}
414-
415-
private ILogging logger;
416-
protected ILogging Logger
417-
{
418-
get
419-
{
420-
if (logger == null)
421-
logger = Logging.GetLogger(GetType());
422-
return logger;
423-
}
424-
}
425-
}
426-
427-
enum CommitState
428-
{
429-
None,
430-
Some,
431-
All
432-
}
433291
}

0 commit comments

Comments
 (0)