I'm using this bit of code (as seen from here) in an Extension I'm building:
IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
if (openDoc == null) {
return;
}
IVsWindowFrame frame;
Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
IVsUIHierarchy hier;
uint itemid;
Guid logicalView = VSConstants.LOGVIEWID_Code;
if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null) {
return;
}
object docData;
frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);
// Get the VsTextBuffer
VsTextBuffer buffer = docData as VsTextBuffer;
if (buffer == null) {
IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
if (bufferProvider != null) {
IVsTextLines lines;
ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
buffer = lines as VsTextBuffer;
Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
if (buffer == null) {
return;
}
}
}
// Finally, perform the navigation.
IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager;
if (mgr == null) {
return;
}
mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column);
Which (according to the post), should open my document, if not already, and focus the document, placing the cursor at the given position. While that all works, the thing that doesn't seem to work, is the focusing of the document, my ToolWindow still has the active focus (i.e. Yellow highlighted headbar), I tried putting this line after the NavigateToLineAndColumn
, to see if it does what I'd expect, but still no dice:
frame.Show()
Which according to MSDN
Renders this window visible, brings the window to the top, and activates the window.
What do I need to do more, to make this give active focus to the opened document?