mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature<Checkout>: add a status panel for checkout progress
This commit is contained in:
parent
001453d6ff
commit
67f5eed9a0
5 changed files with 64 additions and 24 deletions
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
@ -6,13 +7,16 @@ namespace SourceGit.Commands {
|
|||
/// 检出
|
||||
/// </summary>
|
||||
public class Checkout : Command {
|
||||
private Action<string> handler = null;
|
||||
|
||||
public Checkout(string repo) {
|
||||
Cwd = repo;
|
||||
}
|
||||
|
||||
public bool Branch(string branch) {
|
||||
Args = $"checkout {branch}";
|
||||
public bool Branch(string branch, Action<string> onProgress) {
|
||||
Args = $"checkout --progress {branch}";
|
||||
TraitErrorAsOutput = true;
|
||||
handler = onProgress;
|
||||
return Exec();
|
||||
}
|
||||
|
||||
|
@ -42,5 +46,9 @@ namespace SourceGit.Commands {
|
|||
Args = builder.ToString();
|
||||
return Exec();
|
||||
}
|
||||
|
||||
public override void OnReadline(string line) {
|
||||
handler?.Invoke(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/Views/Popups/Checkout.xaml
Normal file
10
src/Views/Popups/Checkout.xaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.Checkout"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="500" Height="100">
|
||||
</controls:PopupWidget>
|
34
src/Views/Popups/Checkout.xaml.cs
Normal file
34
src/Views/Popups/Checkout.xaml.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
|
||||
/// <summary>
|
||||
/// 切换分支
|
||||
/// </summary>
|
||||
public partial class Checkout : Controls.PopupWidget {
|
||||
private string repo;
|
||||
private string branch;
|
||||
|
||||
public Checkout(string repo, string branch) {
|
||||
this.repo = repo;
|
||||
this.branch = branch;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("BranchCM.Checkout", branch);
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
UpdateProgress(GetTitle());
|
||||
|
||||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
new Commands.Checkout(repo).Branch(branch, UpdateProgress);
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -424,7 +424,7 @@ namespace SourceGit.Views.Widgets {
|
|||
if (node.Type == BranchNodeType.Branch) NavigateTo((node.Data as Models.Branch).Head);
|
||||
}
|
||||
|
||||
private async void OnTreeDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
private void OnTreeDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
var item = sender as Controls.TreeItem;
|
||||
if (item == null) return;
|
||||
|
||||
|
@ -434,9 +434,7 @@ namespace SourceGit.Views.Widgets {
|
|||
var branch = node.Data as Models.Branch;
|
||||
if (!branch.IsLocal || branch.IsCurrent) return;
|
||||
|
||||
Models.Watcher.SetEnabled(repo.Path, false);
|
||||
await Task.Run(() => new Commands.Checkout(repo.Path).Branch(branch.Name));
|
||||
Models.Watcher.SetEnabled(repo.Path, true);
|
||||
new Popups.Checkout(repo.Path, branch.Name).ShowAndStart();
|
||||
}
|
||||
|
||||
private void OnTreeContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||
|
@ -510,10 +508,8 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
var checkout = new MenuItem();
|
||||
checkout.Header = App.Text("BranchCM.Checkout", branch.Name);
|
||||
checkout.Click += async (o, e) => {
|
||||
Models.Watcher.SetEnabled(repo.Path, false);
|
||||
await Task.Run(() => new Commands.Checkout(repo.Path).Branch(branch.Name));
|
||||
Models.Watcher.SetEnabled(repo.Path, true);
|
||||
checkout.Click += (o, e) => {
|
||||
new Popups.Checkout(repo.Path, branch.Name).ShowAndStart();
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
|
@ -676,14 +672,11 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
var checkout = new MenuItem();
|
||||
checkout.Header = App.Text("BranchCM.Checkout", branch.Name);
|
||||
checkout.Click += async (o, e) => {
|
||||
checkout.Click += (o, e) => {
|
||||
foreach (var b in repo.Branches) {
|
||||
if (b.IsLocal && b.Upstream == branch.FullName) {
|
||||
if (b.IsCurrent) return;
|
||||
|
||||
Models.Watcher.SetEnabled(repo.Path, false);
|
||||
await Task.Run(() => new Commands.Checkout(repo.Path).Branch(b.Name));
|
||||
Models.Watcher.SetEnabled(repo.Path, true);
|
||||
new Popups.Checkout(repo.Path, b.Name).ShowAndStart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -457,10 +457,8 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
var checkout = new MenuItem();
|
||||
checkout.Header = App.Text("BranchCM.Checkout", branch.Name);
|
||||
checkout.Click += async (o, e) => {
|
||||
Models.Watcher.SetEnabled(repo.Path, false);
|
||||
await Task.Run(() => new Commands.Checkout(repo.Path).Branch(branch.Name));
|
||||
Models.Watcher.SetEnabled(repo.Path, true);
|
||||
checkout.Click += (o, e) => {
|
||||
new Popups.Checkout(repo.Path, branch.Name).ShowAndStart();
|
||||
e.Handled = true;
|
||||
};
|
||||
submenu.Items.Add(checkout);
|
||||
|
@ -528,14 +526,11 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
var checkout = new MenuItem();
|
||||
checkout.Header = App.Text("BranchCM.Checkout", name);
|
||||
checkout.Click += async (o, e) => {
|
||||
checkout.Click += (o, e) => {
|
||||
foreach (var b in repo.Branches) {
|
||||
if (b.IsLocal && b.Upstream == branch.FullName) {
|
||||
if (b.IsCurrent) return;
|
||||
|
||||
Models.Watcher.SetEnabled(repo.Path, false);
|
||||
await Task.Run(() => new Commands.Checkout(repo.Path).Branch(b.Name));
|
||||
Models.Watcher.SetEnabled(repo.Path, true);
|
||||
new Popups.Checkout(repo.Path, b.Name).ShowAndStart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue