Esempio n. 1
0
        protected void SetUp()
        {
            _stylesXML                = new InStyles();
            _storyXML                 = new InStory();
            _testFolderPath           = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
            _outputPath               = Common.PathCombine(_testFolderPath, "output");
            _outputStyles             = Common.PathCombine(_outputPath, "Resources");
            _outputSpread             = Common.PathCombine(_outputPath, "Spreads");
            projInfo.TempOutputFolder = _outputPath;
            _cssProperty              = new Dictionary <string, Dictionary <string, string> >();
            _cssTree = new CssTree();

            _inputCSS1 = Common.DirectoryPathReplace(_testFolderPath + "/input/Page1.css");
            _inputCSS2 = Common.DirectoryPathReplace(_testFolderPath + "/input/Page2.css");

            _facingPages.Add("Spread_1.xml");
            _facingPages.Add("Spread_2.xml");
            _facingPages.Add("Spread_3.xml");

            _singlePages.AddRange(_facingPages);
            _singlePages.Add("Spread_4.xml");
            _singlePages.Add("Spread_5.xml");

            _columnClass.Add("t1");
            _columnClass.Add("t2");
            _columnClass.Add("t3");
        }
        public void IncrementalParse_UnclosedMedia()
        {
            // http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems?id=331654: Closing a comment didn't allow the exposed curly brace
            // to close the prevoius @media block.

            CssTree doc = new CssTree(null)
            {
                TextProvider = new StringTextProvider("@media { /*foo*/ /* }")
            };

            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            MediaDirective md = doc.StyleSheet.Children[0] as MediaDirective;

            Assert.IsNotNull(md);
            Assert.IsTrue(md.IsUnclosed); // this was the bug, directives never said they were unclosed
            Assert.IsTrue(md.Block.HasParseErrors);

            doc.OnTextChange(new StringTextProvider("@media { /*foo*/ /**/ }"), 19, 0, 2);

            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsFalse(md.IsUnclosed);
            Assert.IsFalse(md.Block.HasParseErrors);
            Assert.AreEqual(7, md.Block.Start);
            Assert.AreEqual(23, md.Block.AfterEnd);
        }
        public void IncrementalParse_DestructiveChangeTest()
        {
            CssTree doc = new CssTree(new DefaultParserFactory());

            string text        = "@import 'list.css' .a {color:red} z{} y{} x{}";
            string changedText = "/* comment */ .foo {hello:goodbye} z{} y{} x{}";

            doc.TextProvider = new StringTextProvider(text);

            bool fullTreeUpdateFired = false;
            CssItemsChangedEventArgs itemChangedEventArgs = null;

            doc.TreeUpdated += (object sender, CssTreeUpdateEventArgs eventArgs) =>
            {
                fullTreeUpdateFired = true;
            };

            doc.ItemsChanged += (object sender, CssItemsChangedEventArgs eventArgs) =>
            {
                itemChangedEventArgs = eventArgs;
            };

            doc.OnTextChange(new StringTextProvider(changedText), 0, text.Length - 12, changedText.Length - 12);

            Assert.IsFalse(fullTreeUpdateFired);
            Assert.IsNotNull(itemChangedEventArgs);
            Assert.AreEqual(2, itemChangedEventArgs.InsertedItems.Count);
            Assert.AreEqual(2, itemChangedEventArgs.DeletedItems.Count);
            Assert.AreEqual(0, itemChangedEventArgs.ErrorsChangedItems.Count);
            Assert.AreEqual(doc.StyleSheet, itemChangedEventArgs.InsertedItems[0].Parent);
        }
        public void IncrementalParse_Whitespace()
        {
            CssTree     doc    = new CssTree(null);
            DebugWriter writer = new DebugWriter();

            // Start with some rules
            doc.TextProvider = new StringTextProvider("a { } b { }");
            Assert.AreEqual(2, doc.StyleSheet.Children.Count);
            string origTree = writer.Serialize(doc.TextProvider, doc.StyleSheet);

            // Add space between them
            doc.OnTextChange(new StringTextProvider("a { } \r\n b { }"), 6, 0, 3);
            Assert.AreEqual(2, doc.StyleSheet.Children.Count);
            Assert.AreEqual(origTree, writer.Serialize(doc.TextProvider, doc.StyleSheet));

            // Delete spaces between them
            doc.OnTextChange(new StringTextProvider("a { } b { }"), 6, 3, 0);
            Assert.AreEqual(2, doc.StyleSheet.Children.Count);
            Assert.AreEqual(origTree, writer.Serialize(doc.TextProvider, doc.StyleSheet));

            // Change all the text, but only really add one more space
            doc.OnTextChange(new StringTextProvider("a { } b {  }"), 0, 11, 12);
            Assert.AreEqual(2, doc.StyleSheet.Children.Count);
            Assert.AreEqual(origTree, writer.Serialize(doc.TextProvider, doc.StyleSheet));
        }
        public void IncrementalParse_SimpleChangeTest()
        {
            CssTree       doc   = new CssTree(new DefaultParserFactory());
            ITextProvider text1 = new StringTextProvider(".foo { color: red } .bar { /* comment */ color: rgb(100 }");

            doc.TextProvider = text1;

            bool fullTreeUpdateFired = false;
            CssItemsChangedEventArgs changeEventArgs = null;

            doc.TreeUpdated += (object sender, CssTreeUpdateEventArgs eventArgs) =>
            {
                fullTreeUpdateFired = true;
            };

            doc.ItemsChanged += (object sender, CssItemsChangedEventArgs eventArgs) =>
            {
                changeEventArgs = eventArgs;
            };

            ITextProvider text2 = new StringTextProvider(".foo { color: BLUE; } .bar { /* comment */ color: rgb(100 }");

            doc.OnTextChange(text2, 14, 3, 5);

            Assert.IsFalse(fullTreeUpdateFired);
            Assert.IsNotNull(changeEventArgs);
            Assert.AreEqual(1, changeEventArgs.DeletedItems.Count);
            Assert.AreEqual(1, changeEventArgs.InsertedItems.Count);

            Declaration oldDecl = changeEventArgs.DeletedItems[0] as Declaration;
            Declaration newDecl = changeEventArgs.InsertedItems[0] as Declaration;

            Assert.AreEqual("color: red", text1.GetText(oldDecl.Start, oldDecl.Length));
            Assert.AreEqual("color: BLUE;", text2.GetText(newDecl.Start, newDecl.Length));
        }
        public void IncrementalParse_InsertDeleteAndAppendRule()
        {
            CssTree doc = new CssTree(null);

            Assert.IsNull(doc.StyleSheet);
            doc.OnTextChange(new StringTextProvider("foo"), 0, 0, 3);
            // Changes are ignored before the initial parse
            Assert.IsNull(doc.StyleSheet);

            // Start with two rules
            doc.TextProvider = new StringTextProvider("a { } b { }");
            Assert.AreEqual("a { }", doc.StyleSheet.RuleSets[0].Text);
            Assert.AreEqual("b { }", doc.StyleSheet.RuleSets[1].Text);

            // Insert a rule "c"
            doc.OnTextChange(new StringTextProvider("a { } c { } b { }"), 6, 0, 6);
            Assert.AreEqual("a { }", doc.StyleSheet.RuleSets[0].Text);
            Assert.AreEqual("c { }", doc.StyleSheet.RuleSets[1].Text);
            Assert.AreEqual("b { }", doc.StyleSheet.RuleSets[2].Text);

            // Delete the rule "c" (and rename "b")
            doc.OnTextChange(new StringTextProvider("a { } bb { }"), 6, 6, 1);
            Assert.AreEqual("a { }", doc.StyleSheet.RuleSets[0].Text);
            Assert.AreEqual("bb { }", doc.StyleSheet.RuleSets[1].Text);

            // Append a rule "c"
            doc.OnTextChange(new StringTextProvider("a { } bb { } c { }"), 11, 1, 7);
            Assert.AreEqual("a { }", doc.StyleSheet.RuleSets[0].Text);
            Assert.AreEqual("bb { }", doc.StyleSheet.RuleSets[1].Text);
            Assert.AreEqual("c { }", doc.StyleSheet.RuleSets[2].Text);
        }
