Skip to content

Commit e076cbf

Browse files
committed
refactor: remove ViewModels.WorkingCopy.StashAllAsync method
Signed-off-by: leo <[email protected]>
1 parent ac1239b commit e076cbf

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

src/ViewModels/Repository.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,14 @@ public void SetBranchFilterMode(BranchTreeNode node, Models.FilterMode mode, boo
11121112

11131113
public async Task StashAllAsync(bool autoStart)
11141114
{
1115-
if (_workingCopy != null)
1116-
await _workingCopy.StashAllAsync(autoStart);
1115+
if (!CanCreatePopup())
1116+
return;
1117+
1118+
var popup = new StashChanges(this, null);
1119+
if (autoStart)
1120+
await ShowAndStartPopupAsync(popup);
1121+
else
1122+
ShowPopup(popup);
11171123
}
11181124

11191125
public async Task SkipMergeAsync()

src/ViewModels/StashChanges.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public string Message
1515

1616
public bool HasSelectedFiles
1717
{
18-
get;
18+
get => _changes != null;
1919
}
2020

2121
public bool IncludeUntracked
@@ -43,11 +43,10 @@ public int ChangesAfterStashing
4343
set => _repo.Settings.ChangesAfterStashing = value;
4444
}
4545

46-
public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelectedFiles)
46+
public StashChanges(Repository repo, List<Models.Change> selectedChanges)
4747
{
4848
_repo = repo;
49-
_changes = changes;
50-
HasSelectedFiles = hasSelectedFiles;
49+
_changes = selectedChanges;
5150
}
5251

5352
public override async Task<bool> Sure()
@@ -62,7 +61,7 @@ public override async Task<bool> Sure()
6261
var keepIndex = mode == DealWithChangesAfterStashing.KeepIndex;
6362
bool succ;
6463

65-
if (!HasSelectedFiles)
64+
if (_changes == null)
6665
{
6766
if (OnlyStaged)
6867
{
@@ -74,8 +73,12 @@ public override async Task<bool> Sure()
7473
}
7574
else
7675
{
76+
var all = await new Commands.QueryLocalChanges(_repo.FullPath, false)
77+
.Use(log)
78+
.GetResultAsync();
79+
7780
var staged = new List<Models.Change>();
78-
foreach (var c in _changes)
81+
foreach (var c in all)
7982
{
8083
if (c.Index != Models.ChangeState.None && c.Index != Models.ChangeState.Untracked)
8184
staged.Add(c);

src/ViewModels/WorkingCopy.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,6 @@ public void OpenWithDefaultEditor(Models.Change c)
342342
Native.OS.OpenWithDefaultEditor(absPath);
343343
}
344344

345-
public async Task StashAllAsync(bool autoStart)
346-
{
347-
if (!_repo.CanCreatePopup())
348-
return;
349-
350-
if (autoStart)
351-
await _repo.ShowAndStartPopupAsync(new StashChanges(_repo, _cached, false));
352-
else
353-
_repo.ShowPopup(new StashChanges(_repo, _cached, false));
354-
}
355-
356345
public async Task StageChangesAsync(List<Models.Change> changes, Models.Change next)
357346
{
358347
var canStaged = await GetCanStageChangesAsync(changes);

src/Views/WorkingCopy.axaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.WorkingCopy v
372372
stash.Click += (_, e) =>
373373
{
374374
if (repo.CanCreatePopup())
375-
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged, true));
375+
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged));
376376

377377
e.Handled = true;
378378
};
@@ -769,7 +769,7 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.WorkingCopy v
769769
stash.Click += (_, e) =>
770770
{
771771
if (repo.CanCreatePopup())
772-
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged, true));
772+
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged));
773773

774774
e.Handled = true;
775775
};
@@ -956,7 +956,7 @@ public ContextMenu CreateContextMenuForStagedChanges(ViewModels.WorkingCopy vm,
956956
stash.Click += (_, e) =>
957957
{
958958
if (repo.CanCreatePopup())
959-
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged, true));
959+
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged));
960960

961961
e.Handled = true;
962962
};
@@ -1164,7 +1164,7 @@ public ContextMenu CreateContextMenuForStagedChanges(ViewModels.WorkingCopy vm,
11641164
stash.Click += (_, e) =>
11651165
{
11661166
if (repo.CanCreatePopup())
1167-
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged, true));
1167+
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged));
11681168

11691169
e.Handled = true;
11701170
};

0 commit comments

Comments
 (0)