Last updated on July 19th, 2010
Feature Peek 2011 will consist of a series of blogs that will provide a sneak peek of new features which will appear in the 2011 edition of PrimalScript Studio products.
In this blog we will provide you with a sneak peek at the new Snippet Editor tool for PrimalScript 2011 and Visual PowerShell 2011.
(Fig 1: The Snippet Editor Application)
For those of you who are not familiar with snippets, they are small pieces of reusable code that can be quickly inserted in your script while editing. This piece or snippet of code can come in a various forms, such as, a full fledged function or a simple single line statement. Snippets can also come in various languages such VBScript, PowerShell, C#, etc.
The Snippet Editor tool allows users to quickly create or edit snippets. These snippets are Microsoft Visual Studio compatible; therefore, you can painlessly import your existing snippets into PrimalScript 2011 and Visual PowerShell 2011.
The example below demonstrates how to create and edit a snippet that consists of a simple header using Visual PowerShell 2011. Simply start by selecting the part of the script you wish to convert into a snippet and use the “Create Snippet…” context menu option.
(Fig 2: Context menu option “Create Snippet…”)
The Snippet Editor will open preloaded with the selected script and appropriate language setting. Next add a description and edit the snippet’s title to fit your needs.
(Fig 3: Snippet Editor with prefilled script)
The header in this example is ready but the snippet will not be useful to others if it contains the same user and company name. This problem is resolved by creating substitute variables that allow users to quickly change the user name and company name when they insert the snippet.
(Fig 4: Context Menu option “Add Variable”)
In the editor simply select the section of text you want to convert into a variable and click on the “Add Variable” option in the context menu. The new variable will then appear on the Variables Panel. Then you have the option to rename new variable.
(Fig 5: Variables Panel)
In the Variable Details Panel you can add a default value to these variables and provide Tooltip text.
(Fig 6: Variable Details Panel)
Now save the snippet and it is ready to use:
(Fig 7: Inserted Snippet with highlighted variables and tooltip)
As you can see the new Snippet Editor makes it fast and easy to create your own custom snippets.