Esempio n. 7
0
 protected void SetUp()
 {
     _cssTree            = new CssTree();
     _stylesXML          = new InStyles();
     _cssProperty        = new Dictionary <string, Dictionary <string, string> >();
     _testFolderPath     = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
     _outputPath         = Common.PathCombine(_testFolderPath, "output");
     _outputResourcePath = Common.PathCombine(_outputPath, "Resources");
 }
Esempio n. 8
0
        protected void SetUp()
        {
            _graphicXML     = new InGraphic();
            _testFolderPath = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
            ClassProperty   = _expected; //Note: All Reference address initialized here
            _output         = Common.PathCombine(_testFolderPath, "output");

            _cssProperty = new Dictionary <string, Dictionary <string, string> >();
            _cssTree     = new CssTree();
        }
        public void IncrementalParse_Comments()
        {
            CssTree doc = new CssTree(null)
            {
                // Start with some rules
                TextProvider = new StringTextProvider("a { } b { }")
            };

            Assert.AreEqual("a { }", doc.StyleSheet.RuleSets[0].Text);
            Assert.AreEqual("b { }", doc.StyleSheet.RuleSets[1].Text);

            // Start to comment them out
            doc.OnTextChange(new StringTextProvider("/* a { } b { }"), 0, 0, 3);
            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(CComment));

            // Finish commenting them out
            doc.OnTextChange(new StringTextProvider("/* a { } b { } */"), 14, 0, 3);
            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(CComment));

            // Start to uncomment
            doc.OnTextChange(new StringTextProvider("* a { } b { } */"), 0, 1, 0);
            Assert.AreEqual(3, doc.StyleSheet.Children.Count);
            Assert.AreEqual("* a { }", doc.StyleSheet.Children[0].Text);
            Assert.AreEqual("b { }", doc.StyleSheet.Children[1].Text);
            Assert.AreEqual("*/", doc.StyleSheet.Children[2].Text);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(RuleSet));
            Assert.IsInstanceOfType(doc.StyleSheet.Children[1], typeof(RuleSet));
            Assert.IsInstanceOfType(doc.StyleSheet.Children[2], typeof(RuleSet));

            // Finish uncommenting (and delete "b")
            doc.OnTextChange(new StringTextProvider("* a { }"), 7, 9, 0);
            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.AreEqual("* a { }", doc.StyleSheet.Children[0].Text);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(RuleSet));

            // Start over
            doc.TextProvider = new StringTextProvider("a { } /* foo */ b { }");
            Assert.AreEqual("a { }", doc.StyleSheet.Children[0].Text);
            Assert.AreEqual("/* foo */", doc.StyleSheet.Children[1].Text);
            Assert.AreEqual("b { }", doc.StyleSheet.Children[2].Text);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(RuleSet));
            Assert.IsInstanceOfType(doc.StyleSheet.Children[1], typeof(CComment));
            Assert.IsInstanceOfType(doc.StyleSheet.Children[2], typeof(RuleSet));

            // Add text in the comment
            doc.OnTextChange(new StringTextProvider("a { } /* barfoo */ b { }"), 9, 3, 6);
            Assert.AreEqual("a { }", doc.StyleSheet.Children[0].Text);
            Assert.AreEqual("/* barfoo */", doc.StyleSheet.Children[1].Text);
            Assert.AreEqual("b { }", doc.StyleSheet.Children[2].Text);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(RuleSet));
            Assert.IsInstanceOfType(doc.StyleSheet.Children[1], typeof(CComment));
            Assert.IsInstanceOfType(doc.StyleSheet.Children[2], typeof(RuleSet));
        }
