/// <inheritdoc /> protected override void Execute(object sender, EventArgs e) { var dte = ServiceProvider.GetService(typeof(DTE)) as DTE; var textDocument = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (textDocument != null) { var selection = textDocument.Selection; var selectedText = selection.Text; selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText)); } }
/// <inheritdoc /> protected override void Execute(object sender, EventArgs e) { var dte = ServiceProvider.GetService(typeof(DTE)) as DTE; var textDocument = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (textDocument != null) { var convertPatterns = ((CaseConverterPackage)Package).GetGeneralOption().Patterns.ToList(); var selection = textDocument.Selection; if (selection.IsEmpty == false) { var selectedText = selection.Text; selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText, convertPatterns)); } else { var point = selection.ActivePoint; var startPoint = CreateStartPoint(point); var endPoint = CreateEndPoint(point, startPoint); var targetText = startPoint.GetText(endPoint); var word = targetText.TrimEnd(' '); var convertedWord = StringCaseConverter.Convert(word, convertPatterns); if (word != convertedWord) { var left = point.AbsoluteCharOffset - startPoint.AbsoluteCharOffset; selection.CharLeft(false, left); var trimCount = targetText.Length - word.Length; var right = endPoint.AbsoluteCharOffset - point.AbsoluteCharOffset - trimCount; selection.CharRight(true, right); selection.ReplaceText(word, convertedWord); } } } }
/// <inheritdoc /> protected override void Execute(object sender, EventArgs e) { var dte = ServiceProvider.GetService(typeof(DTE)) as DTE; var textDocument = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (textDocument != null) { var convertPatterns = ((CaseConverterPackage)Package).GetGeneralOption().Patterns.ToList(); var selection = textDocument.Selection; if (selection.IsEmpty == false) { //var selectedText = selection.Text; //selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText, convertPatterns)); if (selection.TextRanges.Count > 1) { int options = (int)(vsFindOptions.vsFindOptionsMatchWholeWord | vsFindOptions.vsFindOptionsMatchCase | vsFindOptions.vsFindOptionsMatchInHiddenText | vsFindOptions.vsFindOptionsSearchSubfolders | vsFindOptions.vsFindOptionsKeepModifiedDocumentsOpen); var words = StringCaseConverter.GetVariableWords(selection.Text); foreach (var word in words) { dte.Find.FindReplace(vsFindAction.vsFindActionReplaceAll, word, options, StringCaseConverter.Convert(word, convertPatterns), vsFindTarget.vsFindTargetCurrentDocumentSelection, ResultsLocation: vsFindResultsLocation.vsFindResultsNone); } } else { var selectedText = selection.Text; selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText, convertPatterns)); } } else { var point = selection.ActivePoint; var startPoint = CreateStartPoint(point); var endPoint = CreateEndPoint(point, startPoint); var targetText = startPoint.GetText(endPoint); var word = targetText.TrimEnd(' '); var convertedWord = StringCaseConverter.Convert(word, convertPatterns); if (word != convertedWord) { var left = point.AbsoluteCharOffset - startPoint.AbsoluteCharOffset; selection.CharLeft(false, left); var trimCount = targetText.Length - word.Length; var right = endPoint.AbsoluteCharOffset - point.AbsoluteCharOffset - trimCount; selection.CharRight(true, right); selection.ReplaceText(word, convertedWord); } } } }