Пример #1
0
        public CodeTabView()
        {
            this.InitializeComponent();

            this.shaderTextEditor          = this.CreateTextEditor();
            this.shaderTextEditor.Encoding = System.Text.Encoding.ASCII;
            //// _shaderTextEditor.TextChanged += new EventHandler(_shaderTextEditor_TextChanged);
            //// _shaderTextEditor.Document.TextContentChanged += new EventHandler(Document_TextContentChanged);
            this.shaderTextEditor.Document.DocumentChanged += this.DocumentDocumentChanged;
            using (var stream = typeof(CodeTabView).Assembly.GetManifestResourceStream("Shazzam.Resources.HLSLSyntax.xshd"))
            {
                if (stream != null)
                {
                    using (var reader = new XmlTextReader(stream))
                    {
                        var sm = new SyntaxMode("HLSL.xshd", "HLSL", ".fx");
                        this.hlslHs = HighlightingDefinitionParser.Parse(sm, reader);
                        this.hlslHs.ResolveReferences(); // don't forget this!
                        reader.Close();
                    }
                }
            }

            this.shaderTextEditor.Document.HighlightingStrategy = this.hlslHs;
            this.FormsHost.Child = this.shaderTextEditor;

            this.csTextEditor      = this.CreateTextEditor();
            this.FormsHostCs.Child = this.csTextEditor;

            this.compiler = new ShaderCompiler();
            this.compiler.Reset();
            this.OutputTextBox.DataContext = this.compiler;
            this.Loaded += this.CodeTabViewLoaded;
        }
Пример #2
0
        public CodeTabView()
        {
            InitializeComponent();

            _shaderTextEditor          = CreateTextEditor();
            _shaderTextEditor.Encoding = System.Text.Encoding.ASCII;
            //	_shaderTextEditor.TextChanged += new EventHandler(_shaderTextEditor_TextChanged);
            //	_shaderTextEditor.Document.TextContentChanged += new EventHandler(Document_TextContentChanged);
            _shaderTextEditor.Document.DocumentChanged += new DocumentEventHandler(Document_DocumentChanged);
            using (var stream = typeof(CodeTabView).Assembly.GetManifestResourceStream("Shazzam.Resources.HLSLSyntax.xshd"))
            {
                using (var reader = new XmlTextReader(stream))
                {
                    var sm = new SyntaxMode("HLSL.xshd", "HLSL", ".fx");
                    _hlslHS = HighlightingDefinitionParser.Parse(sm, reader);
                    _hlslHS.ResolveReferences(); // don't forget this!
                    reader.Close();
                }
            }

            _shaderTextEditor.Document.HighlightingStrategy = _hlslHS;
            this.formsHost.Child = _shaderTextEditor;

            _csTextEditor          = CreateTextEditor();
            this.formsHostCs.Child = _csTextEditor;

            _vbTextEditor          = CreateTextEditor();
            this.formsHostVb.Child = _vbTextEditor;

            _compiler = new ShaderCompiler();
            _compiler.Reset();
            outputTextBox.DataContext = _compiler;
            this.Loaded += CodeTabView_Loaded;
        }
Пример #3
0
        private void ReadItemtemplates(ZipFile z)
        {
            var t     = Info["Templates"] as ObjectValue;
            var items = (t.Value["Item"] as ArrayValue).Value;

            JsonExtensionResolver.Archive = z;

            foreach (var tt in items)
            {
                var obj = (tt as ObjectValue).Value;
                var te  = new ItemTemplate(this);

                te.ProjectID = Guid.Parse(JsonExtensionResolver.Resolve <string>(Info["ID"].ToString()));

                te.Name      = obj["Name"].ToString();
                te.Extension = obj["Extension"].ToString();
                te.ID        = Guid.Parse(JsonExtensionResolver.Resolve <string>(obj["ID"].ToString()));

                var ms = new MemoryStream();
                z["Templates/Items/" + obj["Template"]].OpenReader().CopyTo(ms);

                te.Raw = ms.ToArray();

                if (Icons.Count > 0)
                {
                    te.Icon = Icons[obj["Icon"].ToString()];
                    SolutionExplorer.Icons.Add(te.ID, ResizeIcon(te.Icon, new Size(16, 16)));
                }

                if (obj.ContainsKey("View"))
                {
                    te.View       = View.FromXaml(new StreamReader(z["Views/" + obj["View"]].OpenReader()).ReadToEnd());
                    te.ViewSource = new StreamReader(z["Sources/" + obj["View"].ToString().Replace("xaml", "js")].OpenReader()).ReadToEnd();
                }

                var h = z["Highlighting/" + obj["Highlighting"].ToString()];
                te.Highlighting = obj["Highlighting"].ToString();

                var hs = HighlightingDefinitionParser.Parse(new SyntaxMode(te.Highlighting, te.Name, te.Extension),
                                                            new XmlTextReader(h.OpenReader()));

                HighlightingManager.Manager.AddHighlightingStrategy(hs);
                hs.ResolveReferences();

                ItemTemplates.Add(te);
            }
        }