Esempio n. 10
0
        public void Dispose()
        {
            _tree       = null;
            _textBuffer = null;

            if (_textView != null)
            {
                _textView.Caret.PositionChanged -= OnCaretPositionChanged;
                _textView = null;
            }
        }
Esempio n. 11
0
 protected void SetUp()
 {
     _stylesXML                = new InStyles();
     _storyXML                 = new InStory();
     _testFolderPath           = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
     ClassProperty             = _expected;  //Note: All Reference address initialized here
     _outputPath               = Common.PathCombine(_testFolderPath, "output");
     _outputStyles             = Common.PathCombine(_outputPath, "Resources");
     projInfo.TempOutputFolder = _outputPath;
     _cssProperty              = new Dictionary <string, Dictionary <string, string> >();
     _cssTree = new CssTree();
 }
Esempio n. 12
0
 protected void SetUp()
 {
     _stylesXML           = new InStyles();
     _expectedList        = new ArrayList();
     _designmapXML        = new InDesignMap();
     _idAllClass          = new Dictionary <string, Dictionary <string, string> >();
     _testFolderPath      = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
     ClassProperty        = _expected;
     _outputPath          = Common.PathCombine(_testFolderPath, "output");
     _outputStyles        = Common.PathCombine(_outputPath, "Resources");
     _outputMasterSpreads = Common.PathCombine(_outputPath, "MasterSpreads");
     _cssProperty         = new Dictionary <string, Dictionary <string, string> >();
     _cssTree             = new CssTree();
 }
