Skip to content

Commit 3d8d6f2

Browse files
committed
enhance: startup location when selecting private SSH key
Signed-off-by: leo <longshuang@msn.cn>
1 parent 8fbda46 commit 3d8d6f2

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/Views/AddRemote.axaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using System.IO;
3+
14
using Avalonia.Controls;
25
using Avalonia.Interactivity;
36
using Avalonia.Platform.Storage;
@@ -17,10 +20,17 @@ private async void SelectSSHKey(object _, RoutedEventArgs e)
1720
if (toplevel == null)
1821
return;
1922

23+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
24+
var startupDir = Path.Combine(home, ".ssh");
25+
if (!Directory.Exists(startupDir))
26+
startupDir = home;
27+
28+
var suggestedStartLocation = await toplevel.StorageProvider.TryGetFolderFromPathAsync(startupDir);
2029
var options = new FilePickerOpenOptions()
2130
{
2231
AllowMultiple = false,
23-
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }]
32+
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }],
33+
SuggestedStartLocation = suggestedStartLocation,
2434
};
2535

2636
var selected = await toplevel.StorageProvider.OpenFilePickerAsync(options);

src/Views/Clone.axaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ private async void SelectSSHKey(object _, RoutedEventArgs e)
7373
if (toplevel == null)
7474
return;
7575

76+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
77+
var startupDir = Path.Combine(home, ".ssh");
78+
if (!Directory.Exists(startupDir))
79+
startupDir = home;
80+
81+
var suggestedStartLocation = await toplevel.StorageProvider.TryGetFolderFromPathAsync(startupDir);
7682
var options = new FilePickerOpenOptions()
7783
{
7884
AllowMultiple = false,
79-
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }]
85+
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }],
86+
SuggestedStartLocation = suggestedStartLocation
8087
};
8188

8289
var selected = await toplevel.StorageProvider.OpenFilePickerAsync(options);

src/Views/EditRemote.axaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using System.IO;
3+
14
using Avalonia.Controls;
25
using Avalonia.Interactivity;
36
using Avalonia.Platform.Storage;
@@ -17,10 +20,17 @@ private async void SelectSSHKey(object _, RoutedEventArgs e)
1720
if (toplevel == null)
1821
return;
1922

23+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
24+
var startupDir = Path.Combine(home, ".ssh");
25+
if (!Directory.Exists(startupDir))
26+
startupDir = home;
27+
28+
var suggestedStartLocation = await toplevel.StorageProvider.TryGetFolderFromPathAsync(startupDir);
2029
var options = new FilePickerOpenOptions()
2130
{
2231
AllowMultiple = false,
23-
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }]
32+
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }],
33+
SuggestedStartLocation = suggestedStartLocation
2434
};
2535

2636
var selected = await toplevel.StorageProvider.OpenFilePickerAsync(options);

src/Views/ExecuteCustomAction.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private async void SelectPath(object sender, RoutedEventArgs e)
4747
var options = new FilePickerOpenOptions()
4848
{
4949
AllowMultiple = false,
50-
FileTypeFilter = [new("SSHKey") { Patterns = ["*"] }]
50+
FileTypeFilter = [new("All Files") { Patterns = ["*"] }]
5151
};
5252

5353
var selected = await topLevel.StorageProvider.OpenFilePickerAsync(options);

0 commit comments

Comments
 (0)