@@ -9,26 +9,36 @@ namespace GitHub.Unity
9
9
[ Serializable ]
10
10
public class GitLockEntryDictionary : SerializableDictionary < string , GitLockEntry > { }
11
11
12
+ [ Serializable ]
13
+ public class GitStatusDictionary : SerializableDictionary < string , GitStatus > { }
14
+
12
15
[ Serializable ]
13
16
public class GitLockEntry
14
17
{
15
- public static GitLockEntry Default = new GitLockEntry ( Unity . GitLock . Default ) ;
18
+ public static GitLockEntry Default = new GitLockEntry ( GitLock . Default , GitFileStatus . None ) ;
16
19
17
20
[ SerializeField ] private GitLock gitLock ;
21
+ [ SerializeField ] private GitFileStatus gitFileStatus ;
18
22
19
23
[ NonSerialized ] public Texture Icon ;
20
- [ NonSerialized ] public GUIContent Content ;
24
+ [ NonSerialized ] public Texture IconBadge ;
21
25
22
- public GitLockEntry ( GitLock gitLock )
26
+ public GitLockEntry ( GitLock gitLock , GitFileStatus gitFileStatus )
23
27
{
24
28
this . gitLock = gitLock ;
29
+ this . gitFileStatus = gitFileStatus ;
25
30
}
26
31
27
32
public GitLock GitLock
28
33
{
29
34
get { return gitLock ; }
30
35
}
31
36
37
+ public GitFileStatus GitFileStatus
38
+ {
39
+ get { return gitFileStatus ; }
40
+ }
41
+
32
42
public string PrettyTimeString
33
43
{
34
44
get
@@ -44,6 +54,7 @@ class LocksControl
44
54
[ SerializeField ] private Vector2 scroll ;
45
55
[ SerializeField ] private List < GitLockEntry > gitLockEntries = new List < GitLockEntry > ( ) ;
46
56
[ SerializeField ] public GitLockEntryDictionary assets = new GitLockEntryDictionary ( ) ;
57
+ [ SerializeField ] public GitStatusDictionary gitStatusDictionary = new GitStatusDictionary ( ) ;
47
58
48
59
[ NonSerialized ] private Action < GitLock > rightClickNextRender ;
49
60
[ NonSerialized ] private GitLockEntry rightClickNextRenderEntry ;
@@ -127,23 +138,26 @@ private void RenderEntry(Rect entryRect, GitLockEntry entry)
127
138
{
128
139
var isSelected = entry == SelectedEntry ;
129
140
130
- var iconWidth = 48 ;
131
- var iconHeight = 48 ;
132
- var iconRect = new Rect ( entryRect . x + Styles . BaseSpacing / 2 , entryRect . y + ( Styles . LocksEntryHeight - iconHeight ) / 2 , iconWidth + Styles . BaseSpacing , iconHeight ) ;
141
+ var iconWidth = 32 ;
142
+ var iconHeight = 32 ;
143
+ var iconRect = new Rect ( entryRect . x + Styles . BaseSpacing / 2 , entryRect . y + ( Styles . LocksEntryHeight - iconHeight ) / 2 , iconWidth , iconHeight ) ;
133
144
134
- var xIconRectRightSidePadded = iconRect . x + iconRect . width ;
145
+ var iconBadgeWidth = 16 ;
146
+ var iconBasgeHeight = 16 ;
147
+ var iconBadgeRect = new Rect ( iconRect . x + iconBadgeWidth , iconRect . y + iconBasgeHeight , iconBadgeWidth , iconBasgeHeight ) ;
135
148
136
- var pathRect = new Rect ( xIconRectRightSidePadded , entryRect . y + Styles . BaseSpacing / 2 , entryRect . width , Styles . LocksSummaryHeight + Styles . BaseSpacing ) ;
137
- var userRect = new Rect ( xIconRectRightSidePadded , pathRect . y + pathRect . height + Styles . BaseSpacing / 2 , entryRect . width , Styles . LocksUserHeight + Styles . BaseSpacing ) ;
138
- var dateRect = new Rect ( xIconRectRightSidePadded , userRect . y + userRect . height + Styles . BaseSpacing / 2 , entryRect . width , Styles . LocksDateHeight + Styles . BaseSpacing ) ;
149
+ var entryBodyX = iconRect . x + iconRect . width + Styles . BaseSpacing / 2 ;
150
+
151
+ var pathRect = new Rect ( entryBodyX , entryRect . y + Styles . BaseSpacing , entryRect . width - entryBodyX , 11f * 2 ) ;
152
+ var metaDataRect = new Rect ( entryBodyX , pathRect . y + pathRect . height + 2 , entryRect . width - entryBodyX , 9f * 2 ) ;
139
153
140
154
var hasKeyboardFocus = GUIUtility . keyboardControl == controlId ;
141
155
142
156
Styles . Label . Draw ( entryRect , GUIContent . none , false , false , isSelected , hasKeyboardFocus ) ;
143
- Styles . Label . Draw ( iconRect , entry . Content , false , false , isSelected , hasKeyboardFocus ) ;
144
- Styles . Label . Draw ( pathRect , entry . GitLock . Path , false , false , isSelected , hasKeyboardFocus ) ;
145
- Styles . Label . Draw ( userRect , entry . GitLock . Owner . Name , false , false , isSelected , hasKeyboardFocus ) ;
146
- Styles . Label . Draw ( dateRect , entry . PrettyTimeString , false , false , isSelected , hasKeyboardFocus ) ;
157
+ Styles . Label . Draw ( iconRect , entry . Icon , false , false , isSelected , hasKeyboardFocus ) ;
158
+ Styles . Label . Draw ( iconBadgeRect , entry . IconBadge , false , false , isSelected , hasKeyboardFocus ) ;
159
+ Styles . LockPathStyle . Draw ( pathRect , entry . GitLock . Path , false , false , isSelected , hasKeyboardFocus ) ;
160
+ Styles . LockMetaDataStyle . Draw ( metaDataRect , string . Format ( "Locked {0} by {1}" , entry . PrettyTimeString , entry . GitLock . Owner . Name ) , false , false , isSelected , hasKeyboardFocus ) ;
147
161
}
148
162
149
163
private bool HandleInput ( Rect rect , GitLockEntry entry , int index , Action < GitLock > singleClick = null ,
@@ -198,8 +212,10 @@ private bool HandleInput(Rect rect, GitLockEntry entry, int index, Action<GitLoc
198
212
return requiresRepaint ;
199
213
}
200
214
201
- public void Load ( List < GitLock > locks )
215
+ public void Load ( List < GitLock > locks , List < GitStatusEntry > gitStatusEntries )
202
216
{
217
+ var statusEntries = gitStatusEntries . ToDictionary ( entry => entry . Path . ToNPath ( ) . ToString ( SlashMode . Forward ) , entry => entry . status ) ;
218
+
203
219
var selectedLockId = SelectedEntry != null && SelectedEntry . GitLock != GitLock . Default
204
220
? ( int ? ) SelectedEntry . GitLock . ID
205
221
: null ;
@@ -213,8 +229,15 @@ public void Load(List<GitLock> locks)
213
229
assets . Clear ( ) ;
214
230
215
231
gitLockEntries = locks . Select ( gitLock => {
216
- var gitLockEntry = new GitLockEntry ( gitLock ) ;
217
- LoadIcon ( gitLockEntry ) ;
232
+
233
+ GitFileStatus gitFileStatus ;
234
+ if ( ! statusEntries . TryGetValue ( gitLock . Path . ToString ( SlashMode . Forward ) , out gitFileStatus ) )
235
+ {
236
+ gitFileStatus = GitFileStatus . None ;
237
+ }
238
+
239
+ var gitLockEntry = new GitLockEntry ( gitLock , gitFileStatus ) ;
240
+ LoadIcon ( gitLockEntry , true ) ;
218
241
219
242
var assetGuid = AssetDatabase . AssetPathToGUID ( gitLock . Path ) ;
220
243
if ( ! string . IsNullOrEmpty ( assetGuid ) )
@@ -265,17 +288,16 @@ public void LoadIcons()
265
288
}
266
289
}
267
290
268
- private void LoadIcon ( GitLockEntry gitLockEntry )
291
+ private void LoadIcon ( GitLockEntry gitLockEntry , bool force = false )
269
292
{
270
- if ( gitLockEntry . Icon == null )
293
+ if ( force || gitLockEntry . Icon == null )
271
294
{
272
- var nodeIcon = GetNodeIcon ( gitLockEntry . GitLock ) ;
273
- gitLockEntry . Icon = nodeIcon ;
295
+ gitLockEntry . Icon = GetNodeIcon ( gitLockEntry . GitLock ) ;
274
296
}
275
297
276
- if ( gitLockEntry . Content == null )
298
+ if ( force || gitLockEntry . IconBadge == null )
277
299
{
278
- gitLockEntry . Content = new GUIContent ( gitLockEntry . Icon ) ;
300
+ gitLockEntry . IconBadge = Styles . GetFileStatusIcon ( gitLockEntry . GitFileStatus , true ) ;
279
301
}
280
302
}
281
303
@@ -357,13 +379,18 @@ public bool OnSelectionChange()
357
379
[ Serializable ]
358
380
class LocksView : Subview
359
381
{
382
+ [ NonSerialized ] private bool currentStatusEntriesHasUpdate ;
360
383
[ NonSerialized ] private bool currentLocksHasUpdate ;
361
384
362
385
[ SerializeField ] private LocksControl locksControl ;
363
386
[ SerializeField ] private GitLock selectedEntry = GitLock . Default ;
364
387
365
388
[ SerializeField ] private CacheUpdateEvent lastLocksChangedEvent ;
389
+ [ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
390
+
366
391
[ SerializeField ] private List < GitLock > lockedFiles = new List < GitLock > ( ) ;
392
+ [ SerializeField ] private List < GitStatusEntry > gitStatusEntries = new List < GitStatusEntry > ( ) ;
393
+
367
394
[ SerializeField ] private string currentUsername ;
368
395
369
396
public override void OnEnable ( )
@@ -385,6 +412,13 @@ public override void OnDisable()
385
412
DetachHandlers ( Repository ) ;
386
413
}
387
414
415
+ public override void Refresh ( )
416
+ {
417
+ base . Refresh ( ) ;
418
+ Repository . Refresh ( CacheType . GitStatus ) ;
419
+ Repository . Refresh ( CacheType . GitLocks ) ;
420
+ }
421
+
388
422
public override void OnDataUpdate ( )
389
423
{
390
424
base . OnDataUpdate ( ) ;
@@ -450,6 +484,7 @@ private void AttachHandlers(IRepository repository)
450
484
}
451
485
452
486
repository . LocksChanged += RepositoryOnLocksChanged ;
487
+ repository . LocksChanged += RepositoryOnStatusEntriesChanged ;
453
488
}
454
489
455
490
private void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
@@ -462,6 +497,16 @@ private void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
462
497
}
463
498
}
464
499
500
+ private void RepositoryOnStatusEntriesChanged ( CacheUpdateEvent cacheUpdateEvent )
501
+ {
502
+ if ( ! lastStatusEntriesChangedEvent . Equals ( cacheUpdateEvent ) )
503
+ {
504
+ lastStatusEntriesChangedEvent = cacheUpdateEvent ;
505
+ currentStatusEntriesHasUpdate = true ;
506
+ Redraw ( ) ;
507
+ }
508
+ }
509
+
465
510
private void DetachHandlers ( IRepository repository )
466
511
{
467
512
if ( repository == null )
@@ -470,11 +515,13 @@ private void DetachHandlers(IRepository repository)
470
515
}
471
516
472
517
repository . LocksChanged -= RepositoryOnLocksChanged ;
518
+ repository . LocksChanged -= RepositoryOnStatusEntriesChanged ;
473
519
}
474
520
475
521
private void ValidateCachedData ( IRepository repository )
476
522
{
477
523
repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitLocks , lastLocksChangedEvent ) ;
524
+ repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitStatus , lastStatusEntriesChangedEvent ) ;
478
525
}
479
526
480
527
private void MaybeUpdateData ( )
@@ -486,13 +533,22 @@ private void MaybeUpdateData()
486
533
487
534
if ( currentLocksHasUpdate )
488
535
{
489
- currentLocksHasUpdate = false ;
490
-
491
536
lockedFiles = Repository . CurrentLocks ;
492
537
493
538
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
494
539
var keychainConnection = Platform . Keychain . Connections . First ( ) ;
495
540
currentUsername = keychainConnection . Username ;
541
+ }
542
+
543
+ if ( currentStatusEntriesHasUpdate )
544
+ {
545
+ gitStatusEntries = Repository . CurrentChanges . Where ( x => x . Status != GitFileStatus . Ignored ) . ToList ( ) ;
546
+ }
547
+
548
+ if ( currentStatusEntriesHasUpdate || currentLocksHasUpdate )
549
+ {
550
+ currentStatusEntriesHasUpdate = false ;
551
+ currentLocksHasUpdate = false ;
496
552
497
553
BuildLocksControl ( ) ;
498
554
}
@@ -505,7 +561,8 @@ private void BuildLocksControl()
505
561
locksControl = new LocksControl ( ) ;
506
562
}
507
563
508
- locksControl . Load ( lockedFiles ) ;
564
+ locksControl . Load ( lockedFiles , gitStatusEntries ) ;
565
+
509
566
if ( ! selectedEntry . Equals ( GitLock . Default )
510
567
&& selectedEntry . ID != locksControl . SelectedEntry . GitLock . ID )
511
568
{
0 commit comments