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

Commit 01a69ec

Browse files
Adding a Force Unlock option when dealing with other user's locks
1 parent b26c5f1 commit 01a69ec

File tree

1 file changed

+29
-3
lines changed
  • src/UnityExtension/Assets/Editor/GitHub.Unity/UI

1 file changed

+29
-3
lines changed

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class LocksView : Subview
310310

311311
[SerializeField] private CacheUpdateEvent lastLocksChangedEvent;
312312
[SerializeField] private List<GitLock> lockedFiles = new List<GitLock>();
313+
[SerializeField] private string currentUsername;
313314

314315
public override void OnEnable()
315316
{
@@ -349,8 +350,22 @@ public override void OnGUI()
349350
},
350351
entry => { },
351352
entry => {
352-
GenericMenu menu = new GenericMenu();
353-
menu.AddItem(new GUIContent("Unlock File"), false, UnlockFile);
353+
string unlockFile;
354+
GenericMenu.MenuFunction menuFunction;
355+
356+
if (entry.User == currentUsername)
357+
{
358+
unlockFile = "Unlock File";
359+
menuFunction = UnlockSelectedEntry;
360+
}
361+
else
362+
{
363+
unlockFile = "Force Unlock File";
364+
menuFunction = ForceUnlockSelectedEntry;
365+
}
366+
367+
var menu = new GenericMenu();
368+
menu.AddItem(new GUIContent(unlockFile), false, menuFunction);
354369
menu.ShowAsContext();
355370
});
356371

@@ -359,7 +374,14 @@ public override void OnGUI()
359374
}
360375
}
361376

362-
private void UnlockFile()
377+
private void UnlockSelectedEntry()
378+
{
379+
Repository
380+
.ReleaseLock(selectedEntry.Path, false)
381+
.Start();
382+
}
383+
384+
private void ForceUnlockSelectedEntry()
363385
{
364386
Repository
365387
.ReleaseLock(selectedEntry.Path, true)
@@ -414,6 +436,10 @@ private void MaybeUpdateData()
414436

415437
lockedFiles = Repository.CurrentLocks;
416438

439+
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
440+
var keychainConnection = Platform.Keychain.Connections.First();
441+
currentUsername = keychainConnection.Username;
442+
417443
BuildLocksControl();
418444
}
419445
}

0 commit comments

Comments
 (0)