Rory Becker - DevExpress CodeRush Blog
  • AlexS rocks the CodeRush Tips n Tricks

    You’ve got to love this: http://www.skorkin.com is a site dedicated to Tips and Tricks relating to CodeRush, Refactor! and The DXCore.

    The blog currently contains 130 different tips on the use of the DevExpress IDE Tools, with more being added all the time.

    There’s a great selection of sub-categories as well so you can quickly find what you’re looking for.

    Oh and did I mention? Alex is one of the CodeRush Devs, so he knows exactly what he’s talking about.

    SkorkinDotCom

  • CodeRush – Common TextCommands

    TextCommands

    Compared to StringProviders, TextCommands are rather more complicated to explain. This is because they are used for a more diverse set of tasks.

    To this end I will explain several of the more commonly used TextCommands and show you exactly how they are used.

    They don’t inject text in the location they occupy. Instead their location is typically used as a reference for some other sort of operation.

    As always, we’ll start of simply.

    «Caret» and «BlockAnchor»

    The «Caret» TextCommand is exactly what it sounds like. It indicates where your Caret (The blinky thing, that emits text when you type) will be placed after your template has been expanded.

    The «BlockAnchor» TextCommand is an optional counterpart to the «Caret». If used together, text placed between them will be selected once the template has expanded.

    So if you wanted to write a simple C# class template with no constructor you could do so using the following text:

    TemplateClassCaretBlockAnchor

    This would emit the basic text and would select the phrase “DefaultClassName”

    TemplateClassCaretBlockAnchorExpanded

    Markers

    You can enhance the template above with the use of a «Marker» TextCommand. We’ll leave a full description of markers until another time, suffice to say that a marker is like a breadcrumb. You (or indeed templates and other features) can leave a trail of them, and then later you can jump back to the most recent one, and pick it up by pressing Esc.

    Thus if we amend our previous template like so…

    TemplateClassMarker

    TemplateClassMarkerExpanded

    … then the template will emit a small blue triangle called a Marker. When we expand the Template, and overtype the selected area, we can then hit Esc and the caret will jump down to the indicated area and ‘collect’ the Marker.

    It’s worth noting that this basic (blue) marker will also disappear if the line it’s on is altered. If you’d like to produce one that does not disappear under these circumstances, than you should use the alternative «HardMarker» TextCommand. This type of Marker will only disappear if it is ‘collected’.

    Links

    The «Link» TextCommand is used in groups of 2 or more, to connect identical pieces of text to each other, and to keep them the same if one of them is edited.

    The classical example of this, is seen through the C# version of the c<space> template.

    The creators of C# took the decision that constructors should be named after classes they exist within. So if you create a C# class called MyVerySpecialClassWhichDoesSomethingVeryClever, then you have to use this (rather lengthy) name for any constructors that you create. The downside of this, is that you’ll have to do a lot more typing than if you were able to use a simple keyword for the same task.

    By using a couple of «Link» TextCommands, we can link the name of the class to that of the constructor, ensuring that the actual naming need only be done once.

    TemplateClassLink

    In this manner, the class name and the constructor name are linked together at the moment of expansion, and as one changes, so will the other.

     TemplateClassLinkExpanded

    A Link TextCommand links itself to all other Links that contain the same text. This allows the creator of the template, to link several pieces of text together.

    The user may also navigate between linked items through the use of either Tab or Shift+Tab.

    Check out this template for creating properties (of the non auto-implemented variety)

    TemplatePropertyMultipleLinks

    It links together 4 separate instances of the phrase “MyVariable”. When one is altered, all are altered. This enables the property, it’s underlying field and the 2 references to the field, to be renamed as a unit.

    TemplatePropertyMultipleLinksExpanded

    I think you’ll agree that this is very useful indeed.

    Other Types of Link

    The «Link» TextCommand accepts only characters that are valid in an identifier. ie alphanumeric characters or an underscore (‘_’).  If you wish to create links which allow additional characters within them, consider the use of either a «TypeLink» or a «TextLink».

    A «TypeLink» can accept any character which is deemed valid as a part of a Type, therefore it will also accept periods ('.'), commas (','), spaces, angle brackets ('<>') in C#, square brackets ('[]') in C# and parentheses ('()') in VB.

    Finally, the least restrictive of the link types is the «TextLink». If you require the user of your Template to be able to type characters not listed above, then you should consider using a «TextLink» TextCommand instead.

    So far we’ve shown Templates which highlight some of their emitted text, and allow the user to make amendments to it. Further we have shown how bits of text can be linked together so that alterations to one, will affect others.

    These links can be very useful, but what if we want the user to be able to make several such edits once the expansion of the template has occurred? Well you can place as many sets of links within a Template as you like, but your user will have to navigate between them on their own. By themselves, links provide no method for navigation to other link sets.

    However we do have fields….

    Fields

    Each «Field» TextCommand in a Template represents a distinct point of data entry. Upon expansion, the caret is deposited, in the first «Field» and as usual the user is free to modify the resulting text or indeed move elsewhere. If the user hits enter whilst the caret within a field, the field will be accepted, will disappear and the caret will jump to the next field.

    A simple example of the use of fields is the following template designed for creating auto-implemented properties.

    TemplateAutoPropertyGeneral

    The first field is positioned to allow the user to indicate the Type of the property. The second is to allow for the Name.

    TemplateAutoPropertyGeneralExpanded

    If the example given doesn’t seem so useful, consider the following custom Template, used in the creation of my own CodeRush plugins.

    TemplateNewActionPartialCS

    When expanded this Template provides the following output:

    TemplateNewActionPartialCSExpanded

    In this example we see a few techniques being used together. We have 3 fields, one of which is linked to 8 separate other locations via links. At this stage, you may or may not know much about plugin creation, but you can clearly see that there’s a whole lot of typing to be saved using this template. As for the previously unmentioned «FieldStart» and «FieldEnd», these are simply another form of the «Field» TextCommand.

    So why do we need another form of the «Field» TextCommand? Well it’s for times like the one demonstrated, when you need to wrap other TextCommands in a field. If you recall, TextCommands don’t return a result in the same way as StringProviders do, and the standard Field TextCommand requires a parameter. The «FieldStart» and «FieldEnd» TextCommands do not require such a parameter, instead acquiring the data they need from the text rendered between them.

    The last Template in this group is «FinalTarget». This TextCommand works within the context of a template already using 1 or more fields. It acts as the final field in a sequence. The difference being, that it is a point rather than a range and it requires no parameter. Use this TextCommand to indicate where the caret should jump to when all fields have been filled.

    And Finally

    The last 2 TextCommands I’d like to mention in this post are «AddAssemblyReference» and «AddNamespace». They perform pretty much as you’d expect, acting on the periphery of any function they supplement.

    «AddAssemblyReference» takes a single parameter which indicates the name of the reference to add. This results in no direct changes to the active TextDocument, but as you might imagine, the project to which it is attached receives a minor alteration adding a reference to the passed assembly.

    «AddNamespace» likewise takes a single parameter. This time indicating a single namespace which should be referenced by this file via an “Imports” or “Using” directive as appropriate. Said directive is added at the top of the file.

    ..and that about wraps it up for this post.

    We’ve covered the ins and outs of 13 separate TextCommands. That’s a little over 20% of the 61 TextCommands in my copy of CodeRush. As before this should be enough to get your feet wet, and also help you to understand a much larger quantity of the shipping templates that use them.

  • CodeRush – Common StringProviders

    StringProviders are little bits of dynamic that (Along with TextCommands and Aliases), can be injected into otherwise static Templates in order to increase their usefulness.

    Essentially they represent string returning functions, and like string functions they are unrestricted in the logic they can use to construct and return these strings. Examples include, but are not limited to, Environ vars, DateTime, Web services and even data from the file system.

    In this post, we’re going to show you a selection of those StringProviders available to you out of the box.

    To use any StringProvider in a template, simply add the text “«?MyStringProvider» to your template replacing “MyStringProvider” with the name of the provider you wish to use. If parameters are required, you should add brackets inside the » and place the params inside these.  Thus: “«?MyStringProvider(SomeParam)»

    Note: The « and » can be produced by holding down the ALT key and typing either 0171 or 0187 on your numeric keyboard.

    Simple StringProviders

    This first batch of StringProviders are very simple and emit strings exactly as their names suggest:

    StringProvider Outputs
    «?Date» The current date in short date format (i.e. 19/11/2010)
    «?DateLong» The current date in long date format (i.e. 19 November 2010)
    «?DateTimeNow» The current date in formatted as dd/MM/yyyy HH:mm:ss. (19/11/2010 15:25:55)
    «?UserName» The full username of the current user. i.e. Alpha-7\Rory.Becker
    «?Paste» The contents of the clipboard as a string.

    Some StringProviders draw information from the context in which they find themselves in.
    These next few StringProviders base their results on the active file.

    StringProvider Outputs
    «?FileBase» The base name of the active file without path or extension.
    «?FileDrive» The drive of the active file (ie ‘C:\’ )
    «?FileExtension» The extension of the active file (ie ‘.cs’)
    «?FileName» The name of the active file including the path.
    «?FilePath» The path of the active file.

    Parameters

    Some StringProviders can also take parameters:

    StringProvider Parameter Outputs
    «?DateTimeNow(Param)» A format String The current date formatted using the passed format
    «?FormatFieldName(Param)» The string to format The string formatted as a Field (based on CodeRush settings)
    «?FormatLocalName(Param)» The string to format The string formatted as a Local (based on CodeRush settings)
    «?FormatParamName(Param)» The string to format The string formatted as a Param (based on CodeRush settings)

    This can lead to some interesting combinations. You could use the «?Paste» StringProvider to sensibly feed 3 of the above StringProviders and thus avoid having to ask the user to indicate the  variable in question. Of course the clipboard might not contain anything sensible, but this can be checked for through the use of the “Editor\Clipboard\*” contexts.

    The User Guide

    In my current copy of CodeRush (The 10.2 RC), I count 90 StringProviders. This number may vary before full release, and there may be some in there which have been provided by 3rd party plugins.  In any case, I think you’ll agree that this should provide more than enough to be going on with.

    If you’d like to see a full list of StringProvider provided by your copy of CodeRush, you can do so by using our user guide. (Available via DevExpress\User Guide)

    UserGuide

    If you Type “String Providers” into the search bar at the top you will be taken to a page which provides a dynamically generated list of all StringProviders currently registered with the DXCore. Each should have an accompanying explanation of the string they’re expected to produce.

    UserGuideStringProviders

    Looking through this list, you should soon find yourself very comfortable with the wide array of available StringProviders.

    In a future tutorial, we’ll show you just how to create your own StringProvider, use it in a Template and even have it show up in the user guide.

  • Community Callout – Change Target Framework

    This week my attention was called to a plugin written by one of our community.

    Steven Rasmussen has recently updated his “Change Target Framework” plugin to support .NET 4.0

    You can find a link to Steven’s plugin in an XAF thread in our forums.

    After installation, you will find a couple of extra menu options on the project and solution context menus in the solution explorer.

    ChangeTargetFrameworkSolutionChangeTargetFrameworkProject

    After selecting one of these options you’ll be presented with a choice of frameworks to select from:

    ChangeTargetFrameworkSelection
    Note: This list allows you to pick any framework 2.0 through 4.0 and includes options for client profiles.

    Pick the framework you’d like to change to, and click Ok.

    After a few moments (depending on the size of your project/solution) your designated project(s) will have had their framework version altered, and will be ready to continue working with.

    And you’re all done. It’s that simple.

    Life has been made that little bit easier, thanks to Steven Rasmussen and CodeRush.

  • TechEd 2010 - Day 2

    Well what can I say? TechEd is an experience.

    The reason I didn’t blog about day 1 is because, frankly, I was exhausted.

    We were on the booth until after 9pm (The Expo hall closed at 8pm - People hung around to talk because a. (As Gary would say…) ”We’re awesome” and b. Our products rock .) People were just that enthused.

    The doors open and the delegates flood the place. At some points during the day, it feels like all 6500 of them decide to enter the expo hall at once.

    Meet the people

    It’s great to get out and meet our customers (and future customers) and interact with them on a personal level.  It’s so much easier to do a good job of evangelising a product when you can ask people what they’d like to see, or have explained. Without this personal level of interaction, you’re usually stuck with just guessing. Also the feedback loop is much tighter and you can customize what you’re saying specifically for their needs. More often than not, others will be listening in the background and when the first person leaves, the others jump in with questions. The only disadvantage is that you worry that you might be repeating yourself. This is fine if it’s to different people, but in the back of your mind, you’re wondering if you were talking to these people a few minutes/ hours ago, and did you already tell them this.

    What’s really great is the number of time I’ve been approached by people who needed no information at all, but just dropped by to tell us that we (DevExpress) rock. They comment on the controls, the IDE Tools and also on the support. At one point, I was in the middle of talking to attendee #1, explaining how you can use the support center for questions as well as bugs and suggestions, only to be “interrupted” (in the nicest possible sense) by attendee #2, so he could completely agree with my statements, and add that he thinks our support is some of the best he’s used.

    Our multitude of products

    I’ve spoken to people on WPF, WinForms, ASP.Net, Silverlight, a little bit of XAF/XPO (enough to indicate “You want Gary. He’s over there” Smile).

    I’ve even spoken to people about a little known product called CodeRush.

    It’s really only having attended something like TechEd, and being forced to think on my feet (which only added to my *cough* considerable preparation), that you realise just what an extraordinary breadth of good stuff we have. It’s great to be an evangelist for a product (or products) that you really believe in.

    CodeRush

    As you might expect, CodeRush goes over very well indeed. We’ve had one of our CodeRush videos playing in a loop almost constantly, and people almost can’t walk past it. Obviously people don’t grok everything all at once, but everyone seems to be able to point to pieces that they love, typically the piece(s) they can see immediate use for. Generally this is enough to pull them where they will ask for more info.

    Gary and I have also done a few CodeRush demos which have also been a good hook for further conversation. Typically we only need to point to one or more of our Refactorings, Code Generation (Consume First Code Providers / Templates) and Navigation / Analysis (Quick Navigation, TabToNextReference and References Toolwindow) features and you can see people eyes just light up.

    TechEd Rocks

    All in all, it’s been a great (if a little manic in a fun sort of way) couple of days so far, and I have no real reason to think the next few days will differ.

    If you’re here at TechEd swing the DevExpress booth and say hello. We’ll be happy to demo any products, and we have T-shirts too!

  • CodeRush Templates – Creation Basics

    Even the simplest of CodeRush Templates (one without any TextCommands or StringProviders) can be really useful. Such a template expands exactly the same every time it’s used.

    In this post we’re going to create one such simple template.

    Our scenario is one in which you are building a web page and you’d like to quickly generate some simple but authentic looking text to flesh the page out with.

    This scenario is typically dealt with using lorem ipsum text. This text is typically generated by a computer to the specification of a user. It has similar flow to most Latin based languages and makes for realistic looking content, when mocking out a page.

    We’re going to make a template which delivers the same paragraph of Lorem Ipsum each time it’s invoked. You’ll be able to type “lorem<space>” and have it expand to the pre-calculated piece of text.

    So let’s not hold back any more… let’s get on with it.

    Which language?

    • Open up the Templates options page and change the language dropdown to HTML (Details here).

    We’re doing this because it’s rarely useful to inject quantities of “lorem Ipsum” text into VB or C# code. Instead we restrict the template to only expand into files understood to contain html.

    Create a Custom folder

    • Right click in the template tree and choose “New Root Category”
    • Name the Folder “Custom”

    TemplateTreeContextMenuWe always recommend creating your new templates within a top-level folder of your own (typically called ‘Custom’). The main reason for doing this is for organisational purposes. By placing your templates under a single top level folder, you can export them as a group.

    This can ease processes like backing up or sharing the templates and it’s why, in my screencasts, you’ll often see a Custom folder in my templates tree that does not ship with CodeRush.

    Create a new blank template

    • Right click the “Custom” folder and choose “New Template” (you can also use the NewTemplateIcon icon above the template tree.)
    • Type “lorem” (without the quotes") and hit ok

    NewTemplateLorem

    Add the detail

    As with all pure literal templates, the expansion for this one is very simple indeed. I generated the following paragraph of lorem ipsum text using http://www.lipsum.com/

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas blandit sapien sed metus porttitor convallis. Aenean eget tortor arcu, sollicitudin tincidunt lectus. Donec eget justo lorem, ut tempor nulla. Nulla facilisi. Nulla a urna sed nulla ultricies sollicitudin vitae a lacus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi turpis nunc, hendrerit at pretium nec, vulputate nec velit. Nullam facilisis, erat scelerisque fermentum consequat, lectus dui pretium sem, a hendrerit massa erat eu mi. Integer dignissim est eget libero auctor accumsan.’

    Copy this text to the clipboard and paste it into the expansion box

    ExpansionLorum

    You should now have…

    • a folder called ‘Custom’
    • a new template called ‘lorem’ who’s expansion contains some lorem ipsum text.

    That’s about all there is to it.  Hit the ok button and let’s test it…

    Open or create a new html page, locate a reasonable spot and type ‘lorem<space>’

    You should find that CodeRush immediately fills the space your caret was located, with a single paragraph of lorem ipsum text.

    Typically you’d create the basic structure of your web page. (Typically DIV tags with CSS, although there are some who still use tables.) Once this basic structure is laid out, you can fill each piece with some lorem ipsum and this will make your structure seem that much firmer/

    I’ll be the first to admit that this template isn’t the most awe-inspiring thing in the world, but it could definitely save you a whole bunch of typing or failing that, it would at least save you from navigating to a lorem ipsum generator and then cutting and pasting back to your html file.

    Next time we’ll show you how to use some StringProviders and TextCommands

  • CodeRush Templates - The ‘Templates’ options page.

    Having established in previous posts that CodeRush Templates absolutely rock, we’re going to move on and start to show you how to create and modify your own templates.

    We’ll start slowly though, and just show you around for now. Template editing is done via the Templates options page:

    TemplatesOptionsPageCSharp

    This screen is reached through the DevExpress \ Options menu or by pressing Ctrl+Shift+Alt+O. once on this screen you should use the page tree to navigate to the Editor\Templates page.

    OptionsScreenCollapseSplitterWhen creating or editing a template, it’s useful to give yourself as much space as possible. To this end, I recommend collapsing the page tree and maximizing the options screen. The page tree is collapsed by clicking the border on it’s right. As you hover over this border, it lights up with a series of blue arrows, helping to indicate that this isn’t your typical splitter.  These techniques will of course work on any of the option pages.

    Great stuff. Ok now let’s show you around.

    OptionsPageTemplatesCSharp

    TemplateCategoriesThe Template Tree
    On the left of your screen is a tree of Templates. The templates in this tree are grouped in folders and subfolders, which help to make locating templates a little easier. Folders of templates may also be enabled or disabled by removing the tick mark beside the folder in question.

    Even a short glance at the template tree, will tell you that it holds a lot of templates. These are organised in a large hierarchy of folders and subfolders. However even this is not the full list of templates. Your view is being filtered at all times by the value in the language dropdown.

    CodeRush provides  templates out of the box for C#, VB.Net, C++, JavaScript, HTML, XAML and XML. However if your favourite language isn’t listed there, don’t worry. CodeRush will happily support the creation of templates for any language service installed with studio. Out of the box these include VB.Net, C#, C++, F#, CSS, JavaScript, HTML, T-SQL, XML, XAML and Plain Text, but additional services are often added by third party vendors and CodeRush will happily work with any of these.

    Don’t be concerned if you have less entries than this in you list of languages. CodeRush doesn’t add them until it sees that you are actually going to work with file of the type in question. This saves presenting more options than you will practically use.

    In addition to the previously listed language entries, you will see an additional item labelled *neutral*.  Templates contained within the *neutral* category will expand within any document rather than restricting themselves to a single document type. It is therefore important that care be taken when creating templates in this section, lest you unintentionally create a template which causes unintended side effects within document types you didn’t mean to.

    The Template Tree Context MenuTemplateTreeContextMenu

    Right clicking an item (folder or template) in the template tree, will yield this context menu. From here you can see a number of functions including the creation of new folders and templates as well as the import and export of templates. Importing and Exporting will be covered in a future post. Suffice to say that this can be useful when either sharing templates or when upgrading to a fresh set of templates.

    The Expansion Box
    This sits near the top of the screen. The text in this box represents the instructions that will be followed when CodeRush expands your template. Most text entered is interpreted literally, however there are 3 special types of command you can enter into this box. Aliases, StringProviders and TextCommands.

    • Aliases are used to inject another template into the current expansion and take the form «:TemplateName».
    • StringProviders are used to inject calculated strings into the template and take the form «?StringProviderName(Params)»  examples include «?Username», «?Paste» and «?Member»
    • TextCommands are used to cause other secondary side effects within the TextDocument (The DXCore representation of text file) associated with the current operation, and take the form «TextCommandName(Parameters)».  Good examples of Simple TextCommands are «Marker», «BlockAnchor» and «Caret»

    TemplateExpansionBoxCSharpBlock

    You can enter your template expansions directly into this box using nothing more than your keyboard, but if you’d like a little help, you can use some of the tools provided in the panel underneath the expansion box. TemplateTextCommandOptionsThis panel provides quick access to some of the more commonly used StringProviders and TextCommands.  From left to right the icons represent…the «?Paste» StringProvider and the «Caret», «BlockAnchor» and «DropMarker» TextCommands. Other TextCommands are available through the drop down list. In addition, the full range of StringProviders, TextCommands and Aliases is available through the context (Right Click) menu of the expansion box, along with the usual clipboard related items.TemplateExpansionContextMenu

    The Context Panel
    This panel provides a tree of contexts supported by CodeRush. A context is a condition which may either be true or false. For example Editor \ Code \ InClass or Editor \ Code \ InComment are 2 conditions relating to the location of the caret within the active document. The template expansion engine will evaluate these based on the configuration of each of their checkboxes. A tick indicates TemplatesContextTreethat the condition is required to be true, while a cross indicates that the condition must be explicitly false. An empty (default) checkbox indicates that the template does not care about the state of this condition and it will not be evaluated at expansion time.

    Many CodeRush features use contexts to allow them to be more specific about when they should operate. In the case of templates, the contexts dictate preconditions which must be held true in order for the template to expand. So for example if you want your template to only expand if the caret is not within a comment, then you should set a cross against the Editor \ Code \ InComment.

    TriggerTemplateWith

    Template triggering.

    This next panel allows you to specify how your template is triggered. By default all templates are triggered by the Primary expansion key (<Space>). However you can alter a template’s settings so that it is instead triggered by the secondary expansion key (<Shift>+<Space>). This 2-key shortcut is not typically used during coding, therefore it follows that a more deliberate act is required in order to trigger a template which requires this trigger.

    These settings can be used to ensure that certain templates are not expanded without the user making a very conscious effort to do so. Some consider this an effective way to disable individual templates from expanding.

    ….and that concludes our introduction to the Templates options page.

    Next time we’re going to create a brand new template from scratch. 

  • 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.

  • CodeRush Plugins – Plugin Components

    So you’ve created your base plugin project.

    Now you’ll need to decide on which components are necessary to implement the functionality you’re after.

    In order to do that, you’ll need at least a brief overview of some of the more common components and what they are used for.

    In a nutshell these components are: Action, StringProvider, TextCommand, RefactoringProvider, CodeProvider, IssueProvider and MetricProvider.

    iconActionAction
    The simplest of plugin component: Actions wrap managed code which can then be bound to either mouse or keyboard shortcuts by the end user/developer. Actions can also be rendered as menu options on any of the standard Studio menus.

    iconStringProviderStringProvider
    Used within Templates, Selection Embedding and similar features, StringProviders return strings to the features which they are placed within. The string in question can be sourced from anywhere: Settings, Envrionment, DateTime, the Clipboard or even a Web Service. Built-in examples include «?Username», «?FieldPrefix», «?DayOfWeek», «?Paste» and «?SolutionName».

    iconTextCommandTextCommand
    TextCommands, like StringProviders, are used in higher level features to provide blocks of functionality to those features. They may be considered ‘Void Proc’ versions of the StringProviders, in that they are unable to return any value to said calling function. Instead they provide functionality via the current TextDocument (Internal representation of the current text file) which they can both access and affect. Examples of shipping TextCommands include: «Caret», «BlockAnchor», «AddAssemblyReference» and «Marker».

    iconRefactoringProviderRefactoringProvider
    This component is used to add items to the Refactor menu within the CodeRush SmartTag. The RefactoringProvider provides events both for determining if your refactoring is suitable based on the current circumstances, and also for applying the refactoring itself when it is chosen. The RefactoringProvider should be used when providing a true refactoring to the end user. ie When the operation is required to not change the functionality of the code being acted upon.

    iconCodeProviderCodeProvider
    The CodeProvider compliments the RefactoringProvider and is use to add items to the Code menu within the CodeRush SmartTag. The CodeProvider should be used instead of a RefactoringProvider when the operation is required to change the functionality of the code being acted upon. Examples of CodeProviders include the ‘Declare X’ range of items of the Code menu, used to declare things like variables, enums and classes based on examples of their usage.

    iconIssueProviderIssueProvider
    Used to define your own Code Issues (inline hints, warnings and errors) which will then be presented within the environment. This component can be combined with either the CodeProvider or RefactoringProvider in order to provide a method of fixing the raised CodeIssue. Some good examples of using this component can be found in the CR_StyleNinja community plugin.

    iconCodeMetricProviderMetricProvider
    This component allows you to provide an algorithm, which produces a numeric value based on a code element (usually a member of a type). Said value is then shown inline in the editor or within the Metrics Toolwindow. Examples of existing metrics shipping with CodeRush include the ‘Line Count’, ‘Cyclomatic Complexity’ and ‘Maintenance Complexity’.

    This list is by no means definitive, but is intended only to represent the most commonly used components.

    It should be noted that your plugin can have many of these components on it’s design surface, and is not limited to just one or indeed even just one type. Your plugin might ultimately make use of 2 Actions, 3 RefactoringProviders and a MetricProvider. However, for the purposes of these first few examples, we’ll be concentrating on just one component at a time.

    In the coming posts I’ll be explaining these components in much greater detail. I’ll cover the specific use of each, and couple that with a complete example. Soon you’ll creating your own plugins to achieve all manner of clever things.

    The steps here are common to all plugins, and I’ll be referring back to them from each of my plugin examples.

    Next up we’ll create our first complete plugin – “DX_HelloWorld”

  • Starting a CodeRush Plugin Project

    This post is for primarily for reference. In it we are going to demonstrate the first steps for creating a DXCore plugin. These steps should remain the same for any plugin you choose to create, and therefore it makes sense to separate them into a common post which can be referenced in the future.

    There are 2 ways to create a DXCore plugin project

    Firstly you might create it via the standard “New Project” dialog.

    Choose File \ New \ Project … then … [Language] \ DXCore \ Standard Plug-in.

    NewProjectDialog-DXCorePlugin

    Alternatively chose DevExpress \ New Plugin

    NewDXCorePluginProject

    In either case you’ll arrive at this dialog:

    DXCoreProjectPluginSettings

    From here you’ll mostly be able to just leave the defaults. In case you’re interested the differences are:

    • System plugins are loaded a stage earlier in the initialization process than other plugins.
    • Load Manually causes the DXCore to ignore your plugin until such time as you explicitly ask for it to be loaded.
    • Alternatives to ‘On Demand’ are ‘On Idle’ and ‘At Start-up’.

    Once your choices are made here, VS will construct your initial DXCore Plugin project and show you it’s design surface.

    DXCoreDesignSurface

    From here, your next step will be to place some DXCore components on this design surface, fill out some properties and handle some events.

    We’ll stop here for now, and pick up next time with an introduction of some of the more common DXCore components.

3 4 5 6 7 8 9
10
11 12
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners