Exemple #1
0
        // ----------------------------------------------------------------------------------
        /// <summary>
        /// Initialize the editor
        /// </summary>
        // ----------------------------------------------------------------------------------
        private void InitializeEditor()
        {
            const string message = "";

            var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(
                typeof(SComponentModel));

            _OleServiceProvider = (IServiceProvider)GetService(typeof(IServiceProvider));
            _BufferFactory      = componentModel.GetService <ITextBufferFactoryService>();

            _EditorAdapterFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            _BufferAdapter        = _EditorAdapterFactory.CreateVsTextBufferAdapter(_OleServiceProvider,
                                                                                    _BufferFactory.TextContentType);
            _BufferAdapter.InitializeContent(message, message.Length);

            _ViewAdapter = _EditorAdapterFactory.CreateVsTextViewAdapter(_OleServiceProvider);
            ((IVsWindowPane)_ViewAdapter).SetSite(_OleServiceProvider);

            var initView = new[] { new INITVIEW() };

            initView[0].fSelectionMargin = 0; // original: 0
            initView[0].fWidgetMargin    = 0; // original: 0
            initView[0].fVirtualSpace    = 0;
            initView[0].fDragDropMove    = 1;
            initView[0].fVirtualSpace    = 0;

            _ViewAdapter.Initialize(_BufferAdapter as IVsTextLines, IntPtr.Zero,
                                    (uint)TextViewInitFlags.VIF_HSCROLL |
                                    (uint)TextViewInitFlags3.VIF_NO_HWND_SUPPORT, initView);
        }
Exemple #2
0
        protected override void Initialize()
        {
            base.Initialize();

            IComponentModel                 compMod         = GetService(typeof(SComponentModel)) as IComponentModel;
            ITextBufferFactoryService       bufferFactory   = compMod.GetService <ITextBufferFactoryService>();
            ITextEditorFactoryService       editorFactory   = compMod.GetService <ITextEditorFactoryService>();
            IVsEditorAdaptersFactoryService adapterFactory  = compMod.GetService <IVsEditorAdaptersFactoryService>();
            IContentTypeRegistryService     registryService = compMod.GetService <IContentTypeRegistryService>();

            //completionBroker = compMod.GetService<ICompletionBroker>();

            textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider);
            IVsTextBuffer textBuffer        = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider);
            uint          textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT |
                                              (uint)TextViewInitFlags.VIF_HSCROLL |
                                              (uint)TextViewInitFlags.VIF_VSCROLL;

            textBuffer.InitializeContent("", 0);
            textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null);

            // Create Dev10 objects
            _textView     = adapterFactory.GetWpfTextView(textView);
            mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer);

            IVsUserData userData = textView as IVsUserData;

            if (userData != null)
            {
                Guid   g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
                object obj;
                int    hr = userData.GetData(ref g, out obj);
                if (hr == VSConstants.S_OK)
                {
                    _textViewHost = obj as IWpfTextViewHost;
                }
            }

            // disable zoom view
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.ZoomControlId, false);

            //Initialize the history
            if (null == history)
            {
                history = new HistoryBuffer();
            }

            adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length));


            IContentType ivsdContentType = registryService.GetContentType(VSDContentTypeDefinition.ContentType);

            mefTextBuffer.ChangeContentType(ivsdContentType, null);

            // init console input
            WriteConsoleInputSymbol();

            return;
        }
        private bool InitializeText(string newText)
        {
            newText = newText ?? "";
            if (ErrorHandler.Failed(bufferAdapter.InitializeContent(newText, newText.Length)))
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
        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 override IWpfTextViewHost /*!*/ CreateTextViewHost()
            {
                var adapterFactory = ComponentModel.GetService <IVsEditorAdaptersFactoryService>();
                var provider       = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_window.GetService(typeof(Microsoft.VisualStudio.OLE.Interop.IServiceProvider));

                // create the buffer adapter and initialize it
                IVsTextBuffer bufferAdapter = adapterFactory.CreateVsTextBufferAdapter(provider, ContentType);
                int           result        = bufferAdapter.InitializeContent("", 0);

                bufferAdapter.SetLanguageServiceID(_window.LanguageServiceGuid);

                // ITextEditor is available only after InitializeContent was called:
                ITextBuffer textBuffer = adapterFactory.GetDataBuffer(bufferAdapter);

                // we need to set IReplProptProvider property before TextViewHost is instantiated so that ReplPromptTaggerProvider can bind to it
                if (Evaluator.DisplayPromptInMargin)
                {
                    textBuffer.Properties.AddProperty(typeof(IReplPromptProvider), this);
                }

                // Create and inititalize text view adapter.
                // WARNING: This might trigger various services like IntelliSense, margins, taggers, etc.
                IVsTextView textViewAdapter = adapterFactory.CreateVsTextViewAdapter(provider, GetReplRoles());

                ((IVsWindowPane)textViewAdapter).SetSite(provider);

                // make us a code window so we'll have the same colors as a normal code window.
                IVsTextEditorPropertyContainer propContainer;

                ((IVsTextEditorPropertyCategoryContainer)textViewAdapter).GetPropertyCategory(Microsoft.VisualStudio.Editor.DefGuidList.guidEditPropCategoryViewMasterSettings, out propContainer);
                propContainer.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewComposite_AllCodeWindowDefaults, true);

                textViewAdapter.Initialize(
                    (IVsTextLines)bufferAdapter,
                    IntPtr.Zero,
                    (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL,
                    new[] { new INITVIEW {
                                fSelectionMargin = 0, fWidgetMargin = 0, fVirtualSpace = 0, fDragDropMove = 1
                            } }
                    );

                // disable change tracking because everything will be changed
                var res = adapterFactory.GetWpfTextViewHost(textViewAdapter);

                res.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.ChangeTrackingId, false);
                return(res);
            }
