using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace SourceGit.UI { /// /// Reset branch to revision dialog. /// public partial class Reset : UserControl { private Git.Repository repo = null; private string revision = null; /// /// Reset mode. /// public class Mode { public Brush Color { get; set; } public string Name { get; set; } public string Desc { get; set; } public string Arg { get; set; } public Mode(Brush b, string n, string d, string a) { Color = b; Name = n; Desc = d; Arg = a; } } /// /// Constructor. /// /// /// /// public Reset(Git.Repository opened, Git.Branch current, Git.Commit commit) { InitializeComponent(); repo = opened; revision = commit.SHA; branch.Content = current.Name; desc.Content = $"{commit.ShortSHA} {commit.Subject}"; combMode.ItemsSource = new Mode[] { new Mode(Brushes.Green, "Soft", "Keep all changes. Stage differences", "--soft"), new Mode(Brushes.Yellow, "Mixed", "Keep all changes. Unstage differences", "--mixed"), new Mode(Brushes.Red, "Hard", "Discard all changes", "--hard"), }; combMode.SelectedIndex = 0; } /// /// Show dialog. /// /// /// public static void Show(Git.Repository repo, Git.Commit commit) { var current = repo.CurrentBranch(); if (current == null) return; PopupManager.Show(new Reset(repo, current, commit)); } /// /// Start reset. /// /// /// private async void Start(object sender, RoutedEventArgs e) { var mode = combMode.SelectedItem as Mode; if (mode == null) return; PopupManager.Lock(); await Task.Run(() => repo.Reset(revision, mode.Arg)); PopupManager.Close(true); } /// /// Cancel. /// /// /// private void Cancel(object sender, RoutedEventArgs e) { PopupManager.Close(); } } }