public TabControllerModel(
     MainReducer reducer,
     PageControllerReducer controllerReducer,
     TabPageHost host)
 {
     reducer.Select(state => state.DragData).Subscribe(data => {
         if (data == null)
         {
             foreach (var tabItem in this.Tabs)
             {
                 tabItem.MouseMove -= OpenTabOnHover;
             }
         }
         else
         {
             foreach (var tabItem in this.Tabs)
             {
                 tabItem.MouseMove += OpenTabOnHover;
             }
         }
     });
     reducer.Select(state => state.FullscreenMode)
     .Subscribe(isFullscreen => this.IsHeaderVisible = !isFullscreen);
     host.WhenTabAdded
     .ObserveOnDispatcher(DispatcherPriority.Background)
     .Subscribe(tab => {
         this.Tabs.Add(tab);
         this.ActiveTab = tab;
         if (this.ActiveTab == null)
         {
             return;
         }
         this.ActiveTab.AllowDrop = true;
     });
     host.WhenTabClosed
     .ObserveOnDispatcher(DispatcherPriority.Background)
     .Subscribe(RemoveTab);
     this.WhenAnyValue(model => model.ActiveTab)
     .Where(LambdaHelper.NotNull)
     .ObserveOnDispatcher(DispatcherPriority.Background)
     .Subscribe(tab => {
         tab.IsSelected   = true;
         var activeTabUid = tab.Uid;
         var hostPage     = host.Pages.GetOrDefault(activeTabUid);
         if (hostPage == default)
         {
             return;
         }
         controllerReducer.DispatchSetValueAction(state => state.SelectedPage,
                                                  hostPage.Token);
     });
 }
Exemple #2
0
        public PageControllerModel(
            PageControllerToken token,
            ModuleActivator activator,
            PageControllerReducer reducer,
            SerialUtil serialUtil,
            MainReducer mainReducer,
            WindowPageHost windowPageHost,
            DatabaseManager databaseManager,
            DatabaseBackupService databaseBackupService
            )
        {
            _activator             = activator;
            _windowPageHost        = windowPageHost;
            _databaseManager       = databaseManager;
            _databaseBackupService = databaseBackupService;
            this._serialUtil       = serialUtil;
            InitHandlers();
            ActivateContent(token);

            this.WhenActivated((c) => {
                mainReducer.Select(state => state.FullscreenMode)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(isFullScreen => this.MenuVisibility = !isFullScreen)
                .DisposeWith(c);
                reducer.Select(state => state.SelectedPage)
                .Where(LambdaHelper.NotNull)
                .WithLatestFrom(reducer.Select(state => state.Controls), LambdaHelper.ToTuple)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(tuple => {
                    var(selectedPage, controlsDict) = tuple;
                    var controls = selectedPage == null
                            ? new List <ButtonConfig>()
                            : controlsDict.GetOrDefault(selectedPage.Id) ?? new List <ButtonConfig>();
                    SetActionButtons(controls);
                })
                .DisposeWith(c);
                _serialUtil.ConnectionStatus
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Select(status => status.IsConnected)
                .Subscribe(status => {
                    this.ReaderMenuText = status
                            ? Localization["Отключить считыватель"]
                            : Localization["Включить считыватель"];
                })
                .DisposeWith(c);
            });
        }
        public WindowSubscriptionContainer(
            Window window,
            IModuleToken token,
            MainReducer reducer
            )
        {
            _window  = window;
            _token   = token;
            _reducer = reducer;

            window.KeyDown    += OnWindowOnKeyDown;
            token.Deactivated += OuterDeactivationHandler;
            window.Closed     += DeactivationHandler;
            _subscription      = reducer.Select(state => state.FullscreenMode)
                                 .Subscribe(isFullscreen => {
                window.WindowStyle = isFullscreen ? WindowStyle.None : WindowStyle.SingleBorderWindow;
                window.WindowState = isFullscreen ? WindowState.Maximized : WindowState.Normal;
            });
        }
Exemple #4
0
        private void InitTableConfigs()
        {
            this.RegisteredStudentsTableConfig = new TableConfig {
                Sorts      = RegisteredStudentsSorts,
                Filter     = this.Filter,
                DragConfig = new DragConfig {
                    SourceId         = _token.Id + nameof(this.RegisteredStudentsTableConfig),
                    SourceType       = nameof(StudentLessonEntity),
                    DropAvailability = data => data.Data.Count > 0 &&
                                       ((data.SenderType.Equals(nameof(StudentLessonEntity)) &&
                                         data.SenderId.Equals(this.LessonStudentsTableConfig.DragConfig
                                                              .SourceId)
                                         ) ||
                                        data.SenderType.Equals(nameof(StudentEntity))),
                    Drop = async() => {
                        var dragData = await _mainReducer.Select(state => state.DragData).FirstOrDefaultAsync();

                        if (dragData == null)
                        {
                            return;
                        }

                        if (nameof(StudentLessonEntity).Equals(dragData.SenderType))
                        {
                            RunInUiThread(Register);
                        }

                        if (nameof(StudentEntity).Equals(dragData.SenderType))
                        {
                            RunInUiThread(() => AcceptDropFromStudentTable(dragData.Data));
                        }

                        dragData.Accept();
                    },
                    DragStart = data => _mainReducer.DispatchSetValueAction(state => state.DragData, data),
                },
                ColumnWidths = new[] {
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                }
            };
            this.AllStudentsTableConfig = new TableConfig {
                Sorts      = Sorts,
                Filter     = this.AllStudentsFilter,
                DragConfig = new DragConfig {
                    SourceId      = _token.Id + nameof(this.AllStudentsTableConfig),
                    SourceType    = nameof(StudentEntity),
                    DragValuePath = "Student",
                    DragStart     = data => _mainReducer.DispatchSetValueAction(state => state.DragData, data)
                },
                IsFilterDependsOnlyOnFilterValue = false,
                ColumnWidths = new[] {
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(100),
                }
            };
            this.LessonStudentsTableConfig = new TableConfig {
                Sorts      = Sorts,
                Filter     = this.Filter,
                DragConfig = new DragConfig {
                    SourceId         = _token.Id + nameof(this.LessonStudentsTableConfig),
                    SourceType       = nameof(StudentLessonEntity),
                    DropAvailability = data => data.Data.Count > 0 &&
                                       data.SenderId.Equals(this.RegisteredStudentsTableConfig.DragConfig
                                                            .SourceId),
                    Drop = async() => {
                        var dragData = await _mainReducer.Select(state => state.DragData).FirstAsync();

                        RunInUiThread(UnRegister);
                        dragData.Accept();
                    },
                    DragStart = data => _mainReducer.DispatchSetValueAction(state => state.DragData, data)
                },
                ColumnWidths = new[] {
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                    new GridLength(1, GridUnitType.Star),
                }
            };
        }