@@ -74,7 +74,11 @@ private static bool ContextMenu_CanLock()
74
74
if ( Repository == null || ! Repository . CurrentRemote . HasValue )
75
75
return false ;
76
76
77
- var selected = Selection . activeObject ;
77
+ return Selection . objects . Any ( IsObjectUnlocked ) ;
78
+ }
79
+
80
+ private static bool IsObjectUnlocked ( Object selected )
81
+ {
78
82
if ( selected == null )
79
83
return false ;
80
84
if ( locks == null )
@@ -89,6 +93,7 @@ private static bool ContextMenu_CanLock()
89
93
{
90
94
status = entries . FirstOrDefault ( x => repositoryPath == x . Path . ToNPath ( ) ) . Status ;
91
95
}
96
+
92
97
return ! alreadyLocked && status != GitFileStatus . Untracked && status != GitFileStatus . Ignored ;
93
98
}
94
99
@@ -98,32 +103,32 @@ private static void ContextMenu_Lock()
98
103
isBusy = true ;
99
104
var selected = Selection . activeObject ;
100
105
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
+ {
101
116
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
102
117
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
103
118
104
- Repository
105
- . RequestLock ( repositoryPath )
106
- . FinallyInUI ( ( success , ex ) =>
119
+ Repository . RequestLock ( repositoryPath ) . FinallyInUI ( ( success , ex ) => {
120
+ if ( success )
107
121
{
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 ( ) ;
127
132
}
128
133
129
134
[ MenuItem ( AssetsMenuReleaseLock , true , 1000 ) ]
@@ -134,7 +139,11 @@ private static bool ContextMenu_CanUnlock()
134
139
if ( Repository == null || ! Repository . CurrentRemote . HasValue )
135
140
return false ;
136
141
137
- var selected = Selection . activeObject ;
142
+ return Selection . objects . Any ( IsObjectLocked ) ;
143
+ }
144
+
145
+ private static bool IsObjectLocked ( Object selected )
146
+ {
138
147
if ( selected == null )
139
148
return false ;
140
149
if ( locks == null || locks . Count == 0 )
@@ -153,32 +162,13 @@ private static void ContextMenu_Unlock()
153
162
isBusy = true ;
154
163
var selected = Selection . activeObject ;
155
164
156
- NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
157
- NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
165
+ var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
158
166
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 ( ) ;
182
172
}
183
173
184
174
[ MenuItem ( AssetsMenuReleaseLockForced , true , 1000 ) ]
@@ -207,33 +197,35 @@ private static void ContextMenu_UnlockForce()
207
197
{
208
198
isBusy = true ;
209
199
var selected = Selection . activeObject ;
200
+ var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
210
201
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
+ {
211
211
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
212
212
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
213
213
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 ( ) ;
237
229
}
238
230
239
231
private static void OnLocksUpdate ( )
0 commit comments