Skip to content

Commit 4436003

Browse files
committed
Switched to referencing GitStatus.
1 parent 33ca535 commit 4436003

File tree

2 files changed

+14
-134
lines changed

2 files changed

+14
-134
lines changed

Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/GitStatusPanel.cs

Lines changed: 11 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
#if UNITY_EDITOR
44
using System;
5-
using System.Collections;
6-
using Unity.EditorCoroutines.Editor;
75
using UnityEditor;
8-
using UnityEditorInternal;
96
using UnityEngine;
107

118
namespace CandyCoded.GitStatus
@@ -14,24 +11,6 @@ namespace CandyCoded.GitStatus
1411
public class GitStatusPanel : EditorWindow
1512
{
1613

17-
private readonly EditorWaitForSeconds _delayBetweenUpdates = new EditorWaitForSeconds(60);
18-
19-
private string _branch;
20-
21-
private string[] _branches;
22-
23-
private string[] _changedFiles;
24-
25-
private string[] _untrackedFiles;
26-
27-
private string[] _lockedFiles;
28-
29-
private DateTime _lastUpdated;
30-
31-
private EditorCoroutine _coroutine;
32-
33-
private bool _isEditorFocused;
34-
3514
[MenuItem("Git/Git Status")]
3615
public static void ShowWindow()
3716
{
@@ -40,123 +19,51 @@ public static void ShowWindow()
4019

4120
}
4221

43-
private void Update()
44-
{
45-
46-
if (InternalEditorUtility.isApplicationActive && !_isEditorFocused)
47-
{
48-
49-
UpdateData();
50-
51-
}
52-
53-
_isEditorFocused = InternalEditorUtility.isApplicationActive;
54-
55-
}
56-
5722
private void OnGUI()
5823
{
5924

6025
GUILayout.Space(5);
6126

62-
var selectedBranch = Array.IndexOf(_branches, _branch);
27+
var selectedBranch = Array.IndexOf(GitStatus.branches, GitStatus.branch);
6328

64-
selectedBranch = EditorGUILayout.Popup("Branch:", selectedBranch, _branches);
29+
selectedBranch = EditorGUILayout.Popup("Branch:", selectedBranch, GitStatus.branches);
6530

66-
if (!_branches[selectedBranch].Equals(_branch))
31+
if (!GitStatus.branches[selectedBranch].Equals(GitStatus.branch))
6732
{
6833

69-
if (_changedFiles?.Length > 0)
34+
if (GitStatus.changedFiles?.Length > 0)
7035
{
7136

7237
EditorUtility.DisplayDialog(
7338
"Unable to checkout branch",
74-
$"Unable to checkout {_branches[selectedBranch]} as with {_changedFiles?.Length} changes. " +
39+
$"Unable to checkout {GitStatus.branches[selectedBranch]} as with {GitStatus.changedFiles?.Length} changes. " +
7540
"Commit, discard or stash before checking out a different branch.",
7641
"Ok");
7742

7843
}
7944
else
8045
{
8146

82-
Git.CheckoutBranch(_branches[selectedBranch]);
83-
84-
_branch = _branches[selectedBranch];
47+
Git.CheckoutBranch(GitStatus.branches[selectedBranch]);
8548

8649
}
8750

8851
}
8952

90-
GUILayout.Label($"Number of Changes: {_changedFiles?.Length}");
91-
GUILayout.Label($"Untracked Files: {_untrackedFiles?.Length}");
92-
GUILayout.Label($"Locked Files: {_lockedFiles?.Length}");
93-
GUILayout.Label($"Last Updated: {_lastUpdated}");
53+
GUILayout.Label($"Number of Changes: {GitStatus.changedFiles?.Length}");
54+
GUILayout.Label($"Untracked Files: {GitStatus.untrackedFiles?.Length}");
55+
GUILayout.Label($"Locked Files: {GitStatus.lockedFiles?.Length}");
56+
GUILayout.Label($"Last Updated: {GitStatus.lastUpdated}");
9457

9558
if (GUILayout.Button("Refresh"))
9659
{
9760

98-
UpdateData();
61+
GitStatus.Update();
9962

10063
}
10164

10265
}
10366

104-
private void UpdateData()
105-
{
106-
107-
_branch = Git.Branch();
108-
109-
_branches = Git.Branches();
110-
111-
_changedFiles = Git.ChangedFiles();
112-
113-
_untrackedFiles = Git.UntrackedFiles();
114-
115-
_lockedFiles = Git.LockedFiles();
116-
117-
_lastUpdated = DateTime.Now;
118-
119-
Repaint();
120-
121-
}
122-
123-
private IEnumerator UpdateCoroutine()
124-
{
125-
126-
while (true)
127-
{
128-
129-
UpdateData();
130-
131-
yield return _delayBetweenUpdates;
132-
133-
}
134-
135-
}
136-
137-
private void OnEnable()
138-
{
139-
140-
_coroutine = EditorCoroutineUtility.StartCoroutine(UpdateCoroutine(), this);
141-
142-
}
143-
144-
private void OnDisable()
145-
{
146-
147-
EditorCoroutineUtility.StopCoroutine(_coroutine);
148-
149-
_coroutine = null;
150-
151-
}
152-
153-
private void OnFocus()
154-
{
155-
156-
UpdateData();
157-
158-
}
159-
16067
}
16168

