using System; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace SourceGit.UI { /// /// Clone dialog. /// public partial class Clone : UserControl { /// /// Remote repository /// public string RemoteUri { get; set; } /// /// Parent folder. /// public string ParentFolder { get; set; } /// /// Local name. /// public string LocalName { get; set; } /// /// Constructor. /// public Clone() { ParentFolder = App.Preference.GitDefaultCloneDir; InitializeComponent(); } /// /// Show clone dialog. /// public static void Show() { PopupManager.Show(new Clone()); } /// /// Select parent folder. /// /// /// private void SelectParentFolder(object sender, RoutedEventArgs e) { var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Git Repository URL"; dialog.RootFolder = Environment.SpecialFolder.MyComputer; dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtParentFolder.Text = dialog.SelectedPath; } } /// /// Start clone /// /// /// private async void Start(object sender, RoutedEventArgs e) { txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtUrl)) return; txtParentFolder.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtParentFolder)) return; string repoName; if (string.IsNullOrWhiteSpace(LocalName)) { var from = RemoteUri.LastIndexOfAny(new char[] { '\\', '/' }); if (from <= 0) return; var name = RemoteUri.Substring(from + 1); repoName = name.Replace(".git", ""); } else { repoName = LocalName; } PopupManager.Lock(); var repo = await Task.Run(() => { return Git.Repository.Clone(RemoteUri, ParentFolder, repoName, PopupManager.UpdateStatus); }); if (repo == null) { PopupManager.Unlock(); } else { PopupManager.Close(true); repo.Open(); } } /// /// Cancel. /// /// /// private void Cancel(object sender, RoutedEventArgs e) { PopupManager.Close(); } } }