From dd01c74d11edf405cd12186c3c9a75e37526b72e Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 24 Jun 2025 21:19:52 +0800 Subject: [PATCH] feature: supports to scan workspace's default clone dir (#1454) Signed-off-by: leo --- src/Models/ScanDir.cs | 8 ++++++++ src/ViewModels/ScanRepositories.cs | 30 +++++++++++++++++++++++++----- src/ViewModels/Welcome.cs | 13 +++---------- src/Views/ScanRepositories.axaml | 28 +++++++++++++++++++++++----- 4 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 src/Models/ScanDir.cs diff --git a/src/Models/ScanDir.cs b/src/Models/ScanDir.cs new file mode 100644 index 00000000..eb78a79c --- /dev/null +++ b/src/Models/ScanDir.cs @@ -0,0 +1,8 @@ +namespace SourceGit.Models +{ + public record ScanDir(string path, string desc) + { + public string Path { get; set; } = path; + public string Desc { get; set; } = desc; + } +} diff --git a/src/ViewModels/ScanRepositories.cs b/src/ViewModels/ScanRepositories.cs index 4d05a996..fe5cd19e 100644 --- a/src/ViewModels/ScanRepositories.cs +++ b/src/ViewModels/ScanRepositories.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.IO; using System.Threading.Tasks; @@ -10,27 +11,45 @@ namespace SourceGit.ViewModels { public class ScanRepositories : Popup { - public string RootDir + public List ScanDirs { get; } - public ScanRepositories(string rootDir) + [Required(ErrorMessage = "Scan directory is required!!!")] + public Models.ScanDir Selected { + get => _selected; + set => SetProperty(ref _selected, value, true); + } + + public ScanRepositories() + { + ScanDirs = new List(); + + if (!string.IsNullOrEmpty(Preferences.Instance.GitDefaultCloneDir)) + ScanDirs.Add(new Models.ScanDir(Preferences.Instance.GitDefaultCloneDir, "Global")); + + var workspace = Preferences.Instance.GetActiveWorkspace(); + if (!string.IsNullOrEmpty(workspace.DefaultCloneDir)) + ScanDirs.Add(new Models.ScanDir(workspace.DefaultCloneDir, "Workspace")); + + if (ScanDirs.Count > 0) + _selected = ScanDirs[0]; + GetManagedRepositories(Preferences.Instance.RepositoryNodes, _managed); - RootDir = rootDir; } public override Task Sure() { - ProgressDescription = $"Scan repositories under '{RootDir}' ..."; + ProgressDescription = $"Scan repositories under '{_selected.Path}' ..."; return Task.Run(() => { var watch = new Stopwatch(); watch.Start(); - var rootDir = new DirectoryInfo(RootDir); + var rootDir = new DirectoryInfo(_selected.Path); var found = new List(); GetUnmanagedRepositories(rootDir, found, new EnumerationOptions() { @@ -159,5 +178,6 @@ namespace SourceGit.ViewModels } private HashSet _managed = new(); + private Models.ScanDir _selected = null; } } diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index b726c413..78dfefba 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -150,22 +150,15 @@ namespace SourceGit.ViewModels public void ScanDefaultCloneDir() { - var defaultCloneDir = Preferences.Instance.GitDefaultCloneDir; - if (string.IsNullOrEmpty(defaultCloneDir)) + if (!Preferences.Instance.IsGitConfigured()) { - App.RaiseException(string.Empty, "The default clone directory hasn't been configured!"); - return; - } - - if (!Directory.Exists(defaultCloneDir)) - { - App.RaiseException(string.Empty, $"The default clone directory '{defaultCloneDir}' does not exist!"); + App.RaiseException(string.Empty, App.Text("NotConfigured")); return; } var activePage = App.GetLauncher().ActivePage; if (activePage != null && activePage.CanCreatePopup()) - activePage.StartPopup(new ScanRepositories(defaultCloneDir)); + activePage.Popup = new ScanRepositories(); } public void ClearSearchFilter() diff --git a/src/Views/ScanRepositories.axaml b/src/Views/ScanRepositories.axaml index 90274700..b9e87b46 100644 --- a/src/Views/ScanRepositories.axaml +++ b/src/Views/ScanRepositories.axaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.ScanRepositories" @@ -10,16 +11,33 @@ - + + + + + + - - - - + + + + + + + + +