Skip to content

Commit b09b7d2

Browse files
committed
Replaced EditorCoroutines with FileWatcher and GitStatus classes.
1 parent 44d2c81 commit b09b7d2

File tree

4 files changed

+12
-126
lines changed

4 files changed

+12
-126
lines changed

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

Lines changed: 10 additions & 99 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,22 +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 DateTime _lastUpdated;
28-
29-
private EditorCoroutine _coroutine;
30-
31-
private bool _isEditorFocused;
32-
3314
[MenuItem("Git/Git Status")]
3415
public static void ShowWindow()
3516
{
@@ -38,120 +19,50 @@ public static void ShowWindow()
3819

3920
}
4021

41-
private void Update()
42-
{
43-
44-
if (InternalEditorUtility.isApplicationActive && !_isEditorFocused)
45-
{
46-
47-
UpdateData();
48-
49-
}
50-
51-
_isEditorFocused = InternalEditorUtility.isApplicationActive;
52-
53-
}
54-
5522
private void OnGUI()
5623
{
5724

5825
GUILayout.Space(5);
5926

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

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

64-
if (!_branches[selectedBranch].Equals(_branch))
31+
if (!GitStatus.branches[selectedBranch].Equals(GitStatus.branch))
6532
{
6633

67-
if (_changedFiles?.Length > 0)
34+
if (GitStatus.changedFiles?.Length > 0)
6835
{
6936

7037
EditorUtility.DisplayDialog(
7138
"Unable to checkout branch",
72-
$"Unable to checkout {_branches[selectedBranch]} as with {_changedFiles?.Length} changes. " +
39+
$"Unable to checkout {GitStatus.branches[selectedBranch]} as with {GitStatus.changedFiles?.Length} changes. " +
7340
"Commit, discard or stash before checking out a different branch.",
7441
"Ok");
7542

7643
}
7744
else
7845
{
7946

80-
Git.CheckoutBranch(_branches[selectedBranch]);
81-
82-
_branch = _branches[selectedBranch];
47+
Git.CheckoutBranch(GitStatus.branches[selectedBranch]);
8348

8449
}
8550

8651
}
8752

88-
GUILayout.Label($"Number of Changes: {_changedFiles?.Length}");
89-
GUILayout.Label($"Untracked Files: {_untrackedFiles?.Length}");
90-
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($"Last Updated: {GitStatus.lastUpdated}");
9156

9257
if (GUILayout.Button("Refresh"))
9358
{
9459

95-
UpdateData();
60+
GitStatus.Update();
9661

9762
}
9863

9964
}
10065

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

15768
}

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +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-
2319
static ProjectPanel()
2420
{
2521

2622
EditorApplication.projectWindowItemOnGUI -= ProjectWindowItemOnGui;
2723
EditorApplication.projectWindowItemOnGUI += ProjectWindowItemOnGui;
2824

29-
_changedFiles = Git.ChangedFiles();
30-
31-
_untrackedFiles = Git.UntrackedFiles();
32-
3325
}
3426

3527
private static void ProjectWindowItemOnGui(string guid, Rect selectionRect)
@@ -59,13 +51,13 @@ private static void ProjectWindowItemOnGui(string guid, Rect selectionRect)
5951
iconSize - ICON_PADDING,
6052
iconSize - ICON_PADDING);
6153

62-
if (_changedFiles.Contains(path))
54+
if (GitStatus.changedFiles.Contains(path))
6355
{
6456

6557
GUI.DrawTexture(rect, GitIcons.Changed, ScaleMode.ScaleToFit);
6658

6759
}
68-
else if (_untrackedFiles.Contains(path))
60+
else if (GitStatus.untrackedFiles.Contains(path))
6961
{
7062

7163
GUI.DrawTexture(rect, GitIcons.Untracked, ScaleMode.ScaleToFit);
@@ -74,19 +66,6 @@ private static void ProjectWindowItemOnGui(string guid, Rect selectionRect)
7466

7567
}
7668

77-
private static void OnPostprocessAllAssets(
78-
string[] importedAssets,
79-
string[] deletedAssets,
80-
string[] movedAssets,
81-
string[] movedFromAssetPaths)
82-
{
83-
84-
_changedFiles = Git.ChangedFiles();
85-
86-
_untrackedFiles = Git.UntrackedFiles();
87-
88-
}
89-
9069
}
9170

9271
}

Assets/Plugins/CandyCoded.GitStatus/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"unityRelease": "13f1",
77
"description": "Unity editor panel that displays the current git status.",
88
"license": "MIT",
9-
"dependencies": {
10-
"com.unity.editorcoroutines": "0.0.2-preview.1"
11-
},
129
"keywords": [
1310
"unity",
1411
"editor",

Packages/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"dependencies": {
3-
"com.unity.editorcoroutines": "0.0.2-preview.1",
43
"com.unity.ide.rider": "1.1.1",
54
"com.unity.test-framework": "1.1.3"
65
}

0 commit comments

Comments
 (0)