@@ -17,16 +17,18 @@ public class GitLockEntry
17
17
{
18
18
public static GitLockEntry Default = new GitLockEntry ( GitLock . Default , GitFileStatus . None ) ;
19
19
20
- [ SerializeField ] private GitLock gitLock ;
21
- [ SerializeField ] private GitFileStatus gitFileStatus ;
22
-
23
20
[ NonSerialized ] public Texture Icon ;
24
21
[ NonSerialized ] public Texture IconBadge ;
25
22
23
+ [ SerializeField ] private GitLock gitLock ;
24
+ [ SerializeField ] private GitFileStatus gitFileStatus ;
25
+ [ SerializeField ] private string lockedAt ;
26
+
26
27
public GitLockEntry ( GitLock gitLock , GitFileStatus gitFileStatus )
27
28
{
28
29
this . gitLock = gitLock ;
29
30
this . gitFileStatus = gitFileStatus ;
31
+ this . lockedAt = gitLock . LockedAt . ToLocalTime ( ) . CreateRelativeTime ( DateTimeOffset . Now ) ;
30
32
}
31
33
32
34
public GitLock GitLock
@@ -39,29 +41,23 @@ public GitFileStatus GitFileStatus
39
41
get { return gitFileStatus ; }
40
42
}
41
43
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 ; } }
49
45
}
50
46
51
47
[ Serializable ]
52
48
class LocksControl
53
49
{
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
-
59
50
[ NonSerialized ] private Action < GitLock > rightClickNextRender ;
60
51
[ NonSerialized ] private GitLockEntry rightClickNextRenderEntry ;
61
- [ NonSerialized ] private GitLockEntry selectedEntry ;
62
52
[ NonSerialized ] private int controlId ;
63
53
[ NonSerialized ] private UnityEngine . Object lastActivatedObject ;
64
54
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
+
65
61
public GitLockEntry SelectedEntry
66
62
{
67
63
get
@@ -72,8 +68,8 @@ public GitLockEntry SelectedEntry
72
68
{
73
69
selectedEntry = value ;
74
70
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 ) )
77
73
: null ;
78
74
79
75
lastActivatedObject = activeObject ;
@@ -115,16 +111,16 @@ public bool Render(Rect containingRect, Action<GitLock> singleClick = null,
115
111
var entryRect = new Rect ( rect . x , rect . y , rect . width , Styles . LocksEntryHeight ) ;
116
112
117
113
var shouldRenderEntry = ! ( entryRect . y > endDisplay || entryRect . yMax < startDisplay ) ;
118
- if ( shouldRenderEntry && Event . current . type == EventType . Repaint )
114
+ if ( shouldRenderEntry )
119
115
{
120
- RenderEntry ( entryRect , entry ) ;
116
+ entryRect = RenderEntry ( entryRect , entry ) ;
121
117
}
122
118
123
119
var entryRequiresRepaint =
124
120
HandleInput ( entryRect , entry , index , singleClick , doubleClick , rightClick ) ;
125
121
requiresRepaint = requiresRepaint || entryRequiresRepaint ;
126
122
127
- rect . y += Styles . LocksEntryHeight ;
123
+ rect . y += entryRect . height ;
128
124
}
129
125
130
126
GUILayout . Space ( rect . y - containingRect . y ) ;
@@ -134,30 +130,30 @@ public bool Render(Rect containingRect, Action<GitLock> singleClick = null,
134
130
return requiresRepaint ;
135
131
}
136
132
137
- private void RenderEntry ( Rect entryRect , GitLockEntry entry )
133
+ private Rect RenderEntry ( Rect entryRect , GitLockEntry entry )
138
134
{
139
135
var isSelected = entry == SelectedEntry ;
140
-
141
136
var iconWidth = 32 ;
142
137
var iconHeight = 32 ;
143
- var iconRect = new Rect ( entryRect . x + Styles . BaseSpacing / 2 , entryRect . y + ( Styles . LocksEntryHeight - iconHeight ) / 2 , iconWidth , iconHeight ) ;
144
-
145
138
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 ;
154
140
var hasKeyboardFocus = GUIUtility . keyboardControl == controlId ;
155
141
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 ;
161
157
}
162
158
163
159
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
214
210
215
211
public void Load ( List < GitLock > locks , List < GitStatusEntry > gitStatusEntries )
216
212
{
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 ) ;
219
216
var selectedLockId = SelectedEntry != null && SelectedEntry . GitLock != GitLock . Default
220
217
? ( int ? ) SelectedEntry . GitLock . ID
221
218
: null ;
222
219
223
220
var scrollValue = scroll . y ;
224
-
225
221
var previousCount = gitLockEntries . Count ;
226
-
227
222
var scrollIndex = ( int ) ( scrollValue / Styles . LocksEntryHeight ) ;
228
223
229
224
assets . Clear ( ) ;
230
225
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 ) )
235
231
{
236
- gitFileStatus = GitFileStatus . None ;
232
+ gitFileStatus = gitStatusEntries [ index ] . Status ;
237
233
}
238
234
239
235
var gitLockEntry = new GitLockEntry ( gitLock , gitFileStatus ) ;
240
236
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 ) ;
243
239
if ( ! string . IsNullOrEmpty ( assetGuid ) )
244
240
{
245
241
assets . Add ( assetGuid , gitLockEntry ) ;
@@ -359,12 +355,10 @@ public bool OnSelectionChange()
359
355
if ( ! LocksControlHasFocus )
360
356
{
361
357
GitLockEntry gitLockEntry = GitLockEntry . Default ;
362
-
363
358
if ( Selection . activeObject != lastActivatedObject )
364
359
{
365
360
var activeAssetPath = AssetDatabase . GetAssetPath ( Selection . activeObject ) ;
366
361
var activeAssetGuid = AssetDatabase . AssetPathToGUID ( activeAssetPath ) ;
367
-
368
362
assets . TryGetValue ( activeAssetGuid , out gitLockEntry ) ;
369
363
}
370
364
@@ -383,7 +377,6 @@ class LocksView : Subview
383
377
[ NonSerialized ] private bool currentLocksHasUpdate ;
384
378
385
379
[ SerializeField ] private LocksControl locksControl ;
386
- [ SerializeField ] private GitLock selectedEntry = GitLock . Default ;
387
380
388
381
[ SerializeField ] private CacheUpdateEvent lastLocksChangedEvent ;
389
382
[ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
@@ -430,11 +423,10 @@ public override void OnGUI()
430
423
var rect = GUILayoutUtility . GetLastRect ( ) ;
431
424
if ( locksControl != null )
432
425
{
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 ) ;
434
427
435
428
var requiresRepaint = locksControl . Render ( lockControlRect ,
436
429
entry => {
437
- selectedEntry = entry ;
438
430
} ,
439
431
entry => { } ,
440
432
entry => {
@@ -446,11 +438,8 @@ public override void OnGUI()
446
438
unlockFile = "Unlock File" ;
447
439
menuFunction = UnlockSelectedEntry ;
448
440
}
449
- else
450
- {
451
- unlockFile = "Force Unlock File" ;
452
- menuFunction = ForceUnlockSelectedEntry ;
453
- }
441
+ unlockFile = "Force Unlock File" ;
442
+ menuFunction = ForceUnlockSelectedEntry ;
454
443
455
444
var menu = new GenericMenu ( ) ;
456
445
menu . AddItem ( new GUIContent ( unlockFile ) , false , menuFunction ) ;
@@ -465,14 +454,14 @@ public override void OnGUI()
465
454
private void UnlockSelectedEntry ( )
466
455
{
467
456
Repository
468
- . ReleaseLock ( selectedEntry . Path , false )
457
+ . ReleaseLock ( locksControl . SelectedEntry . GitLock . Path , false )
469
458
. Start ( ) ;
470
459
}
471
460
472
461
private void ForceUnlockSelectedEntry ( )
473
462
{
474
463
Repository
475
- . ReleaseLock ( selectedEntry . Path , true )
464
+ . ReleaseLock ( locksControl . SelectedEntry . GitLock . Path , true )
476
465
. Start ( ) ;
477
466
}
478
467
@@ -549,7 +538,6 @@ private void MaybeUpdateData()
549
538
{
550
539
currentStatusEntriesHasUpdate = false ;
551
540
currentLocksHasUpdate = false ;
552
-
553
541
BuildLocksControl ( ) ;
554
542
}
555
543
}
@@ -562,12 +550,6 @@ private void BuildLocksControl()
562
550
}
563
551
564
552
locksControl . Load ( lockedFiles , gitStatusEntries ) ;
565
-
566
- if ( ! selectedEntry . Equals ( GitLock . Default )
567
- && selectedEntry . ID != locksControl . SelectedEntry . GitLock . ID )
568
- {
569
- selectedEntry = GitLock . Default ;
570
- }
571
553
}
572
554
public override void OnSelectionChange ( )
573
555
{
0 commit comments