@@ -101,34 +101,37 @@ private static bool IsObjectUnlocked(Object selected)
101101 private static void ContextMenu_Lock ( )
102102 {
103103 isBusy = true ;
104- var selected = Selection . activeObject ;
105104
106105 var unlockedObjects = Selection . objects . Where ( IsObjectUnlocked ) . ToArray ( ) ;
107- LockObject ( selected ) ;
106+ var tasks = unlockedObjects . Select ( LockObject ) . ToArray ( ) ;
108107
109- isBusy = false ;
110- Selection . activeGameObject = null ;
111- EditorApplication . RepaintProjectWindow ( ) ;
108+ var taskQueue = new TaskQueue ( ) ;
109+ foreach ( var task in tasks )
110+ {
111+ taskQueue . Queue ( task ) ;
112+ }
113+
114+ taskQueue . FinallyInUI ( ( success , exception ) =>
115+ {
116+ isBusy = false ;
117+ Selection . activeGameObject = null ;
118+ EditorApplication . RepaintProjectWindow ( ) ;
119+ } ) . Start ( ) ;
112120 }
113121
114- private static void LockObject ( Object selected )
122+ private static ITask LockObject ( Object selected )
115123 {
116124 NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
117125 NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
118126
119- Repository . RequestLock ( repositoryPath ) . FinallyInUI ( ( success , ex ) => {
120- if ( success )
121- {
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 ( ) ;
127+ return Repository . RequestLock ( repositoryPath )
128+ . FinallyInUI ( ( success , ex ) =>
129+ {
130+ if ( success )
131+ {
132+ manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsLock , null ) ;
133+ }
134+ } ) ;
132135 }
133136
134137 [ MenuItem ( AssetsMenuReleaseLock , true , 1000 ) ]
@@ -160,15 +163,22 @@ private static bool IsObjectLocked(Object selected)
160163 private static void ContextMenu_Unlock ( )
161164 {
162165 isBusy = true ;
163- var selected = Selection . activeObject ;
164166
165167 var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
168+ var tasks = lockedObjects . Select ( o => UnlockObject ( o , false ) ) . ToArray ( ) ;
166169
167- UnlockObject ( selected , false ) ;
170+ var taskQueue = new TaskQueue ( ) ;
171+ foreach ( var task in tasks )
172+ {
173+ taskQueue . Queue ( task ) ;
174+ }
168175
169- isBusy = false ;
170- Selection . activeGameObject = null ;
171- EditorApplication . RepaintProjectWindow ( ) ;
176+ taskQueue . FinallyInUI ( ( success , exception ) =>
177+ {
178+ isBusy = false ;
179+ Selection . activeGameObject = null ;
180+ EditorApplication . RepaintProjectWindow ( ) ;
181+ } ) . Start ( ) ;
172182 }
173183
174184 [ MenuItem ( AssetsMenuReleaseLockForced , true , 1000 ) ]
@@ -196,36 +206,37 @@ private static bool ContextMenu_CanUnlockForce()
196206 private static void ContextMenu_UnlockForce ( )
197207 {
198208 isBusy = true ;
199- var selected = Selection . activeObject ;
209+
200210 var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
211+ var tasks = lockedObjects . Select ( o => UnlockObject ( o , true ) ) . ToArray ( ) ;
201212
202- UnlockObject ( selected , true ) ;
213+ var taskQueue = new TaskQueue ( ) ;
214+ foreach ( var task in tasks )
215+ {
216+ taskQueue . Queue ( task ) ;
217+ }
203218
204- isBusy = false ;
205- Selection . activeGameObject = null ;
206- EditorApplication . RepaintProjectWindow ( ) ;
219+ taskQueue . FinallyInUI ( ( success , exception ) =>
220+ {
221+ isBusy = false ;
222+ Selection . activeGameObject = null ;
223+ EditorApplication . RepaintProjectWindow ( ) ;
224+ } ) . Start ( ) ;
207225 }
208226
209- private static void UnlockObject ( Object selected , bool force )
227+ private static ITask UnlockObject ( Object selected , bool force )
210228 {
211229 NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
212230 NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
213231
214- Repository . ReleaseLock ( repositoryPath , force )
232+ return Repository . ReleaseLock ( repositoryPath , force )
215233 . FinallyInUI ( ( success , ex ) =>
216234 {
217235 if ( success )
218236 {
219237 manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsUnlock , null ) ;
220238 }
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 ( ) ;
239+ } ) ;
229240 }
230241
231242 private static void OnLocksUpdate ( )
0 commit comments