Exemple #6
0
        public void InitializeEditor()
        {
            VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            IOleServiceProvider oleServiceProvider = codeWindowHost.ServiceProvider;

            bufferAdapter = editorAdapterFactoryService.CreateVsTextBufferAdapter(oleServiceProvider, codeSnippetContentType);
            int result = bufferAdapter.InitializeContent("", 0);

            viewAdapter = editorAdapterFactoryService.CreateVsTextViewAdapter(oleServiceProvider);
            ((IVsWindowPane)viewAdapter).SetSite(oleServiceProvider);

            var initView = new[] { new INITVIEW() };

            initView[0].fSelectionMargin = 1;
            initView[0].fWidgetMargin    = 0;
            initView[0].fVirtualSpace    = 0;
            initView[0].fDragDropMove    = 1;
            initView[0].fVirtualSpace    = 0;


            uint readOnlyValue = 0;

            if (codeWindowHost.ReadOnlyCodeWindow)
            {
                readOnlyValue = (uint)TextViewInitFlags2.VIF_READONLY;
            }

            uint flags =
                (uint)TextViewInitFlags.VIF_SET_SELECTION_MARGIN |
                (uint)TextViewInitFlags.VIF_SET_DRAGDROPMOVE |
                (uint)TextViewInitFlags2.VIF_SUPPRESS_STATUS_BAR_UPDATE |
                (uint)TextViewInitFlags2.VIF_SUPPRESSBORDER |
                (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKCHANGES |
                (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKGOBACK |
                (uint)TextViewInitFlags.VIF_HSCROLL |
                (uint)TextViewInitFlags.VIF_VSCROLL |
                (uint)TextViewInitFlags3.VIF_NO_HWND_SUPPORT |
                readOnlyValue;

            viewAdapter.Initialize(bufferAdapter as IVsTextLines, Handle, flags, initView);
        }
        private void InitializeEditor()
        {
            IComponentModel m_componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));

            oleServiceProvider = (IOleServiceProvider)GetService(typeof(IOleServiceProvider));
            bufferFactory      = m_componentModel.GetService <ITextBufferFactoryService>();

            m_EditorAdapterFactory = m_componentModel.GetService <IVsEditorAdaptersFactoryService>();
            bufferAdapter          = m_EditorAdapterFactory.CreateVsTextBufferAdapter(oleServiceProvider, bufferFactory.TextContentType);
            int result = bufferAdapter.InitializeContent("ed", 2);

            viewAdapter = m_EditorAdapterFactory.CreateVsTextViewAdapter(oleServiceProvider);
            ((IVsWindowPane)viewAdapter).SetSite(oleServiceProvider);

            INITVIEW[] _initView = new INITVIEW[] { new INITVIEW() };
            _initView[0].fSelectionMargin = 0;
            _initView[0].fWidgetMargin    = 0;
            _initView[0].fVirtualSpace    = 0;
            _initView[0].fDragDropMove    = 1;
            _initView[0].fVirtualSpace    = 0;

            viewAdapter.Initialize(bufferAdapter as IVsTextLines, IntPtr.Zero, (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags3.VIF_NO_HWND_SUPPORT, _initView);
        }
Exemple #8
0
        private void CreateHostedEditor()
        {
            //Get the component model so we can request the editor adapter factory which we can use to spin up an editor instance.
            IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));

            IContentTypeRegistryService contentTypeRegistry = componentModel.GetService <IContentTypeRegistryService>();
            IContentType contentType = contentTypeRegistry.GetContentType("CSharp");

            IVsEditorAdaptersFactoryService editorAdapterFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();

            this.textBuffer = editorAdapterFactory.CreateVsTextBufferAdapter(OleServiceProvider);
            Guid CSharpLanguageService = new Guid("{694DD9B6-B865-4C5B-AD85-86356E9C88DC}");

            ErrorHandler.ThrowOnFailure(textBuffer.SetLanguageServiceID(ref CSharpLanguageService));

            string initialContents = String.Format("using System;{0}{0}namespace Lazers{0}{{{0}{1}public class Awesome{0}{1}{{{0}{1}}}{0}}}", Environment.NewLine, "    ");

            ErrorHandler.ThrowOnFailure(textBuffer.InitializeContent(initialContents, initialContents.Length));

            //Disable the splitter due to a crashing bug if we don't :(
            this.codeWindow = editorAdapterFactory.CreateVsCodeWindowAdapter(OleServiceProvider);
            ((IVsCodeWindowEx)this.codeWindow).Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER,
                                                          VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter,
                                                          "",
                                                          "",
                                                          0,
                                                          new INITVIEW[1]);

            this.codeWindow.SetBuffer((IVsTextLines)this.textBuffer);

            ErrorHandler.ThrowOnFailure(this.codeWindow.GetPrimaryView(out this.textView));
            this.textViewHost = editorAdapterFactory.GetWpfTextViewHost(this.textView);

            this.Content             = textViewHost.HostControl;
            this.editorCommandTarget = (IOleCommandTarget)this.textView;
        }
        protected override void Initialize()
        {
            base.Initialize();

            IComponentModel                 compMod         = GetService(typeof(SComponentModel)) as IComponentModel;
            ITextBufferFactoryService       bufferFactory   = compMod.GetService <ITextBufferFactoryService>();
            ITextEditorFactoryService       editorFactory   = compMod.GetService <ITextEditorFactoryService>();
            IVsEditorAdaptersFactoryService adapterFactory  = compMod.GetService <IVsEditorAdaptersFactoryService>();
            IContentTypeRegistryService     registryService = compMod.GetService <IContentTypeRegistryService>();

            completionBroker = compMod.GetService <ICompletionBroker>();

            textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider);
            IVsTextBuffer textBuffer        = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider);
            uint          textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT
                                              | (uint)TextViewInitFlags.VIF_HSCROLL
                                              | (uint)TextViewInitFlags.VIF_VSCROLL;

            textBuffer.InitializeContent("", 0);
            textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null);

            // Create Dev10 objects
            _textView     = adapterFactory.GetWpfTextView(textView);
            mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer);

            IVsUserData userData = textView as IVsUserData;

            if (userData != null)
            {
                Guid   g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
                object obj;
                int    hr = userData.GetData(ref g, out obj);
                if (hr == VSConstants.S_OK)
                {
                    _textViewHost = obj as IWpfTextViewHost;
                }
            }


            //Initialize the history
            history = new HistoryBuffer();

            // Create the stream on top of the text buffer.
            textStream = new TextBufferStream(mefTextBuffer);

            // Initialize the engine.
            InitializeEngine();

            IContentType ipContentType = registryService.GetContentType(PyContentTypeDefinition.ConsoleContentType);

            mefTextBuffer.ChangeContentType(ipContentType, null);

            adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length));

            // Set the title of the window.
            this.Caption = Resources.ToolWindowTitle;

            // Set the icon of the toolwindow.
            this.BitmapResourceID = 301;
            this.BitmapIndex      = 0;

            return;
        }
    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(MySqlLanguageService.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);
      }
    }
