Language: C#
ReSharper plugin for converting spaces to underscores
[ContextAction(Group = "C#", Name = "ConvertSpacesToUnderscore", Description = "Adds context action to convert spaces in method names to underscore")] public class ConvertSpacesToUnderscore : BulbItemImpl, IContextAction { readonly ICSharpContextActionDataProvider _provider; public ConvertSpacesToUnderscore(ICSharpContextActionDataProvider provider) { _provider = provider; } protected override Action<ITextControl> ExecuteTransaction(ISolution solution, IProgressIndicator progress) { var selection = _provider.Selection; var document = _provider.Document; var selectedText = document.GetText(selection); var adjustedText = selectedText.Replace(" ", "_"); document.ReplaceText(selection, adjustedText); return null; //Causes an exception being thrown: //"All documents should be committed, but these are dirty: <PathToEditedFile>" } public override string Text { get { return "Convert spaces to underscore"; } } public bool IsAvailable(IUserDataHolder cache) { var selection = _provider.Selection; var document = _provider.Document; if (selection.Length > 1) { //Should find a way to enable the plugin only if there is a problem in the current line/selection var selectedText = document.GetText(selection); return selectedText.Contains(" "); } return false; } }
Tags:
Comment:
I'm trying to create a plugin for quickly fixing method names when I write test code, so that I can quickly write a method name with spaces, select the range and replace all spaces with underscores.
Might be a better way to enable the plugin (only if the current line/selection has error and selection contains spaces)
It currently throws an exception when executed => "All documents should be committed, but these are dirty: <PathToEditedFile>"
Might be a better way to enable the plugin (only if the current line/selection has error and selection contains spaces)
It currently throws an exception when executed => "All documents should be committed, but these are dirty: <PathToEditedFile>"
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

