Esempio n. 1
0
        private static SelectorMatch MatchDescendent(IStyleable control, Selector previous)
        {
            ILogical c = (ILogical)control;
            List <IObservable <bool> > descendentMatches = new List <IObservable <bool> >();

            while (c != null)
            {
                c = c.LogicalParent;

                if (c is IStyleable)
                {
                    var match = previous.Match((IStyleable)c);

                    if (match.ImmediateResult != null)
                    {
                        if (match.ImmediateResult == true)
                        {
                            return(SelectorMatch.True);
                        }
                    }
                    else
                    {
                        descendentMatches.Add(match.ObservableResult);
                    }
                }
            }

            return(new SelectorMatch(StyleActivator.Or(descendentMatches)));
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to match the selector with a control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns>A <see cref="SelectorMatch"/>.</returns>
        public SelectorMatch Match(IStyleable control)
        {
            List <IObservable <bool> > inputs = new List <IObservable <bool> >();
            Selector selector = this;

            while (selector != null)
            {
                if (selector._inTemplate && control.TemplatedParent == null)
                {
                    return(SelectorMatch.False);
                }

                var match = selector._evaluate(control);

                if (match.ImmediateResult == false)
                {
                    return(match);
                }
                else if (match.ObservableResult != null)
                {
                    inputs.Add(match.ObservableResult);
                }

                selector = selector.MovePrevious();
            }

            if (inputs.Count > 0)
            {
                return(new SelectorMatch(StyleActivator.And(inputs)));
            }
            else
            {
                return(SelectorMatch.True);
            }
        }
Esempio n. 3
0
        public void Activator_And_Should_Follow_Single_Input()
        {
            var inputs = new[] { new TestSubject<bool>(false) };
            var target = new StyleActivator(inputs, ActivatorMode.And);
            var result = new TestObserver<bool>();

            target.Subscribe(result);
            Assert.False(result.GetValue());
            inputs[0].OnNext(true);
            Assert.True(result.GetValue());
            inputs[0].OnNext(false);
            Assert.False(result.GetValue());
            inputs[0].OnNext(true);
            Assert.True(result.GetValue());

            Assert.Equal(1, inputs[0].SubscriberCount);
        }
Esempio n. 4
0
        public void Activator_And_Should_Not_Unsubscribe_All_When_Input_Completes_On_True()
        {
            var inputs = new[]
            {
                new TestSubject<bool>(false),
                new TestSubject<bool>(false),
                new TestSubject<bool>(true),
            };
            var target = new StyleActivator(inputs, ActivatorMode.And);
            var result = new TestObserver<bool>();

            target.Subscribe(result);
            Assert.False(result.GetValue());
            inputs[0].OnNext(true);
            inputs[0].OnCompleted();

            Assert.Equal(1, inputs[0].SubscriberCount);
            Assert.Equal(1, inputs[1].SubscriberCount);
            Assert.Equal(1, inputs[2].SubscriberCount);
        }
Esempio n. 5
0
        public void Attach(IStyleable control)
        {
            string         description = "Style " + this.Selector.ToString();
            StyleActivator activator   = this.Selector.GetActivator(control);

            if (activator.CurrentValue || !activator.HasCompleted)
            {
                IObservable <bool> observable = activator;

                // If the activator has completed, then we want its value to be true forever.
                // Because of this we can't pass the activator directly as it will complete
                // immediately and remove the binding.
                if (activator.HasCompleted)
                {
                    observable = Observable.Never <bool>().StartWith(true);
                }

                foreach (Setter setter in this.Setters)
                {
                    StyleBinding binding = new StyleBinding(observable, setter.Value, description);
                    control.Bind(setter.Property, binding, this.Selector.Priority);
                }
            }
        }
Esempio n. 6
0
        protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
        {
            ILogical c = (ILogical)control;
            List <IObservable <bool> > descendentMatches = new List <IObservable <bool> >();

            while (c != null)
            {
                c = c.LogicalParent;

                if (c is IStyleable)
                {
                    var match = _parent.Match((IStyleable)c, subscribe);

                    if (match.ImmediateResult != null)
                    {
                        if (match.ImmediateResult == true)
                        {
                            return(SelectorMatch.True);
                        }
                    }
                    else
                    {
                        descendentMatches.Add(match.ObservableResult);
                    }
                }
            }

            if (descendentMatches.Count > 0)
            {
                return(new SelectorMatch(StyleActivator.Or(descendentMatches)));
            }
            else
            {
                return(SelectorMatch.False);
            }
        }
Esempio n. 7
0
        public void Completed_Activator_Should_Signal_OnCompleted()
        {
            var inputs = new[]
            {
                Observable.Return(false),
            };

            var target = new StyleActivator(inputs, ActivatorMode.Or);
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);

            Assert.True(completed);
        }
Esempio n. 8
0
        public void Activator_Or_Should_OR_Multiple_Inputs()
        {
            var inputs = new[]
            {
                new TestSubject<bool>(false),
                new TestSubject<bool>(false),
                new TestSubject<bool>(true),
            };
            var target = new StyleActivator(inputs, ActivatorMode.Or);
            var result = new TestObserver<bool>();

            target.Subscribe(result);
            Assert.True(result.GetValue());
            inputs[2].OnNext(false);
            Assert.False(result.GetValue());
            inputs[0].OnNext(true);
            Assert.True(result.GetValue());

            Assert.Equal(1, inputs[0].SubscriberCount);
            Assert.Equal(1, inputs[1].SubscriberCount);
            Assert.Equal(1, inputs[2].SubscriberCount);
        }