Exemple #11
0
        public void InitializeEditor()
        {
            IOleServiceProvider oleServiceProvider = codeWindowHost.ServiceProvider;
            bufferAdapter = editorAdapterFactoryService.CreateVsTextBufferAdapter(oleServiceProvider, codeSnippetContentType);
            int result = bufferAdapter.InitializeContent("", 0);
            viewAdapter = editorAdapterFactoryService.CreateVsTextViewAdapter(oleServiceProvider);
            ((IVsWindowPane) viewAdapter).SetSite(oleServiceProvider);

            var initView = new[] {new INITVIEW()};
            initView[0].fSelectionMargin = 1;
            initView[0].fWidgetMargin = 0;
            initView[0].fVirtualSpace = 0;
            initView[0].fDragDropMove = 1;
            initView[0].fVirtualSpace = 0;

            uint readOnlyValue = 0;
            if (codeWindowHost.ReadOnlyCodeWindow)
            {
                readOnlyValue = (uint) TextViewInitFlags2.VIF_READONLY;
            }

            uint flags =
                (uint) TextViewInitFlags.VIF_SET_SELECTION_MARGIN |
                (uint) TextViewInitFlags.VIF_SET_DRAGDROPMOVE |
                (uint) TextViewInitFlags2.VIF_SUPPRESS_STATUS_BAR_UPDATE |
                (uint) TextViewInitFlags2.VIF_SUPPRESSBORDER |
                (uint) TextViewInitFlags2.VIF_SUPPRESSTRACKCHANGES |
                (uint) TextViewInitFlags2.VIF_SUPPRESSTRACKGOBACK |
                (uint) TextViewInitFlags.VIF_HSCROLL |
                (uint) TextViewInitFlags.VIF_VSCROLL |
                (uint) TextViewInitFlags3.VIF_NO_HWND_SUPPORT |
                readOnlyValue;

            viewAdapter.Initialize(bufferAdapter as IVsTextLines, Handle, flags, initView);
        }
