Skip to content

Commit 1522da8

Browse files
committed
refactor: more changes to use async methods
Signed-off-by: leo <[email protected]>
1 parent f0adb02 commit 1522da8

12 files changed

+113
-96
lines changed

src/ViewModels/Histories.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void Select(IList commits)
193193
}
194194
}
195195

196-
public bool CheckoutBranchByDecorator(Models.Decorator decorator)
196+
public async Task<bool> CheckoutBranchByDecoratorAsync(Models.Decorator decorator)
197197
{
198198
if (decorator == null)
199199
return false;
@@ -208,7 +208,7 @@ public bool CheckoutBranchByDecorator(Models.Decorator decorator)
208208
if (b == null)
209209
return false;
210210

211-
_repo.CheckoutBranch(b);
211+
await _repo.CheckoutBranchAsync(b);
212212
return true;
213213
}
214214

@@ -231,7 +231,7 @@ public bool CheckoutBranchByDecorator(Models.Decorator decorator)
231231
}
232232
else if (!lb.IsCurrent)
233233
{
234-
_repo.CheckoutBranch(lb);
234+
await _repo.CheckoutBranchAsync(lb);
235235
}
236236

237237
return true;
@@ -240,7 +240,7 @@ public bool CheckoutBranchByDecorator(Models.Decorator decorator)
240240
return false;
241241
}
242242

243-
public void CheckoutBranchByCommit(Models.Commit commit)
243+
public async Task CheckoutBranchByCommitAsync(Models.Commit commit)
244244
{
245245
if (commit.IsCurrentHead)
246246
return;
@@ -254,7 +254,7 @@ public void CheckoutBranchByCommit(Models.Commit commit)
254254
if (b == null)
255255
continue;
256256

257-
_repo.CheckoutBranch(b);
257+
await _repo.CheckoutBranchAsync(b);
258258
return;
259259
}
260260

src/ViewModels/LauncherPage.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,7 @@ public bool CanCreatePopup()
8989
return _popup is not { InProgress: true };
9090
}
9191

92-
public void StartPopup(Popup popup)
93-
{
94-
Popup = popup;
95-
96-
if (popup.CanStartDirectly())
97-
ProcessPopup();
98-
}
99-
100-
public async void ProcessPopup()
92+
public async Task ProcessPopupAsync()
10193
{
10294
if (_popup is { InProgress: false } dump)
10395
{

src/ViewModels/Repository.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,13 @@ public void ShowPopup(Popup popup)
636636
page.Popup = popup;
637637
}
638638

639-
public void ShowAndStartPopup(Popup popup)
639+
public async Task ShowAndStartPopupAsync(Popup popup)
640640
{
641-
GetOwnerPage()?.StartPopup(popup);
641+
var page = GetOwnerPage();
642+
page.Popup = popup;
643+
644+
if (popup.CanStartDirectly())
645+
await page.ProcessPopupAsync();
642646
}
643647

644648
public bool IsGitFlowEnabled()
@@ -802,7 +806,7 @@ public void RefreshAll()
802806
});
803807
}
804808

805-
public void Fetch(bool autoStart)
809+
public async Task FetchAsync(bool autoStart)
806810
{
807811
if (!CanCreatePopup())
808812
return;
@@ -814,12 +818,12 @@ public void Fetch(bool autoStart)
814818
}
815819

816820
if (autoStart)
817-
ShowAndStartPopup(new Fetch(this));
821+
await ShowAndStartPopupAsync(new Fetch(this));
818822
else
819823
ShowPopup(new Fetch(this));
820824
}
821825

822-
public void Pull(bool autoStart)
826+
public async Task PullAsync(bool autoStart)
823827
{
824828
if (IsBare || !CanCreatePopup())
825829
return;
@@ -838,12 +842,12 @@ public void Pull(bool autoStart)
838842

839843
var pull = new Pull(this, null);
840844
if (autoStart && pull.SelectedBranch != null)
841-
ShowAndStartPopup(pull);
845+
await ShowAndStartPopupAsync(pull);
842846
else
843847
ShowPopup(pull);
844848
}
845849

846-
public void Push(bool autoStart)
850+
public async Task PushAsync(bool autoStart)
847851
{
848852
if (!CanCreatePopup())
849853
return;
@@ -861,7 +865,7 @@ public void Push(bool autoStart)
861865
}
862866

863867
if (autoStart)
864-
ShowAndStartPopup(new Push(this, null));
868+
await ShowAndStartPopupAsync(new Push(this, null));
865869
else
866870
ShowPopup(new Push(this, null));
867871
}
@@ -872,7 +876,7 @@ public void ApplyPatch()
872876
ShowPopup(new Apply(this));
873877
}
874878

875-
public void ExecCustomAction(Models.CustomAction action, object scope)
879+
public async Task ExecCustomActionAsync(Models.CustomAction action, object scope)
876880
{
877881
if (!CanCreatePopup())
878882
return;
@@ -886,15 +890,15 @@ public void ExecCustomAction(Models.CustomAction action, object scope)
886890
};
887891

