Skip to content

Commit

Permalink
Merge branch 'sourcegit-scm:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiboz authored Sep 26, 2024
2 parents a0c17d9 + d34aa8c commit 663c1ab
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
3 changes: 3 additions & 0 deletions src/Converters/ListConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public static class ListConverters
public static readonly FuncValueConverter<IList, string> ToCount =
new FuncValueConverter<IList, string>(v => v == null ? " (0)" : $" ({v.Count})");

public static readonly FuncValueConverter<IList, bool> IsNullOrEmpty =
new FuncValueConverter<IList, bool>(v => v == null || v.Count == 0);

public static readonly FuncValueConverter<IList, bool> IsNotNullOrEmpty =
new FuncValueConverter<IList, bool>(v => v != null && v.Count > 0);

Expand Down
2 changes: 1 addition & 1 deletion src/Models/ResetMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ResetMode
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
new ResetMode("Merge", "Reset to a commit, keeping unmerged changes", "--merge", Brushes.Green),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", Brushes.Green),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", Brushes.Green),
];

Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<x:String x:Key="Text.GitLFS.Locks" xml:space="preserve">Show Locks</x:String>
<x:String x:Key="Text.GitLFS.Locks.Empty" xml:space="preserve">No Locked Files</x:String>
<x:String x:Key="Text.GitLFS.Locks.Lock" xml:space="preserve">Lock</x:String>
<x:String x:Key="Text.GitLFS.Locks.OnlyMine" xml:space="preserve">Show only my locks</x:String>
<x:String x:Key="Text.GitLFS.Locks.Title" xml:space="preserve">LFS Locks</x:String>
<x:String x:Key="Text.GitLFS.Locks.Unlock" xml:space="preserve">Unlock</x:String>
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">Force Unlock</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<x:String x:Key="Text.GitLFS.Locks" xml:space="preserve">显示LFS对象锁</x:String>
<x:String x:Key="Text.GitLFS.Locks.Empty" xml:space="preserve">没有锁定的LFS文件</x:String>
<x:String x:Key="Text.GitLFS.Locks.Lock" xml:space="preserve">锁定</x:String>
<x:String x:Key="Text.GitLFS.Locks.OnlyMine" xml:space="preserve">仅显示被我锁定的文件</x:String>
<x:String x:Key="Text.GitLFS.Locks.Title" xml:space="preserve">LFS对象锁状态</x:String>
<x:String x:Key="Text.GitLFS.Locks.Unlock" xml:space="preserve">解锁</x:String>
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">强制解锁</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<x:String x:Key="Text.GitLFS.Locks" xml:space="preserve">顯示 LFS 物件鎖</x:String>
<x:String x:Key="Text.GitLFS.Locks.Empty" xml:space="preserve">沒有鎖定的 LFS 物件</x:String>
<x:String x:Key="Text.GitLFS.Locks.Lock" xml:space="preserve">鎖定</x:String>
<x:String x:Key="Text.GitLFS.Locks.OnlyMine" xml:space="preserve">僅顯示被我鎖定的檔案</x:String>
<x:String x:Key="Text.GitLFS.Locks.Title" xml:space="preserve">LFS 物件鎖</x:String>
<x:String x:Key="Text.GitLFS.Locks.Unlock" xml:space="preserve">解鎖</x:String>
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">強制解鎖</x:String>
Expand Down
69 changes: 51 additions & 18 deletions src/ViewModels/LFSLocks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;

using Avalonia.Collections;
using Avalonia.Threading;

