Note: The template referred to by this post does not ship with CodeRush. To install it, see instructions towards the end of the post
This post describes the first new plugin template in a series. The series itself is introduced in my previous post - So you want to write a CodeRush plugin
The NewAction template provides the single quickest way to create a new action for your plugin. Actions are named bits of code which an user can trigger via a shortcut (mouse, keyboard or menu).
Each new action creates an entry which will be placed in the commands dropdown on the shortcuts page.
Usage
First you’ll need a plugin project. An existing project is fine, or you can create a new one via:
- File \ New \ Project
- DxCore \ (VSIX) Standard Plug-in
Once you are in your new project, you’ll see code like this:
As indicated in the screenshot, there you should:
- Expand the template in the body of your main plugin class.
- Call the new registerXXXX method from within the InitializePlugin method.
In more detail the steps are:
- Expand the template
- Fill out the generated fields: The first is used to name the methods associated with your action. the second is used to provide the internal name of your action. The one which CodeRush will use and which must be bound to a shortcut in order to be triggered.
- Add a call to the generated Register method to your plugin’s InitializePlugin method.
- Add your plugin specific code to the generated Execute method. In the example below I have added a simple call to show a simple "”Hello World” MessageBox.
All of these steps involve coding. None of them take you through designers, and there’s no searching for the right properties or events.
The Action does, of course, have more properties and events to investigate, but this template provides the basic setup which almost every action will require.
Download and Install
This template is available in the CodeRush Plugin Templates repository on Github
To install this template you need (the raw version of) CS_NewAction.xml from the repository.
- Visit the CodeRush Plugin Templates repository
- Download the raw version of CS_NewAction.xml
- Import the downloaded file using instructions from my previous post - Exporting and Importing CodeRush Templates
Update: If you’re using the Template Importer plugin, you can pass it this url to import the NewAction template straight off the web.