public bool IsAvailable(IUserDataHolder cache) { SelectedXmlTag = DataProvider.FindNodeAtCaret <IXmlTag>(); if (SelectedXmlTag != null && !SelectedXmlTag.IsEmptyTag && !SelectedXmlTag.Children().CountIs(0)) { // TODO: remove the next block once you know how to auto-save the doc after executing the action if (!SelectedXmlTag.PathToRoot().CountIs(0)) { return(false); } //end SelectedXmlTagInnerText = SelectedXmlTag.InnerText; SelectedXmlTagMinifiedInnerText = Minifier.Minify(SelectedXmlTagInnerText); bool isAvailable = !string.Equals(SelectedXmlTagInnerText, SelectedXmlTagMinifiedInnerText); return(isAvailable); } return(false); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { if (SelectedXmlTag != null) { IPsiSourceFile sourceFile = SelectedXmlTag.GetSourceFile(); TreeTextRange valueRange = SelectedXmlTag.GetValueRange(); TextRange textRange = new TextRange(valueRange.StartOffset.Offset, valueRange.EndOffset.Offset); if (sourceFile != null) { try { sourceFile.Document.DeleteText(textRange); sourceFile.Document.InsertText(textRange.StartOffset, SelectedXmlTagMinifiedInnerText); } catch { // nomnom... } } } return(null); }