Compare commits

..

No commits in common. "d34aa8cb7eda202a5af374b0088259ae932e48a5" and "1ba294a07bc665dcc5f0f9681abf8b85101b193c" have entirely different histories.

7 changed files with 25 additions and 86 deletions

View file

@ -10,9 +10,6 @@ namespace SourceGit.Converters
public static readonly FuncValueConverter<IList, string> ToCount = public static readonly FuncValueConverter<IList, string> ToCount =
new FuncValueConverter<IList, string>(v => v == null ? " (0)" : $" ({v.Count})"); 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 = public static readonly FuncValueConverter<IList, bool> IsNotNullOrEmpty =
new FuncValueConverter<IList, bool>(v => v != null && v.Count > 0); new FuncValueConverter<IList, bool>(v => v != null && v.Count > 0);

View file

@ -9,8 +9,6 @@ namespace SourceGit.Models
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green), new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange), new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red), new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", Brushes.Green),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", Brushes.Green),
]; ];
public string Name { get; set; } public string Name { get; set; }

View file

@ -291,7 +291,6 @@
<x:String x:Key="Text.GitLFS.Locks" xml:space="preserve">Show Locks</x:String> <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.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.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.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.Unlock" xml:space="preserve">Unlock</x:String>
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">Force Unlock</x:String> <x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">Force Unlock</x:String>

View file

@ -294,7 +294,6 @@
<x:String x:Key="Text.GitLFS.Locks" xml:space="preserve">显示LFS对象锁</x:String> <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.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.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.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.Unlock" xml:space="preserve">解锁</x:String>
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">强制解锁</x:String> <x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">强制解锁</x:String>

View file

@ -294,7 +294,6 @@
<x:String x:Key="Text.GitLFS.Locks" xml:space="preserve">顯示 LFS 物件鎖</x:String> <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.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.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.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.Unlock" xml:space="preserve">解鎖</x:String>
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">強制解鎖</x:String> <x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">強制解鎖</x:String>

View file

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Threading.Tasks;
using System.Threading.Tasks;
using Avalonia.Collections;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -9,49 +9,40 @@ namespace SourceGit.ViewModels
{ {
public class LFSLocks : ObservableObject public class LFSLocks : ObservableObject
{ {
public bool HasValidUserName
{
get;
private set;
} = false;
public bool IsLoading public bool IsLoading
{ {
get => _isLoading; get => _isLoading;
private set => SetProperty(ref _isLoading, value); private set => SetProperty(ref _isLoading, value);
} }
public bool ShowOnlyMyLocks public bool IsEmpty
{ {
get => _showOnlyMyLocks; get => _isEmpty;
set private set => SetProperty(ref _isEmpty, value);
{
if (SetProperty(ref _showOnlyMyLocks, value))
UpdateVisibleLocks();
}
} }
public List<Models.LFSLock> VisibleLocks public AvaloniaList<Models.LFSLock> Locks
{ {
get => _visibleLocks; get;
private set => SetProperty(ref _visibleLocks, value); private set;
} }
public LFSLocks(string repo, string remote) public LFSLocks(string repo, string remote)
{ {
_repo = repo; _repo = repo;
_remote = remote; _remote = remote;
_userName = new Commands.Config(repo).Get("user.name"); Locks = new AvaloniaList<Models.LFSLock>();
HasValidUserName = !string.IsNullOrEmpty(_userName);
Task.Run(() => Task.Run(() =>
{ {
_cachedLocks = new Commands.LFS(_repo).Locks(_remote); var collect = new Commands.LFS(_repo).Locks(_remote);
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
UpdateVisibleLocks(); if (collect.Count > 0)
Locks.AddRange(collect);
IsLoading = false; IsLoading = false;
IsEmpty = collect.Count == 0;
}); });
}); });
} }
@ -68,41 +59,17 @@ namespace SourceGit.ViewModels
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
if (succ) if (succ)
{ Locks.Remove(lfsLock);
_cachedLocks.Remove(lfsLock);
UpdateVisibleLocks();
}
IsLoading = false; 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 _repo;
private string _remote; private string _remote;
private bool _isLoading = true; private bool _isLoading = true;
private List<Models.LFSLock> _cachedLocks = []; private bool _isEmpty = false;
private List<Models.LFSLock> _visibleLocks = [];
private bool _showOnlyMyLocks = false;
private string _userName;
} }
} }

View file

@ -5,7 +5,6 @@
xmlns:m="using:SourceGit.Models" xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels" xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views" xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.LFSLocks" x:Class="SourceGit.Views.LFSLocks"
x:DataType="vm:LFSLocks" x:DataType="vm:LFSLocks"
@ -14,7 +13,7 @@
Title="{DynamicResource Text.GitLFS.Locks.Title}" Title="{DynamicResource Text.GitLFS.Locks.Title}"
Width="600" Height="400" Width="600" Height="400"
WindowStartupLocation="CenterOwner"> WindowStartupLocation="CenterOwner">
<Grid RowDefinitions="Auto,Auto,*"> <Grid RowDefinitions="Auto,*">
<!-- TitleBar --> <!-- TitleBar -->
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}"> <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<Border Grid.Column="0" Grid.ColumnSpan="3" <Border Grid.Column="0" Grid.ColumnSpan="3"
@ -44,25 +43,11 @@
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
</Grid> </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 --> <!-- Locked Files -->
<Grid Grid.Row="2"> <Grid Grid.Row="1">
<ListBox Margin="8,0,8,8" <ListBox Margin="8"
Background="{DynamicResource Brush.Contents}" Background="{DynamicResource Brush.Contents}"
ItemsSource="{Binding VisibleLocks}" ItemsSource="{Binding Locks}"
SelectionMode="Single" SelectionMode="Single"
BorderThickness="1" BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}" BorderBrush="{DynamicResource Brush.Border2}"
@ -104,14 +89,9 @@
</ListBox> </ListBox>
<!-- Empty --> <!-- Empty -->
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel Orientation="Vertical"
<StackPanel.IsVisible> HorizontalAlignment="Center" VerticalAlignment="Center"
<MultiBinding Converter="{x:Static BoolConverters.And}"> IsVisible="{Binding IsEmpty}">
<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}"/> <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}"/> <TextBlock Margin="0,16,0,0" Text="{DynamicResource Text.GitLFS.Locks.Empty}" Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel> </StackPanel>