Skip to content

Commit 0539a94

Browse files
committed
feature: mark deleted repository and auto remove it after scan default clone dir (#576)
1 parent 9668efb commit 0539a94

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

src/ViewModels/Preference.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ public void SortByRenamedNode(RepositoryNode node)
453453
Save();
454454
}
455455

456+
public void AutoRemoveInvalidNode()
457+
{
458+
var changed = RemoveInvalidRepositoriesRecursive(RepositoryNodes);
459+
if (changed)
460+
Save();
461+
}
462+
456463
public void Save()
457464
{
458465
if (_isLoading)
@@ -567,6 +574,27 @@ private bool RemoveNodeRecursive(RepositoryNode node, List<RepositoryNode> colle
567574
return false;
568575
}
569576

577+
private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
578+
{
579+
bool changed = false;
580+
581+
for (int i = collection.Count - 1; i >= 0; i--)
582+
{
583+
var node = collection[i];
584+
if (node.IsInvalid)
585+
{
586+
collection.RemoveAt(i);
587+
changed = true;
588+
}
589+
else if (!node.IsRepository)
590+
{
591+
changed |= RemoveInvalidRepositoriesRecursive(node.SubNodes);
592+
}
593+
}
594+
595+
return changed;
596+
}
597+
570598
private static Preference _instance = null;
571599
private static bool _isLoading = false;
572600

src/ViewModels/RepositoryNode.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.IO;
23
using System.Text.Json.Serialization;
34

45
using CommunityToolkit.Mvvm.ComponentModel;
@@ -48,6 +49,12 @@ public bool IsVisible
4849
set => SetProperty(ref _isVisible, value);
4950
}
5051

52+
[JsonIgnore]
53+
public bool IsInvalid
54+
{
55+
get => _isRepository && !Directory.Exists(_id);
56+
}
57+
5158
[JsonIgnore]
5259
public int Depth
5360
{

src/ViewModels/ScanRepositories.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ public override Task<bool> Sure()
5656
var group = FindOrCreateGroupRecursive(Preference.Instance.RepositoryNodes, relative);
5757
Preference.Instance.FindOrAddNodeByRepositoryPath(f, group, false);
5858
}
59-
else
60-
{
61-
// Should not happen.
62-
}
6359
}
6460

61+
Preference.Instance.AutoRemoveInvalidNode();
6562
Welcome.Instance.Refresh();
6663
});
6764

src/Views/Welcome.axaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,15 @@
131131
IsChecked="{Binding IsExpanded}"
132132
IsVisible="{Binding !IsRepository}"/>
133133

134-
<TextBlock Grid.Column="2"
135-
Classes="primary"
136-
VerticalAlignment="Center"
137-
Text="{Binding Name}"/>
134+
<StackPanel Grid.Column="2" Orientation="Horizontal">
135+
<TextBlock Classes="primary" VerticalAlignment="Center" Text="{Binding Name}"/>
136+
<Path Margin="2,0,0,0"
137+
Width="12" Height="12"
138+
Data="{StaticResource Icons.Error}"
139+
Fill="Orange"
140+
IsVisible="{Binding IsInvalid}"/>
141+
</StackPanel>
142+
138143
<TextBlock Grid.Column="3"
139144
Classes="primary"
140145
Margin="8,0"

0 commit comments

Comments
 (0)