public void Reset()
 {
     m_Path.Clear();
     m_References.Clear();
     m_ParentStack.Clear();
     m_IgnoreNextInspectorsCount = 0;
 }
Ejemplo n.º 2
0
        public void PropertyElement_Changes_ArePropagated()
        {
            Element.SetTarget(GetContainer());

            var expectedPath = new PropertyPath();

            Element.OnChanged += (propertyElement, path) =>
            {
                Assert.That(path.ToString(), Is.EqualTo(expectedPath.ToString()));
            };

            {
                var field = Element.Query <FloatField>()
                            .Where(f => f.bindingPath == nameof(ComplexUIContainer.FloatField)).First();
                expectedPath.Clear();
                expectedPath.PushName(nameof(ComplexUIContainer.FloatField));
                field.value = 25.0f;
            }

            {
                var field = Element.Query <IntegerField>()
                            .Where(f => f.bindingPath == nameof(ComplexUIContainer.IntField)).First();
                expectedPath.Clear();
                expectedPath.PushName(nameof(ComplexUIContainer.IntField));
                field.value = 50;
            }

            {
                var field = Element.Query <TextField>()
                            .Where(f => f.bindingPath == nameof(ComplexUIContainer.StringField)).First();
                expectedPath.Clear();
                expectedPath.PushName(nameof(ComplexUIContainer.StringField));
                field.value = "Mueueue";
            }

            {
                var field = Element.Query <IListElement <List <int>, int> >()
                            .Where(f => f.bindingPath == nameof(ComplexUIContainer.IntListField)).First()
                            .Query <IntegerField>().Where(f => f.bindingPath == "2").First();
                expectedPath.Clear();
                expectedPath.PushName(nameof(ComplexUIContainer.IntListField));
                expectedPath.PushIndex(2);
                field.value = 4;
            }

            {
                var kvps = Element.Query <DictionaryElement <Dictionary <int, int>, int, int> >()
                           .Where(f => f.bindingPath == nameof(ComplexUIContainer.IntIntDictionary)).First()
                           .Query <IntegerField>().Where(f => f.bindingPath == "Value").ToList();
                for (var i = 0; i < kvps.Count; ++i)
                {
                    var field = kvps[i];
                    expectedPath.Clear();
                    expectedPath.PushName(nameof(ComplexUIContainer.IntIntDictionary));
                    expectedPath.PushKey(i);
                    expectedPath.PushName("Value");
                    field.value = 20;
                }
            }
        }
Ejemplo n.º 3
0
        public void PropertyElement_IsPathValid_ReturnsTrueForValidPath()
        {
            var element   = new PropertyElement();
            var container = GetContainer();

            element.SetTarget(container);

            var path = new PropertyPath();
            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.FloatField));
                Assert.That(element.IsPathValid(path), Is.True);
            }

            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.IntField));
                Assert.That(element.IsPathValid(path), Is.True);
            }

            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.StringField));
                Assert.That(element.IsPathValid(path), Is.True);
            }

            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.IntListField));
                Assert.That(element.IsPathValid(path), Is.True);
                for (var i = 0; i < container.IntListField.Count; ++i)
                {
                    path.PushIndex(i);
                    Assert.That(element.IsPathValid(path), Is.True);
                    path.Pop();
                }
            }

            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.IntIntDictionary));
                Assert.That(element.IsPathValid(path), Is.True);
                foreach (var kvp in container.IntIntDictionary.ToList())
                {
                    path.PushKey(kvp.Key);
                    Assert.That(element.IsPathValid(path), Is.True);

                    path.PushName("Key");
                    Assert.That(element.IsPathValid(path), Is.True);
                    path.Pop();

                    path.PushName("Value");
                    Assert.That(element.IsPathValid(path), Is.True);
                    path.Pop();

                    path.Pop();
                }
            }
        }
        public void CanConstructPropertyPathManually()
        {
            var propertyPath = new PropertyPath();

            Assert.That(propertyPath.PartsCount, Is.EqualTo(0));
            propertyPath.Push("Foo");
            Assert.That(propertyPath.PartsCount, Is.EqualTo(1));
            Assert.That(propertyPath[0].IsListItem, Is.EqualTo(false));
            Assert.That(propertyPath[0].Name, Is.EqualTo("Foo"));
            Assert.That(propertyPath[0].Index, Is.EqualTo(-1));

            propertyPath.Push("Bar", 5);
            Assert.That(propertyPath.PartsCount, Is.EqualTo(2));
            Assert.That(propertyPath[1].IsListItem, Is.EqualTo(true));
            Assert.That(propertyPath[1].Name, Is.EqualTo("Bar"));
            Assert.That(propertyPath[1].Index, Is.EqualTo(5));

            propertyPath.Push("Bee", PropertyPath.InvalidListIndex);
            Assert.That(propertyPath.PartsCount, Is.EqualTo(3));
            Assert.That(propertyPath[2].IsListItem, Is.EqualTo(false));
            Assert.That(propertyPath[2].Name, Is.EqualTo("Bee"));
            Assert.That(propertyPath[2].Index, Is.EqualTo(-1));

            Assert.That(propertyPath.ToString(), Is.EqualTo("Foo.Bar[5].Bee"));

            propertyPath.Pop();

            Assert.That(propertyPath.PartsCount, Is.EqualTo(2));
            Assert.That(propertyPath.ToString(), Is.EqualTo("Foo.Bar[5]"));

            propertyPath.Clear();

            Assert.That(propertyPath.PartsCount, Is.EqualTo(0));
            Assert.That(propertyPath.ToString(), Is.EqualTo(string.Empty));
        }