888892
if (action.Controls.Count == 0)
889-
ShowAndStartPopup(popup);
893+
await ShowAndStartPopupAsync(popup);
890894
else
891895
ShowPopup(popup);
892896
}
893897

894-
public void Cleanup()
898+
public async Task CleanupAsync()
895899
{
896900
if (CanCreatePopup())
897-
ShowAndStartPopup(new Cleanup(this));
901+
await ShowAndStartPopupAsync(new Cleanup(this));
898902
}
899903

900904
public void ClearFilter()
@@ -1126,9 +1130,9 @@ public void SetBranchFilterMode(BranchTreeNode node, Models.FilterMode mode, boo
11261130
RefreshHistoriesFilters(refresh);
11271131
}
11281132

1129-
public void StashAll(bool autoStart)
1133+
public async Task StashAllAsync(bool autoStart)
11301134
{
1131-
_workingCopy?.StashAll(autoStart);
1135+
await _workingCopy?.StashAllAsync(autoStart);
11321136
}
11331137

11341138
public async Task SkipMergeAsync()
@@ -1441,7 +1445,7 @@ public void CreateNewBranch()
14411445
ShowPopup(new CreateBranch(this, _currentBranch));
14421446
}
14431447

1444-
public void CheckoutBranch(Models.Branch branch)
1448+
public async Task CheckoutBranchAsync(Models.Branch branch)
14451449
{
14461450
if (branch.IsLocal)
14471451
{
@@ -1464,7 +1468,7 @@ public void CheckoutBranch(Models.Branch branch)
14641468
if (_localChangesCount > 0 || _submodules.Count > 0)
14651469
ShowPopup(new Checkout(this, branch.Name));
14661470
else
1467-
ShowAndStartPopup(new Checkout(this, branch.Name));
1471+
await ShowAndStartPopupAsync(new Checkout(this, branch.Name));
14681472
}
14691473
else
14701474
{
@@ -1477,7 +1481,7 @@ public void CheckoutBranch(Models.Branch branch)
14771481
if (b.TrackStatus.Behind.Count > 0)
14781482
ShowPopup(new CheckoutAndFastForward(this, b, branch));
14791483
else if (!b.IsCurrent)
1480-
CheckoutBranch(b);
1484+
await CheckoutBranchAsync(b);
14811485

14821486
return;
14831487
}
@@ -1491,7 +1495,7 @@ public async Task CheckoutTagAsync(Models.Tag tag)
14911495
{
14921496
var c = await new Commands.QuerySingleCommit(_fullpath, tag.SHA).GetResultAsync();
14931497
if (c != null)
1494-
_histories?.CheckoutBranchByCommit(c);
1498+
await _histories?.CheckoutBranchByCommitAsync(c);
14951499
}
14961500

14971501
public async Task CompareBranchWithWorktree(Models.Branch branch)
@@ -1593,10 +1597,10 @@ public void AddWorktree()
15931597
ShowPopup(new AddWorktree(this));
15941598
}
15951599

1596-
public void PruneWorktrees()
1600+
public async Task PruneWorktreesAsync()
15971601
{
15981602
if (CanCreatePopup())
1599-
ShowAndStartPopup(new PruneWorktrees(this));
1603+
await ShowAndStartPopupAsync(new PruneWorktrees(this));
16001604
}
16011605

16021606
public void OpenWorktree(Models.Worktree worktree)

src/ViewModels/WorkingCopy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,13 @@ public void OpenWithDefaultEditor(Models.Change c)
330330
Native.OS.OpenWithDefaultEditor(absPath);
331331
}
332332

333-
public void StashAll(bool autoStart)
333+
public async Task StashAllAsync(bool autoStart)
334334
{
335335
if (!_repo.CanCreatePopup())
336336
return;
337337

338338
if (autoStart)
339-
_repo.ShowAndStartPopup(new StashChanges(_repo, _cached, false));
339+
await _repo.ShowAndStartPopupAsync(new StashChanges(_repo, _cached, false));
340340
else
341341
_repo.ShowPopup(new StashChanges(_repo, _cached, false));
342342
}
@@ -679,7 +679,7 @@ public async Task CommitAsync(bool autoStage, bool autoPush, Models.CommitCheckP
679679
}
680680

681681
if (_repo.CanCreatePopup())
682-
_repo.ShowAndStartPopup(new Push(_repo, pushBranch));
682+
await _repo.ShowAndStartPopupAsync(new Push(_repo, pushBranch));
683683
}
684684
}
685685

src/Views/BranchTree.axaml.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ private void OnTreeKeyDown(object _, KeyEventArgs e)
516516
e.Handled = true;
517517
}
518518

