@@ -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 }
0 commit comments