Esempio n. 13
0
        private static void Update(ParseItem rule, CssTree tree)
        {
            BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;

            object[] parameters = new object[3];
            parameters[0] = new ParseItemList();
            parameters[1] = new ParseItemList();
            parameters[2] = new ParseItemList()
            {
                rule
            };

            typeof(CssTree).InvokeMember("FireOnItemsChanged", flags, null, tree, parameters);
        }
Esempio n. 14
0
        /// <summary>
        /// This must be delayed so that the TextViewConnectionListener
        /// has a chance to initialize the WebEditor host.
        /// </summary>
        public bool EnsureTreeInitialized()
        {
            if (_tree == null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree = document.Tree;
                }
                catch
                { }
            }

            return(_tree != null);
        }
Esempio n. 15
0
        public void Dispose()
        {
            _tree = null;
            if (_textBuffer != null)
            {
                _textBuffer.ChangedLowPriority -= BufferChanged;
                _textBuffer = null;
            }

            if (_textView != null)
            {
                _textView.Caret.PositionChanged -= OnCaretPositionChanged;
                _textView = null;
            }
        }
        public bool EnsureInitialized()
        {
            if (_tree == null && Microsoft.Web.Editor.WebEditor.Host != null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(TextView.TextBuffer);
                    _tree = document.Tree;
                }
                catch (ArgumentNullException)
                { }
            }

            return _tree != null;
        }
Esempio n. 17
0
        public bool EnsureInitialized()
        {
            if (_tree == null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(TextView.TextBuffer);
                    _tree = document.Tree;
                }
                catch (ArgumentNullException)
                { }
            }

            return(_tree != null);
        }
        /// <summary>
        /// This must be delayed so that the TextViewConnectionListener
        /// has a chance to initialize the WebEditor host.
        /// </summary>
        public bool EnsureTreeInitialized()
        {
            if (_tree == null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree = document.Tree;
                }
                catch (Exception)
                {
                }
            }

            return _tree != null;
        }
Esempio n. 19
0
        /// <summary>
        /// This must be delayed so that the TextViewConnectionListener
        /// has a chance to initialize the WebEditor host.
        /// </summary>
        public bool EnsureTreeInitialized()
        {
            if (_tree == null)// && WebEditor.GetHost(CssContentTypeDefinition.CssContentType) != null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree = document.Tree;
                }
                catch (Exception)
                {
                }
            }

            return(_tree != null);
        }
