@@ -24,8 +24,8 @@ class BranchesView : Subview
24
24
private const string WarningCheckoutBranchExistsOK = "Ok" ;
25
25
private const string NewBranchCancelButton = "x" ;
26
26
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 " ;
29
29
private const string CreateBranchTitle = "Create Branch" ;
30
30
private const string LocalTitle = "Local branches" ;
31
31
private const string RemoteTitle = "Remote branches" ;
@@ -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 ) ;
@@ -268,12 +286,12 @@ public void OnEmbeddedGUI()
268
286
269
287
private int CompareBranches ( GitBranch a , GitBranch b )
270
288
{
271
- if ( GetFavourite ( a . Name ) )
289
+ if ( IsFavourite ( a . Name ) )
272
290
{
273
291
return - 1 ;
274
292
}
275
293
276
- if ( GetFavourite ( b . Name ) )
294
+ if ( IsFavourite ( b . Name ) )
277
295
{
278
296
return 1 ;
279
297
}
@@ -291,19 +309,19 @@ private int CompareBranches(GitBranch a, GitBranch b)
291
309
return 0 ;
292
310
}
293
311
294
- private bool GetFavourite ( BranchTreeNode branch )
312
+ private bool IsFavourite ( BranchTreeNode branch )
295
313
{
296
- return GetFavourite ( branch . Name ) ;
314
+ return IsFavourite ( branch . Name ) ;
297
315
}
298
316
299
- private bool GetFavourite ( string branchName )
317
+ private bool IsFavourite ( string branchName )
300
318
{
301
319
if ( string . IsNullOrEmpty ( branchName ) )
302
320
{
303
321
return false ;
304
322
}
305
323
306
- return Manager . LocalSettings . Get ( FavoritesSetting , new List < string > ( ) ) . Contains ( branchName ) ;
324
+ return favouritesList . Contains ( branchName ) ;
307
325
}
308
326
309
327
private void OnLocalBranchesUpdate ( IEnumerable < GitBranch > list )
@@ -334,7 +352,6 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
334
352
335
353
// Prepare for updated favourites listing
336
354
favourites . Clear ( ) ;
337
- var cachedFavs = Manager . LocalSettings . Get < List < string > > ( FavoritesSetting , new List < string > ( ) ) ;
338
355
339
356
// Just build directly on the local root, keep track of active branch
340
357
localRoot = new BranchTreeNode ( "" , NodeType . Folder , false ) ;
@@ -364,7 +381,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
364
381
}
365
382
366
383
// Add to favourites
367
- if ( cachedFavs . Contains ( branch . Name ) )
384
+ if ( favouritesList . Contains ( branch . Name ) )
368
385
{
369
386
favourites . Add ( node ) ;
370
387
}
@@ -408,7 +425,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
408
425
}
409
426
410
427
// Add to favourites
411
- if ( cachedFavs . Contains ( branch . Name ) )
428
+ if ( favouritesList . Contains ( branch . Name ) )
412
429
{
413
430
favourites . Add ( node ) ;
414
431
}
@@ -619,7 +636,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
619
636
620
637
if ( node . Type != NodeType . Folder )
621
638
{
622
- var favourite = GetFavourite ( node ) ;
639
+ var favourite = IsFavourite ( node ) ;
623
640
if ( Event . current . type == EventType . Repaint )
624
641
{
625
642
GUI . DrawTexture ( favouriteRect , favourite ? Styles . FavouriteIconOn : Styles . FavouriteIconOff ) ;
@@ -632,7 +649,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
632
649
}
633
650
}
634
651
// 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 ) )
636
653
{
637
654
GUI . DrawTexture ( favouriteRect , Styles . FavouriteIconOn ) ;
638
655
}
0 commit comments