@@ -43,6 +43,7 @@ class BranchesView : Subview
43
43
[ NonSerialized ] private List < GitBranch > newLocalBranches ;
44
44
[ NonSerialized ] private BranchTreeNode newNodeSelection ;
45
45
[ NonSerialized ] private BranchesMode targetMode ;
46
+ [ NonSerialized ] private bool favouritesHasChanged ;
46
47
47
48
[ SerializeField ] private BranchTreeNode activeBranchNode ;
48
49
[ SerializeField ] private BranchTreeNode localRoot ;
@@ -51,6 +52,7 @@ class BranchesView : Subview
51
52
[ SerializeField ] private List < Remote > remotes = new List < Remote > ( ) ;
52
53
[ SerializeField ] private Vector2 scroll ;
53
54
[ SerializeField ] private BranchTreeNode selectedNode ;
55
+ private List < string > favouritesList ;
54
56
55
57
public override void InitializeView ( IView parent )
56
58
{
@@ -62,6 +64,7 @@ public override void OnEnable()
62
64
{
63
65
base . OnEnable ( ) ;
64
66
AttachHandlers ( Repository ) ;
67
+ favouritesHasChanged = true ;
65
68
}
66
69
67
70
public override void OnDisable ( )
@@ -70,6 +73,21 @@ public override void OnDisable()
70
73
DetachHandlers ( Repository ) ;
71
74
}
72
75
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
+
73
91
public override void OnRepositoryChanged ( IRepository oldRepository )
74
92
{
75
93
base . OnRepositoryChanged ( oldRepository ) ;
@@ -246,12 +264,12 @@ public void OnEmbeddedGUI()
246
264
247
265
private int CompareBranches ( GitBranch a , GitBranch b )
248
266
{
249
- if ( GetFavourite ( a . Name ) )
267
+ if ( IsFavourite ( a . Name ) )
250
268
{
251
269
return - 1 ;
252
270
}
253
271
254
- if ( GetFavourite ( b . Name ) )
272
+ if ( IsFavourite ( b . Name ) )
255
273
{
256
274
return 1 ;
257
275
}
@@ -269,19 +287,9 @@ private int CompareBranches(GitBranch a, GitBranch b)
269
287
return 0 ;
270
288
}
271
289
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 )
278
291
{
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 ) ;
285
293
}
286
294
287
295
private void OnLocalBranchesUpdate ( IEnumerable < GitBranch > list )
@@ -312,7 +320,6 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
312
320
313
321
// Prepare for updated favourites listing
314
322
favourites . Clear ( ) ;
315
- var cachedFavs = Manager . LocalSettings . Get < List < string > > ( FavoritesSetting , new List < string > ( ) ) ;
316
323
317
324
// Just build directly on the local root, keep track of active branch
318
325
localRoot = new BranchTreeNode ( "" , NodeType . Folder , false ) ;
@@ -342,7 +349,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
342
349
}
343
350
344
351
// Add to favourites
345
- if ( cachedFavs . Contains ( branch . Name ) )
352
+ if ( favouritesList . Contains ( branch . Name ) )
346
353
{
347
354
favourites . Add ( node ) ;
348
355
}
@@ -386,7 +393,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
386
393
}
387
394
388
395
// Add to favourites
389
- if ( cachedFavs . Contains ( branch . Name ) )
396
+ if ( favouritesList . Contains ( branch . Name ) )
390
397
{
391
398
favourites . Add ( node ) ;
392
399
}
@@ -597,7 +604,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
597
604
598
605
if ( node . Type != NodeType . Folder )
599
606
{
600
- var favourite = GetFavourite ( node ) ;
607
+ var favourite = IsFavourite ( node . Name ) ;
601
608
if ( Event . current . type == EventType . Repaint )
602
609
{
603
610
GUI . DrawTexture ( favouriteRect , favourite ? Styles . FavouriteIconOn : Styles . FavouriteIconOff ) ;
@@ -610,7 +617,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
610
617
}
611
618
}
612
619
// 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 ) )
614
621
{
615
622
GUI . DrawTexture ( favouriteRect , Styles . FavouriteIconOn ) ;
616
623
}
0 commit comments