Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ViewModels/CommitDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,18 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
return;

var options = new FolderPickerOpenOptions() { AllowMultiple = false };
var selected = await storageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
try
{
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
var selected = await storageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
{
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
}
}
catch (Exception e)
{
App.RaiseException(_repo.FullPath, $"Failed to save file: {e.Message}");
}

ev.Handled = true;
Expand Down
17 changes: 12 additions & 5 deletions src/ViewModels/Histories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,19 @@ public ContextMenu MakeContextMenu(DataGrid datagrid)
return;

var options = new FolderPickerOpenOptions() { AllowMultiple = false };
var selected = await storageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
try
{
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, selected[0].Path.LocalPath).Exec();
if (succ)
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
var selected = await storageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
{
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, selected[0].Path.LocalPath).Exec();
if (succ)
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
}
}
catch (Exception exception)
{
App.RaiseException(_repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
Expand Down
9 changes: 8 additions & 1 deletion src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,14 @@ public void Close()
SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect

var settingsSerialized = JsonSerializer.Serialize(_settings, JsonCodeGen.Default.RepositorySettings);
File.WriteAllText(Path.Combine(_gitDir, "sourcegit.settings"), settingsSerialized);
try
{
File.WriteAllText(Path.Combine(_gitDir, "sourcegit.settings"), settingsSerialized);
}
catch (DirectoryNotFoundException)
{
// Ignore
}
_settings = null;

_watcher?.Dispose();
Expand Down
14 changes: 11 additions & 3 deletions src/Views/AddWorktree.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
Expand All @@ -18,9 +19,16 @@ private async void SelectLocation(object _, RoutedEventArgs e)
return;

var options = new FolderPickerOpenOptions() { AllowMultiple = false };
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
TxtLocation.Text = selected[0].Path.LocalPath;
try
{
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
TxtLocation.Text = selected[0].Path.LocalPath;
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to select location: {exception.Message}");
}

e.Handled = true;
}
Expand Down
14 changes: 11 additions & 3 deletions src/Views/Clone.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
Expand All @@ -18,9 +19,16 @@ private async void SelectParentFolder(object _, RoutedEventArgs e)
if (toplevel == null)
return;

var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
TxtParentFolder.Text = selected[0].Path.LocalPath;
try
{
var selected = await toplevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
TxtParentFolder.Text = selected[0].Path.LocalPath;
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to select parent folder: {exception.Message}");
}

e.Handled = true;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Views/Preference.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,17 @@ private async void SelectGitExecutable(object _, RoutedEventArgs e)
private async void SelectDefaultCloneDir(object _1, RoutedEventArgs _2)
{
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
var selected = await StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
try
{
var selected = await StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
{
ViewModels.Preference.Instance.GitDefaultCloneDir = selected[0].Path.LocalPath;
}
}
catch (Exception e)
{
ViewModels.Preference.Instance.GitDefaultCloneDir = selected[0].Path.LocalPath;
App.RaiseException(string.Empty, $"Failed to select default clone directory: {e.Message}");
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/Views/WelcomeToolbar.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;

using Avalonia.Controls;
Expand Down Expand Up @@ -30,9 +31,16 @@ private async void OpenLocalRepository(object _1, RoutedEventArgs e)
options.SuggestedStartLocation = folder;
}

var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
OpenOrInitRepository(selected[0].Path.LocalPath);
try
{
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
OpenOrInitRepository(selected[0].Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to open repository: {exception.Message}");
}

e.Handled = true;
}
Expand Down