Пример #4
0
        public void SetResourceHighlight(string name, Func <string> loader, bool forceLoad)
        {
            if (!HighlightingManager.Manager.HighlightingDefinitions.ContainsKey(name) || forceLoad)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(loader());

                using (XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement))
                {
                    var strategy = HighlightingDefinitionParser.Parse(
                        new SyntaxMode(name + ".xml", name, new string[] { }), reader);
                    HighlightingManager.Manager.HighlightingDefinitions[name] = strategy;
                    strategy.ResolveReferences();
                    Document.HighlightingStrategy = strategy;
                }
            }
            else
            {
                Document.HighlightingStrategy = (IHighlightingStrategy)HighlightingManager.Manager.HighlightingDefinitions[name];
            }
        }
Пример #5
0
        public void SetupFixture()
        {
            // Add forms designer addin to the AddInTree.
            bool formsDesignerAddInExists = false;

            foreach (AddIn addIn in AddInTree.AddIns)
            {
                if (addIn.Manifest.Identities.ContainsKey("ICSharpCode.FormsDesigner"))
                {
                    formsDesignerAddInExists = true;
                    break;
                }
            }

            if (!formsDesignerAddInExists)
            {
                formsDesignerAddIn         = AddIn.Load(new StringReader(GetFormsDesignerAddInFile()));
                formsDesignerAddIn.Enabled = true;

                string codeBase = typeof(PythonSyntaxModeTestFixture).Assembly.CodeBase.Replace("file:///", String.Empty);
                string folder   = Path.GetDirectoryName(codeBase);

                Type      type      = formsDesignerAddIn.GetType();
                FieldInfo fieldInfo = type.GetField("addInFileName", BindingFlags.NonPublic | BindingFlags.Instance);
                fieldInfo.SetValue(formsDesignerAddIn, Path.Combine(folder, "FormsDesigner.addin"));
                AddInTree.InsertAddIn(formsDesignerAddIn);
            }

            using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
                addin = AddIn.Load(reader, String.Empty);

                // Get syntax mode codon.
                syntaxModeCodon = null;
                ExtensionPath path = addin.Paths[SyntaxModePath];
                foreach (Codon codon in path.Codons)
                {
                    if (codon.Id == "Python.SyntaxMode")
                    {
                        syntaxModeCodon = codon;
                        break;
                    }
                }

                // Get syntax mode.
                highlightingStrategy = null;
                if (syntaxModeCodon != null)
                {
                    SyntaxModeDoozer    doozer     = new SyntaxModeDoozer();
                    AddInTreeSyntaxMode syntaxMode = (AddInTreeSyntaxMode)doozer.BuildItem(null, syntaxModeCodon, null);
                    highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, syntaxMode.CreateTextReader());

                    // Load Python syntax file into XML document since
                    // we cannot get all the information stored in this
                    // document through the HighlightRuleSet class. For
                    // example KeyWords are only accessible through a
                    // LookupTable does not have a getter which is easy
                    // to use.
                    syntaxModeDocument = new XmlDocument();
                    syntaxModeDocument.Load(syntaxMode.CreateTextReader());

                    // Get default ruleset.
                    foreach (HighlightRuleSet ruleSet in highlightingStrategy.Rules)
                    {
                        if (String.IsNullOrEmpty(ruleSet.Name))
                        {
                            defaultRuleSet = ruleSet;
                            break;
                        }
                    }

                    // Get keywords elements.
                    importsKeyWordsElement             = GetKeyWordsElement("Imports");
                    iterationStatementsKeyWordsElement = GetKeyWordsElement("IterationStatements");
                    jumpStatementsKeyWordsElement      = GetKeyWordsElement("JumpStatements");
                    operatorStatementsKeyWordsElement  = GetKeyWordsElement("OperatorStatements");
                    selectionStatementsKeyWordsElement = GetKeyWordsElement("SelectionStatements");
                    functionDefinitionKeyWordsElement  = GetKeyWordsElement("FunctionDefinition");
                    exceptionHandlingKeyWordsElement   = GetKeyWordsElement("ExceptionHandlingStatements");
                    withStatementKeyWordsElement       = GetKeyWordsElement("WithStatement");
                    passStatementKeyWordsElement       = GetKeyWordsElement("PassStatement");
                    classStatementKeyWordsElement      = GetKeyWordsElement("ClassStatement");
                    builtInStatementsKeyWordsElement   = GetKeyWordsElement("BuiltInStatements");

                    // Get mark previous.
                    markPreviousElement = syntaxModeDocument.SelectSingleNode("//MarkPrevious") as XmlElement;
                }

                // Get line comment span.
                if (defaultRuleSet != null)
                {
                    foreach (Span s in defaultRuleSet.Spans)
                    {
                        if (s.Name == "LineComment")
                        {
                            lineCommentSpan = s;
                        }
                        else if (s.Name == "String")
                        {
                            stringSpan = s;
                        }
                        else if (s.Name == "Char")
                        {
                            charSpan = s;
                        }
                        else if (s.Name == "DocComment")
                        {
                            docCommentSpan = s;
                        }
                        else if (s.Name == "SingleQuoteDocComment")
                        {
                            singleQuoteDocCommentSpan = s;
                        }
                    }
                }
            }
        }