Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting cursor position with Visual Studio Extension
    primarykey
    data
    text
    <p>I'm writing my own Visual Studio 2010 Extension that should help me navigating a rather large solution.<br> I already have a dialog based VS Extension that shows me a class name and a function name depending on some search criteria. I now can click this class/method and I then already can open the correct file and jump to the function.<br> What I now want to do is to set the cursor at the start of that function.<br> My code to jump to the function is:</p> <pre><code>Solution currentSolution = ((EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0")).Solution; ProjectItem requestedItem = GetRequestedProjectItemToOpen(currentSolution.Projects, "fileToBeOpened"); if (requestedItem != null) { // open the document Window window = requestedItem.Open(Constants.vsViewKindCode); window.Activate(); // search for the function to be opened foreach (CodeElement codeElement in requestedItem.FileCodeModel.CodeElements) { // get the namespace elements if (codeElement.Kind == vsCMElement.vsCMElementNamespace) { foreach (CodeElement namespaceElement in codeElement.Children) { // get the class elements if (namespaceElement.Kind == vsCMElement.vsCMElementClass) { foreach (CodeElement classElement in namespaceElement.Children) { try { // get the function elements if (classElement.Kind == vsCMElement.vsCMElementFunction) { if (classElement.Name.Equals("functionToBeOpened", StringComparison.Ordinal)) { classElement.StartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop, null); this.Close(); } } } catch { } } } } } } } </code></pre> <p>The important points here are <code>window.Activate();</code> to open the correct file and <code>classElement.StartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop, null);</code> to jump to the correct function.<br> Unfortunately the cursor is not set to the start of the requested function. How can I do this? I'm thinking of something like <code>classElement.StartPoint.SetCursor()</code>.<br> Cheers Simon</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload