@@ -17,16 +17,18 @@ public class GitLockEntry
1717 {
1818 public static GitLockEntry Default = new GitLockEntry ( GitLock . Default , GitFileStatus . None ) ;
1919
20- [ SerializeField ] private GitLock gitLock ;
21- [ SerializeField ] private GitFileStatus gitFileStatus ;
22-
2320 [ NonSerialized ] public Texture Icon ;
2421 [ NonSerialized ] public Texture IconBadge ;
2522
23+ [ SerializeField ] private GitLock gitLock ;
24+ [ SerializeField ] private GitFileStatus gitFileStatus ;
25+ [ SerializeField ] private string lockedAt ;
26+
2627 public GitLockEntry ( GitLock gitLock , GitFileStatus gitFileStatus )
2728 {
2829 this . gitLock = gitLock ;
2930 this . gitFileStatus = gitFileStatus ;
31+ this . lockedAt = gitLock . LockedAt . ToLocalTime ( ) . CreateRelativeTime ( DateTimeOffset . Now ) ;
3032 }
3133
3234 public GitLock GitLock
@@ -39,29 +41,23 @@ public GitFileStatus GitFileStatus
3941 get { return gitFileStatus ; }
4042 }
4143
42- public string PrettyTimeString
43- {
44- get
45- {
46- return gitLock . LockedAt . ToLocalTime ( ) . CreateRelativeTime ( DateTimeOffset . Now ) ;
47- }
48- }
44+ public string LockedAt { get { return lockedAt ; } }
4945 }
5046
5147 [ Serializable ]
5248 class LocksControl
5349 {
54- [ SerializeField ] private Vector2 scroll ;
55- [ SerializeField ] private List < GitLockEntry > gitLockEntries = new List < GitLockEntry > ( ) ;
56- [ SerializeField ] public GitLockEntryDictionary assets = new GitLockEntryDictionary ( ) ;
57- [ SerializeField ] public GitStatusDictionary gitStatusDictionary = new GitStatusDictionary ( ) ;
58-
5950 [ NonSerialized ] private Action < GitLock > rightClickNextRender ;
6051 [ NonSerialized ] private GitLockEntry rightClickNextRenderEntry ;
61- [ NonSerialized ] private GitLockEntry selectedEntry ;
6252 [ NonSerialized ] private int controlId ;
6353 [ NonSerialized ] private UnityEngine . Object lastActivatedObject ;
6454
55+ [ SerializeField ] private Vector2 scroll ;
56+ [ SerializeField ] private List < GitLockEntry > gitLockEntries = new List < GitLockEntry > ( ) ;
57+ [ SerializeField ] public GitLockEntryDictionary assets = new GitLockEntryDictionary ( ) ;
58+ [ SerializeField ] public GitStatusDictionary gitStatusDictionary = new GitStatusDictionary ( ) ;
59+ [ SerializeField ] private GitLockEntry selectedEntry ;
60+
6561 public GitLockEntry SelectedEntry
6662 {
6763 get
@@ -72,8 +68,8 @@ public GitLockEntry SelectedEntry
7268 {
7369 selectedEntry = value ;
7470
75- var activeObject = selectedEntry != null
76- ? AssetDatabase . LoadMainAssetAtPath ( selectedEntry . GitLock . Path )
71+ var activeObject = selectedEntry != null && selectedEntry . GitLock != GitLock . Default
72+ ? AssetDatabase . LoadMainAssetAtPath ( selectedEntry . GitLock . Path . MakeAbsolute ( ) . RelativeTo ( EntryPoint . Environment . UnityProjectPath ) )
7773 : null ;
7874
7975 lastActivatedObject = activeObject ;
@@ -115,16 +111,16 @@ public bool Render(Rect containingRect, Action<GitLock> singleClick = null,
115111 var entryRect = new Rect ( rect . x , rect . y , rect . width , Styles . LocksEntryHeight ) ;
116112
117113 var shouldRenderEntry = ! ( entryRect . y > endDisplay || entryRect . yMax < startDisplay ) ;
118- if ( shouldRenderEntry && Event . current . type == EventType . Repaint )
114+ if ( shouldRenderEntry )
119115 {
120- RenderEntry ( entryRect , entry ) ;
116+ entryRect = RenderEntry ( entryRect , entry ) ;
121117 }
122118
123119 var entryRequiresRepaint =
124120 HandleInput ( entryRect , entry , index , singleClick , doubleClick , rightClick ) ;
125121 requiresRepaint = requiresRepaint || entryRequiresRepaint ;
126122
127- rect . y += Styles . LocksEntryHeight ;
123+ rect . y += entryRect . height ;
128124 }
129125
130126 GUILayout . Space ( rect . y - containingRect . y ) ;
@@ -134,30 +130,30 @@ public bool Render(Rect containingRect, Action<GitLock> singleClick = null,
134130 return requiresRepaint ;
135131 }
136132
137- private void RenderEntry ( Rect entryRect , GitLockEntry entry )
133+ private Rect RenderEntry ( Rect entryRect , GitLockEntry entry )
138134 {
139135 var isSelected = entry == SelectedEntry ;
140-
141136 var iconWidth = 32 ;
142137 var iconHeight = 32 ;
143- var iconRect = new Rect ( entryRect . x + Styles . BaseSpacing / 2 , entryRect . y + ( Styles . LocksEntryHeight - iconHeight ) / 2 , iconWidth , iconHeight ) ;
144-
145138 var iconBadgeWidth = 16 ;
146- var iconBasgeHeight = 16 ;
147- var iconBadgeRect = new Rect ( iconRect . x + iconBadgeWidth , iconRect . y + iconBasgeHeight , iconBadgeWidth , iconBasgeHeight ) ;
148-
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 ) ;
153-
139+ var iconBadgeHeight = 16 ;
154140 var hasKeyboardFocus = GUIUtility . keyboardControl == controlId ;
155141
156- Styles . Label . Draw ( entryRect , GUIContent . none , 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 ) ;
142+ GUILayout . BeginHorizontal ( isSelected ? Styles . SelectedArea : Styles . Label ) ;
143+ GUILayout . Label ( entry . Icon , GUILayout . Height ( iconWidth ) , GUILayout . Width ( iconHeight ) ) ;
144+ if ( Event . current . type == EventType . Repaint )
145+ {
146+ var iconRect = GUILayoutUtility . GetLastRect ( ) ;
147+ var iconBadgeRect = new Rect ( iconRect . x + iconBadgeWidth , iconRect . y + iconBadgeHeight , iconBadgeWidth , iconBadgeHeight ) ;
148+ Styles . Label . Draw ( iconBadgeRect , entry . IconBadge , false , false , false , hasKeyboardFocus ) ;
149+ }
150+ GUILayout . BeginVertical ( ) ;
151+ GUILayout . Label ( entry . GitLock . Path , isSelected ? Styles . SelectedLabel : Styles . Label ) ;
152+ GUILayout . Label ( string . Format ( "Locked {0} by {1}" , entry . LockedAt , entry . GitLock . Owner . Name ) , isSelected ? Styles . SelectedLabel : Styles . Label ) ;
153+ GUILayout . EndVertical ( ) ;
154+ GUILayout . EndHorizontal ( ) ;
155+ var itemRect = GUILayoutUtility . GetLastRect ( ) ;
156+ return itemRect ;
161157 }
162158
163159 private bool HandleInput ( Rect rect , GitLockEntry entry , int index , Action < GitLock > singleClick = null ,
@@ -214,32 +210,32 @@ private bool HandleInput(Rect rect, GitLockEntry entry, int index, Action<GitLoc
214210
215211 public void Load ( List < GitLock > locks , List < GitStatusEntry > gitStatusEntries )
216212 {
217- var statusEntries = gitStatusEntries . ToDictionary ( entry => entry . Path . ToNPath ( ) . ToString ( SlashMode . Forward ) , entry => entry . status ) ;
218-
213+ var statusEntries = new Dictionary < string , int > ( ) ;
214+ for ( int i = 0 ; i < gitStatusEntries . Count ; i ++ )
215+ statusEntries . Add ( gitStatusEntries [ i ] . Path . ToNPath ( ) . ToString ( SlashMode . Forward ) , i ) ;
219216 var selectedLockId = SelectedEntry != null && SelectedEntry . GitLock != GitLock . Default
220217 ? ( int ? ) SelectedEntry . GitLock . ID
221218 : null ;
222219
223220 var scrollValue = scroll . y ;
224-
225221 var previousCount = gitLockEntries . Count ;
226-
227222 var scrollIndex = ( int ) ( scrollValue / Styles . LocksEntryHeight ) ;
228223
229224 assets . Clear ( ) ;
230225
231- gitLockEntries = locks . Select ( gitLock => {
232-
233- GitFileStatus gitFileStatus ;
234- if ( ! statusEntries . TryGetValue ( gitLock . Path . ToString ( SlashMode . Forward ) , out gitFileStatus ) )
226+ gitLockEntries = locks . Select ( gitLock =>
227+ {
228+ int index = - 1 ;
229+ GitFileStatus gitFileStatus = GitFileStatus . None ;
230+ if ( statusEntries . TryGetValue ( gitLock . Path . ToString ( SlashMode . Forward ) , out index ) )
235231 {
236- gitFileStatus = GitFileStatus . None ;
232+ gitFileStatus = gitStatusEntries [ index ] . Status ;
237233 }
238234
239235 var gitLockEntry = new GitLockEntry ( gitLock , gitFileStatus ) ;
240236 LoadIcon ( gitLockEntry , true ) ;
241-
242- var assetGuid = AssetDatabase . AssetPathToGUID ( gitLock . Path ) ;
237+ var path = gitLock . Path . MakeAbsolute ( ) . RelativeTo ( EntryPoint . Environment . UnityProjectPath ) ;
238+ var assetGuid = AssetDatabase . AssetPathToGUID ( path ) ;
243239 if ( ! string . IsNullOrEmpty ( assetGuid ) )
244240 {
245241 assets . Add ( assetGuid , gitLockEntry ) ;
@@ -359,12 +355,10 @@ public bool OnSelectionChange()
359355 if ( ! LocksControlHasFocus )
360356 {
361357 GitLockEntry gitLockEntry = GitLockEntry . Default ;
362-
363358 if ( Selection . activeObject != lastActivatedObject )
364359 {
365360 var activeAssetPath = AssetDatabase . GetAssetPath ( Selection . activeObject ) ;
366361 var activeAssetGuid = AssetDatabase . AssetPathToGUID ( activeAssetPath ) ;
367-
368362 assets . TryGetValue ( activeAssetGuid , out gitLockEntry ) ;
369363 }
370364
@@ -383,7 +377,6 @@ class LocksView : Subview
383377 [ NonSerialized ] private bool currentLocksHasUpdate ;
384378
385379 [ SerializeField ] private LocksControl locksControl ;
386- [ SerializeField ] private GitLock selectedEntry = GitLock . Default ;
387380
388381 [ SerializeField ] private CacheUpdateEvent lastLocksChangedEvent ;
389382 [ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
@@ -430,11 +423,10 @@ public override void OnGUI()
430423 var rect = GUILayoutUtility . GetLastRect ( ) ;
431424 if ( locksControl != null )
432425 {
433- var lockControlRect = new Rect ( 0f , 0f , Position . width , Position . height - rect . height ) ;
426+ var lockControlRect = new Rect ( rect . x , rect . y , Position . width , Position . height - rect . height ) ;
434427
435428 var requiresRepaint = locksControl . Render ( lockControlRect ,
436429 entry => {
437- selectedEntry = entry ;
438430 } ,
439431 entry => { } ,
440432 entry => {
@@ -446,11 +438,8 @@ public override void OnGUI()
446438 unlockFile = "Unlock File" ;
447439 menuFunction = UnlockSelectedEntry ;
448440 }
449- else
450- {
451- unlockFile = "Force Unlock File" ;
452- menuFunction = ForceUnlockSelectedEntry ;
453- }
441+ unlockFile = "Force Unlock File" ;
442+ menuFunction = ForceUnlockSelectedEntry ;
454443
455444 var menu = new GenericMenu ( ) ;
456445 menu . AddItem ( new GUIContent ( unlockFile ) , false , menuFunction ) ;
@@ -465,14 +454,14 @@ public override void OnGUI()
465454 private void UnlockSelectedEntry ( )
466455 {
467456 Repository
468- . ReleaseLock ( selectedEntry . Path , false )
457+ . ReleaseLock ( locksControl . SelectedEntry . GitLock . Path , false )
469458 . Start ( ) ;
470459 }
471460
472461 private void ForceUnlockSelectedEntry ( )
473462 {
474463 Repository
475- . ReleaseLock ( selectedEntry . Path , true )
464+ . ReleaseLock ( locksControl . SelectedEntry . GitLock . Path , true )
476465 . Start ( ) ;
477466 }
478467
@@ -549,7 +538,6 @@ private void MaybeUpdateData()
549538 {
550539 currentStatusEntriesHasUpdate = false ;
551540 currentLocksHasUpdate = false ;
552-
553541 BuildLocksControl ( ) ;
554542 }
555543 }
@@ -562,12 +550,6 @@ private void BuildLocksControl()
562550 }
563551
564552 locksControl . Load ( lockedFiles , gitStatusEntries ) ;
565-
566- if ( ! selectedEntry . Equals ( GitLock . Default )
567- && selectedEntry . ID != locksControl . SelectedEntry . GitLock . ID )
568- {
569- selectedEntry = GitLock . Default ;
570- }
571553 }
572554 public override void OnSelectionChange ( )
573555 {
0 commit comments