Skip to content
13 changes: 12 additions & 1 deletion src/ViewModels/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public Clone(string pageId)
_pageId = pageId;
View = new Views.Clone() { DataContext = this };

// Use workspace-specific DefaultCloneDir if available
var activeWorkspace = Preferences.Instance.GetActiveWorkspace();
if (activeWorkspace != null && !string.IsNullOrEmpty(activeWorkspace.DefaultCloneDir))
{
ParentFolder = activeWorkspace.DefaultCloneDir;
}
else
{
ParentFolder = Preferences.Instance.GitDefaultCloneDir;
}

Task.Run(async () =>
{
try
Expand Down Expand Up @@ -170,7 +181,7 @@ public override Task<bool> Sure()
private string _remote = string.Empty;
private bool _useSSH = false;
private string _sshKey = string.Empty;
private string _parentFolder = Preferences.Instance.GitDefaultCloneDir;
private string _parentFolder = string.Empty;
private string _local = string.Empty;
private string _extraArgs = string.Empty;
}
Expand Down
7 changes: 7 additions & 0 deletions src/ViewModels/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public bool RestoreOnStartup
set => SetProperty(ref _restoreOnStartup, value);
}

public string DefaultCloneDir
{
get => _defaultCloneDir;
set => SetProperty(ref _defaultCloneDir, value);
}

public IBrush Brush
{
get => new SolidColorBrush(_color);
Expand All @@ -55,5 +61,6 @@ public IBrush Brush
private uint _color = 4278221015;
private bool _isActive = false;
private bool _restoreOnStartup = true;
private string _defaultCloneDir = string.Empty;
}
}
13 changes: 10 additions & 3 deletions src/Views/ConfigureWorkspace.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,20 @@
<ContentControl Grid.Column="2" Content="{Binding Selected}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:Workspace">
<Grid RowDefinitions="32,32,Auto,Auto">
<Grid RowDefinitions="32,32,32,32,Auto,Auto">
<TextBox Grid.Row="0" CornerRadius="3" Height="28" Text="{Binding Name, Mode=TwoWay}"/>
<CheckBox Grid.Row="1"
Content="{DynamicResource Text.ConfigureWorkspace.Restore}"
IsChecked="{Binding RestoreOnStartup, Mode=TwoWay}"/>
<TextBlock Grid.Row="2" Margin="0,16,0,4" Text="{DynamicResource Text.ConfigureWorkspace.Color}"/>
<v:ColorPicker Grid.Row="3" HorizontalAlignment="Left" Value="{Binding Color, Mode=TwoWay}"/>
<TextBlock Grid.Row="2" Margin="0,16,0,4" Text="{DynamicResource Text.Preferences.Git.DefaultCloneDir}"/>
<Grid Grid.Row="3" ColumnDefinitions="*,Auto">
<TextBox Grid.Column="0" CornerRadius="3" Height="28" Text="{Binding DefaultCloneDir, Mode=TwoWay}"/>
<Button Grid.Column="1" Classes="icon_button" Width="30" Height="30" Click="SelectDefaultCloneDir">
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
</Button>
</Grid>
<TextBlock Grid.Row="4" Margin="0,16,0,4" Text="{DynamicResource Text.ConfigureWorkspace.Color}"/>
<v:ColorPicker Grid.Row="5" HorizontalAlignment="Left" Value="{Binding Color, Mode=TwoWay}"/>
</Grid>
</DataTemplate>
</ContentControl.DataTemplates>
Expand Down
26 changes: 26 additions & 0 deletions src/Views/ConfigureWorkspace.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using System;

namespace SourceGit.Views
{
Expand All @@ -16,5 +19,28 @@ protected override void OnClosing(WindowClosingEventArgs e)
if (!Design.IsDesignMode)
ViewModels.Preferences.Instance.Save();
}

private async void SelectDefaultCloneDir(object _, RoutedEventArgs e)
{
var workspace = DataContext as ViewModels.ConfigureWorkspace;
if (workspace?.Selected == null)
return;

var options = new FolderPickerOpenOptions() { AllowMultiple = false };
try
{
var selected = await StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
{
workspace.Selected.DefaultCloneDir = selected[0].Path.LocalPath;
}
}
catch (Exception ex)
{
App.RaiseException(string.Empty, $"Failed to select default clone directory: {ex.Message}");
}

e.Handled = true;
}
}
}