Blogs

Rory Becker - DevExpress CodeRush Blog

CodeRush - Navigational TextCommands

     

Navigational TextCommands are those which pertain to the movement of the current text insertion point. The insertion point is the point at which text will be emitted during the execution of a template or other TextDocument manipulation.

Some example Navigational TextCommands are «GotoFileTop» and «GotoFileBottom» which, as you might guess, move the insertion point to the top and bottom of the current file respectively.

But what if you want to jump to one of these locations, emit some text and the jump back to where you started?

Well this has also been thought of.

The «StoreInsertionPoint» and «GotoInsertionPoint» TextCommands are for exactly this purpose. The «StoreInsertionPoint» will store the current location of the insertion point, using a lookup key passed to the command as its first parameter. The «GotoInsertionPoint» will retrieve a previously stored location likewise using a lookup key passed to it as a first parameter.

Consider the following template:
-------------------------------------------------------------
«StoreInsertionPoint(Origin)»«GotoFileTop»using System.Data;
«GotoInsertionPoint(Origin)»DataSet MyDataSet;
-------------------------------------------------------------

It performs the following steps:

  • Store the current location of the insertion point in a variable called Origin
  • Move the insertion point to the top of the current file.
  • Emit using System.Data; followed by a newline
  • Move the insertion point back to the location previously stored.
  • Emit DataSet MyDataSet; followed by another newline

As you can see, this places the using statement at the top of the file, whilst emitting the new DataSet variable at the point the user invoked the template.

Navigational TextCommands are certainly a powerful concept. We’ll be providing more of these commands in the future and also showing you how you can create your own.

Published Jun 01 2011, 09:50 AM by Rory Becker - DevExpress
Technorati tags: TextCommands, Navigation, DXCore
Bookmark and Share

Comments

No Comments
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.