Beispiel #1
0
        public WipFile(Repository repos, bool isInStaging, string path)
        {
            Debug.Assert(repos != null);
            _repos = repos;

            _isInStaging = isInStaging;

            _path = path;
        }
Beispiel #2
0
        public WipBaseFileVm(Repository repos, WipFile model)
            : base(true)
        {
            Debug.Assert(repos != null);
            Debug.Assert(model != null);
            _model = model;

            #region IsInStaging, IsInStagingFromModel

            IsInStaging = new ReactiveProperty<bool>(model.IsInStaging)
                .AddTo(MultipleDisposable);

            IsInStaging.Subscribe(x =>
            {
                if (x)
                    model.Stage();
                else
                    model.Unstage();
            }).AddTo(MultipleDisposable);

            IsInStagingFromModel = model.ObserveProperty(x => x.IsInStaging)
                .ToReadOnlyReactiveProperty()
                .AddTo(MultipleDisposable);

            IsInStagingFromModel
                .Subscribe(x => IsInStaging.Value = x)
                .AddTo(MultipleDisposable);

            #endregion

            if (_model.IsBinary == false)
                this.MakeDiff(_model.Patch);

            IsSelected = new ReactiveProperty<bool>()
                .AddTo(MultipleDisposable);

            DiscardChangesCommand = new ReactiveCommand()
                .AddTo(MultipleDisposable);

            DiscardChangesCommand
                .Subscribe(_ => repos.DiscardChanges(new[] {Path}))
                .AddTo(MultipleDisposable);
        }
Beispiel #3
0
        public WipFileVm(Repository repos, WipFile model)
            : base(true)
        {
            Debug.Assert(repos != null);
            Debug.Assert(model != null);

            _model = model;

            MultipleDisposable.AddFirst(() =>
            {
                lock (_diffMakingLockObj)
                {
                    if (IsDiffMaking)
                        _disposeResetEvent = new ManualResetEventSlim();
                }
            });

            //
            Path = model.ObserveProperty(x => x.Path).ToReactiveProperty().AddTo(MultipleDisposable);
            Status = model.ObserveProperty(x => x.Status).ToReactiveProperty().AddTo(MultipleDisposable);
            //
            DiffLines.AddTo(MultipleDisposable);

            //LinesAdded = model.ObserveProperty(x => x.LinesAdded, false).ToReactiveProperty().AddTo(MultipleDisposable);
            //LinesDeleted = model.ObserveProperty(x => x.LinesDeleted, false).ToReactiveProperty().AddTo(MultipleDisposable);
            IsBinary = model.ObserveProperty(x => x.IsBinary, false).ToReactiveProperty().AddTo(MultipleDisposable);

            #region IsInStaging, IsInStagingFromModel

            IsInStaging = new ReactiveProperty<bool>(model.IsInStaging)
                .AddTo(MultipleDisposable);

            IsInStaging.Subscribe(x =>
            {
                if (x)
                    model.Stage();
                else
                    model.Unstage();
            }).AddTo(MultipleDisposable);

            IsInStagingFromModel = model.ObserveProperty(x => x.IsInStaging)
                .ToReadOnlyReactiveProperty()
                .AddTo(MultipleDisposable);

            IsInStagingFromModel
                .Subscribe(x => IsInStaging.Value = x)
                .AddTo(MultipleDisposable);

            #endregion

            IsSelected = new ReactiveProperty<bool>()
                .AddTo(MultipleDisposable);

            DiscardChangesCommand = new ReactiveCommand()
                .AddTo(MultipleDisposable);

            DiscardChangesCommand
                .Subscribe(_ => repos.DiscardChanges(new[] {Path.Value}))
                .AddTo(MultipleDisposable);

            model.ObserveProperty(x => x.Patch, false)
                .Subscribe(x => Diff = null)
                .AddTo(MultipleDisposable);
        }
Beispiel #4
0
        public RepositoryVm(Repository model, MainWindowVm parent)
        {
            Debug.Assert(model != null);
            Debug.Assert(parent != null);

            _model = model;
            _parent = parent;

            JobSummaries = _model.JobSummaries
                .ToReadOnlyReactiveCollection()
                .AddTo(MultipleDisposable);

            WorkingJob = _model.WorkingJob
                .ToReadOnlyReactiveProperty()
                .AddTo(MultipleDisposable);

            // ブランチ
            LocalBranches = _model.Branches
                .ToReadOnlyReactiveCollection()
                .ToFilteredReadOnlyObservableCollection(x => !x.IsRemote)
                .ToReadOnlyReactiveCollection(x => new BranchVm(this, x))
                .AddTo(MultipleDisposable);

            RemoteBranches = _model.Branches
                .ToReadOnlyReactiveCollection()
                .ToFilteredReadOnlyObservableCollection(x => x.IsRemote)
                .ToReadOnlyReactiveCollection(x => new BranchVm(this, x))
                .AddTo(MultipleDisposable);

            // アウトライナー
            Outliner = new ReactiveProperty<RepositoryOutlinerVm>(new RepositoryOutlinerVm(this))
                .AddTo(MultipleDisposable);
            MultipleDisposable.Add(() => Outliner.Value.Dispose());

            // ファイルステータス
            FileStatus = new FileStatusVm(model)
                .AddTo(MultipleDisposable);

            WordFilter = new ReactiveProperty<WordFilter>(new WordFilter()).AddTo(MultipleDisposable);
            IsFiltering = new ReactiveProperty<bool>().AddTo(MultipleDisposable);

            // コミット
            ICommitVm selectedCommitVm = null;

            Commits = FileStatus.WipFiles.CombineLatest(_model.ObserveProperty(x => x.Commits), WordFilter,
                (wipFiles, commits, wordFilter) => new {wipFiles, commits, wordFilter})
                .Do(_ => IsFiltering.Value = true)
                .Do(_ => _oldCommits.Enqueue(Commits?.Value))
                .Select(x =>
                {
                    selectedCommitVm = null;

                    var selectedCommitHash = (SelectedCommit?.Value as DoneCommitVm)?.Hash;

                    var allCommits = new ObservableCollection<ICommitVm>();
                    {
                        if (x.wipFiles.Any())
                            allCommits.Add(new WipCommitVm(this, TwoPaneLayout));

                        x.commits
                            .AsParallel()
                            .AsOrdered()
                            .Where(y => x.wordFilter.IsMatch(y.Message))
                            .Select(y =>
                            {
                                var commit = new DoneCommitVm(this, y, TwoPaneLayout);

                                if (commit.Hash == selectedCommitHash)
                                    selectedCommitVm = commit;

                                return (ICommitVm) commit;
                            })
                            .ForEach(y => allCommits.Add(y));
                    }

                    return allCommits;
                })
                .Do(_ => IsFiltering.Value = false)
                .ToReactiveProperty()
                .AddTo(MultipleDisposable);

            MultipleDisposable.Add(() => Commits?.Value?.OfType<IDisposable>().ForEach(x => x.Dispose()));

            // 選択アイテム
            SelectedLocalBranch = new ReactiveProperty<BranchVm>().AddTo(MultipleDisposable);
            SelectedRemoteBranch = new ReactiveProperty<BranchVm>().AddTo(MultipleDisposable);

            SelectedCommit = Commits
                .Select(c => selectedCommitVm ?? c?.FirstOrDefault())
                .ToReactiveProperty()
                .AddTo(MultipleDisposable);

            SelectedCommitDelay = SelectedCommit
                .Sample(TimeSpan.FromMilliseconds(150))
                .ToReadOnlyReactiveProperty()
                .AddTo(MultipleDisposable);

            Commits
                .Delay(TimeSpan.FromMilliseconds(1000))
                .Subscribe(_ =>
                {
                    ObservableCollection<ICommitVm> oldCommits;
                    var i = _oldCommits.TryDequeue(out oldCommits);
                    Debug.Assert(i);

                    oldCommits?.OfType<IDisposable>().ForEach(x => x.Dispose());
                }).AddTo(MultipleDisposable);

            Observable.FromEventPattern<ExceptionEventArgs>(_model, nameof(_model.JobExecutingException))
                .Select(x => x.EventArgs)
                .ObserveOnUIDispatcher()
                .Subscribe(e => ShowDialog(e.Exception, e.Summary))
                .AddTo(MultipleDisposable);

            InitializeCommands();
        }