diff --git a/src/Commands/Stash.cs b/src/Commands/Stash.cs index d2e12be8..7acfdf38 100644 --- a/src/Commands/Stash.cs +++ b/src/Commands/Stash.cs @@ -73,27 +73,22 @@ namespace SourceGit.Commands return Exec(); } - public bool Apply(string name = null) + public bool Apply(string name, bool restoreIndex) { - Args = "stash apply -q"; - if (!string.IsNullOrEmpty(name)) - Args += $" \"{name}\""; + var opts = restoreIndex ? "--index" : string.Empty; + Args = $"stash apply -q {opts} \"{name}\""; return Exec(); } - public bool Pop(string name = null) + public bool Pop(string name) { - Args = "stash pop -q"; - if (!string.IsNullOrEmpty(name)) - Args += $" \"{name}\""; + Args = $"stash pop -q \"{name}\""; return Exec(); } - public bool Drop(string name = null) + public bool Drop(string name) { - Args = "stash drop -q"; - if (!string.IsNullOrEmpty(name)) - Args += $" \"{name}\""; + Args = $"stash drop -q \"{name}\""; return Exec(); } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 631722ad..b2118a3e 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -34,6 +34,10 @@ Warn Outputs warnings for a few such errors, but applies Whitespace: + Apply Stash + Delete after applying + Reinstate the index's changes + Stash: Archive... Save Archive To: Select archive file path diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index b220b9ae..e4a38e9c 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -37,6 +37,10 @@ 警告 应用补丁,输出关于空白符的警告 空白符号处理 : + 应用贮藏 + 在成功应用后丢弃该贮藏 + 恢复索引中已暂存的变化 + 已选贮藏 : 存档(archive) ... 存档文件路径: 选择存档文件的存放路径 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 948cb2a8..c2008445 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -37,6 +37,10 @@ 警告 套用修補檔,輸出關於空白字元的警告 空白字元處理: + 套用擱置 + 在成功套用后捨棄擱置 + 恢復索引中已暫存的變更 + 已選擇擱置 : 封存 (archive)... 封存檔案路徑: 選擇封存檔案的儲存路徑 diff --git a/src/ViewModels/ApplyStash.cs b/src/ViewModels/ApplyStash.cs new file mode 100644 index 00000000..03ce0f43 --- /dev/null +++ b/src/ViewModels/ApplyStash.cs @@ -0,0 +1,48 @@ +using System.Threading.Tasks; + +namespace SourceGit.ViewModels +{ + public class ApplyStash : Popup + { + public Models.Stash Stash + { + get; + private set; + } + + public bool RestoreIndex + { + get; + set; + } = true; + + public bool DropAfterApply + { + get; + set; + } = false; + + public ApplyStash(string repo, Models.Stash stash) + { + _repo = repo; + Stash = stash; + View = new Views.ApplyStash() { DataContext = this }; + } + + public override Task Sure() + { + ProgressDescription = $"Applying stash: {Stash.Name}"; + + return Task.Run(() => + { + var succ = new Commands.Stash(_repo).Apply(Stash.Name, RestoreIndex); + if (succ && DropAfterApply) + new Commands.Stash(_repo).Drop(Stash.Name); + + return true; + }); + } + + private readonly string _repo; + } +} diff --git a/src/ViewModels/StashChanges.cs b/src/ViewModels/StashChanges.cs index 3b5608f7..33ebb1f3 100644 --- a/src/ViewModels/StashChanges.cs +++ b/src/ViewModels/StashChanges.cs @@ -91,7 +91,7 @@ namespace SourceGit.ViewModels } if (AutoRestore && succ) - succ = new Commands.Stash(_repo.FullPath).Apply(); + succ = new Commands.Stash(_repo.FullPath).Apply("stash@{0}", true); CallUIThread(() => { diff --git a/src/ViewModels/StashesPage.cs b/src/ViewModels/StashesPage.cs index e5755a91..4a3bf933 100644 --- a/src/ViewModels/StashesPage.cs +++ b/src/ViewModels/StashesPage.cs @@ -141,15 +141,9 @@ namespace SourceGit.ViewModels apply.Header = App.Text("StashCM.Apply"); apply.Click += (_, ev) => { - Task.Run(() => new Commands.Stash(_repo.FullPath).Apply(stash.Name)); - ev.Handled = true; - }; + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new ApplyStash(_repo.FullPath, stash)); - var pop = new MenuItem(); - pop.Header = App.Text("StashCM.Pop"); - pop.Click += (_, ev) => - { - Task.Run(() => new Commands.Stash(_repo.FullPath).Pop(stash.Name)); ev.Handled = true; }; @@ -165,7 +159,6 @@ namespace SourceGit.ViewModels var menu = new ContextMenu(); menu.Items.Add(apply); - menu.Items.Add(pop); menu.Items.Add(drop); return menu; } diff --git a/src/Views/ApplyStash.axaml b/src/Views/ApplyStash.axaml new file mode 100644 index 00000000..44a97f42 --- /dev/null +++ b/src/Views/ApplyStash.axaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/Views/ApplyStash.axaml.cs b/src/Views/ApplyStash.axaml.cs new file mode 100644 index 00000000..07b6cf90 --- /dev/null +++ b/src/Views/ApplyStash.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia.Controls; + +namespace SourceGit.Views +{ + public partial class ApplyStash : UserControl + { + public ApplyStash() + { + InitializeComponent(); + } + } +} +