using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace SourceGit.UI { /// /// Rename branch dialog. /// public partial class RenameBranch : UserControl { private Git.Repository repo = null; private Git.Branch branch = null; /// /// New branch name. /// public string NewName { get; set; } /// /// Constructor. /// /// Opened repository. /// Branch to rename. public RenameBranch(Git.Repository opened, Git.Branch target) { repo = opened; branch = target; NewName = target.Name; InitializeComponent(); nameValidator.Repo = opened; txtOldName.Text = target.Name; } /// /// Show this dialog /// /// /// public static void Show(Git.Repository opened, Git.Branch branch) { opened.GetPopupManager()?.Show(new RenameBranch(opened, branch)); } /// /// Rename /// /// /// private async void Sure(object sender, RoutedEventArgs e) { txtNewName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtNewName)) return; var popup = repo.GetPopupManager(); popup?.Lock(); await Task.Run(() => branch.Rename(repo, NewName)); popup?.Close(true); } /// /// Cancel merge. /// /// /// private void Cancel(object sender, RoutedEventArgs e) { repo.GetPopupManager()?.Close(); } } }