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

Commit c6ef21f

Browse files
committed
Fix switching views
Switching views was happening in such a way that the new view would not get OnDataUpdate called between OnEnable and OnUI, because OnDataUpdate only gets called during layout events, and we switch the view (calling OnEnable on it) during the onmouseup event. That meant that the newly-active view would not load data until the next ui cycle, which causes exceptions to be thrown, given that the rendering code relies on data to always be there in some way (either cached or empty or whatever, but *something* needs to exist) This ensures that OnDataUpdate gets called on the new view manually. This means that the event type for OnUI is going to be mouseup... which might confuse the new view if it's trying to handle it? I think it's probably fine because by this point the event object has been marked as used, which means other controls that want to handle the event will ignore it.
1 parent 64e45bd commit c6ef21f

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,13 @@ public override void OnDataUpdate()
8585
}
8686

8787
private void RepositoryOnLocalAndRemoteBranchListChanged(CacheUpdateEvent cacheUpdateEvent)
88+
{
8889
{
8990
if (!lastLocalAndRemoteBranchListChangedEvent.Equals(cacheUpdateEvent))
9091
{
91-
new ActionTask(TaskManager.Token, () =>
92-
{
93-
lastLocalAndRemoteBranchListChangedEvent = cacheUpdateEvent;
94-
localAndRemoteBranchListHasUpdate = true;
95-
Redraw();
96-
})
97-
{ Affinity = TaskAffinity.UI }.Start();
92+
lastLocalAndRemoteBranchListChangedEvent = cacheUpdateEvent;
93+
localAndRemoteBranchListHasUpdate = true;
94+
Redraw();
9895
}
9996
}
10097

@@ -114,16 +111,11 @@ private void MaybeUpdateData()
114111

115112
private void AttachHandlers(IRepository repository)
116113
{
117-
if (repository == null)
118-
return;
119-
120114
repository.LocalAndRemoteBranchListChanged += RepositoryOnLocalAndRemoteBranchListChanged;
121115
}
122116

123117
private void DetachHandlers(IRepository repository)
124118
{
125-
if (repository == null)
126-
return;
127119

128120
repository.LocalAndRemoteBranchListChanged -= RepositoryOnLocalAndRemoteBranchListChanged;
129121
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ public override void OnEnable()
5151
userSettingsView.OnEnable();
5252
AttachHandlers(Repository);
5353

54-
if (Repository != null)
55-
{
56-
Repository.CheckCurrentRemoteChangedEvent(lastCurrentRemoteChangedEvent);
57-
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
58-
}
59-
54+
Repository.CheckCurrentRemoteChangedEvent(lastCurrentRemoteChangedEvent);
55+
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
6056
metricsHasChanged = true;
6157
}
6258

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ public override void OnRepositoryChanged(IRepository oldRepository)
129129
if (Repository != null && activeTab == SubTab.InitProject)
130130
{
131131
changeTab = SubTab.History;
132+
UpdateActiveTab();
132133
}
133-
134-
UpdateActiveTab();
135134
}
136135

137136
public override void OnSelectionChange()
@@ -317,7 +316,6 @@ private void DoToolbarGUI()
317316
// Subtabs & toolbar
318317
GUILayout.BeginHorizontal(EditorStyles.toolbar);
319318
{
320-
changeTab = activeTab;
321319
EditorGUI.BeginChangeCheck();
322320
{
323321
if (HasRepository)
@@ -352,7 +350,8 @@ private void UpdateActiveTab()
352350
{
353351
var fromView = ActiveView;
354352
activeTab = changeTab;
355-
SwitchView(fromView, ActiveView);
353+
var toView = ActiveView;
354+
SwitchView(fromView, toView);
356355
}
357356
}
358357

@@ -363,6 +362,7 @@ private void SwitchView(Subview fromView, Subview toView)
363362
if (fromView != null)
364363
fromView.OnDisable();
365364
toView.OnEnable();
365+
toView.OnDataUpdate();
366366

367367
// this triggers a repaint
368368
Repaint();
@@ -424,9 +424,9 @@ public void ShowNotification(GUIContent content, float timeout)
424424
base.ShowNotification(content);
425425
}
426426

427-
private static SubTab TabButton(SubTab tab, string title, SubTab activeTab)
427+
private static SubTab TabButton(SubTab tab, string title, SubTab currentTab)
428428
{
429-
return GUILayout.Toggle(activeTab == tab, title, EditorStyles.toolbarButton) ? tab : activeTab;
429+
return GUILayout.Toggle(currentTab == tab, title, EditorStyles.toolbarButton) ? tab : currentTab;
430430
}
431431

432432
private Subview ToView(SubTab tab)

0 commit comments

Comments
 (0)