protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { IXmlTagHeader tagHeader = GetTagHeader(); if (tagHeader == null) { return(null); } IXmlTag tag = XmlTagNavigator.GetByTagHeader(tagHeader); if (tag == null) { return(null); } XmlElementFactory factory = XmlElementFactory.GetInstance(tag); IXmlAttribute idAttr = factory.CreateAttributeForTag(tag, "id=\"\""); tag.AddAttributeBefore(idAttr, null); // continuation to do after transaction committed return(textControl => // move cursor inside new created id attribute textControl.Caret.MoveTo(idAttr.Value.GetDocumentRange().TextRange.StartOffset, CaretVisualPlacement.Generic)); }
protected override void Change(string csprojFile) { XDocument doc = XDocument.Load(csprojFile); XmlNodeFeature feature1 = new XmlNodeFeature("Reference") { SimilarAttributeFeature = new Dictionary <string, string>() { { "Include", SolutionConfig.DllName.Trim() } } }; XmlNodeFeature feature2 = new XmlNodeFeature("PackageReference") { SimilarAttributeFeature = new Dictionary <string, string>() { { "Include", SolutionConfig.DllName.Trim() } } }; var selectElement = FineXElement(doc, feature1); if (selectElement != null) { XmlElementFactory.ChangeReferenceNode(ref selectElement, SolutionConfig.NewFileAbsolutePath); doc.Save(csprojFile); return; } selectElement = FineXElement(doc, feature2); if (selectElement != null) { // 此方法创建出来的节点,没有 版本号 等其它信息,实际使用中会出问题。 var element = XmlElementFactory.CreateReferenceNode(SolutionConfig.DllName.Trim(), SolutionConfig.NewFileAbsolutePath, doc.Root.Name.NamespaceName); selectElement.Parent.Add(element); selectElement.Remove(); doc.Save(csprojFile); return; } }
public NHTreeBuilder(XmlElementFactory elementFactory, CheckForInterrupt checkForInterrupt) : base(elementFactory, checkForInterrupt, NHLanguageService.NH) { }
public MappingFileTreeBuilder(XmlElementFactory elementFactory, CheckForInterrupt checkForInterrupt) : base(elementFactory, checkForInterrupt, MappingFileLanguageService.MAPPING_FILE) { }
protected override void Change(string csprojFile) { XDocument doc = XDocument.Load(csprojFile); XmlNodeFeature feature1 = new XmlNodeFeature("Reference") { SimilarAttributeFeature = new Dictionary <string, string>() { { "Include", SolutionConfig.DllName.Trim() } } }; XmlNodeFeature feature2 = new XmlNodeFeature("PackageReference") { SimilarAttributeFeature = new Dictionary <string, string>() { { "Include", SolutionConfig.DllName.Trim() } } }; XmlNodeFeature feature3 = new XmlNodeFeature("Reference") { SimilarAttributeFeature = new Dictionary <string, string>() { { "Include", SourceCsprojRootNamespace } } }; XmlNodeFeature feature4 = new XmlNodeFeature("PackageReference") { SimilarAttributeFeature = new Dictionary <string, string>() { { "Include", SourceCsprojRootNamespace } } }; //var selectElement = FindReferenceItem(doc); var selectElement = FineXElement(doc, feature1) ?? FineXElement(doc, feature2); if (selectElement == null && !string.IsNullOrWhiteSpace(SourceCsprojRootNamespace)) { selectElement = FineXElement(doc, feature3) ?? FineXElement(doc, feature4); } if (selectElement == null) { return; } // 添加新节点。 XElement newElement; //if (string.IsNullOrWhiteSpace(SourceCsprojGuid) || string.IsNullOrWhiteSpace(SourceCsprojName)) //{ // newElement = XmlElementFactory.CreateProjectReferenceNode(SourceCsprojFile, doc.Root.Name.NamespaceName); //} //else //{ // newElement = XmlElementFactory.CreateProjectReferenceNode(SourceCsprojFile, SourceCsprojGuid, SourceCsprojName, // doc.Root.Name.NamespaceName); //} newElement = XmlElementFactory.CreateProjectReferenceNode(SourceCsprojFile, doc.Root.Name.NamespaceName); selectElement.Parent.Add(newElement); // 删除此节点。 selectElement.Remove(); doc.Save(csprojFile); RefrenceItems.Add(csprojFile, new RefrenceItem(csprojFile, selectElement, newElement)); }
public L4NTreeBuilder(XmlElementFactory elementFactory, CheckForInterrupt checkForInterrupt) : base(elementFactory, checkForInterrupt, L4NLanguageService.L4N) { }