none
Add a code snippet as a new Menu command

    Question

  • Hi, I created a new Refactoring snippet (well I used Encapsulate field as a starting point, and changed the body as I needed). I saved the new file in the same location (C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Snippets\1033\Refactoring). So it appears in Snippet Manager.

    Now I want to add this new refactoring snippet to edit window context menu. I tried adding it via Tools->Customize->Command->Context menu->Editor Context Menu | Code Window | Refactor. But when I click on Add Command, I don't see the new snippet anywhere!! How to get a new snippet added as a new command under a menu or toolbox?


    Regards, Adarsha

    Wednesday, February 20, 2013 6:11 AM

All replies

  • The only commands you can link to are those defined by extensions.  Snippets are accessed via the Intellisense context menu based upon the user keystrokes so you don't have to add anything to get them to appear.  Note that you can associate a keystroke with the refactoring snippet.

    Michael Taylor - 2/20/2013
    http://msmvps.com/blogs/p3net

    Wednesday, February 20, 2013 1:55 PM
    Moderator
  •  Note that you can associate a keystroke with the refactoring snippet.


    How do I do that? Even Options - > Environment - > Keyboard also expects the command to be in a Menu item in order to associate a keyboard shortcut.

    Regards, Adarsha

    Thursday, February 21, 2013 4:45 AM
  • Hi mvadu,

    I’m afraid that it is not the correct forum about this issue, you can consider try below forum for this issue.

    Visual Studio Extensibility

    http://social.msdn.microsoft.com/forums/en-US/vsx/threads/

    Thanks.


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, February 22, 2013 5:11 AM
    Moderator
  • I don't think so. I am talking about code snippets, and not about Visual Studio Extensions. Code snippets are standard features of Visual Studio. I am just asking a question about how to assign a keyboard shortcut to a code snippet.

    Regards, Adarsha

    Friday, February 22, 2013 5:17 AM
  • Hi mvadu,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 22, 2013 6:17 AM
    Moderator
  • You add a shortcut element to the snippet file - http://msdn.microsoft.com/en-us/library/ms171440(v=vs.100).aspx.  Shortcuts show up in Intellisense so if you defined a shortcut of 'Tester' and then started typing 'Te' then 'Tester' would appear in the list.  Selecting it and pressing TAB causes it to expand.

    Michael Taylor - 2/22/2013
    http://msmvps.com/blogs/p3net

    Friday, February 22, 2013 2:59 PM
    Moderator