Manipulating CodeSnippetLiteral programmatically

SyntaxEditor for Windows Forms Forum

Posted 3 years ago by Muhammad Mujtaba
Version: 20.1
Avatar

Consider the code snippet declaration of SQL Select statement,

public CodeSnippet SelectColumn(){
//Select * from <TableName>
   var snippet = new CodeSnippet(){
      Title = "SELECT",
      Tag = "SELECT",
      Shortcut= "SELECT"
   };
   snippet.CodeText = "SELECT * FROM $<TableName>$";
   snippet.Declarations.Add(new CodeSnippetLiteralDeclaration() { Id = "<TableName>", DefaultText = "<TableName>" });
   return snippet;
}
According to my usecase the user would have selected the TableName from UI Control (a dropdown) and generate the code snippet for that particular table but currently I can not acheive this behaviour.
Is there a way where I can replace the CodeSnippetLiteral with a value programmatically?
 
 
Similarly, In SQL select a user can select multiple columns depending upon his use, Consider the example below.
for eg Select Name,ID,Phone from TableName;

I dont know how many Columns the user would type, therefore I cant hardcode Literal in the CodeText and also can't declare these literals in the snippet.
Is there a way to achive this behaviour where the user can enter as many column as he want until he presses tab twice to reach TableName Literal?  

[Modified 3 years ago]

Comments (1)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

For the next releases of our WPF and WinForms SyntaxEditor, we are adding a ICodeSnippetTemplateSessionEventSink.NotifySessionOpening callback that would let you programmatically set the default text value of literals.  Please see the linked thread for details on that.  Will that accomplish what you need for the first question?

Unfortunately there isn't a way to let the user decide how many literals to support.  The literals have to be declared before the code snippet template session begins.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.