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

Commit b55ec61

Browse files
Merge branch 'fixes/settings-update-on-enable' into fixes/british-favourite
2 parents c9b9bbb + b1b9af2 commit b55ec61

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class BranchesView : Subview
2424
private const string WarningCheckoutBranchExistsOK = "Ok";
2525
private const string NewBranchCancelButton = "x";
2626
private const string NewBranchConfirmButton = "Create";
27-
private const string FavoritesSetting = "Favorites";
28-
private const string FavoritesTitle = "Favorites";
27+
private const string FavoritesSetting = "Favourites";
28+
private const string FavoritesTitle = "Favourites";
2929
private const string CreateBranchTitle = "Create Branch";
3030
private const string LocalTitle = "Local branches";
3131
private const string RemoteTitle = "Remote branches";
@@ -43,6 +43,7 @@ class BranchesView : Subview
4343
[NonSerialized] private List<GitBranch> newLocalBranches;
4444
[NonSerialized] private BranchTreeNode newNodeSelection;
4545
[NonSerialized] private BranchesMode targetMode;
46+
[NonSerialized] private bool favouritesHasChanged;
4647

4748
[SerializeField] private BranchTreeNode activeBranchNode;
4849
[SerializeField] private BranchTreeNode localRoot;
@@ -51,6 +52,7 @@ class BranchesView : Subview
5152
[SerializeField] private List<Remote> remotes = new List<Remote>();
5253
[SerializeField] private Vector2 scroll;
5354
[SerializeField] private BranchTreeNode selectedNode;
55+
private List<string> favouritesList;
5456

5557
public override void InitializeView(IView parent)
5658
{
@@ -62,6 +64,7 @@ public override void OnEnable()
6264
{
6365
base.OnEnable();
6466
AttachHandlers(Repository);
67+
favouritesHasChanged = true;
6568
}
6669

6770
public override void OnDisable()
@@ -70,6 +73,21 @@ public override void OnDisable()
7073
DetachHandlers(Repository);
7174
}
7275

76+
public override void OnDataUpdate()
77+
{
78+
base.OnDataUpdate();
79+
MaybeUpdateData();
80+
}
81+
82+
private void MaybeUpdateData()
83+
{
84+
if (favouritesHasChanged)
85+
{
86+
favouritesList = Manager.LocalSettings.Get(FavoritesSetting, new List<string>());
87+
favouritesHasChanged = false;
88+
}
89+
}
90+
7391
public override void OnRepositoryChanged(IRepository oldRepository)
7492
{
7593
base.OnRepositoryChanged(oldRepository);
@@ -268,12 +286,12 @@ public void OnEmbeddedGUI()
268286

269287
private int CompareBranches(GitBranch a, GitBranch b)
270288
{
271-
if (GetFavourite(a.Name))
289+
if (IsFavourite(a.Name))
272290
{
273291
return -1;
274292
}
275293

276-
if (GetFavourite(b.Name))
294+
if (IsFavourite(b.Name))
277295
{
278296
return 1;
279297
}
@@ -291,19 +309,19 @@ private int CompareBranches(GitBranch a, GitBranch b)
291309
return 0;
292310
}
293311

294-
private bool GetFavourite(BranchTreeNode branch)
312+
private bool IsFavourite(BranchTreeNode branch)
295313
{
296-
return GetFavourite(branch.Name);
314+
return IsFavourite(branch.Name);
297315
}
298316

299-
private bool GetFavourite(string branchName)
317+
private bool IsFavourite(string branchName)
300318
{
301319
if (string.IsNullOrEmpty(branchName))
302320
{
303321
return false;
304322
}
305323

306-
return Manager.LocalSettings.Get(FavoritesSetting, new List<string>()).Contains(branchName);
324+
return favouritesList.Contains(branchName);
307325
}
308326

309327
private void OnLocalBranchesUpdate(IEnumerable<GitBranch> list)
@@ -334,7 +352,6 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
334352

335353
// Prepare for updated favourites listing
336354
favourites.Clear();
337-
var cachedFavs = Manager.LocalSettings.Get<List<string>>(FavoritesSetting, new List<string>());
338355

339356
// Just build directly on the local root, keep track of active branch
340357
localRoot = new BranchTreeNode("", NodeType.Folder, false);
@@ -364,7 +381,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
364381
}
365382