Esempio n. 20
0
        private string GetStyleOutput(string file)
        {
            LOContent contentXML = new LOContent();
            LOStyles  stylesXML  = new LOStyles();
            string    fileOutput = _index > 0 ? file + _index + ".css" : file + ".css";

            //string input = FileInput(file + ".css");
            string input = FileInput(fileOutput);

            _projInfo.DefaultCssFileWithPath = input;
            _projInfo.TempOutputFolder       = _outputPath;

            Dictionary <string, Dictionary <string, string> > cssClass = new Dictionary <string, Dictionary <string, string> >();
            CssTree cssTree = new CssTree();

            cssClass = cssTree.CreateCssProperty(input, true);

            //StyleXML
            string styleOutput = FileOutput(file + _styleFile);
            Dictionary <string, Dictionary <string, string> > idAllClass = stylesXML.CreateStyles(_projInfo, cssClass, styleOutput);

            // ContentXML
            var pageSize = new Dictionary <string, string>();

            pageSize["height"] = cssClass["@page"]["page-height"];
            pageSize["width"]  = cssClass["@page"]["page-width"];
            _projInfo.DefaultXhtmlFileWithPath = FileInput(file + ".xhtml");
            _projInfo.TempOutputFolder         = FileOutput(file);
            _projInfo.HideSpaceVerseNumber     = stylesXML.HideSpaceVerseNumber;

            PreExportProcess preProcessor = new PreExportProcess(_projInfo);

            preProcessor.GetTempFolderPath();
            _projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml;
            if (Param.HyphenEnable)
            {
                preProcessor.IncludeHyphenWordsOnXhtml(_projInfo.DefaultXhtmlFileWithPath);
            }

            AfterBeforeProcess afterBeforeProcess = new AfterBeforeProcess();

            afterBeforeProcess.RemoveAfterBefore(_projInfo, cssClass, cssTree.SpecificityClass, cssTree.CssClassOrder);

            contentXML.CreateStory(_projInfo, idAllClass, cssTree.SpecificityClass, cssTree.CssClassOrder, 325, pageSize);
            _projInfo.TempOutputFolder = _projInfo.TempOutputFolder + _contentFile;
            return(styleOutput);
        }
Esempio n. 21
0
        public void ComplexItem_NextPreviousChildTest()
        {
            CssTree doc = new CssTree(null)
            {
                TextProvider = new StringTextProvider("a{} b{} c{} d{}")
            };

            Assert.AreEqual(4, doc.StyleSheet.RuleSets.Count);

            Assert.IsNull(doc.StyleSheet.NextChild(null));
            Assert.IsNull(doc.StyleSheet.PreviousChild(null));

            Assert.IsNull(doc.StyleSheet.NextChild(doc.StyleSheet.RuleSets[3]));
            Assert.IsNull(doc.StyleSheet.PreviousChild(doc.StyleSheet.RuleSets[0]));

            Assert.AreEqual(doc.StyleSheet.RuleSets[3], doc.StyleSheet.NextChild(doc.StyleSheet.RuleSets[2]));
            Assert.AreEqual(doc.StyleSheet.RuleSets[2], doc.StyleSheet.PreviousChild(doc.StyleSheet.RuleSets[3]));
        }
Esempio n. 22
0
        public void AddAfterTest()
        {
            PublicationInformation projInfo = new PublicationInformation();

            projInfo.DefaultXhtmlFileWithPath = _testFiles.Input("sena3-ipa.xhtml");
            projInfo.DefaultCssFileWithPath   = _testFiles.Input("sena3-ipa.css");
            var cssTree = new CssTree();

            CssClass = cssTree.CreateCssProperty(projInfo.DefaultCssFileWithPath, true);
            var ContentStyles = new DictionaryForMIDsStyle();
            var rec           = new DictionaryForMIDsRec {
                CssClass = CssClass, Styles = ContentStyles
            };
            var input = new DictionaryForMIDsInput(projInfo);
            var node  = input.SelectNodes("//*[@class = 'xsensenumber']")[0];

            rec.AddAfter(node);
            Assert.AreEqual(") ", rec.Rec);
        }
Esempio n. 23
0
        public void ComplexItem_IsUnclosedTest()
        {
            CssTree doc = new CssTree(null)
            {
                TextProvider = new StringTextProvider("a{foo:bar} b{")
            };

            Assert.AreEqual(2, doc.StyleSheet.RuleSets.Count);
            Assert.AreEqual(1, doc.StyleSheet.RuleSets[0].Block.Declarations.Count);

            Assert.IsFalse(doc.StyleSheet.RuleSets[0].IsUnclosed);
            Assert.IsFalse(doc.StyleSheet.RuleSets[0].Selectors[0].IsUnclosed);
            Assert.IsFalse(doc.StyleSheet.RuleSets[0].Block.IsUnclosed);
            Assert.IsTrue(doc.StyleSheet.RuleSets[0].Block.Declarations[0].IsUnclosed);

            Assert.IsTrue(doc.StyleSheet.RuleSets[1].IsUnclosed);
            Assert.IsFalse(doc.StyleSheet.RuleSets[1].Selectors[0].IsUnclosed);
            Assert.IsTrue(doc.StyleSheet.RuleSets[1].Block.IsUnclosed);
        }
