public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site) { this.site = new ServiceProvider(site); // register our independent view with the IVsTextManager so that it knows // the user is working with a view over the text buffer. this will trigger // the text buffer to prompt the user whether to reload the file if it is // edited outside of the development Environment. IVsTextManager textManager = (IVsTextManager)this.site.QueryService(VsConstants.SID_SVsTextManager, typeof(IVsTextManager)); if (textManager != null) { IVsWindowPane windowPane = (IVsWindowPane)this; textManager.RegisterIndependentView(this, (VsTextBuffer)this.buffer); } //register with ComponentManager for Idle processing this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager)); if (componentID == 0) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)OLECRF.olecrfNeedIdleTime | (uint)OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal | (uint)OLECADVF.olecadvfRedrawOff | (uint)OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; this.componentManager.FRegisterComponent(this, crinfo, out this.componentID); } return(0); }
public void EngineInitialization() { using (OleServiceProvider provider = new OleServiceProvider()) { // Create a mock text buffer for the console. BaseMock textLinesMock = MockFactories.CreateBufferWithMarker(); LocalRegistryMock mockLocalRegistry = new LocalRegistryMock(); mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock); provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false); // Create a mock engine provider. BaseMock mockEngineProvider = MockFactories.EngineProviderFactory.GetInstance(); // Create a mock engine. BaseMock mockEngine = MockFactories.CreateStandardEngine(); // Set this engine as the one returned from the GetSharedEngine of the engine provider. mockEngineProvider.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IPythonEngineProvider), "GetSharedEngine"), new object[] { (IEngine)mockEngine }); // Add the engine provider to the list of the services. provider.AddService(typeof(IPythonEngineProvider), mockEngineProvider, false); // Create the console window using (IDisposable disposableObject = CommandWindowHelper.CreateConsoleWindow(provider) as IDisposable) { IVsWindowPane windowPane = disposableObject as IVsWindowPane; Assert.IsNotNull(windowPane); // Verify that the shared engine was get. Assert.IsTrue(1 == mockEngineProvider.FunctionCalls(string.Format("{0}.{1}", typeof(IPythonEngineProvider), "GetSharedEngine"))); Assert.IsTrue(1 == mockEngine.FunctionCalls(string.Format("{0}.{1}", typeof(IEngine), "set_StdErr"))); Assert.IsTrue(1 == mockEngine.FunctionCalls(string.Format("{0}.{1}", typeof(IEngine), "set_StdOut"))); } } }
/// <summary> /// This override allows us to forward these messages to the editor instance as well /// </summary> /// <param name="m"></param> /// <returns></returns> protected override bool PreProcessMessage(ref System.Windows.Forms.Message m) { if (this.TextViewHost != null) { // copy the Message into a MSG[] array, so we can pass // it along to the active core editor's IVsWindowPane.TranslateAccelerator MSG[] pMsg = new MSG[1]; pMsg[0].hwnd = m.HWnd; pMsg[0].message = (uint)m.Msg; pMsg[0].wParam = m.WParam; pMsg[0].lParam = m.LParam; IVsWindowPane vsWindowPane = (IVsWindowPane)this.viewAdapter; if (0 == vsWindowPane.TranslateAccelerator(pMsg)) { return(true); } else { return(false); } } return(base.PreProcessMessage(ref m)); }
public CodeEditor(IDocument document) { Package package = MySqlDataProviderPackage.Instance; Type codeWindowType = typeof(IVsCodeWindow); Guid riid = codeWindowType.GUID; Guid clsid = typeof(VsCodeWindowClass).GUID; IVsCodeWindow window = (IVsCodeWindow)package.CreateInstance(ref clsid, ref riid, codeWindowType); codeWindow = (IVsWindowPane)window; IVsTextLines textLines; // Create a new IVsTextLines buffer. Type textLinesType = typeof(IVsTextLines); riid = textLinesType.GUID; clsid = typeof(VsTextBufferClass).GUID; textLines = package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines; String test = " Package package = MySqlDataProviderPackage.Instance;"; textLines.InitializeContent(test, test.Length); String editorCaption; ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines)); ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null)); ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption)); }
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); } }
internal void OnHandleCreated() { if (_pane == null) { if (_panel == null) { _panel = new Panel(); _panel.Location = new Point(0, 0); _panel.Size = _form.ClientRectangle.Size; _form.Controls.Add(_panel); } _pane = new VSFormContainerPane(_form.Context, this, _panel); IVsWindowPane p = _pane; IntPtr hwnd; Rectangle r = new Rectangle(_form.Location, _form.Size); _form.Location = new Point(0, 0); if (!VSErr.Succeeded(p.CreatePaneWindow(_form.Handle, 0, 0, r.Width, r.Height, out hwnd))) { _pane.Dispose(); _pane = null; return; } _form.Size = r.Size; _panel.Size = _form.ClientSize; IButtonControl cancelButton = _form.CancelButton; IButtonControl acceptButton = _form.AcceptButton; for (int i = 0; i < _form.Controls.Count; i++) { Control cc = _form.Controls[i]; if (cc != _panel) { _panel.Controls.Add(cc); i--; if (cc == cancelButton) { _form.CancelButton = cancelButton; } if (cc == acceptButton) { _form.AcceptButton = acceptButton; } } } _form.SizeChanged += new EventHandler(VSForm_SizeChanged); } if (!_loadRegistered) { _loadRegistered = true; _form.Load += new EventHandler(OnLoad); } }
internal void AddWindowPane(IVsWindowPane pane) { if (_paneList == null) { _paneList = new List <IVsWindowPane>(); } _paneList.Add(pane); }
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 static void CreateToolwindowCallback(object sender, CallbackArgs args) { BaseMock mock = (BaseMock)sender; IVsWindowFrame frame = mock["Frame"] as IVsWindowFrame; Assert.IsInstanceOfType(args.GetParameter(2), CommandWindowHelper.ConsoleType); IVsWindowPane pane = args.GetParameter(2) as IVsWindowPane; IntPtr hwnd; pane.CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out hwnd); args.SetParameter(9, frame); args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK; }
public void AddWindowPane(Ankh.UI.VSContainerForm form, IVsWindowPane pane) { VSCommandRouting routing = VSCommandRouting.FromForm(form); if (routing != null) { routing.AddWindowPane(pane); } else { throw new InvalidOperationException("Command routing not initialized yet"); } }
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); } } }
protected void AddWindowPane(IVsWindowPane pane) { if (pane == null) { throw new ArgumentNullException("pane"); } if (DialogOwner == null) { throw new InvalidOperationException("DialogOwner not available"); } DialogOwner.AddWindowPane(this, pane); }
/// <summary> /// This override allows us to forward these messages to the editor instance as well /// </summary> /// <param name="m"></param> /// <returns></returns> protected override bool PreProcessMessage(ref Message m) { IVsWindowPane vsWindowPane = VsTextView as IVsWindowPane; if (vsWindowPane != null) { MSG[] pMsg = new MSG[1]; pMsg[0].hwnd = m.HWnd; pMsg[0].message = (uint)m.Msg; pMsg[0].wParam = m.WParam; pMsg[0].lParam = m.LParam; return(vsWindowPane.TranslateAccelerator(pMsg) == 0); } return(base.PreProcessMessage(ref m)); }
/// <include file='doc\EditorView.uex' path='docs/doc[@for="SimpleEditorView.SetSite"]/*' /> public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site) { this.site = new ServiceProvider(site); if (this.buffer != null) { // register our independent view with the IVsTextManager so that it knows // the user is working with a view over the text buffer. this will trigger // the text buffer to prompt the user whether to reload the file if it is // edited outside of the development Environment. IVsTextManager textManager = (IVsTextManager)this.site.GetService(typeof(SVsTextManager)); // NOTE: NativeMethods.ThrowOnFailure is removed from this method because you are not allowed // to fail a SetSite call, see debug assert at f:\dd\env\msenv\core\docwp.cpp line 87. int hr = 0; if (textManager != null) { IVsWindowPane windowPane = (IVsWindowPane)this; hr = textManager.RegisterIndependentView(this, (VsTextBuffer)this.buffer); if (!NativeMethods.Succeeded(hr)) { Debug.Assert(false, "RegisterIndependentView failed"); } Marshal.ReleaseComObject(textManager); } } //register with ComponentManager for Idle processing this.componentManager = (IOleComponentManager)this.site.GetService(typeof(SOleComponentManager)); if (componentID == 0) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime | (uint)_OLECRF.olecrfNeedAllActiveNotifs | (uint)_OLECRF.olecrfNeedSpecActiveNotifs; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; int hr = this.componentManager.FRegisterComponent(this, crinfo, out this.componentID); if (!NativeMethods.Succeeded(hr)) { Debug.Assert(false, "FRegisterComponent failed"); } } return(NativeMethods.S_OK); }
public void TextViewCreation() { 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); // Define the mock object for the text view. BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance(); textViewMock.AddMethodCallback(string.Format("{0}.{1}", typeof(IObjectWithSite).FullName, "SetSite"), new EventHandler <CallbackArgs>(TextViewSetSiteCallback)); textViewMock.AddMethodCallback(string.Format("{0}.{1}", typeof(IVsTextView).FullName, "Initialize"), new EventHandler <CallbackArgs>(TextViewInitializeCallback)); mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock); // Add the local registry to the list of services. 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); // Call the CreatePaneWindow method that will force the creation of the text view. IntPtr newHwnd; Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out newHwnd))); // Verify that the text view was used as expected. Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IObjectWithSite), "SetSite"))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextView), "Initialize"))); } } }
public int TranslateAccelerator(MSG[] lpmsg) { // defer to active code window if (_activeTextView != null) { IVsWindowPane vsWindowPane = (IVsWindowPane)_activeTextView; return(vsWindowPane.TranslateAccelerator(lpmsg)); } switch (lpmsg[0].message) { case Win32.WM_KEYDOWN: case Win32.WM_SYSKEYDOWN: case Win32.WM_CHAR: case Win32.WM_SYSCHAR: { Message msg = new Message(); msg.HWnd = lpmsg[0].hwnd; msg.Msg = (int)lpmsg[0].message; msg.LParam = lpmsg[0].lParam; msg.WParam = lpmsg[0].wParam; Control ctrl = Control.FromChildHandle(msg.HWnd); if (ctrl != null && ctrl.PreProcessMessage(ref msg)) { return(VSConstants.S_OK); } } break; default: break; } return(VSConstants.S_FALSE); }
/// <include file='doc\Package.uex' path='docs/doc[@for="Package.CreateToolWindow"]/*' /> /// <devdoc> /// Create a tool window of the specified type with the specified ID. /// </devdoc> /// <param name="toolWindowType">Type of the window to be created</param> /// <param name="id">Instance ID</param> /// <returns>An instance of a class derived from ToolWindowPane</returns> /// <param name="transient">Should creation of this window be forced ?</param> /// <param name="multiInstances">Is this window multiinstanced ?</param> protected ToolWindowPane CreateToolWindow(Type toolWindowType, int id, bool transient, bool multiInstances) { if (toolWindowType == null) { throw new ArgumentNullException("toolWindowType"); } if (id < 0) { throw new ArgumentOutOfRangeException("id"); } if (!toolWindowType.IsSubclassOf(typeof(ToolWindowPane))) { throw new ArgumentException("toolWindowType"); } /////////////////////////////////////////////////////////////////////////////////////// // // this is the only method that should be calling IVsUiShell.CreateToolWindow() // First create an instance of the ToolWindowPane ToolWindowPane window = (ToolWindowPane)Activator.CreateInstance(toolWindowType); // Check if this window has a ToolBar bool hasToolBar = (window.ToolBar != null); uint flags = (uint)__VSCREATETOOLWIN.CTW_fInitNew; if (!transient) { flags |= (uint)__VSCREATETOOLWIN.CTW_fForceCreate; } if (hasToolBar) { flags |= (uint)__VSCREATETOOLWIN.CTW_fToolbarHost; } if (multiInstances) { flags |= (uint)__VSCREATETOOLWIN.CTW_fMultiInstance; } Guid emptyGuid = Guid.Empty; Guid toolClsid = window.ToolClsid; IVsWindowPane windowPane = null; if (toolClsid.CompareTo(Guid.Empty) == 0) { // If a tool CLSID is not specified, then host the IVsWindowPane windowPane = window.GetIVsWindowPane() as IVsWindowPane; } Guid persistenceGuid = toolWindowType.GUID; IVsWindowFrame windowFrame; // Use IVsUIShell to create frame. IVsUIShell vsUiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)); if (vsUiShell == null) { throw new Exception(string.Format("Missing service: {0}", typeof(SVsUIShell).FullName)); } int hr = vsUiShell.CreateToolWindow(flags, // flags (uint)id, // instance ID windowPane, // IVsWindowPane to host in the toolwindow (null if toolClsid is specified) ref toolClsid, // toolClsid to host in the toolwindow (Guid.Empty if windowPane is not null) ref persistenceGuid, // persistence Guid ref emptyGuid, // auto activate Guid null, // service provider window.Caption, // Window title null, out windowFrame); ErrorHandler.ThrowOnFailure(hr); window.Package = null; // this; // If the toolwindow is a component, site it. IComponent component = null; if (window.Window is IComponent) { component = (IComponent)window.Window; } else if (windowPane is IComponent) { component = (IComponent)windowPane; } if (component != null) { if (componentToolWindows == null) { componentToolWindows = new PackageContainer(window); } componentToolWindows.Add(component); } // This generates the OnToolWindowCreated event on the ToolWindowPane window.Frame = windowFrame; if (hasToolBar && windowFrame != null) { // Set the toolbar IVsToolWindowToolbarHost toolBarHost; object obj; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_ToolbarHost, out obj)); toolBarHost = (IVsToolWindowToolbarHost)obj; if (toolBarHost != null) { Guid toolBarCommandSet = window.ToolBar.Guid; ErrorHandler.ThrowOnFailure( toolBarHost.AddToolbar((VSTWT_LOCATION)window.ToolBarLocation, ref toolBarCommandSet, (uint)window.ToolBar.ID)); } } window.OnToolBarAdded(); // keep track of created window: if (toolWindows == null) { toolWindows = new Hashtable(); } toolWindows.Add(GetHash(toolWindowType.GUID, id), window); return(window); }
protected void AddWindowPane(IVsWindowPane pane) { if (pane == null) throw new ArgumentNullException("pane"); if (DialogOwner == null) throw new InvalidOperationException("DialogOwner not available"); DialogOwner.AddWindowPane(this, pane); }
void IVisualGitVSContainerForm.AddWindowPane(IVsWindowPane pane) { AddWindowPane(pane); }
public void AddWindowPane(Ankh.UI.VSContainerForm form, IVsWindowPane pane) { VSCommandRouting routing = VSCommandRouting.FromForm(form); if (routing != null) routing.AddWindowPane(pane); else throw new InvalidOperationException("Command routing not initialized yet"); }
void IAnkhVSContainerForm.AddWindowPane(IVsWindowPane pane) { AddWindowPane(pane); }
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); } } }
public void EngineStreams() { using (OleServiceProvider provider = new OleServiceProvider()) { // Create a mock text buffer for the console. BaseMock textLinesMock = MockFactories.CreateBufferWithMarker(); textLinesMock["Text"] = ""; LocalRegistryMock mockLocalRegistry = new LocalRegistryMock(); mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock); provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false); // Create a mock engine provider. BaseMock mockEngineProvider = MockFactories.EngineProviderFactory.GetInstance(); // Create a mock engine. BaseMock mockEngine = MockFactories.CreateStandardEngine(); // Add the callbacks for the setter methods of stderr and stdout mockEngine.AddMethodCallback( string.Format("{0}.{1}", typeof(IEngine).FullName, "set_StdErr"), new EventHandler <CallbackArgs>(SetEngineStdErr)); mockEngine.AddMethodCallback( string.Format("{0}.{1}", typeof(IEngine).FullName, "set_StdOut"), new EventHandler <CallbackArgs>(SetEngineStdOut)); // Set this engine as the one returned from the GetSharedEngine of the engine provider. mockEngineProvider.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IPythonEngineProvider), "GetSharedEngine"), new object[] { (IEngine)mockEngine }); // Add the engine provider to the list of the services. provider.AddService(typeof(IPythonEngineProvider), mockEngineProvider, false); // Create the console window. using (IDisposable disposableObject = CommandWindowHelper.CreateConsoleWindow(provider) as IDisposable) { IVsWindowPane windowPane = disposableObject as IVsWindowPane; Assert.IsNotNull(windowPane); Assert.IsNotNull(mockEngine["StdErr"]); Assert.IsNotNull(mockEngine["StdOut"]); // Set the callback for the text buffer. textLinesMock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines"), new EventHandler <CallbackArgs>(ReplaceLinesCallback)); // Verify that the standard error stream is associated with the text buffer. System.IO.Stream stream = (System.IO.Stream)mockEngine["StdErr"]; using (System.IO.StreamWriter writer = new System.IO.StreamWriter(stream)) { writer.Write("Test String"); writer.Flush(); Assert.IsTrue((string)textLinesMock["Text"] == "Test String"); textLinesMock["Text"] = ""; } // Verify the standard output. stream = (System.IO.Stream)mockEngine["StdOut"]; using (System.IO.StreamWriter writer = new System.IO.StreamWriter(stream)) { writer.Write("Test String"); writer.Flush(); Assert.IsTrue((string)textLinesMock["Text"] == "Test String"); textLinesMock["Text"] = ""; } } } }
/// <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)); } } }
internal void AddWindowPane(IVsWindowPane pane) { if (_paneList == null) _paneList = new List<IVsWindowPane>(); _paneList.Add(pane); }
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); }