519-
private void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
519+
private async void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
520520
{
521521
if (sender is Grid { DataContext: ViewModels.BranchTreeNode node })
522522
{
@@ -526,7 +526,7 @@ private void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
526526
return;
527527

528528
if (DataContext is ViewModels.Repository { Settings: not null } repo)
529-
repo.CheckoutBranch(branch);
529+
await repo.CheckoutBranchAsync(branch);
530530
}
531531
else
532532
{
@@ -606,10 +606,10 @@ private ContextMenu CreateContextMenuForLocalBranch(ViewModels.Repository repo,
606606
fastForward.Header = App.Text("BranchCM.FastForward", upstream.FriendlyName);
607607
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
608608
fastForward.IsEnabled = branch.TrackStatus.Ahead.Count == 0 && branch.TrackStatus.Behind.Count > 0;
609-
fastForward.Click += (_, e) =>
609+
fastForward.Click += async (_, e) =>
610610
{
611611
if (repo.CanCreatePopup())
612-
repo.ShowAndStartPopup(new ViewModels.Merge(repo, upstream, branch.Name, true));
612+
await repo.ShowAndStartPopupAsync(new ViewModels.Merge(repo, upstream, branch.Name, true));
613613
e.Handled = true;
614614
};
615615

@@ -638,9 +638,9 @@ private ContextMenu CreateContextMenuForLocalBranch(ViewModels.Repository repo,
638638
var checkout = new MenuItem();
639639
checkout.Header = App.Text("BranchCM.Checkout", branch.Name);
640640
checkout.Icon = App.CreateMenuIcon("Icons.Check");
641-
checkout.Click += (_, e) =>
641+
checkout.Click += async (_, e) =>
642642
{
643-
repo.CheckoutBranch(branch);
643+
await repo.CheckoutBranchAsync(branch);
644644
e.Handled = true;
645645
};
646646
menu.Items.Add(checkout);
@@ -654,10 +654,10 @@ private ContextMenu CreateContextMenuForLocalBranch(ViewModels.Repository repo,
654654
fastForward.Header = App.Text("BranchCM.FastForward", upstream.FriendlyName);
655655
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
656656
fastForward.IsEnabled = branch.TrackStatus.Ahead.Count == 0 && branch.TrackStatus.Behind.Count > 0;
657-
fastForward.Click += (_, e) =>
657+
fastForward.Click += async (_, e) =>
658658
{
659659
if (repo.CanCreatePopup())
660-
repo.ShowAndStartPopup(new ViewModels.ResetWithoutCheckout(repo, branch, upstream));
660+
await repo.ShowAndStartPopupAsync(new ViewModels.ResetWithoutCheckout(repo, branch, upstream));
661661
e.Handled = true;
662662
};
663663
menu.Items.Add(fastForward);
@@ -666,10 +666,10 @@ private ContextMenu CreateContextMenuForLocalBranch(ViewModels.Repository repo,
666666
fetchInto.Header = App.Text("BranchCM.FetchInto", upstream.FriendlyName, branch.Name);
667667
fetchInto.Icon = App.CreateMenuIcon("Icons.Fetch");
668668
fetchInto.IsEnabled = branch.TrackStatus.Ahead.Count == 0;
669-
fetchInto.Click += (_, e) =>
669+
fetchInto.Click += async (_, e) =>
670670
{
671671
if (repo.CanCreatePopup())
672-
repo.ShowAndStartPopup(new ViewModels.FetchInto(repo, branch, upstream));
672+
await repo.ShowAndStartPopupAsync(new ViewModels.FetchInto(repo, branch, upstream));
673673
e.Handled = true;
674674
};
675675

@@ -898,10 +898,10 @@ private ContextMenu CreateContextMenuForRemote(ViewModels.Repository repo, Model
898898
var prune = new MenuItem();
899899
prune.Header = App.Text("RemoteCM.Prune");
900900
prune.Icon = App.CreateMenuIcon("Icons.Clean");
901-
prune.Click += (_, e) =>
901+
prune.Click += async (_, e) =>
902902
{
903903
if (repo.CanCreatePopup())
904-
repo.ShowAndStartPopup(new ViewModels.PruneRemote(repo, remote));
904+
await repo.ShowAndStartPopupAsync(new ViewModels.PruneRemote(repo, remote));
905905
e.Handled = true;
906906
};
907907

@@ -952,9 +952,9 @@ public ContextMenu CreateContextMenuForRemoteBranch(ViewModels.Repository repo,
952952
var checkout = new MenuItem();
953953
checkout.Header = App.Text("BranchCM.Checkout", name);
954954
checkout.Icon = App.CreateMenuIcon("Icons.Check");
955-
checkout.Click += (_, e) =>
955+
checkout.Click += async (_, e) =>
956956
{
957-
repo.CheckoutBranch(branch);
957+
await repo.CheckoutBranchAsync(branch);
958958
e.Handled = true;
959959
};
960960
menu.Items.Add(checkout);
@@ -1099,9 +1099,9 @@ private void TryToAddCustomActionsToBranchContextMenu(ViewModels.Repository repo
10991099
var item = new MenuItem();
11001100
item.Icon = App.CreateMenuIcon("Icons.Action");
11011101
item.Header = label;
1102-
item.Click += (_, e) =>
1102+
item.Click += async (_, e) =>
11031103
{
1104-
repo.ExecCustomAction(dup, branch);
1104+
await repo.ExecCustomActionAsync(dup, branch);
11051105
e.Handled = true;
11061106
};
11071107

0 commit comments

Comments
 (0)