Esempio n. 24
0
        private static IEnumerable<ParseItem> GetColors(CssTree tree, SnapshotSpan span)
        {
            ParseItem complexItem = tree.StyleSheet.ItemFromRange(span.Start, span.Length);
            if (complexItem == null || (!(complexItem is AtDirective) && !(complexItem is RuleBlock) && !(complexItem is CssVariableDeclaration) && !(complexItem is FunctionArgument)))
                return Enumerable.Empty<ParseItem>();

            var colorCrawler = new CssItemAggregator<ParseItem>(filter: e => e.AfterEnd > span.Start && e.Start < span.End)
            {
                (HexColorValue h) => h,
                (FunctionColor c) => c,
                (TokenItem i) => (i.PreviousSibling == null || (i.PreviousSibling.Text != "@" && i.PreviousSibling.Text != "$"))    // Ignore variable names that happen to be colors
                               && i.TokenType == CssTokenType.Identifier
                               && (i.FindType<Declaration>() != null || i.FindType<CssExpression>() != null)                       // Ignore classnames that happen to be colors
                               && Color.FromName(i.Text).IsNamedColor
                               ? i : null
            };

            return colorCrawler.Crawl(complexItem).Where(o => o != null);
        }
        public bool EnsureInitialized()
        {
            if (_tree == null && WebEditor.Host != null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree = document.Tree;
                    _tree.TreeUpdated += TreeUpdated;
                    _tree.ItemsChanged += TreeItemsChanged;
                    UpdateCache(_tree.StyleSheet);
                }
                catch (ArgumentNullException)
                {
                }
            }

            return _tree != null;
        }
Esempio n. 26
0
        public bool EnsureInitialized()
        {
            if (_tree == null && WebEditor.Host != null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree               = document.Tree;
                    _tree.TreeUpdated  += TreeUpdated;
                    _tree.ItemsChanged += TreeItemsChanged;
                    UpdateDeclarationCache(_tree.StyleSheet);
                }
                catch (ArgumentNullException)
                {
                }
            }

            return(_tree != null);
        }
Esempio n. 27
0
        public void AddStyleTagTest()
        {
            PublicationInformation projInfo = new PublicationInformation();

            projInfo.DefaultXhtmlFileWithPath = _testFiles.Input("sena3-imba.xhtml");
            projInfo.DefaultCssFileWithPath   = _testFiles.Input("sena3-imba.css");
            var cssTree = new CssTree();

            CssClass = cssTree.CreateCssProperty(projInfo.DefaultCssFileWithPath, true);
            var ContentStyles = new DictionaryForMIDsStyle();
            var rec           = new DictionaryForMIDsRec {
                CssClass = CssClass, Styles = ContentStyles
            };
            var input = new DictionaryForMIDsInput(projInfo);
            var node  = input.SelectNodes("//*[@class = 'partofspeech']//text()")[0];

            rec.AddStyleTag(node);
            Assert.AreEqual(2, ContentStyles.NumStyles);
        }
Esempio n. 28
0
        public void AddStyleTagLangTest()
        {
            PublicationInformation projInfo = new PublicationInformation();

            projInfo.DefaultXhtmlFileWithPath = _testFiles.Input("wasp.xhtml");
            projInfo.DefaultCssFileWithPath   = _testFiles.Input("wasp.css");
            var cssTree = new CssTree();

            CssClass = cssTree.CreateCssProperty(projInfo.DefaultCssFileWithPath, true);
            var ContentStyles = new DictionaryForMIDsStyle();
            var rec           = new DictionaryForMIDsRec {
                CssClass = CssClass, Styles = ContentStyles
            };
            var input = new DictionaryForMIDsInput(projInfo);
            var node  = input.SelectNodes("(//*[@class='xitem'])/*")[1];

            rec.AddStyleTag(node);
            Assert.AreEqual(2, ContentStyles.NumStyles);
            Assert.AreEqual("153,51,102", rec.Styles.FontColor(2));
        }
