public void SetupFixture() { using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) { addin = AddIn.Load(reader, String.Empty); fileFilterCodon = GetCodon("/SharpDevelop/Workbench/FileFilter", "Python"); pythonMenuCodon = GetCodon("/SharpDevelop/Workbench/MainMenu", "Python"); displayBindingCodon = GetCodon("/SharpDevelop/Workbench/DisplayBindings", "PythonDisplayBinding"); const string runMenuExtensionPath = "/SharpDevelop/Workbench/MainMenu/Python"; pythonRunMenuItemCodon = GetCodon(runMenuExtensionPath, "Run"); pythonWithoutDebuggerRunMenuItemCodon = GetCodon(runMenuExtensionPath, "RunWithoutDebugger"); pythonStopMenuItemCodon = GetCodon(runMenuExtensionPath, "Stop"); fileTemplatesCodon = GetCodon("/SharpDevelop/BackendBindings/Templates", "Python"); optionsPanelCodon = GetCodon("/SharpDevelop/Dialogs/OptionsDialog/ToolsOptions", "PythonOptionsPanel"); parserCodon = GetCodon("/Workspace/Parser", "Python"); additionalMSBuildPropertiesCodon = GetCodon("/SharpDevelop/MSBuildEngine/AdditionalProperties", "PythonBinPath"); languageBindingCodon = GetCodon("/SharpDevelop/Workbench/LanguageBindings", "Python"); projectFileFilterCodon = GetCodon("/SharpDevelop/Workbench/Combine/FileFilter", "PythonProject"); codeCompletionBindingCodon = GetCodon("/AddIns/DefaultTextEditor/CodeCompletion", "Python"); applicationSettingsOptionsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "Application"); buildEventsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "BuildEvents"); compilingOptionsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "CompilingOptions"); debugOptionsCodon = GetCodon("/SharpDevelop/BackendBindings/ProjectOptions/Python", "DebugOptions"); convertCodeCodon = GetCodon("/SharpDevelop/Workbench/MainMenu/Tools/ConvertCode", "ConvertToPython"); pythonFileIconCodon = GetCodon("/Workspace/Icons", "PythonFileIcon"); pythonProjectIconCodon = GetCodon("/Workspace/Icons", "PythonProjectIcon"); convertCSharpProjectCodon = GetCodon("/SharpDevelop/Pads/ProjectBrowser/ContextMenu/ProjectActions/Convert", "CSharpProjectToPythonProjectConverter"); convertVBNetProjectCodon = GetCodon("/SharpDevelop/Pads/ProjectBrowser/ContextMenu/ProjectActions/Convert", "VBNetProjectToPythonProjectConverter"); formattingStrategyCodon = GetCodon("/AddIns/DefaultTextEditor/Formatter/Python", "PythonFormatter"); // Get the PythonBinding runtime. foreach (Runtime runtime in addin.Runtimes) { if (runtime.Assembly == "PythonBinding.dll") { pythonBindingRuntime = runtime; } else if (runtime.Assembly == "$ICSharpCode.FormsDesigner/FormsDesigner.dll") { formsDesignerRuntime = runtime; } } // Get the forms designer dependency. foreach (AddInReference addInRef in addin.Manifest.Dependencies) { if (addInRef.Name == "ICSharpCode.FormsDesigner") { formsDesignerAddInRef = addInRef; break; } } } }
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; } } } } }