Exemple #12
0
        /// <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));
                }
            }
        }
Exemple #13
0
        // ----------------------------------------------------------------------------------
        /// <summary>
        /// Initialize the editor
        /// </summary>
        // ----------------------------------------------------------------------------------
        private void InitializeEditor()
        {
            const string message = "";

            var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(
              typeof(SComponentModel));
            _OleServiceProvider = (IServiceProvider)GetService(typeof(IServiceProvider));
            _BufferFactory = componentModel.GetService<ITextBufferFactoryService>();

            _EditorAdapterFactory = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            _BufferAdapter = _EditorAdapterFactory.CreateVsTextBufferAdapter(_OleServiceProvider,
                                                                             _BufferFactory.TextContentType);
            _BufferAdapter.InitializeContent(message, message.Length);

            _ViewAdapter = _EditorAdapterFactory.CreateVsTextViewAdapter(_OleServiceProvider);
            ((IVsWindowPane)_ViewAdapter).SetSite(_OleServiceProvider);

            var initView = new[] { new INITVIEW() };
            initView[0].fSelectionMargin = 0; // original: 0
            initView[0].fWidgetMargin = 0; // original: 0
            initView[0].fVirtualSpace = 0;
            initView[0].fDragDropMove = 1;
            initView[0].fVirtualSpace = 0;

            _ViewAdapter.Initialize(_BufferAdapter as IVsTextLines, IntPtr.Zero,
              (uint)TextViewInitFlags.VIF_HSCROLL |
              (uint)TextViewInitFlags3.VIF_NO_HWND_SUPPORT, initView);
        }
        private void CreateHostedEditor()
        {
            //Get the component model so we can request the editor adapter factory which we can use to spin up an editor instance.
            IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));

            IContentTypeRegistryService contentTypeRegistry = componentModel.GetService<IContentTypeRegistryService>();
            IContentType contentType = contentTypeRegistry.GetContentType("CSharp");

            IVsEditorAdaptersFactoryService editorAdapterFactory = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this.textBuffer = editorAdapterFactory.CreateVsTextBufferAdapter(OleServiceProvider);
            Guid CSharpLanguageService = new Guid("{694DD9B6-B865-4C5B-AD85-86356E9C88DC}");
            ErrorHandler.ThrowOnFailure(textBuffer.SetLanguageServiceID(ref CSharpLanguageService));

            string initialContents = String.Format("using System;{0}{0}namespace Lazers{0}{{{0}{1}public class Awesome{0}{1}{{{0}{1}}}{0}}}", Environment.NewLine, "    ");
            ErrorHandler.ThrowOnFailure(textBuffer.InitializeContent(initialContents, initialContents.Length));

            //Disable the splitter due to a crashing bug if we don't :(
            this.codeWindow = editorAdapterFactory.CreateVsCodeWindowAdapter(OleServiceProvider);
            ((IVsCodeWindowEx)this.codeWindow).Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER,
                                                          VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter,
                                                          "",
                                                          "",
                                                          0,
                                                          new INITVIEW[1]);

            this.codeWindow.SetBuffer((IVsTextLines)this.textBuffer);

            ErrorHandler.ThrowOnFailure(this.codeWindow.GetPrimaryView(out this.textView));
            this.textViewHost = editorAdapterFactory.GetWpfTextViewHost(this.textView);

            this.Content = textViewHost.HostControl;
            this.editorCommandTarget = (IOleCommandTarget)this.textView;
        }
