Skip to content

Commit f14a666

Browse files
massimopaganighmpagani
andauthored
feat: add workspace-specific default clone directory functionality (#1183)
* refactor: improve diff handling for EOL changes and enhance text diff display - Updated `Diff.cs` to streamline whitespace handling in diff arguments. - Enhanced `DiffContext.cs` to check for EOL changes when old and new hashes differ, creating a text diff if necessary. - Added support for showing end-of-line symbols in `TextDiffView.axaml.cs` options. * localization: update translations to include EOF handling in ignore whitespace messages - Modified the ignore whitespace text in multiple language files to specify that EOF changes are also ignored. - Ensured consistency across all localization files for the patch application feature. * revert: Typo in DiffResult comment * revert: update diff arguments to ignore CR at EOL in whitespace handling (like before changes) * revert: update translations to remove EOF references in Text.Apply.IgnoreWS and fixed typo in Text.Diff.IgnoreWhitespace (EOF => EOL) * feat: add workspace-specific default clone directory functionality - Implemented logic in Clone.cs to set ParentFolder based on the active workspace's DefaultCloneDir if available, falling back to the global GitDefaultCloneDir. - Added DefaultCloneDir property to Workspace.cs to store the default clone directory for each workspace. - Updated ConfigureWorkspace.axaml to include a TextBox and Button for setting the DefaultCloneDir in the UI. - Implemented folder selection functionality in ConfigureWorkspace.axaml.cs to allow users to choose a directory for cloning. - This closes issue #1145 --------- Co-authored-by: mpagani <[email protected]>
1 parent e89dbd8 commit f14a666

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

src/ViewModels/Clone.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ public Clone(string pageId)
6464
_pageId = pageId;
6565
View = new Views.Clone() { DataContext = this };
6666

67+
// Use workspace-specific DefaultCloneDir if available
68+
var activeWorkspace = Preferences.Instance.GetActiveWorkspace();
69+
if (activeWorkspace != null && !string.IsNullOrEmpty(activeWorkspace.DefaultCloneDir))
70+
{
71+
ParentFolder = activeWorkspace.DefaultCloneDir;
72+
}
73+
else
74+
{
75+
ParentFolder = Preferences.Instance.GitDefaultCloneDir;
76+
}
77+
6778
Task.Run(async () =>
6879
{
6980
try
@@ -170,7 +181,7 @@ public override Task<bool> Sure()
170181
private string _remote = string.Empty;
171182
private bool _useSSH = false;
172183
private string _sshKey = string.Empty;
173-
private string _parentFolder = Preferences.Instance.GitDefaultCloneDir;
184+
private string _parentFolder = string.Empty;
174185
private string _local = string.Empty;
175186
private string _extraArgs = string.Empty;
176187
}

src/ViewModels/Workspace.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public bool RestoreOnStartup
4646
set => SetProperty(ref _restoreOnStartup, value);
4747
}
4848

49+
public string DefaultCloneDir
50+
{
51+
get => _defaultCloneDir;
52+
set => SetProperty(ref _defaultCloneDir, value);
53+
}
54+
4955
public IBrush Brush
5056
{
5157
get => new SolidColorBrush(_color);
@@ -55,5 +61,6 @@ public IBrush Brush
5561
private uint _color = 4278221015;
5662
private bool _isActive = false;
5763
private bool _restoreOnStartup = true;
64+
private string _defaultCloneDir = string.Empty;
5865
}
5966
}

src/Views/ConfigureWorkspace.axaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,20 @@
9898
<ContentControl Grid.Column="2" Content="{Binding Selected}">
9999
<ContentControl.DataTemplates>
100100
<DataTemplate DataType="vm:Workspace">
101-
<Grid RowDefinitions="32,32,Auto,Auto">
101+
<Grid RowDefinitions="32,32,32,32,Auto,Auto">
102102
<TextBox Grid.Row="0" CornerRadius="3" Height="28" Text="{Binding Name, Mode=TwoWay}"/>
103103
<CheckBox Grid.Row="1"
104104
Content="{DynamicResource Text.ConfigureWorkspace.Restore}"
105105
IsChecked="{Binding RestoreOnStartup, Mode=TwoWay}"/>
106-
<TextBlock Grid.Row="2" Margin="0,16,0,4" Text="{DynamicResource Text.ConfigureWorkspace.Color}"/>
107-
<v:ColorPicker Grid.Row="3" HorizontalAlignment="Left" Value="{Binding Color, Mode=TwoWay}"/>
106+
<TextBlock Grid.Row="2" Margin="0,16,0,4" Text="{DynamicResource Text.Preferences.Git.DefaultCloneDir}"/>
107+
<Grid Grid.Row="3" ColumnDefinitions="*,Auto">
108+
<TextBox Grid.Column="0" CornerRadius="3" Height="28" Text="{Binding DefaultCloneDir, Mode=TwoWay}"/>
109+
<Button Grid.Column="1" Classes="icon_button" Width="30" Height="30" Click="SelectDefaultCloneDir">
110+
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
111+
</Button>
112+
</Grid>
113+
<TextBlock Grid.Row="4" Margin="0,16,0,4" Text="{DynamicResource Text.ConfigureWorkspace.Color}"/>
114+
<v:ColorPicker Grid.Row="5" HorizontalAlignment="Left" Value="{Binding Color, Mode=TwoWay}"/>
108115
</Grid>
109116
</DataTemplate>
110117
</ContentControl.DataTemplates>

src/Views/ConfigureWorkspace.axaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using Avalonia.Controls;
2+
using Avalonia.Interactivity;
3+
using Avalonia.Platform.Storage;
4+
using System;
25

36
namespace SourceGit.Views
47
{
@@ -16,5 +19,28 @@ protected override void OnClosing(WindowClosingEventArgs e)
1619
if (!Design.IsDesignMode)
1720
ViewModels.Preferences.Instance.Save();
1821
}
22+
23+
private async void SelectDefaultCloneDir(object _, RoutedEventArgs e)
24+
{
25+
var workspace = DataContext as ViewModels.ConfigureWorkspace;
26+
if (workspace?.Selected == null)
27+
return;
28+
29+
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
30+
try
31+
{
32+
var selected = await StorageProvider.OpenFolderPickerAsync(options);
33+
if (selected.Count == 1)
34+
{
35+
workspace.Selected.DefaultCloneDir = selected[0].Path.LocalPath;
36+
}
37+
}
38+
catch (Exception ex)
39+
{
40+
App.RaiseException(string.Empty, $"Failed to select default clone directory: {ex.Message}");
41+
}
42+
43+
e.Handled = true;
44+
}
1945
}
2046
}

0 commit comments

Comments
 (0)