public override void Execute(CancellationToken cancellationToken) { var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.UI_SetBindingModeToTwoWay); try { var lineNumber = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition) + 1; if (!string.IsNullOrEmpty(this.Tag.ExistingBindingMode)) { vs.ReplaceInActiveDocOnLine(this.Tag.ExistingBindingMode, "Mode=TwoWay", lineNumber); } else { vs.ReplaceInActiveDocOnLine("}", ", Mode=TwoWay}", lineNumber); } RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
public override void Execute(CancellationToken cancellationToken) { var resPath = this.GetResourceFilePath(); if (resPath == null) { return; } var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.Info_UndoContextMoveStringToResourceFile); try { // If the resource file is open with unsaved changes VS will prompt about data being lost. this.AddResource(resPath, $"{this.Tag.UidValue}.{this.Tag.AttributeName}", this.Tag.Value); if (this.Tag.AttributeType == AttributeType.Inline) { var currentAttribute = $"{this.Tag.AttributeName}=\"{this.Tag.Value}\""; if (this.Tag.UidExists) { vs.RemoveInActiveDocOnLine(currentAttribute, this.Tag.GetDesignerLineNumber()); } else { var uidTag = $"x:Uid=\"{this.Tag.UidValue}\""; vs.ReplaceInActiveDocOnLine(currentAttribute, uidTag, this.Tag.GetDesignerLineNumber()); } } else if (this.Tag.AttributeType == AttributeType.Element) { var currentAttribute = $"<{this.Tag.ElementName}.{this.Tag.AttributeName}>{this.Tag.Value}</{this.Tag.ElementName}.{this.Tag.AttributeName}>"; vs.RemoveInActiveDocOnLine(currentAttribute, this.Tag.GetDesignerLineNumber()); if (!this.Tag.UidExists) { var uidTag = $"<{this.Tag.ElementName} x:Uid=\"{this.Tag.UidValue}\""; vs.ReplaceInActiveDocOnLineOrAbove($"<{this.Tag.ElementName}", uidTag, this.Tag.GetDesignerLineNumber()); } } else if (this.Tag.AttributeType == AttributeType.DefaultValue) { var current = $">{this.Tag.Value}</{this.Tag.ElementName}>"; var replaceWith = this.Tag.UidExists ? " />" : $" x:Uid=\"{this.Tag.UidValue}\" />"; vs.ReplaceInActiveDocOnLine(current, replaceWith, this.Tag.GetDesignerLineNumber()); } RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
public override void Execute(CancellationToken cancellationToken) { var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(this.UndoText); try { vs.ReplaceInActiveDocOnLine(this.Original, this.Replace, this.LineNo); RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
public override void Execute(CancellationToken cancellationToken) { var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.UI_AddMissingEvent); try { var lineNumber = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition) + 1; string newName; if (this.Tag.ExistingName.ToLowerInvariant().Contains("checked")) { if (this.Tag.ExistingIsChecked) { newName = this.Tag.ExistingName.Replace("Checked", "UnChecked").Replace("checked", "Unchecked"); } else { newName = this.Tag.ExistingName.Replace("UnChecked", "Checked").Replace("unchecked", "checked"); } } else { if (this.Tag.ExistingIsChecked) { newName = "OnCheckBoxUnchecked"; } else { newName = "OnCheckBoxChecked"; } } var newEvent = this.Tag.ExistingIsChecked ? $"Unchecked=\"{newName}\"" : $"Checked=\"{newName}\""; vs.ReplaceInActiveDocOnLine("<CheckBox", $"<CheckBox {newEvent} ", lineNumber); RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
public override void Execute(CancellationToken cancellationToken) { var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.Info_UndoContextAddTextBoxInputScope); try { var lineNumber = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition) + 1; vs.ReplaceInActiveDocOnLine("<TextBox ", "<TextBox InputScope=\"Default\" ", lineNumber); RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
public override void Execute(CancellationToken cancellationToken) { var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.UI_ChangeToMediaPlayerElement); try { var lineNumber = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition) + 1; vs.ReplaceInActiveDocOnLine("<MediaElement", "<MediaPlayerElement", lineNumber); RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
public override void Execute(CancellationToken cancellationToken) { var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.UI_UndoContextAddEntryKeyboard); try { var lineNumber = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition) + 1; vs.ReplaceInActiveDocOnLine("<Entry ", $"<Entry Keyboard=\"{this.KeyBoardName}\" ", lineNumber); RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }
#pragma warning disable IDE0060 // Remove unused parameter - cancellationToken private void InnerExecute(VisualStudioTextManipulation vs, CustomAnalysisTag tag, CancellationToken cancellationToken) #pragma warning restore IDE0060 // Remove unused parameter { switch (tag.Action) { case RapidXaml.ActionType.AddAttribute: var lineNumber = tag.Snapshot.GetLineNumberFromPosition(tag.InsertPosition) + 1; // Can't rely on the original element name as this may be supplemental after it's been renamed if (XamlElementProcessor.IsSelfClosing(tag.AnalyzedElement.OriginalString.AsSpan())) { var before = $"/>"; var after = $"{tag.Name}=\"{tag.Value}\" />"; vs.ReplaceInActiveDocOnLine(before, after, lineNumber); } else { var before = $">"; var after = $"{tag.Name}=\"{tag.Value}\" /"; vs.ReplaceInActiveDocOnLine(before, after, lineNumber); } break; case RapidXaml.ActionType.AddChild: var origXaml = tag.AnalyzedElement.OriginalString; // Allow for self-closing elements if (origXaml.EndsWith("/>")) { var replacementXaml = $">{Environment.NewLine}{tag.Content}{Environment.NewLine}</{tag.ElementName}>"; var insertLine = tag.Snapshot.GetLineNumberFromPosition(tag.InsertPosition) + 1; vs.ReplaceInActiveDocOnLine("/>", replacementXaml, insertLine); } else { // Allows for opening and closing tags on same or different lines var insertLine = tag.Snapshot.GetLineNumberFromPosition(tag.InsertPosition) + 1; vs.InsertIntoActiveDocOnLineAfterClosingTag(insertLine, tag.Content); } break; case RapidXaml.ActionType.HighlightWithoutAction: // As the name implies, do nothing. break; case RapidXaml.ActionType.RemoveAttribute: if (tag.IsInlineAttribute ?? false) { var currentAttribute = $" {tag.Name}=\"{tag.Value}\""; vs.RemoveInActiveDocOnLine(currentAttribute, tag.GetDesignerLineNumber()); } else { var attrs = tag.AnalyzedElement.GetAttributes(tag.Name).ToList(); if (attrs.Count() == 1) { var attr = attrs.First(); var toRemove = tag.AnalyzedElement.OriginalString.Substring( attr.Location.Start - tag.InsertPosition, attr.Location.Length); vs.RemoveInActiveDocOnLine(toRemove, tag.GetDesignerLineNumber()); } } break; case RapidXaml.ActionType.RemoveChild: vs.RemoveInActiveDocOnLine(tag.Element.OriginalString, tag.GetDesignerLineNumber()); break; case RapidXaml.ActionType.ReplaceElement: vs.ReplaceInActiveDocOnLine( tag.AnalyzedElement.OriginalString, tag.Content, tag.Snapshot.GetLineNumberFromPosition(tag.AnalyzedElement.Location.Start)); break; case RapidXaml.ActionType.RenameElement: // Just change opening tags as Visual Studio will change closing tags automatically var renameLineNumber = tag.Snapshot.GetLineNumberFromPosition(tag.InsertPosition); vs.ReplaceInActiveDocOnLine(tag.ElementName, tag.Name, renameLineNumber); foreach (var childAttr in tag.AnalyzedElement.ChildAttributes) { renameLineNumber = tag.Snapshot.GetLineNumberFromPosition(childAttr.Location.Start); vs.ReplaceInActiveDocOnLine($"{tag.ElementName}.{childAttr.Name}", $"{tag.Name}.{childAttr.Name}", renameLineNumber); } break; } }