public override bool ShouldEnableFor(Project proj, string projectPath, string language) { foreach (var child in childNodes) { if (FileTemplateCondition.CreateCondition(child).ShouldEnableFor(proj, projectPath, language)) { return(true); } } return(false); }
public static FileTemplateCondition CreateCondition(XmlElement element) { if (conditions == null) { conditions = new List <FileTemplateConditionTypeCodon> (); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/FileTemplateConditionTypes", OnExtensionChanged); } foreach (FileTemplateConditionTypeCodon condition in conditions) { if (condition.ElementName == element.Name) { FileTemplateCondition t = (FileTemplateCondition)condition.CreateInstance(typeof(FileTemplateCondition)); t.Load(element); return(t); } } throw new InvalidOperationException("Unknown file template condition type: " + element.Name); }
internal static FileTemplate LoadFileTemplate(RuntimeAddin addin, XmlDocument xmlDocument, FilePath baseDirectory = new FilePath(), string templateId = "") { //Configuration XmlElement xmlNodeConfig = xmlDocument.DocumentElement ["TemplateConfiguration"]; FileTemplate fileTemplate; if (xmlNodeConfig ["Type"] != null) { Type configType = addin.GetType(xmlNodeConfig ["Type"].InnerText); if (typeof(FileTemplate).IsAssignableFrom(configType)) { fileTemplate = (FileTemplate)Activator.CreateInstance(configType); } else { throw new InvalidOperationException(string.Format("The file template class '{0}' must be a subclass of MonoDevelop.Ide.Templates.FileTemplate", xmlNodeConfig ["Type"].InnerText)); } } else { fileTemplate = new FileTemplate(); } fileTemplate.Originator = xmlDocument.DocumentElement.GetAttribute("Originator"); fileTemplate.Created = xmlDocument.DocumentElement.GetAttribute("Created"); fileTemplate.LastModified = xmlDocument.DocumentElement.GetAttribute("LastModified"); if (xmlNodeConfig ["_Name"] != null) { fileTemplate.Name = xmlNodeConfig ["_Name"].InnerText; } else { throw new InvalidOperationException(string.Format("Missing element '_Name' in file template: {0}", templateId)); } if (xmlNodeConfig ["LanguageName"] != null) { fileTemplate.LanguageName = xmlNodeConfig ["LanguageName"].InnerText; } if (xmlNodeConfig ["ProjectType"] != null) { var projectTypeList = new List <string> (); foreach (var item in xmlNodeConfig["ProjectType"].InnerText.Split(',')) { projectTypeList.Add(item.Trim()); } fileTemplate.ProjectTypes = projectTypeList; } fileTemplate.Categories = new Dictionary <string, string> (); if (xmlNodeConfig ["_Category"] != null) { foreach (XmlNode xmlNode in xmlNodeConfig.GetElementsByTagName("_Category")) { if (xmlNode is XmlElement) { string projectType = ""; if (xmlNode.Attributes ["projectType"] != null) { projectType = xmlNode.Attributes ["projectType"].Value; } if (!string.IsNullOrEmpty(projectType) && fileTemplate.ProjectTypes.Contains(projectType)) { fileTemplate.Categories.Add(projectType, xmlNode.InnerText); } else if (!fileTemplate.Categories.ContainsKey(DefaultCategoryKey)) { fileTemplate.Categories.Add(DefaultCategoryKey, xmlNode.InnerText); } } } } else { throw new InvalidOperationException(string.Format("Missing element '_Category' in file template: {0}", templateId)); } if (xmlNodeConfig ["_Description"] != null) { fileTemplate.Description = xmlNodeConfig ["_Description"].InnerText; } if (xmlNodeConfig ["Icon"] != null) { fileTemplate.Icon = ImageService.GetStockId(addin, xmlNodeConfig ["Icon"].InnerText, IconSize.Dnd); } if (xmlNodeConfig ["Wizard"] != null) { fileTemplate.Icon = xmlNodeConfig ["Wizard"].Attributes ["path"].InnerText; } if (xmlNodeConfig ["DefaultFilename"] != null) { fileTemplate.DefaultFilename = xmlNodeConfig ["DefaultFilename"].InnerText; string isFixed = xmlNodeConfig ["DefaultFilename"].GetAttribute("IsFixed"); if (isFixed.Length > 0) { bool bFixed; if (bool.TryParse(isFixed, out bFixed)) { fileTemplate.IsFixedFilename = bFixed; } else { throw new InvalidOperationException("Invalid value for IsFixed in template."); } } } //Template files XmlNode xmlNodeTemplates = xmlDocument.DocumentElement ["TemplateFiles"]; if (xmlNodeTemplates != null) { foreach (XmlNode xmlNode in xmlNodeTemplates.ChildNodes) { var xmlElement = xmlNode as XmlElement; if (xmlElement != null) { fileTemplate.Files.Add( FileDescriptionTemplate.CreateTemplate(xmlElement, baseDirectory)); } } } //Conditions XmlNode xmlNodeConditions = xmlDocument.DocumentElement ["Conditions"]; if (xmlNodeConditions != null) { foreach (XmlNode xmlNode in xmlNodeConditions.ChildNodes) { var xmlElement = xmlNode as XmlElement; if (xmlElement != null) { fileTemplate.Conditions.Add(FileTemplateCondition.CreateCondition(xmlElement)); } } } return(fileTemplate); }
private static FileTemplate LoadFileTemplate(RuntimeAddin addin, ProjectTemplateCodon codon) { XmlDocument xmlDocument = codon.GetTemplate(); FilePath baseDirectory = codon.BaseDirectory; //Configuration XmlElement xmlNodeConfig = xmlDocument.DocumentElement["TemplateConfiguration"]; FileTemplate fileTemplate = null; if (xmlNodeConfig["Type"] != null) { Type configType = addin.GetType(xmlNodeConfig["Type"].InnerText); if (typeof(FileTemplate).IsAssignableFrom(configType)) { fileTemplate = (FileTemplate)Activator.CreateInstance(configType); } else { throw new InvalidOperationException(string.Format("The file template class '{0}' must be a subclass of MonoDevelop.Ide.Templates.FileTemplate", xmlNodeConfig["Type"].InnerText)); } } else { fileTemplate = new FileTemplate(); } fileTemplate.originator = xmlDocument.DocumentElement.GetAttribute("Originator"); fileTemplate.created = xmlDocument.DocumentElement.GetAttribute("Created"); fileTemplate.lastModified = xmlDocument.DocumentElement.GetAttribute("LastModified"); if (xmlNodeConfig["_Name"] != null) { fileTemplate.name = xmlNodeConfig["_Name"].InnerText; } else { throw new InvalidOperationException(string.Format("Missing element '_Name' in file template: {0}", codon.Id)); } if (xmlNodeConfig["_Category"] != null) { fileTemplate.category = xmlNodeConfig["_Category"].InnerText; } else { throw new InvalidOperationException(string.Format("Missing element '_Category' in file template: {0}", codon.Id)); } if (xmlNodeConfig["LanguageName"] != null) { fileTemplate.languageName = xmlNodeConfig["LanguageName"].InnerText; } if (xmlNodeConfig["ProjectType"] != null) { fileTemplate.projecttype = xmlNodeConfig["ProjectType"].InnerText; } if (xmlNodeConfig["_Description"] != null) { fileTemplate.description = xmlNodeConfig["_Description"].InnerText; } if (xmlNodeConfig["Icon"] != null) { fileTemplate.icon = ImageService.GetStockId(addin, xmlNodeConfig["Icon"].InnerText, IconSize.Dnd); //xmlNodeConfig["_Description"].InnerText; } if (xmlNodeConfig["Wizard"] != null) { fileTemplate.icon = xmlNodeConfig["Wizard"].Attributes["path"].InnerText; } if (xmlNodeConfig["DefaultFilename"] != null) { fileTemplate.defaultFilename = xmlNodeConfig["DefaultFilename"].InnerText; string isFixed = xmlNodeConfig["DefaultFilename"].GetAttribute("IsFixed"); if (isFixed.Length > 0) { bool bFixed; if (bool.TryParse(isFixed, out bFixed)) { fileTemplate.isFixedFilename = bFixed; } else { throw new InvalidOperationException("Invalid value for IsFixed in template."); } } } //Template files XmlNode xmlNodeTemplates = xmlDocument.DocumentElement["TemplateFiles"]; if (xmlNodeTemplates != null) { foreach (XmlNode xmlNode in xmlNodeTemplates.ChildNodes) { if (xmlNode is XmlElement) { fileTemplate.files.Add( FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory)); } } } //Conditions XmlNode xmlNodeConditions = xmlDocument.DocumentElement["Conditions"]; if (xmlNodeConditions != null) { foreach (XmlNode xmlNode in xmlNodeConditions.ChildNodes) { if (xmlNode is XmlElement) { fileTemplate.conditions.Add(FileTemplateCondition.CreateCondition((XmlElement)xmlNode)); } } } return(fileTemplate); }