CodeRush Plugins – Your first ‘Action’ Plugin – “DX_HelloWorld”

Yes that’s right we’re going to create a plugin. Don’t worry it’s very easy and I promise this won’t break studio.

In the grand tradition of programming, we’re going to write a “Hello World” plugin. The idea is that the user/developer will press some key combination and the DXCore will respond by placing the “Hello world!” message on screen.

To do this we’re going to use an Action component.

What is an Action?

An Action represents some managed code which can be bound to either a keyboard or mouse shortcut. The effect of this is to allow the user/developer to invoke the code on demand. Additionally, if the correct properties are set, your action can appear in one of the standard Visual Studio menus.

For example: If you wanted a function to count the number of files on your C:\ whenever you pressed Ctrl+Shift+C, then you’d do this by creating an Action to perform the count, and then bind that Action to the specified key combination.

The choice of task in this case is pretty arbitrary. You can connect any managed code to this action, and as you might appreciate, this doesn’t limit you very much. The choice to use an Action is more about the invocation UX. If your feature is designed to be triggered by a keyboard or mouse shortcut, then the Action is the way forward.

So how do I use an Action?

So on with our example…

Ok so first up, you’ll need to create your plugin project. Call it “DX_HelloWorld”.

Next up take a look at your toolbox (yes the same place you usually find buttons and lists) and find a tab called “DXCore". In here you should see several DXCore components allToolboxDXCore used for various plugin related activities. The one you’re looking for is unsurprisingly named “Action”.

Drag an “Action” to the design surface and set it’s name property to “SayHello”.

Next we need to give our Action a system-wide unique name. In this case we’ll use “MessageBox.SayHello” in order to distinguish ourselves from future actions (perhaps provided by other plugins) which might wish to provide other implementations of “SayHello”

PropertiesActionSayHello 

After this we need to handle the Execute event

 EventsActionSayHello

And call the appropriate code…

Either…
CodeVBActionSayHello

..Or if you really must…
CodeCSharpActionSayHello

…and that’s it. No really … It is. That’s all the code you need to write.

Ok let’s prove it. Press F5 and this copy of studio, will launch another one which, in turn, will load and initialize your plugin.

Notice that absolutely nothing happens.

Don’t worry, this is to be expected. First you will need to bind your action to a shortcut, and then you will need to invoke it using that shortcut.

Funnily this can be one of the harder things to do. Visual Studio and CodeRush already ship many shortcuts between them, and so finding one that is available can prove sometimes prove a little frustrating. When testing, I tend to use (and reuse) Ctrl+Shift+Alt+T. It’s a bit complex, but I’ve not seen it conflict with anything else so it seems to do the job well enough.

Once you’ve bound your key to your action (Yes, I’m going to link that reference a lot) you should be able to press whatever combination you allocated as much as you like and be greeted (along with the rest of the world) whenever you like.

HelloWorld

Note: If you prefer, you can use the properties of your action to specify a menu on which it will be placed. Use either the CommonMenu or ParentMenu properties (Note: These properties are mutually exclusive). The DXCore will then place a menu item beneath your indicated menu using the text specified in your action’s ‘ButtonText’ property.

Well I think that’s about it for this lesson. Stay tuned as we’ll begin to dig deeper into other components, and start branching out into more complicated and indeed more useful plugins.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.