Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

How do I add a point to the navigation history? (For navigate forward/back)

$
0
0

Say I'm implementing a service in a VSIX extension that, when a command is triggered, moves the cursor to a different location (like Go to Definition does).

I'd like to add a point to the navigation history so that if the user decides they want to go back to where they were before they triggered the command, they can do so via View→Navigate Backward (Ctrl -).

So far, I've figured out a way that involves adding one temporary point via IVsUIShell.AddNewBFNavigationItem, then adding another via IVsBackForwardNavigation2 (which seems to only work if AddNewBFNavigationItem was called first), then removing the temporary point. This feels like a hack, and I can't help but wonder if this code will break in future versions of Visual Studio (I'm developing for VS2013, by the way). Is there a better way than this brittle code?

private static void AddNavigationHistoryPoint(IVsWindowFrame frame)
{
    object navServiceObj;
    if (frame.GetProperty((int)__VSFPROPID4.VSFPROPID_NavigationInterface, out navServiceObj) == VSConstants.S_OK)
    {
        var navService = navServiceObj as IVsBackForwardNavigation2;
        if (navService != null && UiShell != null)
        {
            if (UiShell.AddNewBFNavigationItem(frame, "", null, 0) == VSConstants.S_OK)
            {
                navService.RequestAddNavigationItem(frame);
                UiShell.RemoveAdjacentBFNavigationItem(RemoveBFDirection.RemovePrev);
            }
        }
    }
}




Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>