Exemplo n.º 1
0
        private void DataGridEditingExtender_PreviewCurrentChanging(object sender, PreviewChangeEventArgs e)
        {
            UniversalCellInfo oldCell = (UniversalCellInfo)(e.OldValue ?? new UniversalCellInfo());
            UniversalCellInfo newCell = (UniversalCellInfo)(e.NewValue ?? new UniversalCellInfo());

            var focusManager = UIServiceProvider.GetService <IFocusManagementService>(TargetElement);

            using (focusManager.DeferFocusUpdate())
            {
                if (!CanLeaveCurrentCell())
                {
                    CancelNavigation(e);
                }
                else
                if (oldCell.Item != newCell.Item)
                {
                    log.DebugFormat("Processing line change event on {0}", this);

                    if (!CanLeaveCurrentLine())
                    {
                        CancelNavigation(e);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ReplaceServiceListTest()
        {
            // Open a window with a control that has services attached.
            var window = new Window();
            var button = new Button();

            window.Content = button;

            UIServiceCollection serviceCollection = new UIServiceCollection();
            var serviceA = new TestServiceA();

            serviceCollection.Add(new ServiceFactoryMock(serviceA));
            UIServiceProvider.SetServiceList(button, serviceCollection);

            // Replace the assigned, yet unattached services.
            serviceCollection = new UIServiceCollection();
            var serviceA2 = new TestServiceA();

            serviceCollection.Add(new ServiceFactoryMock(serviceA2));
            UIServiceProvider.SetServiceList(button, serviceCollection);

            // Verify the old service was disposed.
            Assert.IsTrue(serviceA.IsDisposed);

            // Verify the old service does not become attached to the element.
            using (TestUtils.AutoCloseWindow(window))
            {
                Assert.IsFalse(serviceA.IsAttached);
                Assert.IsTrue(serviceA2.IsAttached);
            }

            Assert.IsTrue(serviceA2.IsDisposed);
        }
Exemplo n.º 3
0
        private void RegisterKeyGesture(Key key, Action <KeyEventArgs> action)
        {
            InputService inputService = UIServiceProvider.GetService <InputService>(TargetElement);
            var          gesture      = new KeyGesture(key);

            registeredGestures.Add(gesture);
            inputService.RegisterKeyGestureAction(gesture, action);
        }
Exemplo n.º 4
0
            protected override void Cleanup()
            {
                EditMode.TargetElement.RemoveHandler(FrameworkElement.PreviewKeyDownEvent, (RoutedEventHandler)TargetElement_PreviewKeyDown);
                EditMode.TargetElement.RemoveHandler(FrameworkElement.PreviewKeyUpEvent, (RoutedEventHandler)TargetElement_PreviewKeyUp);

                currentCellService = UIServiceProvider.GetService <ICurrentCellService>(EditMode.TargetElement);
                currentCellService.CurrentCellChanged -= currentCellService_CurrentCellChanged;
            }
Exemplo n.º 5
0
        public virtual void Setup()
        {
            CurrentCellService = UIServiceProvider.GetService <ICurrentCellService>(TargetElement);
            CommandRegulator   = UIServiceProvider.GetService <ICommandRegulationService>(TargetElement);

            CommandRegulator.PreviewCanExecute            += PreviewCanExecuteCommand;
            CurrentCellService.PreviewCurrentCellChanging += DataGridEditingExtender_PreviewCurrentChanging;
        }
Exemplo n.º 6
0
            protected override void Setup()
            {
                EditMode.TargetElement.AddHandler(FrameworkElement.PreviewKeyDownEvent, (RoutedEventHandler)TargetElement_PreviewKeyDown, true);
                EditMode.TargetElement.AddHandler(FrameworkElement.PreviewKeyUpEvent, (RoutedEventHandler)TargetElement_PreviewKeyUp, true);

                currentCellService = UIServiceProvider.GetService <ICurrentCellService>(EditMode.TargetElement);
                currentCellService.CurrentCellChanged         += currentCellService_CurrentCellChanged;
                currentCellService.PreviewCurrentCellChanging += currentCellService_PreviewCurrentCellChanging;
            }
Exemplo n.º 7
0
        private void CancelEdit(KeyEventArgs e)
        {
            var editStateService = UIServiceProvider.GetService <IElementEditStateService>(TargetElement);

            if (editStateService.IsEditingField)
            {
                editStateService.CancelItemEdit();
            }
            e.Handled = true;
        }
Exemplo n.º 8
0
        protected override bool CanLeaveCurrentLine()
        {
            var editStateService = UIServiceProvider.GetService <IElementEditStateService>(TargetElement);

            if (editStateService.IsEditingField)
            {
                return(editStateService.CommitItemEdit());
            }
            return(true);
        }
Exemplo n.º 9
0
        public override void Cleanup()
        {
            base.Cleanup();
            InputService inputService = UIServiceProvider.GetService <InputService>(TargetElement);

            foreach (var gesture in registeredGestures)
            {
                inputService.UnregisterGestureAction(gesture);
            }
        }
Exemplo n.º 10
0
        private void ToggleEdit(KeyEventArgs e)
        {
            var editStateService = UIServiceProvider.GetService <IElementEditStateService>(TargetElement);

            if (editStateService.IsEditingField)
            {
                editStateService.CommitItemEdit();
            }
            else
            {
                editStateService.BeginItemEdit();
            }
            e.Handled = true;
        }
Exemplo n.º 11
0
 private void MoveToNextState()
 {
     TargetElement.Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(() =>
     {
         var fms = UIServiceProvider.GetService <IFocusManagementService>(TargetElement);
         using (fms.DeferFocusUpdate())
         {
             log.Debug("Moving to next edit state");
             EditModeState nextState = currentState.GetNextState();
             currentState.Leave();
             currentState = nextState;
             currentState.Enter(this);
         }
     }));
 }
Exemplo n.º 12
0
        public static IDisposable Show(IList dataList, UIServiceCollection dgServiceList, out DataGrid dataGrid)
        {
            var w = new TestWindow();

            if (dgServiceList != null)
            {
                UIServiceProvider.SetServiceList(w.MainDataGrid, dgServiceList);
            }

            w.DataContext = new ListCollectionView(dataList);

            var result = TestUtils.AutoCloseWindow(w);

            dataGrid = w.MainDataGrid;
            return(result);
        }
        public SelectionModeManager(FrameworkElement element)
        {
            ElementSelectionService = UIServiceProvider.GetService <IMultiSelectionService>(element);
            CurrentItemTracker      = UIServiceProvider.GetService <ICurrentItemService>(element);

            CurrentItemTracker.CurrentChanged += CurrentItemTracker_CurrentChanged;

            //ElementSelectionService.AddHandler(FrameworkElement.PreviewKeyDownEvent, new RoutedEventHandler(TargetElement_PreviewKeyDown), true);
            //ElementSelectionService.AddHandler(FrameworkElement.PreviewKeyUpEvent, new RoutedEventHandler(TargetElement_PreviewKeyUp), true);
            //ElementSelectionService.AddHandler(FrameworkElement.PreviewMouseDownEvent, new RoutedEventHandler(TargetElement_PreviewMouseDown), true);

            SingleSelectionMode.Initialize(ElementSelectionService, CurrentItemTracker);
            MultiSelectionMode.Initialize(ElementSelectionService, CurrentItemTracker);

            SetCurrentSelectionMode(SingleSelectionMode);
            currentSelectionMode.Enter();
        }
Exemplo n.º 14
0
        public override void Enter()
        {
            var anchor = CurrentItemTracker.CurrentItem;

            if (ElementSelectionService.SelectedItem != null)
            {
                anchor = ElementSelectionService.SelectedItem;
            }
            log.Debug("Entering multi-selection mode.");
            log.DebugFormat("Anchor is {0}", anchor);
            lastKnownCurrentItem            = anchor;
            lastDistanceFromSelectionAnchor = 0;

            var inputService = UIServiceProvider.GetService <InputService>(ElementSelectionService.Element);

            inputService.RegisterKeyGestureAction(ToggleSelectionKey, (a) => ToggleItemSelection());
        }
Exemplo n.º 15
0
        protected override bool CanLeaveCurrentCell()
        {
            if (EditStateService.IsEditingField)
            {
                var fms = UIServiceProvider.GetService <IFocusManagementService>(TargetElement);
                deferedFocus.Push(fms.DeferFocusUpdate());
                log.Debug("Leaving current cell: Commit");
                if (EditStateService.CommitFieldEdit())
                {
                    return(true);
                }
                else
                {
                    DisposeDeferedFocus();
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 16
0
        public bool BeginFieldEdit()
        {
            if (!canBeginEdit)
            {
                return(false);
            }

            var currentCellService = UIServiceProvider.GetService <ICurrentCellService>(CellContainerOwner);

            editingCell = currentCellService.CurrentCellContainer as VirtualTableCell;
            if (editingCell != null)
            {
                if (editingCell.BeginEdit())
                {
                    OnEditStateChanged();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 17
0
        public void SetServiceProviderTest()
        {
            // Open a window with a control without any service.
            Window window = new Window();
            Button button = new Button();

            window.Content = button;
            using (TestUtils.AutoCloseWindow(window))
            {
                var serviceList = UIServiceProvider_Accessor.GetServiceList(button);
                Assert.IsNotNull(serviceList);
                List <IUIServiceFactory> serviceListWrapper = new List <IUIServiceFactory>(serviceList);
                Assert.AreEqual(0, serviceListWrapper.Count);
                Assert.IsNull(UIServiceProvider_Accessor.GetServiceProvider(button));
                var service = UIServiceProvider.GetService(button, typeof(TestServiceBase));
                Assert.IsNull(service);
            }

            // Open a window with a control that has services attached.
            window         = new Window();
            button         = new Button();
            window.Content = button;

            UIServiceCollection serviceCollection = new UIServiceCollection();
            var serviceA = new TestServiceA();

            serviceCollection.Add(new ServiceFactoryMock(serviceA));
            UIServiceProvider.SetServiceList(button, serviceCollection);

            using (TestUtils.AutoCloseWindow(window))
            {
                Assert.IsNotNull(UIServiceProvider_Accessor.GetServiceList(button));
                Assert.IsNotNull(UIServiceProvider_Accessor.GetServiceProvider(button));
                var service = UIServiceProvider.GetService(button, typeof(TestServiceBase));
                Assert.IsInstanceOfType(service, typeof(TestServiceA));
                Assert.IsFalse(serviceA.IsDisposed);
            }

            Assert.IsTrue(serviceA.IsDisposed);
        }
Exemplo n.º 18
0
        public override void Leave()
        {
            var inputService = UIServiceProvider.GetService <InputService>(ElementSelectionService.Element);

            inputService.UnregisterGestureAction(ToggleSelectionKey);
        }