16269
}

Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/ProjectPanel.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,12 @@ public class ProjectPanel : AssetPostprocessor
1616

1717
private const float ICON_PADDING = 2;
1818

19-
private static string[] _changedFiles;
20-
21-
private static string[] _untrackedFiles;
22-
23-
private static string[] _lockedFiles;
24-
2519
static ProjectPanel()
2620
{
2721

2822
EditorApplication.projectWindowItemOnGUI -= ProjectWindowItemOnGui;
2923
EditorApplication.projectWindowItemOnGUI += ProjectWindowItemOnGui;
3024

31-
_changedFiles = Git.ChangedFiles();
32-
33-
_untrackedFiles = Git.UntrackedFiles();
34-
35-
_lockedFiles = Git.LockedFiles();
36-
3725
}
3826

3927
private static void ProjectWindowItemOnGui(string guid, Rect selectionRect)
@@ -63,19 +51,19 @@ private static void ProjectWindowItemOnGui(string guid, Rect selectionRect)
6351
iconSize - ICON_PADDING,
6452
iconSize - ICON_PADDING);
6553

66-
if (_changedFiles.Contains(path))
54+
if (GitStatus.changedFiles.Contains(path))
6755
{
6856

6957
GUI.DrawTexture(rect, GitIcons.Changed, ScaleMode.ScaleToFit);
7058

7159
}
72-
else if (_untrackedFiles.Contains(path))
60+
else if (GitStatus.untrackedFiles.Contains(path))
7361
{
7462

7563
GUI.DrawTexture(rect, GitIcons.Untracked, ScaleMode.ScaleToFit);
7664

7765
}
78-
else if (_lockedFiles.Contains(path))
66+
else if (GitStatus.lockedFiles.Contains(path))
7967
{
8068

8169
GUI.DrawTexture(rect, GitIcons.Locked, ScaleMode.ScaleToFit);
@@ -84,21 +72,6 @@ private static void ProjectWindowItemOnGui(string guid, Rect selectionRect)
8472

8573
}
8674

87-
private static void OnPostprocessAllAssets(
88-
string[] importedAssets,
89-
string[] deletedAssets,
90-
string[] movedAssets,
91-
string[] movedFromAssetPaths)
92-
{
93-
94-
_changedFiles = Git.ChangedFiles();
95-
96-
_untrackedFiles = Git.UntrackedFiles();
97-
98-
_lockedFiles = Git.LockedFiles();
99-
100-
}
101-
10275
}
10376

10477
}

0 commit comments

Comments
 (0)