mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-02 17:44: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
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public partial class CommitDetail : ObservableObject
|
public partial class CommitDetail : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public int ActivePageIndex
|
public int ActivePageIndex
|
||||||
{
|
{
|
||||||
|
@ -137,7 +137,7 @@ namespace SourceGit.ViewModels
|
||||||
WebLinks = Models.CommitLink.Get(repo.Remotes);
|
WebLinks = Models.CommitLink.Get(repo.Remotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_repo = null;
|
_repo = null;
|
||||||
_commit = null;
|
_commit = null;
|
||||||
|
|
|
@ -12,7 +12,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class Histories : ObservableObject
|
public class Histories : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public Repository Repo
|
public Repository Repo
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ namespace SourceGit.ViewModels
|
||||||
private set => SetProperty(ref _navigationId, value);
|
private set => SetProperty(ref _navigationId, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object DetailContext
|
public IDisposable DetailContext
|
||||||
{
|
{
|
||||||
get => _detailContext;
|
get => _detailContext;
|
||||||
set => SetProperty(ref _detailContext, value);
|
set => SetProperty(ref _detailContext, value);
|
||||||
|
@ -98,23 +98,13 @@ namespace SourceGit.ViewModels
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Commits = new List<Models.Commit>();
|
Commits = [];
|
||||||
|
|
||||||
_repo = null;
|
_repo = null;
|
||||||
_graph = null;
|
_graph = null;
|
||||||
_autoSelectedCommit = null;
|
_autoSelectedCommit = null;
|
||||||
|
_detailContext?.Dispose();
|
||||||
if (_detailContext is CommitDetail cd)
|
|
||||||
{
|
|
||||||
cd.Cleanup();
|
|
||||||
}
|
|
||||||
else if (_detailContext is RevisionCompare rc)
|
|
||||||
{
|
|
||||||
rc.Cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
_detailContext = null;
|
_detailContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +210,7 @@ namespace SourceGit.ViewModels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_repo.SelectedSearchedCommit = null;
|
_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.CommitGraph _graph = null;
|
||||||
private Models.Commit _autoSelectedCommit = null;
|
private Models.Commit _autoSelectedCommit = null;
|
||||||
private long _navigationId = 0;
|
private long _navigationId = 0;
|
||||||
private object _detailContext = null;
|
private IDisposable _detailContext = null;
|
||||||
|
|
||||||
private Models.Bisect _bisect = null;
|
private Models.Bisect _bisect = null;
|
||||||
|
|
||||||
|
|
|
@ -546,9 +546,9 @@ namespace SourceGit.ViewModels
|
||||||
_historiesFilterMode = Models.FilterMode.None;
|
_historiesFilterMode = Models.FilterMode.None;
|
||||||
|
|
||||||
_watcher?.Dispose();
|
_watcher?.Dispose();
|
||||||
_histories.Cleanup();
|
_histories.Dispose();
|
||||||
_workingCopy.Cleanup();
|
_workingCopy.Dispose();
|
||||||
_stashesPage.Cleanup();
|
_stashesPage.Dispose();
|
||||||
|
|
||||||
_watcher = null;
|
_watcher = null;
|
||||||
_histories = null;
|
_histories = null;
|
||||||
|
|
|
@ -10,7 +10,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class RevisionCompare : ObservableObject
|
public class RevisionCompare : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public object StartPoint
|
public object StartPoint
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,7 @@ namespace SourceGit.ViewModels
|
||||||
Task.Run(Refresh);
|
Task.Run(Refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_repo = null;
|
_repo = null;
|
||||||
_startPoint = null;
|
_startPoint = null;
|
||||||
|
|
|
@ -11,7 +11,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class StashesPage : ObservableObject
|
public class StashesPage : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public List<Models.Stash> Stashes
|
public List<Models.Stash> Stashes
|
||||||
{
|
{
|
||||||
|
@ -125,14 +125,13 @@ namespace SourceGit.ViewModels
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_stashes?.Clear();
|
||||||
|
_changes?.Clear();
|
||||||
|
|
||||||
_repo = null;
|
_repo = null;
|
||||||
if (_stashes != null)
|
|
||||||
_stashes.Clear();
|
|
||||||
_selectedStash = null;
|
_selectedStash = null;
|
||||||
if (_changes != null)
|
|
||||||
_changes.Clear();
|
|
||||||
_selectedChange = null;
|
_selectedChange = null;
|
||||||
_diffContext = null;
|
_diffContext = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class WorkingCopy : ObservableObject
|
public class WorkingCopy : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public bool IncludeUntracked
|
public bool IncludeUntracked
|
||||||
{
|
{
|
||||||
|
@ -210,7 +210,7 @@ namespace SourceGit.ViewModels
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_repo = null;
|
_repo = null;
|
||||||
_inProgressContext = null;
|
_inProgressContext = null;
|
||||||
|
|
|
@ -257,7 +257,7 @@
|
||||||
<v:RevisionCompare/>
|
<v:RevisionCompare/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="x:Int32">
|
<DataTemplate DataType="m:Count">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<Path Width="128" Height="128"
|
<Path Width="128" Height="128"
|
||||||
Data="{StaticResource Icons.Detail}"
|
Data="{StaticResource Icons.Detail}"
|
||||||
|
@ -268,7 +268,7 @@
|
||||||
Margin="0,16"
|
Margin="0,16"
|
||||||
FontSize="24" FontWeight="Bold"
|
FontSize="24" FontWeight="Bold"
|
||||||
Foreground="{DynamicResource Brush.FG2}"
|
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>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ContentControl.DataTemplates>
|
</ContentControl.DataTemplates>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue