locked
Hosting VS 2010 core editor in a WPF user control RRS feed

  • Question

  • We have a babel language service extension to the VS core editor to provide coloring, syntax, etc.  This package works fine in VS2010 as a separate editor loaded via file extension (scr).  THis project was ported from VS 2005 and was based on the MPEdit code sample.

    We also use this language service extended editor in a control window in a custom editor, file extension (fld).  This was working in VS2005, but is no longer working in VS2010.  The call to CreatePaneWindow produces an empty blue screen.

    Our legacy code includes the following function that is used to create the code window (_editor is the EditorPane object)

            private void CreateVsCodeWindow()

            {

                int hr = VSConstants.S_OK;

                Guid clsidVsCodeWindow = typeof(VsCodeWindowClass).GUID;

                Guid iidVsCodeWindow = typeof(IVsCodeWindow).GUID;

                Guid clsidVsTextBuffer = typeof(VsTextBufferClass).GUID;

                Guid iidVsTextLines = typeof(IVsTextLines).GUID;

     

                // create/site a VsTextBuffer object

                IVsTextBuffer vsTextBuffer = (IVsTextBuffer)VSPackage.Instance.CreateInstance(ref clsidVsTextBuffer, ref iidVsTextLines, typeof(IVsTextBuffer));

                IObjectWithSite ows = (IObjectWithSite)vsTextBuffer;

                ows.SetSite(_editor);

                hr = vsTextBuffer.SetLanguageServiceID(ref GuidList.guidCRYLangSvc);

               

                vsTextLines = (IVsTextLines)vsTextBuffer;

               

                // create/initialize/site a VsCodeWindow object

                _vsCodeWindow = (IVsCodeWindow)VSPackage.Instance.CreateInstance(ref clsidVsCodeWindow, ref iidVsCodeWindow, typeof(IVsCodeWindow));

     

                INITVIEW[] initView = new INITVIEW[1];

                initView[0].fSelectionMargin = 0;

                initView[0].fWidgetMargin = 0;

                initView[0].fVirtualSpace = 0;

                initView[0].fDragDropMove = 1;

                initView[0].fVirtualSpace = 0;

               

                IVsCodeWindowEx vsCodeWindowEx = (IVsCodeWindowEx)_vsCodeWindow;

                hr = vsCodeWindowEx.Initialize((uint)_codewindowbehaviorflags.CWB_DISABLEDROPDOWNBAR,

                    0, null, null,

                    (uint)TextViewInitFlags.VIF_SET_WIDGET_MARGIN |

                    (uint)TextViewInitFlags.VIF_SET_SELECTION_MARGIN |

                    (uint)TextViewInitFlags.VIF_SET_VIRTUAL_SPACE |

                    (uint)TextViewInitFlags.VIF_SET_DRAGDROPMOVE, //|

                    initView);

     

                hr = _vsCodeWindow.SetBuffer((IVsTextLines)vsTextBuffer);

                IVsWindowPane vsWindowPane = (IVsWindowPane)_vsCodeWindow;

                hr = vsWindowPane.SetSite(_editor);

                hr = vsWindowPane.CreatePaneWindow(this.Handle, 0, 0, this.Parent.Size.Width, this.Parent.Size.Height, out _hWndCodeWindow);

     

                IVsTextView vsTextView;

                hr = _vsCodeWindow.GetPrimaryView(out vsTextView);

               

                // sink IVsTextViewEvents, so we can determine when a VsCodeWindow object actually has the focus.

                IConnectionPointContainer connptCntr = (IConnectionPointContainer)vsTextView;

                Guid riid = typeof(IVsTextViewEvents).GUID;

                IConnectionPoint cp;

                connptCntr.FindConnectionPoint(ref riid, out cp);

                cp.Advise(_editor, out cookie);

     

                // sink IVsTextLinesEvents, so we can determine when the data is changed

                IConnectionPointContainer txtCntr = (IConnectionPointContainer)vsTextBuffer;

                if (txtCntr != null)

                {

                    Guid iidConPt = typeof(IVsTextLinesEvents).GUID;

                    txtCntr.FindConnectionPoint(ref iidConPt, out cp);

                    cp.Advise((IVsTextLinesEvents)this, out txtcookie);

                }

            }

     

    Are there any additional steps to get this VS2005 legacy code to work in VS2010?

     

    Thanks,

    Karl Malbrain

     

    Tuesday, April 12, 2011 11:01 PM

Answers

  • Is this post relevant?

    I notice you also aren't calling InitializeContent, not sure if it would result in an 'empty blue screen', but I figured I would point you at that post as a first stop before digging more deeply :)

    That said if you can convert to 2010 (i.e. don't care about your code running on version previous to 2010) there are ways to get an editor hosted in WPF without having any intervening HWNDs, which is really what you ultimately want. One example of such a task would be here.

    Ryan

    • Marked as answer by Karl_M Wednesday, April 13, 2011 4:51 PM
    Tuesday, April 12, 2011 11:28 PM

All replies

  • Is this post relevant?

    I notice you also aren't calling InitializeContent, not sure if it would result in an 'empty blue screen', but I figured I would point you at that post as a first stop before digging more deeply :)

    That said if you can convert to 2010 (i.e. don't care about your code running on version previous to 2010) there are ways to get an editor hosted in WPF without having any intervening HWNDs, which is really what you ultimately want. One example of such a task would be here.

    Ryan

    • Marked as answer by Karl_M Wednesday, April 13, 2011 4:51 PM
    Tuesday, April 12, 2011 11:28 PM
  • Ryan,

    The InitializeContent comes later. We have a datagrid control in our custom editor that selects code from individual fields to be edited by the VS core editor in a hosting sibling window.  As the datagrid field selection changes, the edited code text is retreived from the textbuffer and stored.  The core editor content is then reloaded from the new field.

    We're looking into your sample code now to get additional ideas on how to proceed with this.  We've been  hoping to upgrade our editor to VS2010 using the advertised legacy interfaces to IvsCodeWindow, but they don't seem to work.

    Karl m

    Wednesday, April 13, 2011 12:37 AM
  • Ahhh, okay.  I am not an editor dev, last time I pinged them they were rather heads down on vNext.  You may try the editor forum, there could be people with far more expertise than me there (it would be hard to find someone with less expertise than me in this area).  That said I believe a large number of people successfully used the shims to continue with their code from previous versions in spite of the rather large editor changes in 2010, so the phrase 'they don't seem to work' may be a bit broad :)

    Have you looked at your UI with the debugger visualizer in VS or a tool like Snoop to see if the editor is indeed inside the container you are trying to host it in?  Does it have non-zero size? I believe it should size to the outer container's size, I don't think it (the editor) would have any intrinsic size in and of itself.

    Ryan

    Wednesday, April 13, 2011 1:33 AM
  • Ryan, thanks for all of your help! 

    We found our problem.  We were using a wrong language service guid for the text buffer. 

    We had tried a dummy InitializeContent on the buffer (We didn't catch your opening link to the other thread, at first), but that had no effect.  Using the correct language service guid for our editor extension fixed the problem completely.  We are up and running.

    Karl Malbrain


    • Edited by Karl_M Wednesday, April 13, 2011 4:52 PM typo
    Wednesday, April 13, 2011 4:51 PM
  • Yay, good to hear!

    Ryan

    Wednesday, April 13, 2011 5:46 PM