mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
feature: mark deleted repository and auto remove it after scan default clone dir (#576)
This commit is contained in:
parent
9668efbd8c
commit
0539a94cbe
4 changed files with 45 additions and 8 deletions
|
@ -453,6 +453,13 @@ namespace SourceGit.ViewModels
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AutoRemoveInvalidNode()
|
||||||
|
{
|
||||||
|
var changed = RemoveInvalidRepositoriesRecursive(RepositoryNodes);
|
||||||
|
if (changed)
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
if (_isLoading)
|
if (_isLoading)
|
||||||
|
@ -567,6 +574,27 @@ namespace SourceGit.ViewModels
|
||||||
return false;
|
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 Preference _instance = null;
|
||||||
private static bool _isLoading = false;
|
private static bool _isLoading = false;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
@ -48,6 +49,12 @@ namespace SourceGit.ViewModels
|
||||||
set => SetProperty(ref _isVisible, value);
|
set => SetProperty(ref _isVisible, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool IsInvalid
|
||||||
|
{
|
||||||
|
get => _isRepository && !Directory.Exists(_id);
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int Depth
|
public int Depth
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,12 +56,9 @@ namespace SourceGit.ViewModels
|
||||||
var group = FindOrCreateGroupRecursive(Preference.Instance.RepositoryNodes, relative);
|
var group = FindOrCreateGroupRecursive(Preference.Instance.RepositoryNodes, relative);
|
||||||
Preference.Instance.FindOrAddNodeByRepositoryPath(f, group, false);
|
Preference.Instance.FindOrAddNodeByRepositoryPath(f, group, false);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Should not happen.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Preference.Instance.AutoRemoveInvalidNode();
|
||||||
Welcome.Instance.Refresh();
|
Welcome.Instance.Refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -131,10 +131,15 @@
|
||||||
IsChecked="{Binding IsExpanded}"
|
IsChecked="{Binding IsExpanded}"
|
||||||
IsVisible="{Binding !IsRepository}"/>
|
IsVisible="{Binding !IsRepository}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="2"
|
<StackPanel Grid.Column="2" Orientation="Horizontal">
|
||||||
Classes="primary"
|
<TextBlock Classes="primary" VerticalAlignment="Center" Text="{Binding Name}"/>
|
||||||
VerticalAlignment="Center"
|
<Path Margin="2,0,0,0"
|
||||||
Text="{Binding Name}"/>
|
Width="12" Height="12"
|
||||||
|
Data="{StaticResource Icons.Error}"
|
||||||
|
Fill="Orange"
|
||||||
|
IsVisible="{Binding IsInvalid}"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock Grid.Column="3"
|
<TextBlock Grid.Column="3"
|
||||||
Classes="primary"
|
Classes="primary"
|
||||||
Margin="8,0"
|
Margin="8,0"
|
||||||
|
|
Loading…
Reference in a new issue