Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PullRequestDetailViewModel"/> class.
        /// </summary>
        /// <param name="repositoryHost">The repository host.</param>
        /// <param name="teservice">The team explorer service.</param>
        /// <param name="pullRequestsService">The pull requests service.</param>
        /// <param name="avatarProvider">The avatar provider.</param>
        public PullRequestDetailViewModel(
            ILocalRepositoryModel repository,
            IModelService modelService,
            IPullRequestService pullRequestsService,
            IPackageSettings settings)
        {
            this.repository          = repository;
            this.modelService        = modelService;
            this.pullRequestsService = pullRequestsService;

            Checkout = ReactiveCommand.CreateAsyncObservable(
                this.WhenAnyValue(x => x.CheckoutState)
                .Cast <CheckoutCommandState>()
                .Select(x => x != null && x.DisabledMessage == null),
                DoCheckout);
            Checkout.ThrownExceptions.Subscribe(x => OperationError = x.Message);

            Pull = ReactiveCommand.CreateAsyncObservable(
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.PullDisabledMessage == null),
                DoPull);
            Pull.ThrownExceptions.Subscribe(x => OperationError = x.Message);

            Push = ReactiveCommand.CreateAsyncObservable(
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.PushDisabledMessage == null),
                DoPush);
            Push.ThrownExceptions.Subscribe(x => OperationError = x.Message);

            OpenOnGitHub = ReactiveCommand.Create();

            ChangedFilesViewType = (settings.UIState?.PullRequestDetailState?.ShowTree ?? true) ?
                                   ChangedFilesViewType.TreeView : ChangedFilesViewType.ListView;

            ToggleChangedFilesView = ReactiveCommand.Create();
            ToggleChangedFilesView.Subscribe(_ =>
            {
                ChangedFilesViewType = ChangedFilesViewType == ChangedFilesViewType.TreeView ?
                                       ChangedFilesViewType.ListView : ChangedFilesViewType.TreeView;
                settings.UIState.PullRequestDetailState.ShowTree = ChangedFilesViewType == ChangedFilesViewType.TreeView;
                settings.Save();
            });

            OpenChangedFileAction = (settings.UIState?.PullRequestDetailState?.DiffOnOpen ?? true) ?
                                    OpenChangedFileAction.Diff : OpenChangedFileAction.Open;

            ToggleOpenChangedFileAction = ReactiveCommand.Create();
            ToggleOpenChangedFileAction.Subscribe(_ =>
            {
                OpenChangedFileAction = OpenChangedFileAction == OpenChangedFileAction.Diff ?
                                        OpenChangedFileAction.Open : OpenChangedFileAction.Diff;
                settings.UIState.PullRequestDetailState.DiffOnOpen = OpenChangedFileAction == OpenChangedFileAction.Diff;
                settings.Save();
            });

            OpenFile = ReactiveCommand.Create();
            DiffFile = ReactiveCommand.Create();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PullRequestDetailViewModel"/> class.
        /// </summary>
        /// <param name="repositoryHost">The repository host.</param>
        /// <param name="teservice">The team explorer service.</param>
        /// <param name="pullRequestsService">The pull requests service.</param>
        /// <param name="avatarProvider">The avatar provider.</param>
        public PullRequestDetailViewModel(
            ILocalRepositoryModel repository,
            IModelService modelService,
            IPullRequestService pullRequestsService)
        {
            this.repository          = repository;
            this.modelService        = modelService;
            this.pullRequestsService = pullRequestsService;

            var canCheckout = this.WhenAnyValue(
                x => x.CheckoutMode,
                x => x.CheckoutDisabledMessage,
                (mode, disabled) => mode != CheckoutMode.UpToDate && mode != CheckoutMode.Push && disabled == null);

            Checkout = ReactiveCommand.CreateAsyncObservable(canCheckout, DoCheckout);

            OpenOnGitHub = ReactiveCommand.Create();

            ToggleChangedFilesView = ReactiveCommand.Create();
            ToggleChangedFilesView.Subscribe(_ =>
            {
                ChangedFilesViewType = ChangedFilesViewType == ChangedFilesViewType.TreeView ?
                                       ChangedFilesViewType.ListView : ChangedFilesViewType.TreeView;
            });

            ToggleOpenChangedFileAction = ReactiveCommand.Create();
            ToggleOpenChangedFileAction.Subscribe(_ =>
            {
                OpenChangedFileAction = OpenChangedFileAction == OpenChangedFileAction.Diff ?
                                        OpenChangedFileAction.Open : OpenChangedFileAction.Diff;
            });

            OpenFile = ReactiveCommand.Create();
            DiffFile = ReactiveCommand.Create();
        }