Skip to content

Commit 9c3294c

Browse files
committed
optimize<*>: App.RaiseException should be called in UIThread; add default progress description for popups;
1 parent dc0b33b commit 9c3294c

35 files changed

Lines changed: 100 additions & 34 deletions

src/Commands/GitFlow.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using Avalonia.Threading;
2+
using System.Collections.Generic;
23

34
namespace SourceGit.Commands {
45
public class GitFlow : Command {
@@ -42,7 +43,9 @@ public bool Start(Models.GitFlowBranchType type, string name) {
4243
Args = $"flow hotfix start {name}";
4344
break;
4445
default:
45-
App.RaiseException(Context, "Bad branch type!!!");
46+
Dispatcher.UIThread.Invoke(() => {
47+
App.RaiseException(Context, "Bad branch type!!!");
48+
});
4649
return false;
4750
}
4851

@@ -62,7 +65,9 @@ public bool Finish(Models.GitFlowBranchType type, string name, bool keepBranch)
6265
Args = $"flow hotfix finish {option} {name} -m \"HOTFIX_DONE\"";
6366
break;
6467
default:
65-
App.RaiseException(Context, "Bad branch type!!!");
68+
Dispatcher.UIThread.Invoke(() => {
69+
App.RaiseException(Context, "Bad branch type!!!");
70+
});
6671
return false;
6772
}
6873

src/Commands/MergeTool.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
using System.IO;
1+
using Avalonia.Threading;
2+
using System.IO;
23

34
namespace SourceGit.Commands {
45
public static class MergeTool {
56
public static bool OpenForMerge(string repo, string tool, string mergeCmd, string file) {
67
if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(mergeCmd)) {
7-
App.RaiseException(repo, "Invalid external merge tool settings!");
8+
Dispatcher.UIThread.Invoke(() => {
9+
App.RaiseException(repo, "Invalid external merge tool settings!");
10+
});
811
return false;
912
}
1013

1114
if (!File.Exists(tool)) {
12-
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
15+
Dispatcher.UIThread.Invoke(() => {
16+
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
17+
});
1318
return false;
1419
}
1520

@@ -22,12 +27,16 @@ public static bool OpenForMerge(string repo, string tool, string mergeCmd, strin
2227

2328
public static bool OpenForDiff(string repo, string tool, string diffCmd, Models.DiffOption option) {
2429
if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(diffCmd)) {
25-
App.RaiseException(repo, "Invalid external merge tool settings!");
30+
Dispatcher.UIThread.Invoke(() => {
31+
App.RaiseException(repo, "Invalid external merge tool settings!");
32+
});
2633
return false;
2734
}
2835

2936
if (!File.Exists(tool)) {
30-
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
37+
Dispatcher.UIThread.Invoke(() => {
38+
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
39+
});
3140
return false;
3241
}
3342

src/Commands/SaveChangesAsPatch.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Avalonia.Threading;
2+
using System;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
@@ -35,7 +36,9 @@ private static bool ProcessSingleChange(string repo, Models.DiffOption opt, File
3536

3637
return rs;
3738
} catch (Exception e) {
38-
App.RaiseException(repo, "Save change to patch failed: " + e.Message);
39+
Dispatcher.UIThread.Invoke(() => {
40+
App.RaiseException(repo, "Save change to patch failed: " + e.Message);
41+
});
3942
return false;
4043
}
4144
}

src/Commands/SaveRevisionFile.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Avalonia.Threading;
2+
using System;
23
using System.Diagnostics;
34
using System.IO;
45

@@ -51,7 +52,9 @@ private static bool ExecCmd(string repo, string args, string outputFile, string
5152

5253
return rs;
5354
} catch (Exception e) {
54-
App.RaiseException(repo, "Save file failed: " + e.Message);
55+
Dispatcher.UIThread.Invoke(() => {
56+
App.RaiseException(repo, "Save file failed: " + e.Message);
57+
});
5558
return false;
5659
}
5760
}

src/ViewModels/AddRemote.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public static ValidationResult ValidateRemoteURL(string url, ValidationContext c
5757

5858
public override Task<bool> Sure() {
5959
_repo.SetWatcherEnabled(false);
60+
ProgressDescription = "Adding remote ...";
61+
6062
return Task.Run(() => {
61-
SetProgressDescription("Adding remote ...");
6263
var succ = new Commands.Remote(_repo.FullPath).Add(_name, _url);
6364
if (succ) {
6465
SetProgressDescription("Fetching from added remote ...");

src/ViewModels/AddSubmodule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static ValidationResult ValidateRelativePath(string path, ValidationConte
4747

4848
public override Task<bool> Sure() {
4949
_repo.SetWatcherEnabled(false);
50+
ProgressDescription = "Adding submodule...";
51+
5052
return Task.Run(() => {
5153
var succ = new Commands.Submodule(_repo.FullPath).Add(_url, _relativePath, Recursive, SetProgressDescription);
5254
CallUIThread(() => _repo.SetWatcherEnabled(true));

src/ViewModels/Apply.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public static ValidationResult ValidatePatchFile(string file, ValidationContext
5151

5252
public override Task<bool> Sure() {
5353
_repo.SetWatcherEnabled(false);
54+
ProgressDescription = "Apply patch...";
55+
5456
return Task.Run(() => {
5557
var succ = new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg).Exec();
5658
CallUIThread(() => _repo.SetWatcherEnabled(true));

src/ViewModels/Archive.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ public Archive(Repository repo, Models.Tag tag) {
4242

4343
public override Task<bool> Sure() {
4444
_repo.SetWatcherEnabled(false);
45+
ProgressDescription = "Archiving ...";
46+
4547
return Task.Run(() => {
4648
var succ = new Commands.Archive(_repo.FullPath, _revision, _saveFile, SetProgressDescription).Exec();
47-
CallUIThread(() => _repo.SetWatcherEnabled(true));
49+
CallUIThread(() => {
50+
_repo.SetWatcherEnabled(true);
51+
if (succ) App.SendNotification(_repo.FullPath, $"Save archive to : {_saveFile}");
52+
});
53+
4854
return succ;
4955
});
5056
}

src/ViewModels/Checkout.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public Checkout(Repository repo, string branch) {
1515

1616
public override Task<bool> Sure() {
1717
_repo.SetWatcherEnabled(false);
18+
ProgressDescription = $"Checkout '{Branch}' ...";
19+
1820
return Task.Run(() => {
19-
SetProgressDescription($"Checkout '{Branch}' ...");
2021
var succ = new Commands.Checkout(_repo.FullPath).Branch(Branch, SetProgressDescription);
2122
CallUIThread(() => _repo.SetWatcherEnabled(true));
2223
return succ;

src/ViewModels/CherryPick.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public CherryPick(Repository repo, Models.Commit target) {
2121

2222
public override Task<bool> Sure() {
2323
_repo.SetWatcherEnabled(false);
24+
ProgressDescription = $"Cherry-Pick commit '{Target.SHA}' ...";
25+
2426
return Task.Run(() => {
25-
SetProgressDescription($"Cherry-Pick commit '{Target.SHA}' ...");
2627
var succ = new Commands.CherryPick(_repo.FullPath, Target.SHA, !AutoCommit).Exec();
2728
CallUIThread(() => _repo.SetWatcherEnabled(true));
2829
return succ;

0 commit comments

Comments
 (0)