using CommunityToolkit.Mvvm.ComponentModel;
Expand All @@ -9,40 +9,49 @@ namespace SourceGit.ViewModels
{
public class LFSLocks : ObservableObject
{
public bool HasValidUserName
{
get;
private set;
} = false;

public bool IsLoading
{
get => _isLoading;
private set => SetProperty(ref _isLoading, value);
}

public bool IsEmpty
public bool ShowOnlyMyLocks
{
get => _isEmpty;
private set => SetProperty(ref _isEmpty, value);
get => _showOnlyMyLocks;
set
{
if (SetProperty(ref _showOnlyMyLocks, value))
UpdateVisibleLocks();
}
}

public AvaloniaList<Models.LFSLock> Locks
public List<Models.LFSLock> VisibleLocks
{
get;
private set;
get => _visibleLocks;
private set => SetProperty(ref _visibleLocks, value);
}

public LFSLocks(string repo, string remote)
{
_repo = repo;
_remote = remote;
Locks = new AvaloniaList<Models.LFSLock>();
_userName = new Commands.Config(repo).Get("user.name");

HasValidUserName = !string.IsNullOrEmpty(_userName);

Task.Run(() =>
{
var collect = new Commands.LFS(_repo).Locks(_remote);
_cachedLocks = new Commands.LFS(_repo).Locks(_remote);
Dispatcher.UIThread.Invoke(() =>
{
if (collect.Count > 0)
Locks.AddRange(collect);
UpdateVisibleLocks();
IsLoading = false;
IsEmpty = collect.Count == 0;
});
});
}
Expand All @@ -59,17 +68,41 @@ public void Unlock(Models.LFSLock lfsLock, bool force)
Dispatcher.UIThread.Invoke(() =>
{
if (succ)
Locks.Remove(lfsLock);
{
_cachedLocks.Remove(lfsLock);
UpdateVisibleLocks();
}
IsLoading = false;
IsEmpty = Locks.Count == 0;
});
});
}

private void UpdateVisibleLocks()
{
if (!_showOnlyMyLocks)
{
VisibleLocks = _cachedLocks;
}
else
{
var visible = new List<Models.LFSLock>();
foreach (var lfsLock in _cachedLocks)
{
if (lfsLock.User == _userName)
visible.Add(lfsLock);
}

VisibleLocks = visible;
}
}

private string _repo;
private string _remote;
private bool _isLoading = true;
private bool _isEmpty = false;
private List<Models.LFSLock> _cachedLocks = [];
private List<Models.LFSLock> _visibleLocks = [];
private bool _showOnlyMyLocks = false;
private string _userName;
}
}
34 changes: 27 additions & 7 deletions src/Views/LFSLocks.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.LFSLocks"
x:DataType="vm:LFSLocks"
Expand All @@ -13,7 +14,7 @@
Title="{DynamicResource Text.GitLFS.Locks.Title}"
Width="600" Height="400"
WindowStartupLocation="CenterOwner">
<Grid RowDefinitions="Auto,*">
<Grid RowDefinitions="Auto,Auto,*">
<!-- TitleBar -->
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<Border Grid.Column="0" Grid.ColumnSpan="3"
Expand Down Expand Up @@ -43,11 +44,25 @@
IsVisible="{OnPlatform True, macOS=False}"/>
</Grid>

<!-- Filter and Unlock All -->
<CheckBox Grid.Row="1"
Margin="8,0,0,0"
Content="{DynamicResource Text.GitLFS.Locks.OnlyMine}"
IsChecked="{Binding ShowOnlyMyLocks, Mode=TwoWay}"
VerticalAlignment="Center">
<CheckBox.IsEnabled>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="HasValidUserName"/>
<Binding Path="!IsLoading"/>
</MultiBinding>
</CheckBox.IsEnabled>
</CheckBox>

<!-- Locked Files -->
<Grid Grid.Row="1">
<ListBox Margin="8"
<Grid Grid.Row="2">
<ListBox Margin="8,0,8,8"
Background="{DynamicResource Brush.Contents}"
ItemsSource="{Binding Locks}"
ItemsSource="{Binding VisibleLocks}"
SelectionMode="Single"
BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}"
Expand Down Expand Up @@ -89,9 +104,14 @@
</ListBox>

<!-- Empty -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsEmpty}">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="!IsLoading"/>
<Binding Path="VisibleLocks" Converter="{x:Static c:ListConverters.IsNullOrEmpty}"/>
</MultiBinding>
</StackPanel.IsVisible>

<Path Width="48" Height="48" Data="{StaticResource Icons.Empty}" Fill="{DynamicResource Brush.FG2}"/>
<TextBlock Margin="0,16,0,0" Text="{DynamicResource Text.GitLFS.Locks.Empty}" Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
Expand Down

0 comments on commit 663c1ab

Please sign in to comment.