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
6 changes: 2 additions & 4 deletions src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Text.RegularExpressions;
using System.Threading;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public partial class Command
Expand Down Expand Up @@ -68,7 +66,7 @@ public bool Exec()
catch (Exception e)
{
if (RaiseError)
Dispatcher.UIThread.Post(() => App.RaiseException(Context, e.Message));
App.RaiseException(Context, e.Message);

Log?.AppendLine(string.Empty);
return false;
Expand Down Expand Up @@ -96,7 +94,7 @@ public bool Exec()
{
var errMsg = string.Join("\n", errs).Trim();
if (!string.IsNullOrEmpty(errMsg))
Dispatcher.UIThread.Post(() => App.RaiseException(Context, errMsg));
App.RaiseException(Context, errMsg);
}

return false;
Expand Down
12 changes: 2 additions & 10 deletions src/Commands/Discard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.IO;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public static class Discard
Expand Down Expand Up @@ -36,10 +34,7 @@ public static void All(string repo, bool includeIgnored, Models.ICommandLog log)
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(repo, $"Failed to discard changes. Reason: {e.Message}");
});
App.RaiseException(repo, $"Failed to discard changes. Reason: {e.Message}");
}

new Reset(repo, "HEAD", "--hard") { Log = log }.Exec();
Expand Down Expand Up @@ -78,10 +73,7 @@ public static void Changes(string repo, List<Models.Change> changes, Models.ICom
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(repo, $"Failed to discard changes. Reason: {e.Message}");
});
App.RaiseException(repo, $"Failed to discard changes. Reason: {e.Message}");
}

if (restores.Count > 0)
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/GenerateCommitMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Text;
using System.Threading;

using Avalonia.Threading;

namespace SourceGit.Commands
{
/// <summary>
Expand Down Expand Up @@ -86,7 +84,7 @@ public void Exec()
}
catch (Exception e)
{
Dispatcher.UIThread.Post(() => App.RaiseException(_repo, $"Failed to generate commit message: {e}"));
App.RaiseException(_repo, $"Failed to generate commit message: {e}");
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/Commands/GitFlow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text;
using Avalonia.Threading;

namespace SourceGit.Commands
{
Expand Down Expand Up @@ -43,7 +42,7 @@ public static bool Start(string repo, Models.GitFlowBranchType type, string name
start.Args = $"flow hotfix start {name}";
break;
default:
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, "Bad git-flow branch type!!!"));
App.RaiseException(repo, "Bad git-flow branch type!!!");
return false;
}

Expand All @@ -68,7 +67,7 @@ public static bool Finish(string repo, Models.GitFlowBranchType type, string nam
builder.Append("hotfix");
break;
default:
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, "Bad git-flow branch type!!!"));
App.RaiseException(repo, "Bad git-flow branch type!!!");
return false;
}

Expand Down
10 changes: 4 additions & 6 deletions src/Commands/MergeTool.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.IO;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public static class MergeTool
Expand All @@ -24,14 +22,14 @@ public static bool OpenForMerge(string repo, int toolType, string toolPath, stri

if (!File.Exists(toolPath))
{
Dispatcher.UIThread.Post(() => App.RaiseException(repo, $"Can NOT find external merge tool in '{toolPath}'!"));
App.RaiseException(repo, $"Can NOT find external merge tool in '{toolPath}'!");
return false;
}

var supported = Models.ExternalMerger.Supported.Find(x => x.Type == toolType);
if (supported == null)
{
Dispatcher.UIThread.Post(() => App.RaiseException(repo, "Invalid merge tool in preference setting!"));
App.RaiseException(repo, "Invalid merge tool in preference setting!");
return false;
}

Expand All @@ -54,14 +52,14 @@ public static bool OpenForDiff(string repo, int toolType, string toolPath, Model

if (!File.Exists(toolPath))
{
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, $"Can NOT find external diff tool in '{toolPath}'!"));
App.RaiseException(repo, $"Can NOT find external diff tool in '{toolPath}'!");
return false;
}

