private void SetViewModel() { bool isBusy = false; Application.Current.Dispatcher.Invoke(() => { isBusy = this.view?.ViewModel != null && this.view.ViewModel.IsBusy; }); if (isBusy) { return; } var showBranches = ReactiveCommand.Create(); showBranches.Subscribe(_ => this.ShowPage(TeamExplorerPageIds.GitBranches)); var showConflicts = ReactiveCommand.Create(); showConflicts.Subscribe(_ => this.ShowPage(TeamExplorerPageIds.GitConflicts)); var showChanges = ReactiveCommand.Create(); showChanges.Subscribe(_ => this.ShowPage(TeamExplorerPageIds.GitChanges)); IGitSquashWrapper squashWrapper = this.GetService <IGitSquashWrapper>(); RxApp.MainThreadScheduler.Schedule(() => { if (this.view != null && squashWrapper != null) { this.view.ViewModel = new SquashViewModel(squashWrapper, showBranches, showConflicts, showChanges); } }); }
private object CreateGitWrapperService(IServiceContainer container, Type serviceType) { this.TraceWriteLine("Service Requested: " + serviceType.FullName); if (typeof(IGitSquashWrapper) == serviceType) { IVsOutputWindowPane outputWindow; var outWindow = GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow; var customGuid = new Guid("E53E7910-5B4F-4C5D-95BE-92BD439178E6"); outWindow.CreatePane(ref customGuid, "Git Squash", 1, 1); outWindow.GetPane(ref customGuid, out outputWindow); IGitSquashWrapper wrapper = null; if (this.gitService.ActiveRepositories.FirstOrDefault() != null) { string path = this.gitService.ActiveRepositories.FirstOrDefault()?.RepositoryPath; this.TraceWriteLine("Creating Wrapper service with path: " + path); wrapper = new GitSquashWrapper(path, new OutputWindowLogger(outputWindow)); } return(wrapper); } throw new ArgumentException(); }
/// <summary> /// Initializes a new instance of the <see cref="SquashViewModel" /> class. /// </summary> /// <param name="squashWrapper">Our model that we retrieve data from.</param> /// <param name="changeBranch">A command to change the current branch.</param> /// <param name="showConflicts">A command to resolve conflicts.</param> /// <param name="showChanges">A command to show the changes tab.</param> public SquashViewModel(IGitSquashWrapper squashWrapper, ICommand changeBranch, ICommand showConflicts, ICommand showChanges) { if (squashWrapper == null) { throw new ArgumentNullException(nameof(squashWrapper)); } if (changeBranch == null) { throw new ArgumentNullException(nameof(changeBranch)); } if (showConflicts == null) { throw new ArgumentNullException(nameof(showConflicts)); } if (showChanges == null) { throw new ArgumentNullException(nameof(showChanges)); } this.SquashWrapper = squashWrapper; this.ChangeBranch = changeBranch; this.ViewConflictsPage = showConflicts; this.ViewChangesPage = showChanges; this.isOperationSuccess = this.WhenAnyValue(x => x.GitCommandResponse).Select(x => x?.Success).ToProperty(this, x => x.OperationSuccess, out this.isOperationSuccess); var canSquashObservable = this.WhenAnyValue(x => x.CurrentBranch, x => x.SquashWrapper, x => x.SelectedCommit, x => x.CommitMessage, x => x.IsBusy, x => x.IsDirty) .Select(x => x.Item1 != null && x.Item2 != null && x.Item3 != null && string.IsNullOrWhiteSpace(x.Item4) == false && x.Item5 == false && x.Item6 == false); var canRebase = this.WhenAnyValue(x => x.IsRebaseInProgress, x => x.IsDirty, x => x.IsBusy, x => x.SelectedRebaseBranch) .Select(x => x.Item1 == false && x.Item2 == false && x.Item3 == false && x.Item4 != null); var canCancel = this.WhenAnyValue(x => x.IsBusy); var canContinueRebase = this.WhenAnyValue(x => x.IsBusy, x => x.SquashWrapper, x => x.IsRebaseInProgress) .Select(x => x.Item1 == false && x.Item2 != null && x.Item3); var isNotBusyObservable = this.WhenAnyValue(x => x.IsBusy).Select(x => x == false); this.cancelOperation = ReactiveCommand.Create(canCancel); this.cancelOperation.Subscribe(_ => this.PerformCancelOperation()); this.squash = this.GenerateGitCommand(canSquashObservable, this.PerformSquash); this.rebase = this.GenerateGitCommand(canRebase, this.PerformRebase); this.continueRebase = this.GenerateGitCommand(canContinueRebase, this.PerformContinueRebase); this.abortRebase = this.GenerateGitCommand(canContinueRebase, this.PerformAbortRebase); this.pushForce = this.GenerateGitCommand(isNotBusyObservable, this.PerformPushForce); this.fetchOrigin = this.GenerateGitCommand(isNotBusyObservable, this.PerformFetchOrigin); this.skip = this.GenerateGitCommand(canContinueRebase, this.PerformSkipRebase); var updateCommand = ReactiveCommand.CreateAsyncTask(async _ => await this.PerformUpdateCommitMessage(CancellationToken.None)); updateCommand.Subscribe(x => this.CommitMessage = x); this.updateCommitMessage = updateCommand; this.WhenAnyValue(x => x.SelectedCommit).InvokeCommand(this.updateCommitMessage); this.LogOptions = new GitLogOptionsViewModel { Value = Settings.Default.HistorySetting }; this.DoForcePush = Settings.Default.PerformPush; this.ApplyRebase = Settings.Default.PerformRebaseAfterSquash; this.WhenAnyValue(x => x.LogOptions, x => x.DoForcePush, x => x.ApplyRebase).Skip(1).Subscribe(x => { Settings.Default.HistorySetting = x.Item1?.Value ?? GitLogOptions.BranchOnlyAndParent; Settings.Default.PerformPush = x.Item2; Settings.Default.PerformRebaseAfterSquash = x.Item3; Settings.Default.Save(); }); this.LogOptions.WhenAnyValue(x => x.Value).Skip(1).Subscribe(x => { Settings.Default.HistorySetting = x; Settings.Default.Save(); this.Refresh(); }); this.refresh = ReactiveCommand.CreateAsyncTask(isNotBusyObservable, async _ => await this.RefreshInternal()); this.WhenAnyValue(x => x.IsBusy).Where(x => x == false).InvokeCommand(this.refresh); }