mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-07 11:54: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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue