mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-01 01:14:59 +00:00
refactor: implement IDisposable
instead of calling custom Cleanup
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
550493b572
commit
75b7724d44
8 changed files with 42 additions and 34 deletions
19
src/Models/Count.cs
Normal file
19
src/Models/Count.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class Count : IDisposable
|
||||
{
|
||||
public int Value { get; set; } = 0;
|
||||
|
||||
public Count(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public partial class CommitDetail : ObservableObject
|
||||
public partial class CommitDetail : ObservableObject, IDisposable
|
||||
{
|
||||
public int ActivePageIndex
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ namespace SourceGit.ViewModels
|
|||
WebLinks = Models.CommitLink.Get(repo.Remotes);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
public void Dispose()
|
||||
{
|
||||
_repo = null;
|
||||
_commit = null;
|
||||
|
|
|
@ -12,7 +12,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class Histories : ObservableObject
|
||||
public class Histories : ObservableObject, IDisposable
|
||||
{
|
||||
public Repository Repo
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ namespace SourceGit.ViewModels
|
|||
private set => SetProperty(ref _navigationId, value);
|
||||
}
|
||||
|
||||
public object DetailContext
|
||||
public IDisposable DetailContext
|
||||
{
|
||||
get => _detailContext;
|
||||
set => SetProperty(ref _detailContext, value);
|
||||
|
@ -98,23 +98,13 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
public void Dispose()
|
||||
{
|
||||
Commits = new List<Models.Commit>();
|
||||
|
||||
Commits = [];
|
||||
_repo = null;
|
||||
_graph = null;
|
||||
_autoSelectedCommit = null;
|
||||
|
||||
if (_detailContext is CommitDetail cd)
|
||||
{
|
||||
cd.Cleanup();
|
||||
}
|
||||
else if (_detailContext is RevisionCompare rc)
|
||||
{
|
||||
rc.Cleanup();
|
||||
}
|
||||
|
||||
_detailContext?.Dispose();
|
||||
_detailContext = null;
|
||||
}
|
||||
|
||||
|
@ -220,7 +210,7 @@ namespace SourceGit.ViewModels
|
|||
else
|
||||
{
|
||||
_repo.SelectedSearchedCommit = null;
|
||||
DetailContext = commits.Count;
|
||||
DetailContext = new Models.Count(commits.Count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1256,7 +1246,7 @@ namespace SourceGit.ViewModels
|
|||
private Models.CommitGraph _graph = null;
|
||||
private Models.Commit _autoSelectedCommit = null;
|
||||
private long _navigationId = 0;
|
||||
private object _detailContext = null;
|
||||
private IDisposable _detailContext = null;
|
||||
|
||||
private Models.Bisect _bisect = null;
|
||||
|
||||
|
|
|
@ -546,9 +546,9 @@ namespace SourceGit.ViewModels
|
|||
_historiesFilterMode = Models.FilterMode.None;
|
||||
|
||||
_watcher?.Dispose();
|
||||
_histories.Cleanup();
|
||||
_workingCopy.Cleanup();
|
||||
_stashesPage.Cleanup();
|
||||
_histories.Dispose();
|
||||
_workingCopy.Dispose();
|
||||
_stashesPage.Dispose();
|
||||
|
||||
_watcher = null;
|
||||
_histories = null;
|
||||
|
|
|
@ -10,7 +10,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class RevisionCompare : ObservableObject
|
||||
public class RevisionCompare : ObservableObject, IDisposable
|
||||
{
|
||||
public object StartPoint
|
||||
{
|
||||
|
@ -83,7 +83,7 @@ namespace SourceGit.ViewModels
|
|||
Task.Run(Refresh);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
public void Dispose()
|
||||
{
|
||||
_repo = null;
|
||||
_startPoint = null;
|
||||
|
|
|
@ -11,7 +11,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class StashesPage : ObservableObject
|
||||
public class StashesPage : ObservableObject, IDisposable
|
||||
{
|
||||
public List<Models.Stash> Stashes
|
||||
{
|
||||
|
@ -125,14 +125,13 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
public void Dispose()
|
||||
{
|
||||
_stashes?.Clear();
|
||||
_changes?.Clear();
|
||||
|
||||
_repo = null;
|
||||
if (_stashes != null)
|
||||
_stashes.Clear();
|
||||
_selectedStash = null;
|
||||
if (_changes != null)
|
||||
_changes.Clear();
|
||||
_selectedChange = null;
|
||||
_diffContext = null;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class WorkingCopy : ObservableObject
|
||||
public class WorkingCopy : ObservableObject, IDisposable
|
||||
{
|
||||
public bool IncludeUntracked
|
||||
{
|
||||
|
@ -210,7 +210,7 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
public void Dispose()
|
||||
{
|
||||
_repo = null;
|
||||
_inProgressContext = null;
|
||||
|
|
|
@ -257,7 +257,7 @@
|
|||
<v:RevisionCompare/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="x:Int32">
|
||||
<DataTemplate DataType="m:Count">
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Path Width="128" Height="128"
|
||||
Data="{StaticResource Icons.Detail}"
|
||||
|
@ -268,7 +268,7 @@
|
|||
Margin="0,16"
|
||||
FontSize="24" FontWeight="Bold"
|
||||
Foreground="{DynamicResource Brush.FG2}"
|
||||
Text="{Binding Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Histories.Selected'}"/>
|
||||
Text="{Binding Value, Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Histories.Selected'}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue