@@ -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 ) ;
@@ -246,12 +264,12 @@ public void OnEmbeddedGUI()
246264
247265 private int CompareBranches ( GitBranch a , GitBranch b )
248266 {
249- if ( GetFavourite ( a . Name ) )
267+ if ( IsFavourite ( a . Name ) )
250268 {
251269 return - 1 ;
252270 }
253271
254- if ( GetFavourite ( b . Name ) )
272+ if ( IsFavourite ( b . Name ) )
255273 {
256274 return 1 ;
257275 }
@@ -269,19 +287,9 @@ private int CompareBranches(GitBranch a, GitBranch b)
269287 return 0 ;
270288 }
271289
272- private bool GetFavourite ( BranchTreeNode branch )
273- {
274- return GetFavourite ( branch . Name ) ;
275- }
276-
277- private bool GetFavourite ( string branchName )
290+ private bool IsFavourite ( string branchName )
278291 {
279- if ( string . IsNullOrEmpty ( branchName ) )
280- {
281- return false ;
282- }
283-
284- return Manager . LocalSettings . Get ( FavoritesSetting , new List < string > ( ) ) . Contains ( branchName ) ;
292+ return ! String . IsNullOrEmpty ( branchName ) && favouritesList . Contains ( branchName ) ;
285293 }
286294
287295 private void OnLocalBranchesUpdate ( IEnumerable < GitBranch > list )
@@ -312,7 +320,6 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
312320
313321 // Prepare for updated favourites listing
314322 favourites . Clear ( ) ;
315- var cachedFavs = Manager . LocalSettings . Get < List < string > > ( FavoritesSetting , new List < string > ( ) ) ;
316323
317324 // Just build directly on the local root, keep track of active branch
318325 localRoot = new BranchTreeNode ( "" , NodeType . Folder , false ) ;
@@ -342,7 +349,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
342349 }
343350
344351 // Add to favourites
345- if ( cachedFavs . Contains ( branch . Name ) )
352+ if ( favouritesList . Contains ( branch . Name ) )
346353 {
347354 favourites . Add ( node ) ;
348355 }
@@ -386,7 +393,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
386393 }
387394
388395 // Add to favourites
389- if ( cachedFavs . Contains ( branch . Name ) )
396+ if ( favouritesList . Contains ( branch . Name ) )
390397 {
391398 favourites . Add ( node ) ;
392399 }
@@ -597,7 +604,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
597604
598605 if ( node . Type != NodeType . Folder )
599606 {
600- var favourite = GetFavourite ( node ) ;
607+ var favourite = IsFavourite ( node . Name ) ;
601608 if ( Event . current . type == EventType . Repaint )
602609 {
603610 GUI . DrawTexture ( favouriteRect , favourite ? Styles . FavouriteIconOn : Styles . FavouriteIconOff ) ;
@@ -610,7 +617,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
610617 }
611618 }
612619 // Favourite status
613- else if ( Event . current . type == EventType . Repaint && node . Type != NodeType . Folder && GetFavourite ( node . Name ) )
620+ else if ( Event . current . type == EventType . Repaint && node . Type != NodeType . Folder && IsFavourite ( node . Name ) )
614621 {
615622 GUI . DrawTexture ( favouriteRect , Styles . FavouriteIconOn ) ;
616623 }
0 commit comments