Exemple #15
0
 internal void SetText(string message)
 {
     _BufferAdapter.InitializeContent(message, message.Length);
 }
Exemple #16
0
        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);
                }
            }
        }
        private void CreateVsCodeWindow()
        {
            int hr = VSConstants.S_OK;
            //ILocalRegistry localRegistry = (ILocalRegistry)Package.GetGlobalService(typeof(SLocalRegistry));
            IComponentModel componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

            Guid clsidVsCodeWindow = typeof(VsCodeWindowClass).GUID;
            Guid iidVsCodeWindow = typeof(IVsCodeWindow).GUID;
            Guid iidVsTextLines = typeof(IVsTextLines).GUID;
            Guid clsidTextBuffer = typeof(VsTextBufferClass).GUID;
            Guid iidTextBuffer = VSConstants.IID_IUnknown;

            // create/site a VsTextBuffer object
            var editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            vsTextBuffer = editorAdaptersFactoryService.CreateVsTextBufferAdapter(OleServiceProvider);

            string strSQL = Global.textStub;
            hr = vsTextBuffer.InitializeContent(strSQL, strSQL.Length);
            hr = vsTextBuffer.SetLanguageServiceID(ref GuidList.guidCppLangSvc);

            // create/initialize/site a VsCodeWindow object
            _vsCodeWindow = editorAdaptersFactoryService.CreateVsCodeWindowAdapter(OleServiceProvider);

            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_READONLY |
                (uint)TextViewInitFlags2.VIF_SUPPRESSBORDER |
                (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKCHANGES |
                (uint)TextViewInitFlags2.VIF_SUPPRESSTRACKGOBACK,
                initView);

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

            IVsTextView vsTextView;
            hr = _vsCodeWindow.GetPrimaryView(out vsTextView);

            textViewHost = editorAdaptersFactoryService.GetWpfTextViewHost(vsTextView);

            textViewHost.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.ChangeTrackingId, false);
            textViewHost.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false);
            textViewHost.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, false);
            textViewHost.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false);

            textViewHost.TextView.Options.SetOptionValue(DefaultTextViewOptions.ViewProhibitUserInputId, true);
            Content = textViewHost.HostControl;
        }