Ejemplo n.º 5
0
        public void PropertyElement_IsPathValid_ReturnsFalseForInvalidPath()
        {
            var element   = new PropertyElement();
            var container = GetContainer();

            element.SetTarget(container);

            var path = new PropertyPath();
            {
                path.Clear();
                path.PushName("jdhj");
                Assert.That(element.IsPathValid(path), Is.False);
            }

            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.IntListField));
                Assert.That(element.IsPathValid(path), Is.True);
                for (var i = container.IntListField.Count; i < container.IntListField.Count + 10; ++i)
                {
                    path.PushIndex(i);
                    Assert.That(element.IsPathValid(path), Is.False);
                    path.Pop();
                }
            }

            {
                path.Clear();
                path.PushName(nameof(ComplexUIContainer.IntIntDictionary));
                Assert.That(element.IsPathValid(path), Is.True);
                foreach (var kvp in container.IntIntDictionary.ToList())
                {
                    path.PushName(kvp.Key.ToString());
                    Assert.That(element.IsPathValid(path), Is.False);
                }
            }
        }
        void RegisterBindings(VisualElement content)
        {
            if (content is CustomInspectorElement && content != this)
            {
                return;
            }

            var popRelativePartCount = 0;

            if (content is BindableElement b && !string.IsNullOrEmpty(b.bindingPath))
            {
                if (b.bindingPath != ".")
                {
                    var previousCount = m_RelativePath.PartsCount;
                    m_RelativePath.AppendPath(b.bindingPath);
                    m_AbsolutePath.AppendPath(b.bindingPath);
                    popRelativePartCount = m_RelativePath.PartsCount - previousCount;
                }

                if (Inspector.IsPathValid(m_RelativePath))
                {
                    RegisterBindings(Inspector, m_RelativePath, content, m_Root);
                }
                else if (Inspector.IsPathValid(m_AbsolutePath))
                {
                    RegisterBindings(Inspector, m_AbsolutePath, content, m_Root);
                }
                m_AbsolutePath.Clear();
            }

            if (!(content is PropertyElement) && !(content is DefaultInspectorElement))
            {
                foreach (var child in content.Children())
                {
                    RegisterBindings(child);
                }
            }

            for (var i = 0; i < popRelativePartCount; ++i)
            {
                m_RelativePath.Pop();
            }
        }
