@@ -9,26 +9,36 @@ namespace GitHub.Unity
99 [ Serializable ]
1010 public class GitLockEntryDictionary : SerializableDictionary < string , GitLockEntry > { }
1111
12+ [ Serializable ]
13+ public class GitStatusDictionary : SerializableDictionary < string , GitStatus > { }
14+
1215 [ Serializable ]
1316 public class GitLockEntry
1417 {
15- public static GitLockEntry Default = new GitLockEntry ( Unity . GitLock . Default ) ;
18+ public static GitLockEntry Default = new GitLockEntry ( GitLock . Default , GitFileStatus . None ) ;
1619
1720 [ SerializeField ] private GitLock gitLock ;
21+ [ SerializeField ] private GitFileStatus gitFileStatus ;
1822
1923 [ NonSerialized ] public Texture Icon ;
20- [ NonSerialized ] public GUIContent Content ;
24+ [ NonSerialized ] public Texture IconBadge ;
2125
22- public GitLockEntry ( GitLock gitLock )
26+ public GitLockEntry ( GitLock gitLock , GitFileStatus gitFileStatus )
2327 {
2428 this . gitLock = gitLock ;
29+ this . gitFileStatus = gitFileStatus ;
2530 }
2631
2732 public GitLock GitLock
2833 {
2934 get { return gitLock ; }
3035 }
3136
37+ public GitFileStatus GitFileStatus
38+ {
39+ get { return gitFileStatus ; }
40+ }
41+
3242 public string PrettyTimeString
3343 {
3444 get
@@ -44,6 +54,7 @@ class LocksControl
4454 [ SerializeField ] private Vector2 scroll ;
4555 [ SerializeField ] private List < GitLockEntry > gitLockEntries = new List < GitLockEntry > ( ) ;
4656 [ SerializeField ] public GitLockEntryDictionary assets = new GitLockEntryDictionary ( ) ;
57+ [ SerializeField ] public GitStatusDictionary gitStatusDictionary = new GitStatusDictionary ( ) ;
4758
4859 [ NonSerialized ] private Action < GitLock > rightClickNextRender ;
4960 [ NonSerialized ] private GitLockEntry rightClickNextRenderEntry ;
@@ -127,23 +138,26 @@ private void RenderEntry(Rect entryRect, GitLockEntry entry)
127138 {
128139 var isSelected = entry == SelectedEntry ;
129140
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 ) ;
133144
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 ) ;
135148
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 ) ;
139153
140154 var hasKeyboardFocus = GUIUtility . keyboardControl == controlId ;
141155
142156 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 ) ;
147161 }
148162
149163 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
198212 return requiresRepaint ;
199213 }
200214
201- public void Load ( List < GitLock > locks )
215+ public void Load ( List < GitLock > locks , List < GitStatusEntry > gitStatusEntries )
202216 {
217+ var statusEntries = gitStatusEntries . ToDictionary ( entry => entry . Path . ToNPath ( ) . ToString ( SlashMode . Forward ) , entry => entry . status ) ;
218+
203219 var selectedLockId = SelectedEntry != null && SelectedEntry . GitLock != GitLock . Default
204220 ? ( int ? ) SelectedEntry . GitLock . ID
205221 : null ;
@@ -213,8 +229,15 @@ public void Load(List<GitLock> locks)
213229 assets . Clear ( ) ;
214230
215231 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 ) ;
218241
219242 var assetGuid = AssetDatabase . AssetPathToGUID ( gitLock . Path ) ;
220243 if ( ! string . IsNullOrEmpty ( assetGuid ) )
@@ -265,17 +288,16 @@ public void LoadIcons()
265288 }
266289 }
267290
268- private void LoadIcon ( GitLockEntry gitLockEntry )
291+ private void LoadIcon ( GitLockEntry gitLockEntry , bool force = false )
269292 {
270- if ( gitLockEntry . Icon == null )
293+ if ( force || gitLockEntry . Icon == null )
271294 {
272- var nodeIcon = GetNodeIcon ( gitLockEntry . GitLock ) ;
273- gitLockEntry . Icon = nodeIcon ;
295+ gitLockEntry . Icon = GetNodeIcon ( gitLockEntry . GitLock ) ;
274296 }
275297
276- if ( gitLockEntry . Content == null )
298+ if ( force || gitLockEntry . IconBadge == null )
277299 {
278- gitLockEntry . Content = new GUIContent ( gitLockEntry . Icon ) ;
300+ gitLockEntry . IconBadge = Styles . GetFileStatusIcon ( gitLockEntry . GitFileStatus , true ) ;
279301 }
280302 }
281303
@@ -357,13 +379,18 @@ public bool OnSelectionChange()
357379 [ Serializable ]
358380 class LocksView : Subview
359381 {
382+ [ NonSerialized ] private bool currentStatusEntriesHasUpdate ;
360383 [ NonSerialized ] private bool currentLocksHasUpdate ;
361384
362385 [ SerializeField ] private LocksControl locksControl ;
363386 [ SerializeField ] private GitLock selectedEntry = GitLock . Default ;
364387
365388 [ SerializeField ] private CacheUpdateEvent lastLocksChangedEvent ;
389+ [ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
390+
366391 [ SerializeField ] private List < GitLock > lockedFiles = new List < GitLock > ( ) ;
392+ [ SerializeField ] private List < GitStatusEntry > gitStatusEntries = new List < GitStatusEntry > ( ) ;
393+
367394 [ SerializeField ] private string currentUsername ;
368395
369396 public override void OnEnable ( )
@@ -385,6 +412,13 @@ public override void OnDisable()
385412 DetachHandlers ( Repository ) ;
386413 }
387414
415+ public override void Refresh ( )
416+ {
417+ base . Refresh ( ) ;
418+ Repository . Refresh ( CacheType . GitStatus ) ;
419+ Repository . Refresh ( CacheType . GitLocks ) ;
420+ }
421+
388422 public override void OnDataUpdate ( )
389423 {
390424 base . OnDataUpdate ( ) ;
@@ -450,6 +484,7 @@ private void AttachHandlers(IRepository repository)
450484 }
451485
452486 repository . LocksChanged += RepositoryOnLocksChanged ;
487+ repository . LocksChanged += RepositoryOnStatusEntriesChanged ;
453488 }
454489
455490 private void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
@@ -462,6 +497,16 @@ private void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
462497 }
463498 }
464499
500+ private void RepositoryOnStatusEntriesChanged ( CacheUpdateEvent cacheUpdateEvent )
501+ {
502+ if ( ! lastStatusEntriesChangedEvent . Equals ( cacheUpdateEvent ) )
503+ {
504+ lastStatusEntriesChangedEvent = cacheUpdateEvent ;
505+ currentStatusEntriesHasUpdate = true ;
506+ Redraw ( ) ;
507+ }
508+ }
509+
465510 private void DetachHandlers ( IRepository repository )
466511 {
467512 if ( repository == null )
@@ -470,11 +515,13 @@ private void DetachHandlers(IRepository repository)
470515 }
471516
472517 repository . LocksChanged -= RepositoryOnLocksChanged ;
518+ repository . LocksChanged -= RepositoryOnStatusEntriesChanged ;
473519 }
474520
475521 private void ValidateCachedData ( IRepository repository )
476522 {
477523 repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitLocks , lastLocksChangedEvent ) ;
524+ repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitStatus , lastStatusEntriesChangedEvent ) ;
478525 }
479526
480527 private void MaybeUpdateData ( )
@@ -486,13 +533,22 @@ private void MaybeUpdateData()
486533
487534 if ( currentLocksHasUpdate )
488535 {
489- currentLocksHasUpdate = false ;
490-
491536 lockedFiles = Repository . CurrentLocks ;
492537
493538 //TODO: ONE_USER_LOGIN This assumes only ever one user can login
494539 var keychainConnection = Platform . Keychain . Connections . First ( ) ;
495540 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 ;
496552
497553 BuildLocksControl ( ) ;
498554 }
@@ -505,7 +561,8 @@ private void BuildLocksControl()
505561 locksControl = new LocksControl ( ) ;
506562 }
507563
508- locksControl . Load ( lockedFiles ) ;
564+ locksControl . Load ( lockedFiles , gitStatusEntries ) ;
565+
509566 if ( ! selectedEntry . Equals ( GitLock . Default )
510567 && selectedEntry . ID != locksControl . SelectedEntry . GitLock . ID )
511568 {
0 commit comments