예제 #1
0
        public PseudoVisualAssignment(IVisualElement toVisual,
                                      ContentAppendType appendType,
                                      IStyleRule rule,
                                      IVisualBootstrapper visualBootstrapper,
                                      IVisualLineage visualLineage,
                                      BuildAssignments assignmentsBuilder)
        {
            Visual      = toVisual;
            _appendType = appendType;
            ILabel applyTo;

            switch (appendType)
            {
            case ContentAppendType.Before:
                if (!(toVisual.BeforeLabel is { } beforeLabel))
                {
                    applyTo = visualBootstrapper.Instantiate <Label>();
                    toVisual.BeforeLabel = applyTo;
                }
                else
                {
                    applyTo = beforeLabel;
                }

                break;
예제 #2
0
        public XElement WriteRule(IStyleRule r)
        {
            var element    = new XElement("style");
            var innerStyle = ProcessSelector(element, r.Selector);

            foreach (var pair in registeredKeys)
            {
                object raw;
                if (r.Style.GetValue(pair.Value, out raw))
                {
                    var propertyElement = new XElement("property");
                    propertyElement.Add(new XAttribute("name", pair.Key));
                    if (InheritMarker.IsInheritMarker(raw))
                    {
                        propertyElement.Add(new XAttribute("inherit", "true"));
                    }
                    else
                    {
                        IStylePropertySerializer p;
                        if (propertyParsers.TryGetValue(pair.Value.ValueType, out p))
                        {
                            p.Write(StyleSystem, propertyElement, raw);
                        }
                        else
                        {
                            throw new StyleWriterException("Key " + pair.Key + " was not registered.");
                        }
                    }
                    innerStyle.Add(propertyElement);
                }
            }

            return(element);
        }
예제 #3
0
        public static async Task AssertNoEnforcementAsync(
            IStyleRule rule, string documentText, Func<OptionSet, OptionSet> applyOptions)
        {
            using (var workspace = new AdhocWorkspace())
            {
                workspace.Options = applyOptions(workspace.Options);

                Project project = workspace.AddProject(BuildProject());
                Document document = workspace.AddDocument(project.Id, "TestFile.cs", SourceText.From(documentText));

                Solution enforcedSolution = await rule.EnforceAsync(document);
                Document enforcedDocument = enforcedSolution.GetDocument(document.Id);

                if (!document.Equals(enforcedDocument))
                {
                    List<TextChange> changes = (await enforcedDocument.GetTextChangesAsync(document)).ToList();
                    if (changes.Count == 0)
                    {
                        Assert.Fail("Solution mutated without document changes");
                    }

                    Console.WriteLine("Document changes:");
                    foreach (TextChange change in changes)
                    {
                        Console.WriteLine($"\t{change}");
                    }

                    Assert.Fail($"Enforced document has {changes.Count} changes; expected none");
                }
            }
        }
예제 #4
0
        public static async Task AssertEnforcementAsync(
            IStyleRule rule, string originalText, string expectedText, Func<OptionSet, OptionSet> applyOptions)
        {
            using (var workspace = new AdhocWorkspace())
            {
                workspace.Options = applyOptions(workspace.Options);

                Project project = workspace.AddProject(BuildProject());
                Document document = workspace.AddDocument(project.Id, "TestFile.cs", SourceText.From(originalText));

                Solution enforcedSolution = await rule.EnforceAsync(document);
                Document enforcedDocument = enforcedSolution.GetDocument(document.Id);

                if (document.Equals(enforcedDocument))
                {
                    Assert.Fail("Expected enforcement, but no changes were made to the document");
                }

                SyntaxTree enforcedSyntax = await enforcedDocument.GetSyntaxTreeAsync();
                SyntaxTree expectedSyntax = SyntaxFactory.ParseCompilationUnit(expectedText).SyntaxTree;
                List<TextChange> unexpectedChanges = expectedSyntax.GetChanges(enforcedSyntax).ToList();
                if (unexpectedChanges.Count > 0)
                {
                    Console.WriteLine("Unexpected changes:");
                    List<TextChange> changes = (await enforcedDocument.GetTextChangesAsync(document)).ToList();
                    foreach (TextChange change in changes)
                    {
                        Console.WriteLine($"\t{change}");
                    }

                    Assert.Fail($"Enforced document has {changes.Count} unexpected changes");
                }
            }
        }
예제 #5
0
        private StyleContainer ToContainer(IStyleRule rule)
        {
            var container = new StyleContainer(rule.SelectorText);

            foreach (var property in rule.Style)
            {
                var propName = StringUtility.ToPascalCase(property.Name);
                if (StyleKeys.TryGetByName(propName, out var styleKey) && context.Converters.TryConvert(property.Value, styleKey.Type, out var propertyValue))
                {
                    styleKey.Set(container, propertyValue);
                }
            }

            return(container);
        }
예제 #6
0
        static internal IStyleRule[] AddRuleFromCollection(string selectorType, Interop.IHTMLStyleSheetRulesCollection rules)
        {
            ArrayList selector = new ArrayList();

            for (int i = 0; i < rules.GetLength(); i++)
            {
                Interop.IHTMLStyleSheetRule rule = (Interop.IHTMLStyleSheetRule)rules.Item(i);
                if (rule.GetSelectorText().Length == 0)
                {
                    continue;
                }
                IStyleRule sr = new StyleRule(rule);

                if (selectorType == null || selectorType.Equals(String.Empty))
                {
                    selector.Add(sr);
                    continue;
                }
                // first char determines type (. = class, # = id, @ = pseudo)
                if (selectorType == "." && rule.GetSelectorText()[0].Equals('.'))
                {
                    selector.Add(sr); //rule.GetSelectorText().Substring(1)
                    continue;
                }
                if (selectorType == "#" && rule.GetSelectorText()[0].Equals('#'))
                {
                    selector.Add(sr); // rule.GetSelectorText().Substring(1)
                    continue;
                }
                if (selectorType == "@" && rule.GetSelectorText()[0].Equals('@'))
                {
                    selector.Add(sr); //rule.GetSelectorText().Substring(1)
                    continue;
                }
                if (selectorType.ToLower().Equals(rule.GetSelectorText().ToLower()))
                {
                    selector.Add(sr); //rule.GetSelectorText().Substring(1)
                    continue;
                }
            }
            IStyleRule[] stylerules = new IStyleRule[selector.Count];
            Array.Copy(selector.ToArray(), stylerules, selector.Count);
            return(stylerules);
        }
 public IEnumerable <IStyleValueAssignment> BuildStyleValueAssignments(IVisualElement visual,
                                                                       IVisualLineage visualLineage,
                                                                       IStyleRule rule,
                                                                       IVisualBootstrapper visualBootstrapper)
 {
     if (rule.Selector.TryGetContentAppendType(out var contentAppend))
     {
         yield return(new PseudoVisualAssignment(visual, contentAppend,
                                                 rule, visualBootstrapper, visualLineage, BuildStyleValueAssignments));
     }
     else
     {
         foreach (var assignment in BuildStyleValueAssignments(visual, visualLineage, rule.Selector,
                                                               rule.Declarations))
         {
             yield return(assignment);
         }
     }
 }
 public AppliedStyleRule(IStyleRule ruleTemplate)
 {
     RuleTemplate = ruleTemplate;
     Conditions   = new List <IStyleCondition>();
     Assignments  = new List <IStyleValueAssignment>();
 }
 public Boolean Equals(IStyleRule other)
 {
     return(other is DependencyPropertyValueRule <TValue> dpvr &&
            dpvr.Selector.Equals(Selector) &&
            dpvr.Declaration.Equals(Declaration));
 }
예제 #10
0
 public static int StyleRuleSortOrder(IStyleRule ruleA, IStyleRule ruleB)
 {
     return(ruleA.Weight.CompareTo(ruleB.Weight));
 }
예제 #11
0
 public static Task AssertEnforcementAsync(IStyleRule rule, string originalText, string expectedText)
 {
     return AssertEnforcementAsync(rule, originalText, expectedText, options => options);
 }
예제 #12
0
 public static Task AssertNoEnforcementAsync(IStyleRule rule, string documentText)
 {
     return AssertNoEnforcementAsync(rule, documentText, options => options);
 }
 public Boolean Equals(IStyleRule other)
 {
     return(other.Selector.Equals(Selector));
 }
 public Boolean Equals(IStyleRule other)
 {
     return(other is DependencyPropertyValueRule dpvr &&
            dpvr.Selector.Equals(Selector));
 }