private void Apply(UxNode uxClass, List <PropertyValue> propertyValues)
        {
            foreach (var child in uxClass.Children.Where(c => c is UxNode).Cast <UxNode>())
            {
                Apply(child, propertyValues);
            }

            if (uxClass.ClassName == "Text")
            {
                var layerName = uxClass.SketchLayerName;
                switch (NameValidator.NameIsValid(layerName))
                {
                case NameValidity.InvalidCharacter:
                    _log.Warning($"Could not create a text property for the layer '{layerName}', as it contains an invalid character. Please only use the letters a-z, numbers, or underscores, and don't start the name with a number.");
                    break;

                case NameValidity.InvalidKeyword:
                    _log.Warning($"Could not create a text property for the layer '{layerName}', as '{layerName}' is a reserved word. Please choose another name.");
                    break;

                case NameValidity.Valid:
                    if (propertyValues.Any(p => p.Name.Equals(layerName)))
                    {
                        _log.Warning($"Could not create a text property for the layer '{layerName}', as a text property for another layer with the same name has already been created. Please use unique names for text layers within the same symbol.");
                    }
                    else
                    {
                        var defaultValue = (UxString)uxClass.Attributes["Value"];
                        propertyValues.Add(new PropertyValue(layerName, defaultValue.Value));
                        uxClass.Attributes["Value"] = new UxString("{Property " + layerName + "}");
                    }
                    break;

                default:
                    throw new NotImplementedException("Internal error");
                }
            }
        }
Esempio n. 2
0
 public void NameIsValid_ValidNames([Values("a", "aAaa", "A1", "a_1", "_a", "_1")] string name)
 {
     Assert.That(NameValidator.NameIsValid(name), Is.EqualTo(NameValidity.Valid));
 }
Esempio n. 3
0
 public void NameIsValid_UnoKeywords([Values("draw", "local", "add")] string name)
 {
     Assert.That(NameValidator.NameIsValid(name), Is.EqualTo(NameValidity.InvalidKeyword));
 }
Esempio n. 4
0
 public void NameIsValid_CSharpKeywords([Values("async", "string", "class")] string name)
 {
     Assert.That(NameValidator.NameIsValid(name), Is.EqualTo(NameValidity.InvalidKeyword));
 }
Esempio n. 5
0
 public void NameIsValid_InvalidCharacters([Values("1", "1A", "", "a B", "aå", "a-b", "a.b")] string name)
 {
     Assert.That(NameValidator.NameIsValid(name), Is.EqualTo(NameValidity.InvalidCharacter));
 }