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

Commit a66a7f8

Browse files
committed
Add a refresh button
There may be times when the filesystem has changed but Unity reloads the domain too fast for us to invalidate the cache, at which point the data will be stale and won't be automatically updated.
1 parent 1f89747 commit a66a7f8

File tree

8 files changed

+48
-17
lines changed

8 files changed

+48
-17
lines changed

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
7878
ITask DeleteBranch(string branch, bool force);
7979
ITask CreateBranch(string branch, string baseBranch);
8080
ITask SwitchBranch(string branch);
81+
void Refresh(CacheType cacheType);
8182
}
8283
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ public bool Equals(IRepository other)
162162

163163
private void RefreshCache(CacheType cacheType)
164164
{
165-
taskManager.RunInUI(() =>
165+
taskManager.RunInUI(() => Refresh(cacheType));
166+
}
167+
168+
public void Refresh(CacheType cacheType)
166169
{
167170
var cache = cacheContainer.GetCache(cacheType);
168171
// if the cache has valid data, we need to force an invalidation to refresh it
169172
// if it doesn't have valid data, it will trigger an invalidation automatically
170173
if (cache.ValidateData())
171174
cache.InvalidateData();
172-
});
173175
}
174176

175177
private void CacheHasBeenInvalidated(CacheType cacheType)

src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Styles
6262
headerRepoLabelStyle,
6363
headerTitleStyle,
6464
headerDescriptionStyle,
65-
historyToolbarButtonStyle,
65+
toolbarButtonStyle,
6666
historyLockStyle,
6767
historyEntrySummaryStyle,
6868
historyEntryDetailsStyle,
@@ -378,18 +378,18 @@ public static GUIStyle LongMessageStyle
378378
}
379379
}
380380

381-
public static GUIStyle HistoryToolbarButtonStyle
381+
public static GUIStyle ToolbarButtonStyle
382382
{
383383
get
384384
{
385-
if (historyToolbarButtonStyle == null)
385+
if (toolbarButtonStyle == null)
386386
{
387-
historyToolbarButtonStyle = new GUIStyle(EditorStyles.toolbarButton);
388-
historyToolbarButtonStyle.name = "HistoryToolbarButtonStyle";
389-
historyToolbarButtonStyle.richText = true;
390-
historyToolbarButtonStyle.wordWrap = true;
387+
toolbarButtonStyle = new GUIStyle(EditorStyles.toolbarButton);
388+
toolbarButtonStyle.name = "HistoryToolbarButtonStyle";
389+
toolbarButtonStyle.richText = true;
390+
toolbarButtonStyle.wordWrap = true;
391391
}
392-
return historyToolbarButtonStyle;
392+
return toolbarButtonStyle;
393393
}
394394
}
395395

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ public override void OnDisable()
9292
DetachHandlers(Repository);
9393
}
9494

95+
public override void Refresh()
96+
{
97+
base.Refresh();
98+
Repository.Refresh(CacheType.Branches);
99+
Repository.Refresh(CacheType.RepositoryInfo);
100+
}
101+
95102
public override void OnDataUpdate()
96103
{
97104
base.OnDataUpdate();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public override void OnDisable()
6060
DetachHandlers(Repository);
6161
}
6262

63+
public override void Refresh()
64+
{
65+
base.Refresh();
66+
Repository.Refresh(CacheType.GitStatus);
67+
Repository.Refresh(CacheType.RepositoryInfo);
68+
Repository.Refresh(CacheType.GitLocks);
69+
}
70+
6371
public override void OnDataUpdate()
6472
{
6573
base.OnDataUpdate();

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ public override void OnDisable()
345345
DetachHandlers(Repository);
346346
}
347347

348+
public override void Refresh()
349+
{
350+
base.Refresh();
351+
Repository.Refresh(CacheType.GitLog);
352+
Repository.Refresh(CacheType.GitAheadBehind);
353+
}
354+
348355
public override void OnDataUpdate()
349356
{
350357
base.OnDataUpdate();
@@ -389,11 +396,11 @@ public override void OnGUI()
389396
// Top bar for scrolling to selection or clearing it
390397
GUILayout.BeginHorizontal(EditorStyles.toolbar);
391398
{
392-
if (GUILayout.Button(CommitDetailsTitle, Styles.HistoryToolbarButtonStyle))
399+
if (GUILayout.Button(CommitDetailsTitle, Styles.ToolbarButtonStyle))
393400
{
394401
historyControl.ScrollTo(historyControl.SelectedIndex);
395402
}
396-
if (GUILayout.Button(ClearSelectionButton, Styles.HistoryToolbarButtonStyle, GUILayout.ExpandWidth(false)))
403+
if (GUILayout.Button(ClearSelectionButton, Styles.ToolbarButtonStyle, GUILayout.ExpandWidth(false)))
397404
{
398405
selectedEntry = GitLogEntry.Default;
399406
historyControl.SelectedIndex = -1;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public override void Refresh()
8787
base.Refresh();
8888
gitPathView.Refresh();
8989
userSettingsView.Refresh();
90+
if (Repository != null)
91+
Repository.Refresh(CacheType.GitLocks);
9092
}
9193

9294
public override void OnGUI()

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,15 +482,15 @@ private void DoActionbarGUI()
482482
EditorGUI.BeginDisabledGroup(currentRemoteName == null);
483483
{
484484
// Fetch button
485-
var fetchClicked = GUILayout.Button(Localization.FetchButtonText, Styles.HistoryToolbarButtonStyle);
485+
var fetchClicked = GUILayout.Button(Localization.FetchButtonText, Styles.ToolbarButtonStyle);
486486
if (fetchClicked)
487487
{
488488
Fetch();
489489
}
490490

491491
// Pull button
492492
var pullButtonText = statusBehind > 0 ? String.Format(Localization.PullButtonCount, statusBehind) : Localization.PullButton;
493-
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
493+
var pullClicked = GUILayout.Button(pullButtonText, Styles.ToolbarButtonStyle);
494494

495495
if (pullClicked &&
496496
EditorUtility.DisplayDialog(Localization.PullConfirmTitle,
@@ -508,7 +508,7 @@ private void DoActionbarGUI()
508508
EditorGUI.BeginDisabledGroup(currentRemoteName == null || statusBehind != 0);
509509
{
510510
var pushButtonText = statusAhead > 0 ? String.Format(Localization.PushButtonCount, statusAhead) : Localization.PushButton;
511-
var pushClicked = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);
511+
var pushClicked = GUILayout.Button(pushButtonText, Styles.ToolbarButtonStyle);
512512

513513
if (pushClicked &&
514514
EditorUtility.DisplayDialog(Localization.PushConfirmTitle,
@@ -525,13 +525,17 @@ private void DoActionbarGUI()
525525
else
526526
{
527527
// Publishing a repo
528-
var publishedClicked = GUILayout.Button(Localization.PublishButton, Styles.HistoryToolbarButtonStyle);
529-
if (publishedClicked)
528+
if (GUILayout.Button(Localization.PublishButton, Styles.ToolbarButtonStyle))
530529
{
531530
PopupWindow.OpenWindow(PopupWindow.PopupViewType.PublishView);
532531
}
533532
}
534533

534+
if (GUILayout.Button(Localization.RefreshButton, Styles.ToolbarButtonStyle))
535+
{
536+
Refresh();
537+
}
538+
535539
GUILayout.FlexibleSpace();
536540

537541
if (GUILayout.Button("Account", EditorStyles.toolbarDropDown))

0 commit comments

Comments
 (0)