var supported = Models.ExternalMerger.Supported.Find(x => x.Type == toolType);
if (supported == null)
{
Dispatcher.UIThread.Post(() => App.RaiseException(repo, "Invalid merge tool in preference setting!"));
App.RaiseException(repo, "Invalid merge tool in preference setting!");
return false;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Commands/QueryLocalChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public partial class QueryLocalChanges : Command
Expand All @@ -25,7 +23,7 @@ public QueryLocalChanges(string repo, bool includeUntracked = true)
var rs = ReadToEnd();
if (!rs.IsSuccess)
{
Dispatcher.UIThread.Post(() => App.RaiseException(Context, rs.StdErr));
App.RaiseException(Context, rs.StdErr);
return outs;
}

Expand Down
7 changes: 1 addition & 6 deletions src/Commands/SaveChangesAsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Diagnostics;
using System.IO;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public static class SaveChangesAsPatch
Expand Down Expand Up @@ -74,10 +72,7 @@ private static bool ProcessSingleChange(string repo, Models.DiffOption opt, File
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(repo, "Save change to patch failed: " + e.Message);
});
App.RaiseException(repo, "Save change to patch failed: " + e.Message);
return false;
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/Commands/SaveRevisionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Diagnostics;
using System.IO;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public static class SaveRevisionFile
Expand Down Expand Up @@ -53,10 +51,7 @@ private static void ExecCmd(string repo, string args, string outputFile, Stream
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(repo, "Save file failed: " + e.Message);
});
App.RaiseException(repo, "Save file failed: " + e.Message);
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/Commands/UnstageChangesForAmend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Diagnostics;
using System.Text;

using Avalonia.Threading;

namespace SourceGit.Commands
{
public class UnstageChangesForAmend
Expand Down Expand Up @@ -75,16 +73,13 @@ public bool Exec()
proc.Close();

if (!rs)
Dispatcher.UIThread.Invoke(() => App.RaiseException(_repo, err));
App.RaiseException(_repo, err);

return rs;
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(_repo, "Failed to unstage changes: " + e.Message);
});
App.RaiseException(_repo, "Failed to unstage changes: " + e.Message);
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ViewModels/ExecuteCustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void Run(string args)
}
catch (Exception e)
{
CallUIThread(() => App.RaiseException(_repo.FullPath, e.Message));
App.RaiseException(_repo.FullPath, e.Message);
}
}

Expand Down Expand Up @@ -284,12 +284,12 @@ private void RunAndWait(string args, Models.ICommandLog log)
{
var errMsg = builder.ToString().Trim();
if (!string.IsNullOrEmpty(errMsg))
CallUIThread(() => App.RaiseException(_repo.FullPath, errMsg));
App.RaiseException(_repo.FullPath, errMsg);
}
}
catch (Exception e)
{
CallUIThread(() => App.RaiseException(_repo.FullPath, e.Message));
App.RaiseException(_repo.FullPath, e.Message);
}

proc.Close();
Expand Down
7 changes: 7 additions & 0 deletions src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Threading;

using CommunityToolkit.Mvvm.ComponentModel;

Expand Down Expand Up @@ -394,6 +395,12 @@ public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)

public void DispatchNotification(string pageId, string message, bool isError)
{
if (!Dispatcher.UIThread.CheckAccess())
{
Dispatcher.UIThread.Invoke(() => DispatchNotification(pageId, message, isError));
return;
}

var notification = new Models.Notification()
{
IsError = isError,
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/RevisionCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void SaveAsPatch(string saveTo)
{
var succ = Commands.SaveChangesAsPatch.ProcessRevisionCompareChanges(_repo, _changes, GetSHA(_startPoint), GetSHA(_endPoint), saveTo);
if (succ)
Dispatcher.UIThread.Invoke(() => App.SendNotification(_repo, App.Text("SaveAsPatchSuccess")));
App.SendNotification(_repo, App.Text("SaveAsPatchSuccess"));
});
}

Expand Down