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

Commit aa9cdeb

Browse files
Disabling the tree when it is busy
1 parent 947e2b9 commit aa9cdeb

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private void OnCommitDetailsAreaGUI()
264264
GUILayout.Space(Styles.CommitAreaPadding);
265265

266266
// Disable committing when already committing or if we don't have all the data needed
267-
EditorGUI.BeginDisabledGroup(isBusy || string.IsNullOrEmpty(commitMessage) || !treeChanges.GetCheckedFiles().Any());
267+
EditorGUI.BeginDisabledGroup(IsBusy || string.IsNullOrEmpty(commitMessage) || !treeChanges.GetCheckedFiles().Any());
268268
{
269269
GUILayout.BeginHorizontal();
270270
{
@@ -301,7 +301,7 @@ private void SelectNone()
301301
private void Commit()
302302
{
303303
// Do not allow new commits before we have received one successful update
304-
isBusy = true;
304+
SetBusy(true);
305305

306306
var files = treeChanges.GetCheckedFiles().ToList();
307307
ITask addTask;
@@ -320,10 +320,16 @@ private void Commit()
320320
{
321321
commitMessage = "";
322322
commitBody = "";
323-
isBusy = false;
323+
SetBusy(false);
324324
}).Start();
325325
}
326326

327+
private void SetBusy(bool value)
328+
{
329+
treeChanges.IsBusy = value;
330+
isBusy = value;
331+
}
332+
327333
public override bool IsBusy
328334
{
329335
get { return isBusy; }

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public abstract class Tree<TNode, TData>: TreeBase<TNode, TData>
2828
[NonSerialized] private TNode rightClickNextRenderNode;
2929

3030
[NonSerialized] private int controlId;
31+
[NonSerialized] private bool isBusy;
3132

3233
public bool IsInitialized { get { return Nodes != null && Nodes.Count > 0 && !String.IsNullOrEmpty(Nodes[0].Path); } }
3334
public bool RequiresRepaint { get; private set; }
@@ -75,7 +76,7 @@ public Rect Render(Rect treeDisplayRect, Vector2 scroll, Action<TNode> singleCli
7576
if (titleDisplay)
7677
{
7778
var isSelected = SelectedNode != null && SelectedNode.Path == titleNode.Path;
78-
renderResult = titleNode.Render(rect, Styles.TreeIndentation, isSelected, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
79+
renderResult = titleNode.Render(rect, Styles.TreeIndentation, isSelected, IsBusy, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
7980
}
8081

8182
if (renderResult == TreeNodeRenderResult.VisibilityChange)
@@ -109,7 +110,7 @@ public Rect Render(Rect treeDisplayRect, Vector2 scroll, Action<TNode> singleCli
109110
if (display)
110111
{
111112
var isSelected = SelectedNode != null && SelectedNode.Path == node.Path;
112-
renderResult = node.Render(rect, Styles.TreeIndentation, isSelected, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
113+
renderResult = node.Render(rect, Styles.TreeIndentation, isSelected, IsBusy, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
113114
}
114115

115116
if (renderResult == TreeNodeRenderResult.VisibilityChange)
@@ -153,6 +154,12 @@ protected bool TreeHasFocus
153154

154155
public abstract bool ViewHasFocus { get; set; }
155156

157+
public bool IsBusy
158+
{
159+
get { return isBusy; }
160+
set { isBusy = value; }
161+
}
162+
156163
public void Focus()
157164
{
158165
bool selectionChanged = false;
@@ -406,10 +413,15 @@ public void Load()
406413
content = new GUIContent(Label, Icon);
407414
}
408415

409-
public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected, GUIStyle toggleStyle, GUIStyle nodeStyle, GUIStyle activeNodeStyle)
416+
public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected, bool treeIsBusy, GUIStyle toggleStyle, GUIStyle nodeStyle, GUIStyle activeNodeStyle)
410417
{
411418
var renderResult = TreeNodeRenderResult.None;
412419

420+
if (treeIsBusy)
421+
{
422+
GUI.enabled = false;
423+
}
424+
413425
if (IsHidden)
414426
return renderResult;
415427

@@ -453,7 +465,7 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
453465

454466
if (Event.current.type == EventType.repaint)
455467
{
456-
toggleStyle.Draw(toggleRect, GUIContent.none, false, false, styleOn, isSelected);
468+
toggleStyle.Draw(toggleRect, GUIContent.none, isHover: false, isActive: false, @on: styleOn, hasKeyboardFocus: isSelected);
457469
}
458470

459471
EditorGUI.BeginChangeCheck();
@@ -500,6 +512,11 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
500512
GUI.DrawTexture(statusRect, IconBadge);
501513
}
502514

515+
if (treeIsBusy)
516+
{
517+
GUI.enabled = true;
518+
}
519+
503520
return renderResult;
504521
}
505522

0 commit comments

Comments
 (0)