From c3c47f616129c674535a824baab753a9bf32ab43 Mon Sep 17 00:00:00 2001 From: Mat Date: Sat, 21 Sep 2024 15:54:35 +0200 Subject: [PATCH 1/5] Added a checkbox in the LFSLocks window to only show the ones locked by "Mat" --- src/ViewModels/LFSLocks.cs | 29 ++++++++++++++++++++++++++--- src/Views/LFSLocks.axaml | 16 ++++++++++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/ViewModels/LFSLocks.cs b/src/ViewModels/LFSLocks.cs index 02b3e9a64..18e99c8b4 100644 --- a/src/ViewModels/LFSLocks.cs +++ b/src/ViewModels/LFSLocks.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Avalonia.Collections; using Avalonia.Threading; @@ -20,11 +22,31 @@ public bool IsEmpty get => _isEmpty; private set => SetProperty(ref _isEmpty, value); } + + public bool ShowOnlyMyLocks + { + get => _showOnlyMyLocks; + set + { + if (!SetProperty(ref _showOnlyMyLocks, value)) + return; + + OnPropertyChanged(nameof(FilteredLocks)); + IsEmpty = !FilteredLocks.Any(); + } + } - public AvaloniaList Locks + private AvaloniaList Locks { get; - private set; + } + + public IEnumerable FilteredLocks + { + get + { + return ShowOnlyMyLocks ? Locks.Where(@lock => @lock.User == "Mat") : Locks; + } } public LFSLocks(string repo, string remote) @@ -71,5 +93,6 @@ public void Unlock(Models.LFSLock lfsLock, bool force) private string _remote; private bool _isLoading = true; private bool _isEmpty = false; + private bool _showOnlyMyLocks = false; } } diff --git a/src/Views/LFSLocks.axaml b/src/Views/LFSLocks.axaml index 533920431..028956fad 100644 --- a/src/Views/LFSLocks.axaml +++ b/src/Views/LFSLocks.axaml @@ -13,7 +13,7 @@ Title="{DynamicResource Text.GitLFS.Locks.Title}" Width="600" Height="400" WindowStartupLocation="CenterOwner"> - + + + + + + - - + Date: Mon, 23 Sep 2024 16:54:26 +0200 Subject: [PATCH 2/5] Waits for the locks list to finish loading before making the checkbox clickable --- src/Views/LFSLocks.axaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Views/LFSLocks.axaml b/src/Views/LFSLocks.axaml index 028956fad..e275a0d86 100644 --- a/src/Views/LFSLocks.axaml +++ b/src/Views/LFSLocks.axaml @@ -48,6 +48,7 @@ From 6e35ac9eb08e1d66b073e6a532cc6c20132c4110 Mon Sep 17 00:00:00 2001 From: Mat Date: Mon, 23 Sep 2024 17:12:51 +0200 Subject: [PATCH 3/5] Now uses correct username for lock filtering. WIP: needs an error popup if user is misconfigured --- src/ViewModels/LFSLocks.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/LFSLocks.cs b/src/ViewModels/LFSLocks.cs index 18e99c8b4..d5820b646 100644 --- a/src/ViewModels/LFSLocks.cs +++ b/src/ViewModels/LFSLocks.cs @@ -45,7 +45,13 @@ public IEnumerable FilteredLocks { get { - return ShowOnlyMyLocks ? Locks.Where(@lock => @lock.User == "Mat") : Locks; + if (string.IsNullOrEmpty(_userName)) + { + //todo: add an error popup + return Locks; + } + + return ShowOnlyMyLocks ? Locks.Where(@lock => @lock.User == _userName) : Locks; } } @@ -54,6 +60,7 @@ public LFSLocks(string repo, string remote) _repo = repo; _remote = remote; Locks = new AvaloniaList(); + new Commands.Config(repo).ListAll().TryGetValue("user.name", out _userName); Task.Run(() => { @@ -94,5 +101,6 @@ public void Unlock(Models.LFSLock lfsLock, bool force) private bool _isLoading = true; private bool _isEmpty = false; private bool _showOnlyMyLocks = false; + private string _userName; } } From 62c006591adf19e4d913f70e93e5ea392b91ac0f Mon Sep 17 00:00:00 2001 From: Mat Date: Mon, 23 Sep 2024 18:06:07 +0200 Subject: [PATCH 4/5] Added an error popup if username is empty on lfs locks --- src/ViewModels/LFSLocks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ViewModels/LFSLocks.cs b/src/ViewModels/LFSLocks.cs index d5820b646..8f2eec406 100644 --- a/src/ViewModels/LFSLocks.cs +++ b/src/ViewModels/LFSLocks.cs @@ -47,7 +47,7 @@ public IEnumerable FilteredLocks { if (string.IsNullOrEmpty(_userName)) { - //todo: add an error popup + App.RaiseException(_repo, "Username is empty"); return Locks; } From 4744414af37619887b8b08fedee9f12f9fc1eafd Mon Sep 17 00:00:00 2001 From: Mat Date: Mon, 23 Sep 2024 18:21:15 +0200 Subject: [PATCH 5/5] Replaced an IEnumerable with a AvaloniaList for consistency --- src/ViewModels/LFSLocks.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ViewModels/LFSLocks.cs b/src/ViewModels/LFSLocks.cs index 8f2eec406..7f3f9c306 100644 --- a/src/ViewModels/LFSLocks.cs +++ b/src/ViewModels/LFSLocks.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Avalonia.Collections; @@ -41,7 +40,7 @@ private AvaloniaList Locks get; } - public IEnumerable FilteredLocks + public AvaloniaList FilteredLocks { get { @@ -51,7 +50,9 @@ public IEnumerable FilteredLocks return Locks; } - return ShowOnlyMyLocks ? Locks.Where(@lock => @lock.User == _userName) : Locks; + return _showOnlyMyLocks ? + new AvaloniaList(Locks.Where(@lock => @lock.User == _userName)) : + Locks; } }