Sunday, March 07, 2010

Designer Free CodeRush Plugins – The new CodeRush plugin Quick Start

Explaining how to start a new CodeRush plugin can be a little complex.

So I’ve knocked up a few CodeRush templates that should make it a lot easier :)

Step 1 - Import these Plugin Templates into your copy of CodeRush.

(DevExpress\Options … Editor\Templates … Right-click Templates … “Import Templates…”)

Step 2 - Create a new DXCore Plugin project via the “New Project” dialog

Step 3 - Activate any one of the following templates inside your plugin class.

  • NewAction<Space>
  • NewRefactoring<Space>
  • NewCodeProvider<Space>
  • NewIssue<Space>

You should now have a “CreateMyX” method which….

  • Creates the relevant component
  • Adds it to the components collection
  • Sets up the minimal mandatory properties.
  • Creates the relevant event handlers.
  • Attaches said event handlers to the component in question.

For example, one of the more simplistic things you might want to do is to create a new custom Action to Bind to a Key.

Here is the Default DXCore plugin as written in CS…

DefaultCSPlugin

And here is what you get after executing “NewAction<Space>”  CSActionPlugin

After a little customization…  CSHelloWorldPlugin

The only think you need to do .. Is to call your new “CreateMyX” method from inside the “InitializePlugIn” method

You have a completely functional Hello World action ready to be bound to the key of your choice

Now you have to admit … That makes things a lot simpler…

I’ve even linked a few sections of code together with some CodeRush «Field» and «TypeLink» tokens in order to make customizing of that default code a little easier.

So if you’re interested in making plugins…. This should make things a little better.

Feel free to leave me some feedback… I’ve done my best to convert the original VB.Net versions to C#…. So it’s possible there were some issues in translation… But that’s what you get for picking such a strange language (I mean C# people… VB.Net FTW! :D)


2 comments:

Anonymous said...

Why not just put this directly into the initialize routine from the get-go?

Rory said...

Unfortunately CodeRush doesn't support a template injecting code inside a named method in this way. An additional plugin would be required.