mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 13:51:53 +08:00
feature: supports to scan custom directory (#1696)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -733,6 +733,7 @@
|
||||
<x:String x:Key="Text.SaveAsPatchSuccess" xml:space="preserve">Patch has been saved successfully!</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories" xml:space="preserve">Scan Repositories</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories.RootDir" xml:space="preserve">Root Dir:</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories.UseCustomDir" xml:space="preserve">Scan another custom directory</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate" xml:space="preserve">Check for Updates...</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate.Available" xml:space="preserve">New version of this software is available: </x:String>
|
||||
<x:String x:Key="Text.SelfUpdate.Error" xml:space="preserve">Check for updates failed!</x:String>
|
||||
|
||||
@@ -737,6 +737,7 @@
|
||||
<x:String x:Key="Text.SaveAsPatchSuccess" xml:space="preserve">补丁已成功保存!</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories" xml:space="preserve">扫描仓库</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories.RootDir" xml:space="preserve">根路径 :</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories.UseCustomDir" xml:space="preserve">扫描其他自定义路径</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate" xml:space="preserve">检测更新...</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate.Available" xml:space="preserve">检测到软件有版本更新: </x:String>
|
||||
<x:String x:Key="Text.SelfUpdate.Error" xml:space="preserve">获取最新版本信息失败!</x:String>
|
||||
|
||||
@@ -737,6 +737,7 @@
|
||||
<x:String x:Key="Text.SaveAsPatchSuccess" xml:space="preserve">修補檔已成功儲存!</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories" xml:space="preserve">掃描存放庫</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories.RootDir" xml:space="preserve">頂層目錄:</x:String>
|
||||
<x:String x:Key="Text.ScanRepositories.UseCustomDir" xml:space="preserve">掃描其他自訂目錄</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate" xml:space="preserve">檢查更新...</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate.Available" xml:space="preserve">軟體有版本更新:</x:String>
|
||||
<x:String x:Key="Text.SelfUpdate.Error" xml:space="preserve">取得最新版本資訊失敗!</x:String>
|
||||
|
||||
@@ -8,6 +8,18 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
public class ScanRepositories : Popup
|
||||
{
|
||||
public bool UseCustomDir
|
||||
{
|
||||
get => _useCustomDir;
|
||||
set => SetProperty(ref _useCustomDir, value);
|
||||
}
|
||||
|
||||
public string CustomDir
|
||||
{
|
||||
get => _customDir;
|
||||
set => SetProperty(ref _customDir, value);
|
||||
}
|
||||
|
||||
public List<Models.ScanDir> ScanDirs
|
||||
{
|
||||
get;
|
||||
@@ -33,16 +45,28 @@ namespace SourceGit.ViewModels
|
||||
|
||||
if (ScanDirs.Count > 0)
|
||||
_selected = ScanDirs[0];
|
||||
else
|
||||
_useCustomDir = true;
|
||||
|
||||
GetManagedRepositories(Preferences.Instance.RepositoryNodes, _managed);
|
||||
}
|
||||
|
||||
public override async Task<bool> Sure()
|
||||
{
|
||||
ProgressDescription = $"Scan repositories under '{_selected.Path}' ...";
|
||||
var selectedDir = _useCustomDir ? _customDir : _selected?.Path;
|
||||
if (string.IsNullOrEmpty(selectedDir))
|
||||
{
|
||||
App.RaiseException(null, "Missing root directory to scan!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(selectedDir))
|
||||
return true;
|
||||
|
||||
ProgressDescription = $"Scan repositories under '{selectedDir}' ...";
|
||||
|
||||
var minDelay = Task.Delay(500);
|
||||
var rootDir = new DirectoryInfo(_selected.Path);
|
||||
var rootDir = new DirectoryInfo(selectedDir);
|
||||
var found = new List<string>();
|
||||
|
||||
await GetUnmanagedRepositoriesAsync(rootDir, found, new EnumerationOptions()
|
||||
@@ -162,6 +186,8 @@ namespace SourceGit.ViewModels
|
||||
}
|
||||
|
||||
private HashSet<string> _managed = new();
|
||||
private bool _useCustomDir = false;
|
||||
private string _customDir = string.Empty;
|
||||
private Models.ScanDir _selected = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<TextBlock FontSize="18"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.ScanRepositories}"/>
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32" ColumnDefinitions="120,*">
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="120,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
@@ -20,7 +20,8 @@
|
||||
Height="28" Padding="4,0"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding ScanDirs, Mode=OneWay}"
|
||||
SelectedItem="{Binding Selected, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Selected, Mode=TwoWay}"
|
||||
IsVisible="{Binding !UseCustomDir, Mode=OneWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="m:ScanDir">
|
||||
<Grid ColumnDefinitions="20,*,Auto">
|
||||
@@ -38,6 +39,21 @@
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<TextBox Grid.Row="0" Grid.Column="1"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding CustomDir, Mode=TwoWay}"
|
||||
IsVisible="{Binding UseCustomDir, Mode=OneWay}">
|
||||
<TextBox.InnerRightContent>
|
||||
<Button Classes="icon_button" Width="30" Height="30" Click="OnSelectRootDir">
|
||||
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
|
||||
</Button>
|
||||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
|
||||
<CheckBox Grid.Row="1" Grid.Column="1"
|
||||
Content="{DynamicResource Text.ScanRepositories.UseCustomDir}"
|
||||
IsChecked="{Binding UseCustomDir, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using System;
|
||||
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
@@ -8,5 +12,33 @@ namespace SourceGit.Views
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void OnSelectRootDir(object _, RoutedEventArgs e)
|
||||
{
|
||||
var provider = TopLevel.GetTopLevel(this)?.StorageProvider;
|
||||
if (provider == null)
|
||||
return;
|
||||
|
||||
if (DataContext is not ViewModels.ScanRepositories vm)
|
||||
return;
|
||||
|
||||
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
||||
try
|
||||
{
|
||||
var selected = await provider.OpenFolderPickerAsync(options);
|
||||
if (selected.Count == 1)
|
||||
{
|
||||
var folder = selected[0];
|
||||
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
|
||||
vm.CustomDir = folderPath;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
App.RaiseException(string.Empty, $"Failed to select root scanning directory: {ex.Message}");
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user