diff --git a/src/GitHub.App/SampleData/RepositoryRecloneViewModelDesigner.cs b/src/GitHub.App/SampleData/RepositoryRecloneViewModelDesigner.cs deleted file mode 100644 index 274f58d9c1..0000000000 --- a/src/GitHub.App/SampleData/RepositoryRecloneViewModelDesigner.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Reactive; -using System.Threading.Tasks; -using System.Windows.Input; -using GitHub.Models; -using GitHub.Validation; -using GitHub.ViewModels; -using GitHub.ViewModels.Dialog; -using ReactiveUI; - -namespace GitHub.SampleData -{ - public class RepositoryRecloneViewModelDesigner : ViewModelBase, IRepositoryRecloneViewModel - { - public string Title { get; set; } - public string BaseRepositoryPath { get; set; } - public ReactivePropertyValidator BaseRepositoryPathValidator { get; } - public ICommand BrowseForDirectory { get; } - public ReactiveCommand CloneCommand { get; } - public RepositoryModel SelectedRepository { get; set; } - public IObservable Done { get; } - - public Task InitializeAsync(IConnection connection) => Task.CompletedTask; - } -} diff --git a/src/GitHub.App/Services/DialogService.cs b/src/GitHub.App/Services/DialogService.cs index 1bf666c7d2..bc4d189fe1 100644 --- a/src/GitHub.App/Services/DialogService.cs +++ b/src/GitHub.App/Services/DialogService.cs @@ -69,15 +69,6 @@ public async Task ShowCloneDialog(IConnection connection, str } } - public async Task ShowReCloneDialog(RepositoryModel repository) - { - Guard.ArgumentNotNull(repository, nameof(repository)); - - var viewModel = factory.CreateViewModel(); - viewModel.SelectedRepository = repository; - return (string)await showDialog.ShowWithFirstConnection(viewModel); - } - public async Task ShowCreateGist(IConnection connection) { var viewModel = factory.CreateViewModel(); diff --git a/src/GitHub.App/ViewModels/Dialog/RepositoryRecloneViewModel.cs b/src/GitHub.App/ViewModels/Dialog/RepositoryRecloneViewModel.cs deleted file mode 100644 index f996cd5b70..0000000000 --- a/src/GitHub.App/ViewModels/Dialog/RepositoryRecloneViewModel.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.ComponentModel.Composition; -using System.Globalization; -using System.IO; -using System.Reactive; -using System.Reactive.Linq; -using System.Threading.Tasks; -using System.Windows.Input; -using GitHub.App; -using GitHub.Extensions; -using GitHub.Logging; -using GitHub.Models; -using GitHub.Services; -using GitHub.Validation; -using ReactiveUI; -using Rothko; -using Serilog; - -namespace GitHub.ViewModels.Dialog -{ - [Export(typeof(IRepositoryRecloneViewModel))] - [PartCreationPolicy(CreationPolicy.NonShared)] - public class RepositoryRecloneViewModel : ViewModelBase, IRepositoryRecloneViewModel - { - static readonly ILogger log = LogManager.ForContext(); - - readonly IOperatingSystem operatingSystem; - readonly ReactiveCommand browseForDirectoryCommand = ReactiveCommand.Create(() => { }); - readonly ObservableAsPropertyHelper canClone; - string baseRepositoryPath; - - [ImportingConstructor] - public RepositoryRecloneViewModel( - IRepositoryCloneService cloneService, - IOperatingSystem operatingSystem) - { - Guard.ArgumentNotNull(cloneService, nameof(cloneService)); - Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem)); - - this.operatingSystem = operatingSystem; - - var baseRepositoryPath = this.WhenAny( - x => x.BaseRepositoryPath, - x => x.SelectedRepository, - (x, y) => x.Value); - - BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath) - .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty) - .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong) - .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters) - .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid) - .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists); - - var canCloneObservable = this.WhenAny( - x => x.SelectedRepository, - x => x.BaseRepositoryPathValidator.ValidationResult.IsValid, - (x, y) => x.Value != null && y.Value); - canClone = canCloneObservable.ToProperty(this, x => x.CanClone); - CloneCommand = ReactiveCommand.Create(() => { }, canCloneObservable); - - browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog()); - this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value) - .Subscribe(); - BaseRepositoryPath = cloneService.DefaultClonePath; - } - - public Task InitializeAsync(IConnection connection) - { - Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, connection.HostAddress.Title); - return Task.CompletedTask; - } - - bool IsAlreadyRepoAtPath(string path) - { - Guard.ArgumentNotNull(path, nameof(path)); - - bool isAlreadyRepoAtPath = false; - - if (SelectedRepository != null) - { - string potentialPath = Path.Combine(path, SelectedRepository.Name); - isAlreadyRepoAtPath = operatingSystem.Directory.Exists(potentialPath); - } - - return isAlreadyRepoAtPath; - } - - IObservable ShowBrowseForDirectoryDialog() - { - return Observable.Start(() => - { - // We store this in a local variable to prevent it changing underneath us while the - // folder dialog is open. - var localBaseRepositoryPath = BaseRepositoryPath; - var browseResult = operatingSystem.Dialog.BrowseForDirectory(localBaseRepositoryPath, Resources.BrowseForDirectory); - - if (!browseResult.Success) - return; - - var directory = browseResult.DirectoryPath ?? localBaseRepositoryPath; - - try - { - BaseRepositoryPath = directory; - } - catch (Exception e) - { - // TODO: We really should limit this to exceptions we know how to handle. - log.Error(e, "Failed to set base repository path. localBaseRepositoryPath = {0} BaseRepositoryPath = {1} Chosen directory = {2}", - localBaseRepositoryPath ?? "(null)", BaseRepositoryPath ?? "(null)", directory ?? "(null)"); - } - }, RxApp.MainThreadScheduler); - } - - /// - /// Gets the dialog title. - /// - public string Title { get; private set; } - - /// - /// Path to clone repositories into - /// - public string BaseRepositoryPath - { - get { return baseRepositoryPath; } - set { this.RaiseAndSetIfChanged(ref baseRepositoryPath, value); } - } - - /// - /// Signals that the user clicked the clone button. - /// - public ReactiveCommand CloneCommand { get; private set; } - - RepositoryModel selectedRepository; - /// - /// Selected repository to clone - /// - public RepositoryModel SelectedRepository - { - get { return selectedRepository; } - set { this.RaiseAndSetIfChanged(ref selectedRepository, value); } - } - - public ICommand BrowseForDirectory - { - get { return browseForDirectoryCommand; } - } - - public bool CanClone - { - get { return canClone.Value; } - } - - public ReactivePropertyValidator BaseRepositoryPathValidator - { - get; - private set; - } - - public IObservable Done => CloneCommand.Select(_ => BaseRepositoryPath); - } -} diff --git a/src/GitHub.Exports.Reactive/ViewModels/Dialog/IRepositoryRecloneViewModel.cs b/src/GitHub.Exports.Reactive/ViewModels/Dialog/IRepositoryRecloneViewModel.cs deleted file mode 100644 index 1929a198e4..0000000000 --- a/src/GitHub.Exports.Reactive/ViewModels/Dialog/IRepositoryRecloneViewModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using GitHub.Models; - -namespace GitHub.ViewModels.Dialog -{ - public interface IRepositoryRecloneViewModel : IDialogContentViewModel, IConnectionInitializedViewModel - { - /// - /// Gets or sets the repository to clone. - /// - RepositoryModel SelectedRepository { get; set; } - } -} diff --git a/src/GitHub.Exports/Services/IDialogService.cs b/src/GitHub.Exports/Services/IDialogService.cs index ea26dd71e1..cc837dc5b4 100644 --- a/src/GitHub.Exports/Services/IDialogService.cs +++ b/src/GitHub.Exports/Services/IDialogService.cs @@ -25,20 +25,6 @@ public interface IDialogService /// Task ShowCloneDialog(IConnection connection, string url = null); - /// - /// Shows the re-clone dialog. - /// - /// The repository to clone. - /// - /// A task that returns the base path for the clone on success, or null if the dialog was - /// cancelled. - /// - /// - /// The re-clone dialog is shown from the VS2017+ start page when the user wants to check - /// out a repository that was previously checked out on another machine. - /// - Task ShowReCloneDialog(RepositoryModel repository); - /// /// Shows the Create Gist dialog. /// diff --git a/src/GitHub.StartPage/StartPagePackage.cs b/src/GitHub.StartPage/StartPagePackage.cs index 935075e9d4..8d3a4703dc 100644 --- a/src/GitHub.StartPage/StartPagePackage.cs +++ b/src/GitHub.StartPage/StartPagePackage.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -90,39 +89,24 @@ static async Task ShowCloneDialog( var dialogService = gitHubServiceProvider.GetService(); var cloneService = gitHubServiceProvider.GetService(); var usageTracker = gitHubServiceProvider.GetService(); - CloneDialogResult result = null; - if (repository == null) - { - result = await dialogService.ShowCloneDialog(null); - } - else - { - var basePath = await dialogService.ShowReCloneDialog(repository); - - if (basePath != null) - { - var path = Path.Combine(basePath, repository.Name); - result = new CloneDialogResult(path, repository.CloneUrl); - } - } - - if (result != null) + var cloneUrl = repository?.CloneUrl; + if (await dialogService.ShowCloneDialog(null, cloneUrl) is CloneDialogResult result) { try { await cloneService.CloneOrOpenRepository(result, progress, cancellationToken); usageTracker.IncrementCounter(x => x.NumberOfStartPageClones).Forget(); + return result; } catch { var teServices = gitHubServiceProvider.TryGetService(); teServices.ShowError($"Failed to clone the repository '{result.Url.RepositoryName}'"); - result = null; } } - return result; + return null; } } } diff --git a/src/GitHub.VisualStudio.UI/Views/Dialog/RepositoryRecloneView.xaml b/src/GitHub.VisualStudio.UI/Views/Dialog/RepositoryRecloneView.xaml deleted file mode 100644 index 9ae951cd21..0000000000 --- a/src/GitHub.VisualStudio.UI/Views/Dialog/RepositoryRecloneView.xaml +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - https://github.com/github/VisualStudio - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -