feature: mark deleted repository and auto remove it after scan default clone dir (#576)

This commit is contained in:
leo 2024-10-20 20:42:14 +08:00
parent 9668efbd8c
commit 0539a94cbe
No known key found for this signature in database
4 changed files with 45 additions and 8 deletions

View file

@ -453,6 +453,13 @@ namespace SourceGit.ViewModels
Save();
}
public void AutoRemoveInvalidNode()
{
var changed = RemoveInvalidRepositoriesRecursive(RepositoryNodes);
if (changed)
Save();
}
public void Save()
{
if (_isLoading)
@ -567,6 +574,27 @@ namespace SourceGit.ViewModels
return false;
}
private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
{
bool changed = false;
for (int i = collection.Count - 1; i >= 0; i--)
{
var node = collection[i];
if (node.IsInvalid)
{
collection.RemoveAt(i);
changed = true;
}
else if (!node.IsRepository)
{
changed |= RemoveInvalidRepositoriesRecursive(node.SubNodes);
}
}
return changed;
}
private static Preference _instance = null;
private static bool _isLoading = false;

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Text.Json.Serialization;
using CommunityToolkit.Mvvm.ComponentModel;
@ -48,6 +49,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _isVisible, value);
}
[JsonIgnore]
public bool IsInvalid
{
get => _isRepository && !Directory.Exists(_id);
}
[JsonIgnore]
public int Depth
{

View file

@ -56,12 +56,9 @@ namespace SourceGit.ViewModels
var group = FindOrCreateGroupRecursive(Preference.Instance.RepositoryNodes, relative);
Preference.Instance.FindOrAddNodeByRepositoryPath(f, group, false);
}
else
{
// Should not happen.
}
}
Preference.Instance.AutoRemoveInvalidNode();
Welcome.Instance.Refresh();
});

View file

@ -131,10 +131,15 @@
IsChecked="{Binding IsExpanded}"
IsVisible="{Binding !IsRepository}"/>
<TextBlock Grid.Column="2"
Classes="primary"
VerticalAlignment="Center"
Text="{Binding Name}"/>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<TextBlock Classes="primary" VerticalAlignment="Center" Text="{Binding Name}"/>
<Path Margin="2,0,0,0"
Width="12" Height="12"
Data="{StaticResource Icons.Error}"
Fill="Orange"
IsVisible="{Binding IsInvalid}"/>
</StackPanel>
<TextBlock Grid.Column="3"
Classes="primary"
Margin="8,0"