Skip to content

Commit dd01c74

Browse files
committed
feature: supports to scan workspace's default clone dir (#1454)
Signed-off-by: leo <[email protected]>
1 parent f657847 commit dd01c74

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

src/Models/ScanDir.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SourceGit.Models
2+
{
3+
public record ScanDir(string path, string desc)
4+
{
5+
public string Path { get; set; } = path;
6+
public string Desc { get; set; } = desc;
7+
}
8+
}

src/ViewModels/ScanRepositories.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.Diagnostics;
45
using System.IO;
56
using System.Threading.Tasks;
@@ -10,27 +11,45 @@ namespace SourceGit.ViewModels
1011
{
1112
public class ScanRepositories : Popup
1213
{
13-
public string RootDir
14+
public List<Models.ScanDir> ScanDirs
1415
{
1516
get;
1617
}
1718

18-
public ScanRepositories(string rootDir)
19+
[Required(ErrorMessage = "Scan directory is required!!!")]
20+
public Models.ScanDir Selected
1921
{
22+
get => _selected;
23+
set => SetProperty(ref _selected, value, true);
24+
}
25+
26+
public ScanRepositories()
27+
{
28+
ScanDirs = new List<Models.ScanDir>();
29+
30+
if (!string.IsNullOrEmpty(Preferences.Instance.GitDefaultCloneDir))
31+
ScanDirs.Add(new Models.ScanDir(Preferences.Instance.GitDefaultCloneDir, "Global"));
32+
33+
var workspace = Preferences.Instance.GetActiveWorkspace();
34+
if (!string.IsNullOrEmpty(workspace.DefaultCloneDir))
35+
ScanDirs.Add(new Models.ScanDir(workspace.DefaultCloneDir, "Workspace"));
36+
37+
if (ScanDirs.Count > 0)
38+
_selected = ScanDirs[0];
39+
2040
GetManagedRepositories(Preferences.Instance.RepositoryNodes, _managed);
21-
RootDir = rootDir;
2241
}
2342

2443
public override Task<bool> Sure()
2544
{
26-
ProgressDescription = $"Scan repositories under '{RootDir}' ...";
45+
ProgressDescription = $"Scan repositories under '{_selected.Path}' ...";
2746

2847
return Task.Run(() =>
2948
{
3049
var watch = new Stopwatch();
3150
watch.Start();
3251

33-
var rootDir = new DirectoryInfo(RootDir);
52+
var rootDir = new DirectoryInfo(_selected.Path);
3453
var found = new List<string>();
3554
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
3655
{
@@ -159,5 +178,6 @@ private RepositoryNode FindOrCreateGroup(List<RepositoryNode> collection, string
159178
}
160179

161180
private HashSet<string> _managed = new();
181+
private Models.ScanDir _selected = null;
162182
}
163183
}

src/ViewModels/Welcome.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,15 @@ public void OpenTerminal()
150150

151151
public void ScanDefaultCloneDir()
152152
{
153-
var defaultCloneDir = Preferences.Instance.GitDefaultCloneDir;
154-
if (string.IsNullOrEmpty(defaultCloneDir))
155-
{
156-
App.RaiseException(string.Empty, "The default clone directory hasn't been configured!");
157-
return;
158-
}
159-
160-
if (!Directory.Exists(defaultCloneDir))
153+
if (!Preferences.Instance.IsGitConfigured())
161154
{
162-
App.RaiseException(string.Empty, $"The default clone directory '{defaultCloneDir}' does not exist!");
155+
App.RaiseException(string.Empty, App.Text("NotConfigured"));
163156
return;
164157
}
165158

166159
var activePage = App.GetLauncher().ActivePage;
167160
if (activePage != null && activePage.CanCreatePopup())
168-
activePage.StartPopup(new ScanRepositories(defaultCloneDir));
161+
activePage.Popup = new ScanRepositories();
169162
}
170163

171164
public void ClearSearchFilter()

src/Views/ScanRepositories.axaml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:m="using:SourceGit.Models"
56
xmlns:vm="using:SourceGit.ViewModels"
67
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
78
x:Class="SourceGit.Views.ScanRepositories"
@@ -10,16 +11,33 @@
1011
<TextBlock FontSize="18"
1112
Classes="bold"
1213
Text="{DynamicResource Text.ScanRepositories}"/>
13-
<Grid Margin="0,16,0,0" RowDefinitions="32" ColumnDefinitions="130,*">
14+
<Grid Margin="0,16,0,0" RowDefinitions="32" ColumnDefinitions="120,*">
1415
<TextBlock Grid.Row="0" Grid.Column="0"
1516
HorizontalAlignment="Right" VerticalAlignment="Center"
1617
Margin="0,0,8,0"
1718
Text="{DynamicResource Text.ScanRepositories.RootDir}"/>
19+
<ComboBox Grid.Row="0" Grid.Column="1"
20+
Height="28" Padding="4,0"
21+
VerticalAlignment="Center" HorizontalAlignment="Stretch"
22+
ItemsSource="{Binding ScanDirs, Mode=OneWay}"
23+
SelectedItem="{Binding Selected, Mode=TwoWay}">
24+
<ComboBox.ItemTemplate>
25+
<DataTemplate DataType="m:ScanDir">
26+
<Grid ColumnDefinitions="20,*,Auto">
27+
<Path Grid.Column="0"
28+
Width="12" Height="12"
29+
Data="{StaticResource Icons.Folder}"
30+
Fill="{DynamicResource Brush.FG1}"/>
1831

19-
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="Auto,*">
20-
<Path Grid.Column="0" Width="14" Height="14" Margin="0,4,0,0" Data="{StaticResource Icons.Folder}"/>
21-
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding RootDir}" Margin="4,0,0,0" TextTrimming="CharacterEllipsis"/>
22-
</Grid>
32+
<TextBlock Grid.Column="1" Margin="4,0" Text="{Binding Path}" VerticalAlignment="Center"/>
33+
34+
<Border Grid.Column="2" Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center">
35+
<TextBlock Classes="primary" Text="{Binding Desc}" Margin="8,0" FontSize="10" Foreground="White"/>
36+
</Border>
37+
</Grid>
38+
</DataTemplate>
39+
</ComboBox.ItemTemplate>
40+
</ComboBox>
2341
</Grid>
2442
</StackPanel>
2543
</UserControl>

0 commit comments

Comments
 (0)