private static void CreateToolWindowCallBack(object caller, CallbackArgs arguments) { arguments.ReturnValue = VSConstants.S_OK; // Create the output mock object for the frame IVsWindowFrame frame = MockWindowFrameProvider.GetBaseFrame(); arguments.SetParameter(9, frame); // The window pane (if one is provided) needs to be sited IVsWindowPane pane = arguments.GetParameter(2) as IVsWindowPane; if (pane != null) { // Create a service provider to site the window pane OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); // It needs to provide STrackSelection GenericMockFactory trackSelectionFactory = MockWindowFrameProvider.TrackSelectionFactory; serviceProvider.AddService(typeof(STrackSelection), trackSelectionFactory.GetInstance(), false); // Add support for output window serviceProvider.AddService(typeof(SVsOutputWindow), new OutputWindowService(), false); // Finally we need support for FindToolWindow serviceProvider.AddService(typeof(SVsUIShell), GetWindowEnumerator0(), false); pane.SetSite(serviceProvider); } }
public void WindowPaneImplementation() { using (OleServiceProvider provider = new OleServiceProvider()) { // Create a mock text buffer for the console. BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance(); LocalRegistryMock mockLocalRegistry = new LocalRegistryMock(); mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock); BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance(); mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock); provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false); // Create the tool window. using (IDisposable disposableObject = CommandWindowHelper.CreateConsoleWindow(provider) as IDisposable) { IVsWindowPane windowPane = disposableObject as IVsWindowPane; Assert.IsNotNull(windowPane); // Now call the IVsWindowPane's methods and check that they are redirect to // the implementation provided by the text view. IntPtr newHwnd; Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out newHwnd))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "CreatePaneWindow"))); Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.GetDefaultSize(null))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "GetDefaultSize"))); Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.LoadViewState(null))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "LoadViewState"))); Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.SaveViewState(null))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "SaveViewState"))); Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.SetSite(null))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "SetSite"))); Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.TranslateAccelerator(null))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "TranslateAccelerator"))); Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.ClosePane())); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsWindowPane).FullName, "ClosePane"))); } // Verify that the text view is closed after Dispose is called on the window pane. Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextView).FullName, "CloseView"))); } }
private void CreateCodeWindow() { // create code window Guid guidVsCodeWindow = typeof(VsCodeWindowClass).GUID; codeWindow = services.CreateObject(services.LocalRegistry, guidVsCodeWindow, typeof(IVsCodeWindow).GUID) as IVsCodeWindow; CustomizeCodeWindow(); // set buffer Guid guidVsTextBuffer = typeof(VsTextBufferClass).GUID; textBuffer = services.CreateObject(services.LocalRegistry, guidVsTextBuffer, typeof(IVsTextBuffer).GUID) as IVsTextBuffer; textBuffer.InitializeContent("ed", 2); Guid langSvc = new Guid("{fa498a2d-116a-4f25-9b55-7938e8e6dda7}"); int hr = textBuffer.SetLanguageServiceID(ref langSvc); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } hr = codeWindow.SetBuffer(textBuffer as IVsTextLines); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } // this is necessary for the adapters to work in VS2010 Initialize(String.Empty); // create pane window IVsWindowPane windowPane = codeWindow as IVsWindowPane; hr = windowPane.SetSite(services.IOleServiceProvider); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } if (parentHandle != IntPtr.Zero) { hr = windowPane.CreatePaneWindow(parentHandle, 0, 0, 100, 100, out hwnd); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } } }
private void CreateCodeWindow() { // create code window Guid guidVsCodeWindow = typeof(VsCodeWindowClass).GUID; codeWindow = services.CreateObject(services.LocalRegistry, guidVsCodeWindow, typeof(IVsCodeWindow).GUID) as IVsCodeWindow; CustomizeCodeWindow(); // set buffer Guid guidVsTextBuffer = typeof(VsTextBufferClass).GUID; textBuffer = services.CreateObject(services.LocalRegistry, guidVsTextBuffer, typeof(IVsTextBuffer).GUID) as IVsTextBuffer; textBuffer.InitializeContent("ed", 2); Guid langSvc = new Guid(); if (parent == null || typeof(SqlEditor) == parent.Editor.GetType()) { langSvc = new Guid(MySqlLanguageService.IID); } else { //TODO: [MYSQLFORVS-276] - CREATE A CLASSIFIER EXTENSION THAT COLORS THE APPROPRIATE TEXT (MYJS FILES). if (parent == null || typeof(MySqlHybridScriptEditor) == parent.Editor.GetType() && ((MySqlHybridScriptEditor)parent.Editor).ScriptLanguageType == ScriptLanguageType.JavaScript) { langSvc = new Guid(MyJsLanguageService.IID); } //else //TODO: [MYSQLFORVS-402] - CREATE A CLASSIFIER EXTENSION THAT COLORS THE APPROPRIATE TEXT (MYPY FILES). else if (parent == null || typeof(MySqlHybridScriptEditor) == parent.Editor.GetType() && ((MySqlHybridScriptEditor)parent.Editor).ScriptLanguageType == ScriptLanguageType.Python) { langSvc = new Guid(MyPyLanguageService.IID); } } int hr = textBuffer.SetLanguageServiceID(ref langSvc); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } hr = codeWindow.SetBuffer(textBuffer as IVsTextLines); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } // this is necessary for the adapters to work in VS2010 Initialize(String.Empty); // create pane window IVsWindowPane windowPane = codeWindow as IVsWindowPane; hr = windowPane.SetSite(services.IOleServiceProvider); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } if (parentHandle != IntPtr.Zero) { hr = windowPane.CreatePaneWindow(parentHandle, 0, 0, 100, 100, out hwnd); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } } }
/// <summary> /// Used to create Code Window /// </summary> /// <param name="parentHandle">Parent window handle</param> /// <param name="place">The place.</param> /// <param name="allowModal">if set to <c>true</c> [allow modal].</param> /// <param name="forceLanguageService"></param> /// <param name="codeWindow">Represents a multiple-document interface (MDI) child that contains one or more code views.</param> private void CreateCodeWindow(IntPtr parentHandle, Rectangle place, bool allowModal, Guid? forceLanguageService, out IVsCodeWindow codeWindow) { codeWindow = CreateLocalInstance<IVsCodeWindow>(typeof(VsCodeWindowClass), _serviceProvider); // initialize code window INITVIEW[] initView = new INITVIEW[1]; initView[0].fSelectionMargin = 0; initView[0].IndentStyle = vsIndentStyle.vsIndentStyleSmart; initView[0].fWidgetMargin = 0; initView[0].fVirtualSpace = 0; initView[0].fDragDropMove = 1; initView[0].fVisibleWhitespace = 0; uint initViewFlags = (uint)TextViewInitFlags.VIF_SET_WIDGET_MARGIN | (uint)TextViewInitFlags.VIF_SET_SELECTION_MARGIN | (uint)TextViewInitFlags2.VIF_SUPPRESSBORDER | //(uint)TextViewInitFlags2.VIF_SUPPRESS_STATUS_BAR_UPDATE | (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKCHANGES; if (allowModal) initViewFlags |= (uint)TextViewInitFlags2.VIF_ACTIVEINMODALSTATE; _codewindowbehaviorflags cwFlags = _codewindowbehaviorflags.CWB_DEFAULT; if (!EnableSplitter) cwFlags |= _codewindowbehaviorflags.CWB_DISABLESPLITTER; if (!EnableNavigationBar) cwFlags |= _codewindowbehaviorflags.CWB_DISABLEDROPDOWNBAR; IVsCodeWindowEx codeWindowEx = codeWindow as IVsCodeWindowEx; ErrorHandler.ThrowOnFailure(codeWindowEx.Initialize((uint)cwFlags, 0, null, null, initViewFlags, initView)); // set buffer _textBuffer = CreateLocalInstance<IVsTextBuffer>(typeof(VsTextBufferClass), _serviceProvider); _textBuffer.InitializeContent("", 0); if (forceLanguageService.HasValue) { Guid languageService = forceLanguageService.Value; SetLanguageServiceInternal(languageService); } ErrorHandler.ThrowOnFailure(codeWindow.SetBuffer((IVsTextLines)_textBuffer)); // create pane window _windowPane = (IVsWindowPane)codeWindow; ErrorHandler.ThrowOnFailure(_windowPane.SetSite(_serviceProvider)); ErrorHandler.ThrowOnFailure(_windowPane.CreatePaneWindow(parentHandle, place.X, place.Y, place.Width, place.Height, out editorHwnd)); //set the inheritKeyBinding guid so that navigation keys work. The VS 2008 SDK does this from the language service. // The VS2005 sdk doesn't IOleServiceProvider sp = codeWindow as IOleServiceProvider; if (sp != null) { ServiceProvider site = new ServiceProvider(sp); IVsWindowFrame frame = site.GetService(typeof(IVsWindowFrame).GUID) as IVsWindowFrame; if (frame != null) { Guid CMDUIGUID_TextEditor = new Guid(0x8B382828, 0x6202, 0x11d1, 0x88, 0x70, 0x00, 0x00, 0xF8, 0x75, 0x79, 0xD2); ErrorHandler.ThrowOnFailure(frame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref CMDUIGUID_TextEditor)); } } }
public int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp) { return(codeWindow.SetSite(psp)); }
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 _vsTextBuffer = (IVsTextBuffer)NuoDbVSPackagePackage.Instance.CreateInstance(ref clsidVsTextBuffer, ref iidVsTextLines, typeof(IVsTextBuffer)); IObjectWithSite ows = (IObjectWithSite)_vsTextBuffer; ows.SetSite(_editor); //string strSQL = "select * from sometable"; //hr = _vsTextBuffer.InitializeContent(strSQL, strSQL.Length); switch (NuoDbVSPackagePackage.Instance.GetMajorVStudioVersion()) { case 10: hr = _vsTextBuffer.SetLanguageServiceID(ref GuidList.guidSQLLangSvc_VS2010); break; case 11: hr = _vsTextBuffer.SetLanguageServiceID(ref GuidList.guidSQLLangSvc_VS2012); break; } // create/initialize/site a VsCodeWindow object _vsCodeWindow = (IVsCodeWindow)NuoDbVSPackagePackage.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 | (uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER, 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 | (uint)TextViewInitFlags2.VIF_SUPPRESS_STATUS_BAR_UPDATE | (uint)TextViewInitFlags2.VIF_SUPPRESSBORDER | (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKCHANGES | (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKGOBACK, 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 a VsCodeWindow text has been changed. connptCntr = (IConnectionPointContainer)_vsTextBuffer; riid = typeof(IVsTextLinesEvents).GUID; connptCntr.FindConnectionPoint(ref riid, out cp); cp.Advise(_editor, out cookie); }