Esempio n. 29
0
        /// <summary>
        /// This must be delayed so that the TextViewConnectionListener
        /// has a chance to initialize the WebEditor host.
        /// </summary>
        public bool EnsureInitialized()
        {
            if (_tree == null && WebEditor.Host != null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_textBuffer);
                    _tree = document.Tree;

                    RegisterSmartTagProviders();

                    WebEditor.OnIdle += OnIdle;
                }
                catch (Exception)
                {
                }
            }

            return(_tree != null);
        }
Esempio n. 30
0
        public void CssDocument_TextTest()
        {
            CssTree tree = new CssTree(new DefaultParserFactory());

            Assert.IsNull(tree.TextProvider);

            string text = "@import 'list.css' .a {color:red}";

            tree.TextProvider = new StringTextProvider(text);
            Assert.AreEqual(text, tree.TextProvider.GetText(0, tree.TextProvider.Length));
            Assert.IsNotNull(tree.StyleSheet);
            Assert.AreEqual(2, tree.StyleSheet.Children.Count);
            Assert.IsTrue(tree.StyleSheet.Children[0] is ImportDirective);

            text = ".a {color:red}";
            tree.TextProvider = new StringTextProvider(text);
            Assert.AreEqual(text, tree.TextProvider.GetText(0, tree.TextProvider.Length));
            Assert.IsNotNull(tree.StyleSheet);
            Assert.AreEqual(1, tree.StyleSheet.Children.Count);
            Assert.IsTrue(tree.StyleSheet.Children[0] is RuleSet);
        }
Esempio n. 31
0
        void Tree_ItemsChanged(object sender, CssItemsChangedEventArgs e)
        {
            CssTree tree = (CssTree)sender;

            foreach (ParseItem item in e.InsertedItems)
            {
                var visitor = new CssItemCollector <Declaration>(true);
                item.Accept(visitor);

                foreach (Declaration dec in visitor.Items)
                {
                    if (dec.PropertyName != null && dec.PropertyName.Text == "display" && dec.Values.Any(v => v.Text == "inline"))
                    {
                        _cache.Add(dec);

                        ParseItem rule = dec.Parent;
                        Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => Update(rule, tree)), DispatcherPriority.Normal);
                    }
                }
            }

            foreach (ParseItem item in e.DeletedItems)
            {
                var visitor = new CssItemCollector <Declaration>(true);
                item.Accept(visitor);

                foreach (Declaration deleted in visitor.Items)
                {
                    if (_cache.Contains(deleted))
                    {
                        _cache.Remove(deleted);

                        ParseItem rule = deleted.Parent;
                        Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => Update(rule, tree)), DispatcherPriority.Normal);
                    }
                }
            }
        }
        public void IncrementalParse_EmptyComment()
        {
            CssTree doc = new CssTree(null)
            {
                TextProvider = new StringTextProvider("/**/")
            };

            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(CComment));
            Assert.IsNull(((CComment)doc.StyleSheet.Children[0]).CommentText);
            Assert.AreEqual(4, doc.StyleSheet.Children[0].Length);

            // Delete the last slash
            doc.OnTextChange(new StringTextProvider("/**"), 3, 1, 0);
            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(CComment));
            Assert.AreEqual("*", ((CComment)doc.StyleSheet.Children[0]).CommentText.Text);
            Assert.AreEqual(3, doc.StyleSheet.Children[0].Length);

            // Delete the last star
            doc.OnTextChange(new StringTextProvider("/*"), 2, 1, 0);
            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(CComment));
            Assert.IsNull(((CComment)doc.StyleSheet.Children[0]).CommentText);
            Assert.AreEqual(2, doc.StyleSheet.Children[0].Length);

            // Delete the last star
            doc.OnTextChange(new StringTextProvider("/"), 1, 1, 0);
            Assert.AreEqual(1, doc.StyleSheet.Children.Count);
            Assert.IsInstanceOfType(doc.StyleSheet.Children[0], typeof(RuleSet));
            Assert.AreEqual(1, doc.StyleSheet.Children[0].Length);

            // Delete the last slash
            doc.OnTextChange(new StringTextProvider(""), 0, 1, 0);
            Assert.AreEqual(0, doc.StyleSheet.Children.Count);
            Assert.AreEqual(0, doc.StyleSheet.Length);
        }
