@@ -74,7 +74,11 @@ private static bool ContextMenu_CanLock()
7474 if ( Repository == null || ! Repository . CurrentRemote . HasValue )
7575 return false ;
7676
77- var selected = Selection . activeObject ;
77+ return Selection . objects . Any ( IsObjectUnlocked ) ;
78+ }
79+
80+ private static bool IsObjectUnlocked ( Object selected )
81+ {
7882 if ( selected == null )
7983 return false ;
8084 if ( locks == null )
@@ -89,6 +93,7 @@ private static bool ContextMenu_CanLock()
8993 {
9094 status = entries . FirstOrDefault ( x => repositoryPath == x . Path . ToNPath ( ) ) . Status ;
9195 }
96+
9297 return ! alreadyLocked && status != GitFileStatus . Untracked && status != GitFileStatus . Ignored ;
9398 }
9499
@@ -98,32 +103,32 @@ private static void ContextMenu_Lock()
98103 isBusy = true ;
99104 var selected = Selection . activeObject ;
100105
106+ var unlockedObjects = Selection . objects . Where ( IsObjectUnlocked ) . ToArray ( ) ;
107+ LockObject ( selected ) ;
108+
109+ isBusy = false ;
110+ Selection . activeGameObject = null ;
111+ EditorApplication . RepaintProjectWindow ( ) ;
112+ }
113+
114+ private static void LockObject ( Object selected )
115+ {
101116 NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
102117 NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
103118
104- Repository
105- . RequestLock ( repositoryPath )
106- . FinallyInUI ( ( success , ex ) =>
119+ Repository . RequestLock ( repositoryPath ) . FinallyInUI ( ( success , ex ) => {
120+ if ( success )
107121 {
108- if ( success )
109- {
110- manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsLock , null ) ;
111- }
112- else
113- {
114- var error = ex . Message ;
115- if ( error . Contains ( "exit status 255" ) )
116- error = "Failed to unlock: no permissions" ;
117- EditorUtility . DisplayDialog ( Localization . RequestLockActionTitle ,
118- error ,
119- Localization . Ok ) ;
120- }
121-
122- isBusy = false ;
123- Selection . activeGameObject = null ;
124- EditorApplication . RepaintProjectWindow ( ) ;
125- } )
126- . Start ( ) ;
122+ manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsLock , null ) ;
123+ }
124+ else
125+ {
126+ var error = ex . Message ;
127+ if ( error . Contains ( "exit status 255" ) )
128+ error = "Failed to unlock: no permissions" ;
129+ EditorUtility . DisplayDialog ( Localization . RequestLockActionTitle , error , Localization . Ok ) ;
130+ }
131+ } ) . Start ( ) ;
127132 }
128133
129134 [ MenuItem ( AssetsMenuReleaseLock , true , 1000 ) ]
@@ -134,7 +139,11 @@ private static bool ContextMenu_CanUnlock()
134139 if ( Repository == null || ! Repository . CurrentRemote . HasValue )
135140 return false ;
136141
137- var selected = Selection . activeObject ;
142+ return Selection . objects . Any ( IsObjectLocked ) ;
143+ }
144+
145+ private static bool IsObjectLocked ( Object selected )
146+ {
138147 if ( selected == null )
139148 return false ;
140149 if ( locks == null || locks . Count == 0 )
@@ -153,32 +162,13 @@ private static void ContextMenu_Unlock()
153162 isBusy = true ;
154163 var selected = Selection . activeObject ;
155164
156- NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
157- NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
165+ var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
158166
159- Repository
160- . ReleaseLock ( repositoryPath , false )
161- . FinallyInUI ( ( success , ex ) =>
162- {
163- if ( success )
164- {
165- manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsUnlock , null ) ;
166- }
167- else
168- {
169- var error = ex . Message ;
170- if ( error . Contains ( "exit status 255" ) )
171- error = "Failed to unlock: no permissions" ;
172- EditorUtility . DisplayDialog ( Localization . ReleaseLockActionTitle ,
173- error ,
174- Localization . Ok ) ;
175- }
176-
177- isBusy = false ;
178- Selection . activeGameObject = null ;
179- EditorApplication . RepaintProjectWindow ( ) ;
180- } )
181- . Start ( ) ;
167+ UnlockObject ( selected , false ) ;
168+
169+ isBusy = false ;
170+ Selection . activeGameObject = null ;
171+ EditorApplication . RepaintProjectWindow ( ) ;
182172 }
183173
184174 [ MenuItem ( AssetsMenuReleaseLockForced , true , 1000 ) ]
@@ -207,33 +197,35 @@ private static void ContextMenu_UnlockForce()
207197 {
208198 isBusy = true ;
209199 var selected = Selection . activeObject ;
200+ var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
210201
202+ UnlockObject ( selected , true ) ;
203+
204+ isBusy = false ;
205+ Selection . activeGameObject = null ;
206+ EditorApplication . RepaintProjectWindow ( ) ;
207+ }
208+
209+ private static void UnlockObject ( Object selected , bool force )
210+ {
211211 NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
212212 NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
213213
214- Repository
215- . ReleaseLock ( repositoryPath , true )
216- . FinallyInUI ( ( success , ex ) =>
217- {
218- if ( success )
219- {
220- manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsUnlock , null ) ;
221- }
222- else
223- {
224- var error = ex . Message ;
225- if ( error . Contains ( "exit status 255" ) )
226- error = "Failed to unlock: no permissions" ;
227- EditorUtility . DisplayDialog ( Localization . ReleaseLockActionTitle ,
228- error ,
229- Localization . Ok ) ;
230- }
231-
232- isBusy = false ;
233- Selection . activeGameObject = null ;
234- EditorApplication . RepaintProjectWindow ( ) ;
235- } )
236- . Start ( ) ;
214+ Repository . ReleaseLock ( repositoryPath , force )
215+ . FinallyInUI ( ( success , ex ) =>
216+ {
217+ if ( success )
218+ {
219+ manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsUnlock , null ) ;
220+ }
221+ else
222+ {
223+ var error = ex . Message ;
224+ if ( error . Contains ( "exit status 255" ) )
225+ error = "Failed to unlock: no permissions" ;
226+ EditorUtility . DisplayDialog ( Localization . ReleaseLockActionTitle , error , Localization . Ok ) ;
227+ }
228+ } ) . Start ( ) ;
237229 }
238230
239231 private static void OnLocksUpdate ( )
0 commit comments