Ejemplo n.º 7
0
        public void CanConstructPropertyPathManually()
        {
            var propertyPath = new PropertyPath();

            Assert.That(propertyPath.PartsCount, Is.EqualTo(0));
            propertyPath.PushName("Foo");
            Assert.That(propertyPath.PartsCount, Is.EqualTo(1));
            Assert.That(propertyPath[0].Type, Is.EqualTo(PropertyPath.PartType.Name));
            Assert.That(propertyPath[0].Name, Is.EqualTo("Foo"));

            propertyPath.PushName("Bar");
            Assert.That(propertyPath.PartsCount, Is.EqualTo(2));
            Assert.That(propertyPath[1].Type, Is.EqualTo(PropertyPath.PartType.Name));
            Assert.That(propertyPath[1].Name, Is.EqualTo("Bar"));

            propertyPath.PushIndex(5);
            Assert.That(propertyPath.PartsCount, Is.EqualTo(3));
            Assert.That(propertyPath[2].Type, Is.EqualTo(PropertyPath.PartType.Index));
            Assert.That(propertyPath[2].Index, Is.EqualTo(5));

            propertyPath.PushName("Bee");
            Assert.That(propertyPath.PartsCount, Is.EqualTo(4));
            Assert.That(propertyPath[3].Type, Is.EqualTo(PropertyPath.PartType.Name));
            Assert.That(propertyPath[3].Name, Is.EqualTo("Bee"));

            Assert.That(propertyPath.ToString(), Is.EqualTo("Foo.Bar[5].Bee"));

            propertyPath.Pop();

            Assert.That(propertyPath.PartsCount, Is.EqualTo(3));
            Assert.That(propertyPath.ToString(), Is.EqualTo("Foo.Bar[5]"));

            propertyPath.Clear();

            Assert.That(propertyPath.PartsCount, Is.EqualTo(0));
            Assert.That(propertyPath.ToString(), Is.EqualTo(string.Empty));
        }
Ejemplo n.º 8
0
        void RegisterBinding(VisualElement content, bool foundRoot = false)
        {
            if (content is CustomInspectorElement && content != this)
            {
                return;
            }

            if (content is PropertyElement)
            {
                return;
            }

            var bindable = false;

            if (content is IBindable b && !string.IsNullOrEmpty(b.bindingPath))
            {
                bindable = true;

                if (!foundRoot)
                {
                    foundRoot = true;
                    switch (m_Inspector.Part.Type)
                    {
                    case PropertyPath.PartType.Name:
                        m_RelativePath.PushName(b.bindingPath);
                        break;

                    case PropertyPath.PartType.Index:
                        m_RelativePath.PushIndex(int.Parse(b.bindingPath.Substring(1, b.bindingPath.Length - 2)));
                        break;

                    case PropertyPath.PartType.Key:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    m_RelativePath.PushName(b.bindingPath);
                }

                if (m_Inspector.IsPathValid(m_RelativePath))
                {
                    var path = new PropertyPath();
                    path.PushPath(m_Inspector.PropertyPath);
                    if (path.PartsCount > 0)
                    {
                        path.Pop();
                    }

                    path.PushPath(m_RelativePath);
                    m_Inspector.RegisterBindings(path, content);
                }

                if (content == m_Content)
                {
                    switch (m_Inspector.Part.Type)
                    {
                    case PropertyPath.PartType.Name:
                        m_AbsolutePath.PushName(b.bindingPath);
                        break;

                    case PropertyPath.PartType.Index:
                        m_RelativePath.PushIndex(int.Parse(b.bindingPath.Substring(1, b.bindingPath.Length - 2)));
                        break;

                    case PropertyPath.PartType.Key:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    m_AbsolutePath.PushName(b.bindingPath);
                }

                if (m_Inspector.IsPathValid(m_AbsolutePath) && m_RelativePath.ToString() != b.bindingPath)
                {
                    var path = new PropertyPath();
                    path.PushPath(m_Inspector.PropertyPath);
                    path.Pop();
                    path.PushPath(m_AbsolutePath);
                    m_Inspector.RegisterBindings(path, content);
                }
                m_AbsolutePath.Clear();
            }
            foreach (var child in content.Children())
            {
                RegisterBinding(child.contentContainer, foundRoot);
            }
            if (bindable)
            {
                m_RelativePath.Pop();
            }
        }
 public void ClearPath()
 {
     m_Path.Clear();
 }