mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
fix: memory leak caused by animation
This commit is contained in:
parent
092bf15906
commit
73cfeca8a9
5 changed files with 109 additions and 24 deletions
|
@ -52,17 +52,13 @@ namespace SourceGit.ViewModels
|
|||
if (task != null)
|
||||
{
|
||||
var finished = await task;
|
||||
_popup.InProgress = false;
|
||||
if (finished)
|
||||
{
|
||||
Popup = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_popup.InProgress = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_popup.InProgress = false;
|
||||
Popup = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -317,23 +317,9 @@
|
|||
</StackPanel>
|
||||
|
||||
<!-- Running -->
|
||||
<StackPanel Orientation="Vertical" Margin="8" IsVisible="{Binding InProgress}">
|
||||
<Rectangle Height="1" Margin="-8,0" HorizontalAlignment="Stretch" Fill="{DynamicResource Brush.Border1}" />
|
||||
<StackPanel Orientation="Horizontal" Margin="0,8">
|
||||
<Path Width="12" Height="12" Classes="waiting" Data="{StaticResource Icons.Waiting}" IsVisible="{Binding InProgress}"/>
|
||||
<TextBlock Margin="6,0,0,0" FontSize="14" FontWeight="Bold" Text="{DynamicResource Text.Running}"/>
|
||||
</StackPanel>
|
||||
<TextBlock HorizontalAlignment="Stretch"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Decrease}}"
|
||||
FontStyle="Italic"
|
||||
Text="{Binding ProgressDescription}"/>
|
||||
<ProgressBar Margin="0,8,0,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
IsIndeterminate="True"
|
||||
Background="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.Accent}"
|
||||
Minimum="0" Maximum="100"/>
|
||||
</StackPanel>
|
||||
<v:PopupRunningStatus Margin="8"
|
||||
Description="{Binding ProgressDescription}"
|
||||
IsVisible="{Binding InProgress}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -17,7 +17,9 @@ namespace SourceGit.Views
|
|||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
StartAnim();
|
||||
|
||||
if (IsVisible)
|
||||
StartAnim();
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
|
|
31
src/Views/PopupRunningStatus.axaml
Normal file
31
src/Views/PopupRunningStatus.axaml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.PopupRunningStatus"
|
||||
x:Name="me">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Rectangle Height="1" Margin="-8,0" HorizontalAlignment="Stretch" Fill="{DynamicResource Brush.Border1}" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,8">
|
||||
<ContentPresenter x:Name="icon" Width="12" Height="12"/>
|
||||
<TextBlock Margin="6,0,0,0" FontSize="14" FontWeight="Bold" Text="{DynamicResource Text.Running}"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock x:Name="txtDesc"
|
||||
HorizontalAlignment="Stretch"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Decrease}}"
|
||||
FontStyle="Italic"
|
||||
Text="{Binding #me.Description}"/>
|
||||
|
||||
<ProgressBar x:Name="progressBar"
|
||||
Margin="0,8,0,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.Accent}"
|
||||
Minimum="0" Maximum="100"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
70
src/Views/PopupRunningStatus.axaml.cs
Normal file
70
src/Views/PopupRunningStatus.axaml.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class PopupRunningStatus : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<string> DescriptionProperty =
|
||||
AvaloniaProperty.Register<PopupRunningStatus, string>(nameof(Description));
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => GetValue(DescriptionProperty);
|
||||
set => SetValue(DescriptionProperty, value);
|
||||
}
|
||||
|
||||
public PopupRunningStatus()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
if (IsVisible)
|
||||
StartAnim();
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
StopAnim();
|
||||
base.OnUnloaded(e);
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == IsVisibleProperty)
|
||||
{
|
||||
if (IsVisible)
|
||||
StartAnim();
|
||||
else
|
||||
StopAnim();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartAnim()
|
||||
{
|
||||
icon.Content = new Path()
|
||||
{
|
||||
Data = this.FindResource("Icons.Loading") as StreamGeometry,
|
||||
Classes = { "rotating" },
|
||||
};
|
||||
progressBar.IsIndeterminate = true;
|
||||
}
|
||||
|
||||
private void StopAnim()
|
||||
{
|
||||
if (icon.Content is Path path)
|
||||
path.Classes.Clear();
|
||||
icon.Content = null;
|
||||
progressBar.IsIndeterminate = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue