Join  |  Sign in
Custom Snippets

21-Oct-2017 10:18 PM

TK

TK

Posts: 2

Hi,

Maybe because I am new, but I have no idea how to add own snippets. I would like to my own snippet when I use Ctrl K + X.


  Reply

23-Oct-2017 11:28 PM

Andrew Medvedev

Andrew Medvedev

Posts: 49

Hi,

You can hanlde NeedCodeCompletion event and assign own snippets :

private void SyntaxEdit1_NeedCodeCompletion(object sender, Alternet.Syntax.CodeCompletionArgs e)
        {
            if (e.CompletionType == Alternet.Syntax.CodeCompletionType.CodeSnippets)
            {
                var provider = new Alternet.Syntax.CodeCompletion.CodeSnippets();
                var snippet = provider.AddSnippet();
                snippet.Header.Description = "test test";
                snippet.Header.Title = "test";
                snippet.Code.Code = "class test {}";
                e.Provider = provider;
                e.ToolTip = false;
                e.CompletionType = Alternet.Syntax.CodeCompletionType.None;
                e.NeedShow = true;
            }
        }

Alternately you can derive own class from one of the SyntaxParser  and override CodeSnippets property and write similar code there.
Snippets can also be loaded from xml/resource.
Please have a look at the CustomSnippets demo:
http://www.alternetsoft.com/projects/CustomSnippets.zip

regards,
Andrew
  Reply

29-Oct-2017 07:00 PM

TK

TK

Posts: 2

Thank you Andrew. Works very well like this.

Torsten

  Reply