locked
Create named bookmark which persist in .suo file RRS feed

  • Question

  • Hello everyone,
    I'm working on a plug-in which provides easy navigation to some code lines within VS, and the lines I have firstly identified may be invalidated by user updates to the code, (ex. I firstly have line number 3 of HelloWorld class and user inserts two more line before line 3 making my interested line #5). So I'm planning to address this by navigating to the code location through bookmarks (which monitors user line inserts updates) so that navigation works fine even after user edits.
    The problem I have now is creating proper bookmarks. I tried using textSelection.SetBookmark(); but this only creates the bookmark in the buffer so it's not maintained in the .suo user file and it doesn't work when file is not already open to navigate.
    How can I create books marks to appear in Bookmarks window(View->Other Windows->Bookmark Window) melodramatically, with filename and line number(preferably with a name too), and use it later to navigate to code location ?

    Thanks,
    Chathuranga
    Saturday, February 27, 2010 6:32 PM

Answers

  • Hello,

    Try  use textSelection.SetBookmark. 

    Dim ts1 As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)

            ts1.SetBookmark()


    If we want to add it to book mark window, we must ensure that the BookMark window open first, Please make our BookMark window open first. Please use  DTE.ExecuteCommand("View.BookmarkWindow") to add the Book Mark window.

    This should do the trick!

    Thansk
    Chao

    • Marked as answer by Chao Kuo Friday, April 23, 2010 6:57 AM
    Friday, April 23, 2010 6:57 AM

All replies

  • Hello, Chathuranga

    As far as invested, we could not do this.

    Both of textSelection.SetBookmark() and IVsTextLines.CreateLineMarker are just to add Mark to the editor for a region, and it doesn’t add the bookmark information to the Bookmark window, so it could not persist in .suo file

    Actually to add an item to the Bookmark window, we need to know some interfaces exposed by Bookmark window like we could in output window, but unfortunately, there are no document could tell us how to do this.

    Thanks

    Chao

    • Proposed as answer by Chao Kuo Friday, March 5, 2010 5:54 AM
    • Marked as answer by Chao Kuo Friday, March 5, 2010 9:21 AM
    • Unmarked as answer by Chao Kuo Friday, April 23, 2010 6:57 AM
    • Marked as answer by Chao Kuo Friday, April 23, 2010 6:57 AM
    • Unmarked as answer by Chao Kuo Friday, April 23, 2010 7:00 AM
    • Unproposed as answer by Chao Kuo Friday, April 23, 2010 7:04 AM
    Friday, March 5, 2010 5:54 AM
  • Hello,

    Try  use textSelection.SetBookmark. 

    Dim ts1 As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)

            ts1.SetBookmark()


    If we want to add it to book mark window, we must ensure that the BookMark window open first, Please make our BookMark window open first. Please use  DTE.ExecuteCommand("View.BookmarkWindow") to add the Book Mark window.

    This should do the trick!

    Thansk
    Chao

    • Marked as answer by Chao Kuo Friday, April 23, 2010 6:57 AM
    Friday, April 23, 2010 6:57 AM
  • Is there a way to have it name each bookmark with the selected text?
    Tuesday, January 4, 2011 10:07 PM