Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 28a44fa

Browse files
author
Andreia Gaita
authored
Merge pull request #968 from github-for-unity/fixes/release-lock-context-menu
Disabling Release Lock when appropriate
2 parents 9ead2b1 + eefd2fd commit 28a44fa

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ProjectWindowInterface : AssetPostprocessor
1818
private static List<GitLock> locks = new List<GitLock>();
1919
private static List<string> guids = new List<string>();
2020
private static List<string> guidsLocks = new List<string>();
21+
private static string loggedInUser;
2122

2223
private static IApplicationManager manager;
2324
private static bool isBusy = false;
@@ -26,6 +27,7 @@ class ProjectWindowInterface : AssetPostprocessor
2627
private static CacheUpdateEvent lastRepositoryStatusChangedEvent;
2728
private static CacheUpdateEvent lastLocksChangedEvent;
2829
private static IRepository Repository { get { return manager != null ? manager.Environment.Repository : null; } }
30+
private static IPlatform Platform { get { return manager != null ? manager.Platform : null; } }
2931
private static bool IsInitialized { get { return Repository != null; } }
3032

3133
public static void Initialize(IApplicationManager theManager)
@@ -35,6 +37,9 @@ public static void Initialize(IApplicationManager theManager)
3537

3638
manager = theManager;
3739

40+
Platform.Keychain.ConnectionsChanged += KeychainMayHaveChanged;
41+
KeychainMayHaveChanged();
42+
3843
if (IsInitialized)
3944
{
4045
Repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
@@ -83,6 +88,11 @@ private static void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
8388
}
8489
}
8590

91+
private static void KeychainMayHaveChanged()
92+
{
93+
loggedInUser = Platform.Keychain.Connections.Select(x => x.Username).FirstOrDefault();
94+
}
95+
8696
[MenuItem(AssetsMenuRequestLock, true, 10000)]
8797
private static bool ContextMenu_CanLock()
8898
{
@@ -104,7 +114,7 @@ private static bool ContextMenu_CanUnlock()
104114
return false;
105115
if (isBusy)
106116
return false;
107-
return Selection.objects.Any(IsObjectLocked);
117+
return Selection.objects.Any(f => IsObjectLocked(f , true));
108118
}
109119

110120
[MenuItem(AssetsMenuReleaseLockForced, true, 10002)]
@@ -180,14 +190,19 @@ private static bool IsObjectUnlocked(Object selected)
180190
}
181191

182192
private static bool IsObjectLocked(Object selected)
193+
{
194+
return IsObjectLocked(selected, false);
195+
}
196+
197+
private static bool IsObjectLocked(Object selected, bool isLockedByCurrentUser)
183198
{
184199
if (selected == null)
185200
return false;
186201

187202
NPath assetPath = AssetDatabase.GetAssetPath(selected.GetInstanceID()).ToNPath();
188203
NPath repositoryPath = manager.Environment.GetRepositoryPath(assetPath);
189204

190-
return locks.Any(x => repositoryPath == x.Path);
205+
return locks.Any(x => repositoryPath == x.Path && (!isLockedByCurrentUser || x.Owner.Name == loggedInUser));
191206
}
192207

193208
private static ITask CreateUnlockObjectTask(Object selected, bool force)

0 commit comments

Comments
 (0)