mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-26 21:04:59 +00:00
feature: supports to scan workspace's default clone dir (#1454)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
f657847129
commit
dd01c74d11
4 changed files with 59 additions and 20 deletions
8
src/Models/ScanDir.cs
Normal file
8
src/Models/ScanDir.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -10,27 +11,45 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class ScanRepositories : Popup
|
public class ScanRepositories : Popup
|
||||||
{
|
{
|
||||||
public string RootDir
|
public List<Models.ScanDir> ScanDirs
|
||||||
{
|
{
|
||||||
get;
|
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<Models.ScanDir>();
|
||||||
|
|
||||||
|
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);
|
GetManagedRepositories(Preferences.Instance.RepositoryNodes, _managed);
|
||||||
RootDir = rootDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> Sure()
|
public override Task<bool> Sure()
|
||||||
{
|
{
|
||||||
ProgressDescription = $"Scan repositories under '{RootDir}' ...";
|
ProgressDescription = $"Scan repositories under '{_selected.Path}' ...";
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var watch = new Stopwatch();
|
var watch = new Stopwatch();
|
||||||
watch.Start();
|
watch.Start();
|
||||||
|
|
||||||
var rootDir = new DirectoryInfo(RootDir);
|
var rootDir = new DirectoryInfo(_selected.Path);
|
||||||
var found = new List<string>();
|
var found = new List<string>();
|
||||||
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
|
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
|
||||||
{
|
{
|
||||||
|
@ -159,5 +178,6 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashSet<string> _managed = new();
|
private HashSet<string> _managed = new();
|
||||||
|
private Models.ScanDir _selected = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,22 +150,15 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void ScanDefaultCloneDir()
|
public void ScanDefaultCloneDir()
|
||||||
{
|
{
|
||||||
var defaultCloneDir = Preferences.Instance.GitDefaultCloneDir;
|
if (!Preferences.Instance.IsGitConfigured())
|
||||||
if (string.IsNullOrEmpty(defaultCloneDir))
|
|
||||||
{
|
{
|
||||||
App.RaiseException(string.Empty, "The default clone directory hasn't been configured!");
|
App.RaiseException(string.Empty, App.Text("NotConfigured"));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Directory.Exists(defaultCloneDir))
|
|
||||||
{
|
|
||||||
App.RaiseException(string.Empty, $"The default clone directory '{defaultCloneDir}' does not exist!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var activePage = App.GetLauncher().ActivePage;
|
var activePage = App.GetLauncher().ActivePage;
|
||||||
if (activePage != null && activePage.CanCreatePopup())
|
if (activePage != null && activePage.CanCreatePopup())
|
||||||
activePage.StartPopup(new ScanRepositories(defaultCloneDir));
|
activePage.Popup = new ScanRepositories();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearSearchFilter()
|
public void ClearSearchFilter()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:m="using:SourceGit.Models"
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SourceGit.Views.ScanRepositories"
|
x:Class="SourceGit.Views.ScanRepositories"
|
||||||
|
@ -10,16 +11,33 @@
|
||||||
<TextBlock FontSize="18"
|
<TextBlock FontSize="18"
|
||||||
Classes="bold"
|
Classes="bold"
|
||||||
Text="{DynamicResource Text.ScanRepositories}"/>
|
Text="{DynamicResource Text.ScanRepositories}"/>
|
||||||
<Grid Margin="0,16,0,0" RowDefinitions="32" ColumnDefinitions="130,*">
|
<Grid Margin="0,16,0,0" RowDefinitions="32" ColumnDefinitions="120,*">
|
||||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
Text="{DynamicResource Text.ScanRepositories.RootDir}"/>
|
Text="{DynamicResource Text.ScanRepositories.RootDir}"/>
|
||||||
|
<ComboBox Grid.Row="0" Grid.Column="1"
|
||||||
|
Height="28" Padding="4,0"
|
||||||
|
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||||
|
ItemsSource="{Binding ScanDirs, Mode=OneWay}"
|
||||||
|
SelectedItem="{Binding Selected, Mode=TwoWay}">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate DataType="m:ScanDir">
|
||||||
|
<Grid ColumnDefinitions="20,*,Auto">
|
||||||
|
<Path Grid.Column="0"
|
||||||
|
Width="12" Height="12"
|
||||||
|
Data="{StaticResource Icons.Folder}"
|
||||||
|
Fill="{DynamicResource Brush.FG1}"/>
|
||||||
|
|
||||||
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="Auto,*">
|
<TextBlock Grid.Column="1" Margin="4,0" Text="{Binding Path}" VerticalAlignment="Center"/>
|
||||||
<Path Grid.Column="0" Width="14" Height="14" Margin="0,4,0,0" Data="{StaticResource Icons.Folder}"/>
|
|
||||||
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding RootDir}" Margin="4,0,0,0" TextTrimming="CharacterEllipsis"/>
|
<Border Grid.Column="2" Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center">
|
||||||
</Grid>
|
<TextBlock Classes="primary" Text="{Binding Desc}" Margin="8,0" FontSize="10" Foreground="White"/>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue