Пример #1
0
        public static SortEditor FactoryMethod(int view)
        {
            SortEditor Result;

            switch (view)
            {
            case 1:
                Result = new SortEditor();
                break;

            default:
                Result = new SortEditor();
                break;
            }

            if (!(Result is IView))
            {
                throw new Exception("Factory method have to return a object.");
            }
            return(Result);
        }
        public CatalogPageViewModel(ClientWindowViewModel parent)
        {
            this.parent  = parent;
            this.client  = parent.Client;
            this.library = parent.Library;
            var core = parent.Core;

            this.Length = client.Length.ToReadOnlyReactiveProperty().AddTo(this.Disposables);

            this.IsInSelecting = this.client.SelectedItemsCount
                                 .Select(x => x > 0)
                                 .ToReadOnlyReactiveProperty()
                                 .AddTo(this.Disposables);

            //表示中のインデックス
            this.StartIndex = this.client
                              .CatalogIndex
                              .Select(x => (x < int.MaxValue) ? (int)x : int.MaxValue)
                              .ToReactiveProperty()
                              .AddTo(this.Disposables);

            this.StartIndex
            .Subscribe(x => this.client.CatalogIndex.Value = x)
            .AddTo(this.Disposables);

            this.DisplayIndex = this.StartIndex.Select(x => x + 1).ToReactiveProperty().AddTo(this.Disposables);
            this.DisplayIndex.Subscribe(x => this.StartIndex.Value = x - 1).AddTo(this.Disposables);

            this.ThumbnailSize = core.ObserveProperty(x => x.ThumbNailSize)
                                 .Select(x => (double)x)
                                 .ToReactiveProperty().AddTo(this.Disposables);

            this.ThumbnailViewSize = this.ThumbnailSize
                                     .Select(x => new Size(x, x))
                                     .ToReadOnlyReactiveProperty()
                                     .AddTo(this.Disposables);

            this.ImagePropertiesVisibility = this.ThumbnailSize
                                             .Select(x => VisibilityHelper.Set(x > 128)).ToReactiveProperty().AddTo(this.Disposables);

            this.ThumbnailMargin = this.ThumbnailSize
                                   .Select(x => new Thickness((x < 128) ? 1 : (x < 256) ? 2 : 4))
                                   .ToReactiveProperty().AddTo(this.Disposables);

            this.IsRefreshEnabled = this.client.IsStateChanging
                                    .Select(x => !x)
                                    .ToReadOnlyReactiveProperty()
                                    .AddTo(this.Disposables);

            this.IsRenderingEnabled = this.client.IsCatalogRenderingEnabled
                                      .CombineLatest(this.client.SelectedPage, (e, p) => e && p == PageType.Catalog)
                                      .ToReadOnlyReactiveProperty(true)
                                      .AddTo(this.Disposables);


            //戻ってきたときにサムネイル再読み込み
            client.BackHistoryCount
            .Pairwise()
            .CombineLatest(client.SelectedPage,
                           (history, page) => history.OldItem > history.NewItem && page == PageType.Catalog)
            .Where(x => x)
            .Subscribe(_ => this.RefreshTrigger = !this.RefreshTrigger)
            .AddTo(this.Disposables);

            client.CacheUpdated
            .SkipUntil(client.StateChanged)
            .Take(1)
            .Repeat()
            .Subscribe(_ => this.RefreshTrigger = !this.RefreshTrigger)
            .AddTo(this.Disposables);


            //スクロールが落ち着いたら再読み込み
            this.StartIndex
            .Throttle(TimeSpan.FromMilliseconds(3000))
            .ObserveOnUIDispatcher()
            .Subscribe(_ => this.RefreshTrigger = !this.RefreshTrigger)
            .AddTo(this.Disposables);

            //スクロール位置復元
            this.client.CatalogScrollIndex
            .Subscribe(x => this.ScrollToIndexAction?.Invoke((int)x))
            .AddTo(this.Disposables);

            //サムネイルクリック
            this.ItemClickCommand = new ReactiveCommand()
                                    .WithSubscribe(context => this.SelectOrShow(context, true), this.Disposables);

            //選択
            this.ItemSelectCommand = new ReactiveCommand()
                                     .WithSubscribe(context => this.SelectOrShow(context, false), this.Disposables);

            //ソート条件編集
            this.EditSortCommand = new ReactiveCommand()
                                   .WithSubscribe(x =>
            {
                var control = x as FrameworkElement;

                var content = new SortEditor()
                {
                    ItemsSource = this.client.GetSort(),
                };

                content.IsEnabledChanged += (o, e) =>
                {
                    var value = e.NewValue as bool?;
                    if (value.HasValue && !value.Value)
                    {
                        this.client.SetSort(content.SortSettings);
                    }
                };

                this.parent.PopupOwner.PopupDialog.Show(content,
                                                        new Thickness(double.NaN, 10.0, 0.0, double.NaN),
                                                        HorizontalAlignment.Right, VerticalAlignment.Bottom, control);
            }, this.Disposables);

            //すべて選択
            this.SelectAllCommand = new ReactiveCommand()
                                    .WithSubscribe(async _ => await this.client.SelectAllAsync(), this.Disposables);

            //選択をクリア
            this.SelectionClearCommand = this.IsInSelecting
                                         .ToReactiveCommand()
                                         .WithSubscribe(_ => this.SelectedItems.Clear(), this.Disposables);

            //グループ化
            this.GroupingCommand = this.client.SelectedItemsCount
                                   .CombineLatest(this.client.IsGroupMode, (c, g) => c > 1 && !g)
                                   .ToReactiveCommand()
                                   .WithSubscribe(_ => this.client.Grouping(), this.Disposables);

            //グループから退去
            this.RemoveFromGroupCommand = this.client.SelectedItemsCount
                                          .CombineLatest(this.client.IsGroupMode, (c, g) => c >= 1 && g)
                                          .ToReactiveCommand()
                                          .WithSubscribe(_ => this.client.RemoveFromGroup(), this.Disposables);

            this.SetToLeaderCommand = this.client.SelectedItemsCount
                                      .CombineLatest(this.client.IsGroupMode, (c, g) => c == 1 && g)
                                      .ToReactiveCommand()
                                      .WithSubscribe(_ => this.client.SetGroupLeader(), this.Disposables);

            this.RefreshCommand = new ReactiveCommand()
                                  .WithSubscribe(_ => this.client.Refresh(), this.Disposables);

            this.RegisterKeyReceiver(parent);
        }