locked
Is it possible to manipulate code editor via VSPackage? RRS feed

  • Question

  • Hi all,

    I'm a newbie for VS SDK. I want to accomplish below tasks:

    1. Create a custom command in VS 2010.

    2. When user create a html file in VS 2010, the command will display.

    3. When user click the command, a pre-defined html text will fill into the code editoer.

    4. When user save the text in the code editor, my code need to detect it and do some operations.

    Is it possible to finish these tasks via VSPackage?

    Saturday, September 4, 2010 4:29 AM

Answers

  • Hi Malone,

     

    Thanks for your post.

    I think you can do it as the following steps:

    1-2. You need a VSPackage to provide command, since you expect the command hide/show some time, please check

    Part 1 – Using UI Contexts

    Part 2 – The BeforeQueryStatus Event

    Part 3 – Custom UI Contexts

    The "Part3" tells how to make a command appear when editing a html file and disappear in other time, and the former two parts indicates some preparation.

    3. When you create a html file, the cursor is at the very beginning, and please try the line

    TextReader tReader = New StreamReader(New FileStream(<path of the file with code you like to insert>, FileMode.Open, FileAccess.ReadWrite))

    DTE.ActiveDocument.Selection.Text = tReader.ReadToEnd()

    4. To detect when document saved, you can try the event DocumentSaved Event, which can help do some operations when it saved.

    If you have further questions, be free to let me know.

     

     

    Best Regards,

    Ziwei Chen

    • Marked as answer by Victor_Chen Monday, September 13, 2010 1:31 AM
    Thursday, September 9, 2010 3:20 AM

All replies

  • Hi Malone,

     

    Thanks for your posting. We are following up with development teams and will get back to you soon.

     

    Best Regards,

    Ziwei Chen

     

    Tuesday, September 7, 2010 3:48 AM
  • Hi Malone,

     

    Thanks for your post.

    I think you can do it as the following steps:

    1-2. You need a VSPackage to provide command, since you expect the command hide/show some time, please check

    Part 1 – Using UI Contexts

    Part 2 – The BeforeQueryStatus Event

    Part 3 – Custom UI Contexts

    The "Part3" tells how to make a command appear when editing a html file and disappear in other time, and the former two parts indicates some preparation.

    3. When you create a html file, the cursor is at the very beginning, and please try the line

    TextReader tReader = New StreamReader(New FileStream(<path of the file with code you like to insert>, FileMode.Open, FileAccess.ReadWrite))

    DTE.ActiveDocument.Selection.Text = tReader.ReadToEnd()

    4. To detect when document saved, you can try the event DocumentSaved Event, which can help do some operations when it saved.

    If you have further questions, be free to let me know.

     

     

    Best Regards,

    Ziwei Chen

    • Marked as answer by Victor_Chen Monday, September 13, 2010 1:31 AM
    Thursday, September 9, 2010 3:20 AM
  • Hi Victor,

    Thanks for your reply. It's really helpful for my development.

    I got one additional question: How to subscribe the "DocumentSaved Event"? Could you please give me some sample code? Thanks again!

    Wednesday, September 22, 2010 4:48 AM