366383
// Add to favourites
367-
if (cachedFavs.Contains(branch.Name))
384+
if (favouritesList.Contains(branch.Name))
368385
{
369386
favourites.Add(node);
370387
}
@@ -408,7 +425,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
408425
}
409426

410427
// Add to favourites
411-
if (cachedFavs.Contains(branch.Name))
428+
if (favouritesList.Contains(branch.Name))
412429
{
413430
favourites.Add(node);
414431
}
@@ -619,7 +636,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
619636

620637
if (node.Type != NodeType.Folder)
621638
{
622-
var favourite = GetFavourite(node);
639+
var favourite = IsFavourite(node);
623640
if (Event.current.type == EventType.Repaint)
624641
{
625642
GUI.DrawTexture(favouriteRect, favourite ? Styles.FavouriteIconOn : Styles.FavouriteIconOff);
@@ -632,7 +649,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
632649
}
633650
}
634651
// Favourite status
635-
else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && GetFavourite(node.Name))
652+
else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && IsFavourite(node.Name))
636653
{
637654
GUI.DrawTexture(favouriteRect, Styles.FavouriteIconOn);
638655
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,25 @@ class SettingsView : Subview
8181
[SerializeField] private bool isBusy;
8282
[SerializeField] private int lockedFileSelection = -1;
8383
[SerializeField] private bool hasRemote;
84-
[SerializeField] private bool remoteHasChanged;
84+
[SerializeField] private bool metricsEnabled;
85+
[NonSerialized] private bool metricsHasChanged;
86+
[NonSerialized] private bool remoteHasChanged;
8587
[NonSerialized] private bool userDataHasChanged;
8688

8789
[SerializeField] private string newGitName;
8890
[SerializeField] private string newGitEmail;
8991
[SerializeField] private string newRepositoryRemoteUrl;
9092
[SerializeField] private User cachedUser;
9193

94+
[NonSerialized] private IUsageTracker usageTracker;
95+
9296
public override void OnEnable()
9397
{
9498
base.OnEnable();
9599
AttachHandlers(Repository);
96100

97101
remoteHasChanged = true;
102+
metricsHasChanged = true;
98103
}
99104

100105
public override void OnDisable()
@@ -175,8 +180,20 @@ public override void OnGUI()
175180
GUILayout.EndScrollView();
176181
}
177182

183+
public override void InitializeView(IView parent)
184+
{
185+
base.InitializeView(parent);
186+
usageTracker = Manager != null && Manager.UsageTracker != null ? Manager.UsageTracker : null;
187+
}
188+
178189
private void MaybeUpdateData()
179190
{
191+
if (metricsHasChanged)
192+
{
193+
metricsEnabled = usageTracker != null && usageTracker.Enabled;
194+
metricsHasChanged = false;
195+
}
196+
180197
if (lockedFiles == null)
181198
lockedFiles = new List<GitLock>();
182199

@@ -752,13 +769,10 @@ private void OnInstallPathGUI()
752769

753770
private void OnPrivacyGui()
754771
{
755-
var service = Manager != null && Manager.UsageTracker != null ? Manager.UsageTracker : null;
756-
757772
GUILayout.Label(PrivacyTitle, EditorStyles.boldLabel);
758773

759-
EditorGUI.BeginDisabledGroup(isBusy || service == null);
774+
EditorGUI.BeginDisabledGroup(isBusy || usageTracker == null);
760775
{
761-
var metricsEnabled = service != null ? service.Enabled : false;
762776
EditorGUI.BeginChangeCheck();
763777
{
764778
metricsEnabled = GUILayout.Toggle(metricsEnabled, MetricsOptInLabel);

0 commit comments

Comments
 (0)