Esempio n. 33
0
        protected void SetUp()
        {
            _testFolderPath  = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
            _inputCSS1       = Common.PathCombine(_testFolderPath, "input/MasterSpread.css");
            _stylesXML       = new InStyles();
            _masterSpreadXML = new InMasterSpread();
            _idAllClass      = new Dictionary <string, Dictionary <string, string> >();
            _testFolderPath  = PathPart.Bin(Environment.CurrentDirectory, "/InDesignConvert/TestFiles");
            ClassProperty    = _expected;
            _outputPath      = Common.PathCombine(_testFolderPath, "output");
            _outputSpread    = Common.PathCombine(_outputPath, "MasterSpreads");
            _outputStyle     = Common.PathCombine(_outputPath, "Resources");
            _outputStory     = Common.PathCombine(_outputPath, "Stories");
            _cssProperty     = new Dictionary <string, Dictionary <string, string> >();
            _cssTree         = new CssTree();

            _listofMasterPages = new ArrayList
            {
                "MasterSpread_First.xml",
                "MasterSpread_All.xml",
                "MasterSpread_Left.xml",
                "MasterSpread_Right.xml"
            };
        }
        private void ItemsChanged(CssTree tree, ITextBuffer buffer, CssItemsChangedEventArgs e)
        {
            foreach (ParseItem item in e.InsertedItems)
            {
                var visitor = new CssItemCollector<Declaration>(true);
                item.Accept(visitor);

                foreach (Declaration dec in visitor.Items)
                {
                    if (dec.PropertyName != null && dec.PropertyName.Text == "display" && dec.Values.Any(v => v.Text == "inline"))
                    {
                        _cache.Add(dec);

                        ParseItem rule = dec.Parent;
                        Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => Update(rule, tree, buffer)), DispatcherPriority.Normal);
                    }
                }
            }

            foreach (ParseItem item in e.DeletedItems)
            {
                var visitor = new CssItemCollector<Declaration>(true);
                item.Accept(visitor);

                foreach (Declaration deleted in visitor.Items)
                {
                    if (_cache.Contains(deleted))
                    {
                        _cache.Remove(deleted);

                        ParseItem rule = deleted.Parent;
                        Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => Update(rule, tree, buffer)), DispatcherPriority.Normal);
                    }
                }
            }
        }
Esempio n. 35
0
        /// <summary>
        /// This must be delayed so that the TextViewConnectionListener
        /// has a chance to initialize the WebEditor host.
        /// </summary>
        public bool EnsureTreeInitialized()
        {
            if (_tree == null)// && WebEditor.GetHost(CssContentTypeDefinition.CssContentType) != null)
            {
                try
                {
                    CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree = document.Tree;
                }
                catch (Exception)
                {
                }
            }

            return _tree != null;
        }
 private static void Update(ParseItem rule, CssTree tree, ITextBuffer buffer)
 {
     CssErrorTagger tagger = CssErrorTagger.FromTextBuffer(buffer);
     ParseItemList list = new ParseItemList() { rule };
     tagger.RecheckItems(list);
 }
        private static void Update(ParseItem rule, CssTree tree)
        {
            const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
            object[] parameters = new object[3];
            parameters[0] = new ParseItemList();
            parameters[1] = new ParseItemList();
            parameters[2] = new ParseItemList() { rule };

            typeof(CssTree).InvokeMember("FireOnItemsChanged", flags, null, tree, parameters);
        }
        public bool EnsureInitialized()
        {
            if (_tree == null && WebEditor.Host != null)
            {
                try
                {
                    _document = CssEditorDocument.FromTextBuffer(_buffer);
                    _tree = _document.Tree;
                    _buffer.PostChanged += _buffer_PostChanged;
                }
                catch (ArgumentNullException)
                {
                }
            }

            return _tree != null;
        }