using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace SourceGit.UI { /// /// Dialog to add new submodule. /// public partial class AddSubmodule : UserControl { private Git.Repository repo = null; /// /// Submodule's repository URL. /// public string RepoURL { get; set; } /// /// Submodule's relative path. /// public string LocalPath { get; set; } /// /// Constructor. /// /// public AddSubmodule(Git.Repository opened) { repo = opened; InitializeComponent(); } /// /// Show this dialog. /// /// public static void Show(Git.Repository repo) { repo.GetPopupManager()?.Show(new AddSubmodule(repo)); } #region EVENTS private void SelectFolder(object sender, RoutedEventArgs e) { var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Select Folder To Clone Repository"; dialog.SelectedPath = repo.Path; dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtPath.Text = dialog.SelectedPath; } } private async void Sure(object sender, RoutedEventArgs e) { txtRepoUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtRepoUrl)) return; txtPath.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtPath)) return; var recursive = chkRecursive.IsChecked == true; var popup = repo.GetPopupManager(); popup?.Lock(); await Task.Run(() => repo.AddSubmodule(RepoURL, LocalPath, recursive, msg => { popup?.UpdateStatus(msg); })); popup?.Close(true); } private void Cancel(object sender, RoutedEventArgs e) { repo.GetPopupManager()?.Close(); } #endregion } }