@@ -18,6 +18,7 @@ class ProjectWindowInterface : AssetPostprocessor
18
18
private static List < GitLock > locks = new List < GitLock > ( ) ;
19
19
private static List < string > guids = new List < string > ( ) ;
20
20
private static List < string > guidsLocks = new List < string > ( ) ;
21
+ private static string loggedInUser ;
21
22
22
23
private static IApplicationManager manager ;
23
24
private static bool isBusy = false ;
@@ -26,6 +27,7 @@ class ProjectWindowInterface : AssetPostprocessor
26
27
private static CacheUpdateEvent lastRepositoryStatusChangedEvent ;
27
28
private static CacheUpdateEvent lastLocksChangedEvent ;
28
29
private static IRepository Repository { get { return manager != null ? manager . Environment . Repository : null ; } }
30
+ private static IPlatform Platform { get { return manager != null ? manager . Platform : null ; } }
29
31
private static bool IsInitialized { get { return Repository != null ; } }
30
32
31
33
public static void Initialize ( IApplicationManager theManager )
@@ -35,6 +37,9 @@ public static void Initialize(IApplicationManager theManager)
35
37
36
38
manager = theManager ;
37
39
40
+ Platform . Keychain . ConnectionsChanged += KeychainMayHaveChanged ;
41
+ KeychainMayHaveChanged ( ) ;
42
+
38
43
if ( IsInitialized )
39
44
{
40
45
Repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
@@ -83,6 +88,11 @@ private static void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
83
88
}
84
89
}
85
90
91
+ private static void KeychainMayHaveChanged ( )
92
+ {
93
+ loggedInUser = Platform . Keychain . Connections . Select ( x => x . Username ) . FirstOrDefault ( ) ;
94
+ }
95
+
86
96
[ MenuItem ( AssetsMenuRequestLock , true , 10000 ) ]
87
97
private static bool ContextMenu_CanLock ( )
88
98
{
@@ -104,7 +114,7 @@ private static bool ContextMenu_CanUnlock()
104
114
return false ;
105
115
if ( isBusy )
106
116
return false ;
107
- return Selection . objects . Any ( IsObjectLocked ) ;
117
+ return Selection . objects . Any ( f => IsObjectLocked ( f , true ) ) ;
108
118
}
109
119
110
120
[ MenuItem ( AssetsMenuReleaseLockForced , true , 10002 ) ]
@@ -180,14 +190,19 @@ private static bool IsObjectUnlocked(Object selected)
180
190
}
181
191
182
192
private static bool IsObjectLocked ( Object selected )
193
+ {
194
+ return IsObjectLocked ( selected , false ) ;
195
+ }
196
+
197
+ private static bool IsObjectLocked ( Object selected , bool isLockedByCurrentUser )
183
198
{
184
199
if ( selected == null )
185
200
return false ;
186
201
187
202
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
188
203
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
189
204
190
- return locks . Any ( x => repositoryPath == x . Path ) ;
205
+ return locks . Any ( x => repositoryPath == x . Path && ( ! isLockedByCurrentUser || x . Owner . Name == loggedInUser ) ) ;
191
206
}
192
207
193
208
private static ITask CreateUnlockObjectTask ( Object selected , bool force )
0 commit comments