Beispiel #1
0
        ITextBuffer IInteractiveWindowEditorFactoryService.CreateAndActivateBuffer(IInteractiveWindow window)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // create buffer adapter to support undo/redo:
            if (!window.Properties.TryGetProperty(typeof(IContentType), out IContentType contentType))
            {
                contentType = _contentTypeRegistry.GetContentType("text");
            }

            var bufferAdapter = _adapterFactory.CreateVsTextBufferAdapter((IOleServiceProvider)_provider, contentType);

            bufferAdapter.InitializeContent("", 0);

            var commandFilter = GetCommandFilter(window);

            if (commandFilter.currentBufferCommandHandler != null)
            {
                ((IVsPersistDocData)commandFilter.currentBufferCommandHandler).Close();
            }

            commandFilter.currentBufferCommandHandler = (IOleCommandTarget)bufferAdapter;

            return(_adapterFactory.GetDocumentBuffer(bufferAdapter));
        }
Beispiel #2
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);
        }
Beispiel #3
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;
        }
Beispiel #4
0
        public int CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW)
        {
            ppunkDocView       = IntPtr.Zero;
            ppunkDocData       = IntPtr.Zero;
            pbstrEditorCaption = String.Empty;

            //pguidCmdUI is the highest priority Guid that Visual Studio Shell looks at when translating key strokes into editor commands.
            //Here we intentionally set it to Guid.Empty so it will not play a part in translating keystrokes at all. The next highest priority
            //will be commands tied to this FSharpEditorFactory (such as Alt-Enter).
            //However, because we are setting pguidCmdUI, we are not going to get typical text editor commands bound to this editor unless we inherit
            //those keybindings on the IVsWindowFrame in which our editor lives.
            pguidCmdUI = Guid.Empty;
            pgrfCDW    = 0;

            IVsTextBuffer textBuffer = null;

            // Is this document already open? If so, let's see if it's a IVsTextBuffer we should re-use. This allows us
            // to properly handle multiple windows open for the same document.
            if (punkDocDataExisting != IntPtr.Zero)
            {
                object docDataExisting = Marshal.GetObjectForIUnknown(punkDocDataExisting);

                textBuffer = docDataExisting as IVsTextBuffer;

                if (textBuffer == null)
                {
                    // We are incompatible with the existing doc data
                    return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                }
            }

            // Do we need to create a text buffer?
            if (textBuffer == null)
            {
                var contentType = _contentTypeRegistryService.GetContentType(Constants.FSharpContentType);
                textBuffer = _editorAdaptersFactoryService.CreateVsTextBufferAdapter(_oleServiceProvider, contentType);
            }

            // If the text buffer is marked as read-only, ensure that the padlock icon is displayed
            // next the new window's title and that [Read Only] is appended to title.
            READONLYSTATUS readOnlyStatus = READONLYSTATUS.ROSTATUS_NotReadOnly;
            uint           textBufferFlags;

            if (ErrorHandler.Succeeded(textBuffer.GetStateFlags(out textBufferFlags)) &&
                0 != (textBufferFlags & ((uint)BUFFERSTATEFLAGS.BSF_FILESYS_READONLY | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY)))
            {
                readOnlyStatus = READONLYSTATUS.ROSTATUS_ReadOnly;
            }

            var codeWindow = _editorAdaptersFactoryService.CreateVsCodeWindowAdapter(_oleServiceProvider);

            codeWindow.SetBuffer((IVsTextLines)textBuffer);
            codeWindow.GetEditorCaption(readOnlyStatus, out pbstrEditorCaption);

            ppunkDocView = Marshal.GetIUnknownForObject(codeWindow);
            ppunkDocData = Marshal.GetIUnknownForObject(textBuffer);

            return(VSConstants.S_OK);
        }
Beispiel #5
0
        /// <summary>
        /// Create an IVsTextBuffer instance and populate it with the existing ITextBuffer value
        /// </summary>
        private IVsTextBuffer CreateVsTextBuffer(ITextBuffer textBuffer, string name)
        {
            // Wrap the result's ITextBuffer so that it can be used with the old VS APIs
            var vsTextBuffer = _vsEditorAdaptersFactoryService.CreateVsTextBufferAdapter(_oleServiceProvider, textBuffer.ContentType);
            var textDocument = _textDocumentFactoryService.CreateTextDocument(textBuffer, name);

            // HACK OF EVIL HACKS: Since there is currently no way to create a text buffer shim
            // for an ITextBuffer that we have already created, we have to create an empty shim,
            // and initialize its underlying ITextBuffer ourselves via reflection
            var vsTextBufferType = vsTextBuffer.GetType();

            vsTextBufferType.GetField("_documentTextBuffer", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(vsTextBuffer, textBuffer);
            vsTextBufferType.GetField("_surfaceTextBuffer", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(vsTextBuffer, textBuffer);
            vsTextBufferType.GetField("_textDocument", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(vsTextBuffer, textDocument);
            vsTextBufferType.GetMethod("InitializeDocumentTextBuffer", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(vsTextBuffer, null);

            return(vsTextBuffer);
        }
Beispiel #6
0
        ITextBuffer IInteractiveWindowEditorFactoryService.CreateAndActivateBuffer(IInteractiveWindow window, IContentType contentType)
        {
            // create buffer adapter to support undo/redo:
            var bufferAdapter = _adapterFactory.CreateVsTextBufferAdapter(_provider, contentType);

            bufferAdapter.InitializeContent("", 0);

            var commandFilter = GetCommandFilter(window);

            if (commandFilter.currentBufferCommandHandler != null)
            {
                ((IVsPersistDocData)commandFilter.currentBufferCommandHandler).Close();
            }

            commandFilter.currentBufferCommandHandler = (IOleCommandTarget)bufferAdapter;

            return(_adapterFactory.GetDocumentBuffer(bufferAdapter));
        }
Beispiel #7
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);
        }
        public Tuple <Control, IVsTextView> SetDisplayedDisassembly()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // @TODO take a parameter of what memory to disasm...

            string       text         = "foo bar\nbaz\n";
            IContentType contentType  = contentTypeRegistryService.GetContentType("text");
            var          textBuffer   = textBufferFactoryService.CreateTextBuffer(text, contentType);
            var          vsTextBuffer = editorAdaptersFactoryService.CreateVsTextBufferAdapter(OleServiceProvider, textBuffer.ContentType);
            var          vsTextLines  = (IVsTextLines)vsTextBuffer;

            ClearEditor();

            /*var editorFactory = OleServiceProvider.GetOleServiceProvider();
             *
             * this.vsCodeWindow = editorAdaptersFactoryService.CreateVsCodeWindowAdapter(OleServiceProvider);
             *
             * IVsCodeWindowEx codeWindowEx = (IVsCodeWindowEx)this.vsCodeWindow;
             * INITVIEW[] initView = new INITVIEW[1];
             * ErrorHandler.ThrowOnFailure(codeWindowEx.Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER, VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, szNameAuxUserContext: "", szValueAuxUserContext: "", InitViewFlags: 0, pInitView: initView));
             * ErrorHandler.ThrowOnFailure(this.vsCodeWindow.SetBuffer(vsTextLines));
             *
             * ErrorHandler.ThrowOnFailure(this.vsCodeWindow.GetPrimaryView(out this.vsTextView));
             * IWpfTextViewHost textViewHost = editorAdaptersFactoryService.GetWpfTextViewHost(this.vsTextView);
             * if (textViewHost == null)
             * {
             *  return null;
             * }
             *
             * // @TODO set options on text view
             *
             * Control part1 = textViewHost.HostControl;
             * IVsTextView part2 = this.vsTextView;
             * return Tuple.Create<Control, IVsTextView>(part1, part2);*/

            return(null);
        }
        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);
        }
Beispiel #10
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;
        }
        public int CreateEditorInstance(
            uint grfCreateDoc,
            string pszMkDocument,
            string pszPhysicalView,
            IVsHierarchy vsHierarchy,
            uint itemid,
            IntPtr punkDocDataExisting,
            out IntPtr ppunkDocView,
            out IntPtr ppunkDocData,
            out string pbstrEditorCaption,
            out Guid pguidCmdUI,
            out int pgrfCDW)
        {
            ppunkDocView       = IntPtr.Zero;
            ppunkDocData       = IntPtr.Zero;
            pbstrEditorCaption = string.Empty;
            pguidCmdUI         = Guid.Empty;
            pgrfCDW            = 0;

            var physicalView = pszPhysicalView == null
                ? "Code"
                : pszPhysicalView;

            IVsTextBuffer textBuffer = null;

            // Is this document already open? If so, let's see if it's a IVsTextBuffer we should re-use. This allows us
            // to properly handle multiple windows open for the same document.
            if (punkDocDataExisting != IntPtr.Zero)
            {
                object docDataExisting = Marshal.GetObjectForIUnknown(punkDocDataExisting);

                textBuffer = docDataExisting as IVsTextBuffer;

                if (textBuffer == null)
                {
                    // We are incompatible with the existing doc data
                    return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                }
            }

            // Do we need to create a text buffer?
            if (textBuffer == null)
            {
                var contentType = _contentTypeRegistryService.GetContentType(ContentTypeName);
                textBuffer = _editorAdaptersFactoryService.CreateVsTextBufferAdapter(_oleServiceProvider, contentType);

                if (_encoding)
                {
                    var userData = textBuffer as IVsUserData;
                    if (userData != null)
                    {
                        // The editor shims require that the boxed value when setting the PromptOnLoad flag is a uint
                        int hresult = userData.SetData(
                            VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid,
                            (uint)__PROMPTONLOADFLAGS.codepagePrompt);

                        if (ErrorHandler.Failed(hresult))
                        {
                            return(hresult);
                        }
                    }
                }
            }

            // If the text buffer is marked as read-only, ensure that the padlock icon is displayed
            // next the new window's title and that [Read Only] is appended to title.
            READONLYSTATUS readOnlyStatus = READONLYSTATUS.ROSTATUS_NotReadOnly;
            uint           textBufferFlags;

            if (ErrorHandler.Succeeded(textBuffer.GetStateFlags(out textBufferFlags)) &&
                0 != (textBufferFlags & ((uint)BUFFERSTATEFLAGS.BSF_FILESYS_READONLY | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY)))
            {
                readOnlyStatus = READONLYSTATUS.ROSTATUS_ReadOnly;
            }

            switch (physicalView)
            {
            case "Form":

                // We must create the WinForms designer here
                const string LoaderName      = "Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader";
                var          designerService = (IVSMDDesignerService)ServiceProvider.GetService(typeof(SVSMDDesignerService));
                var          designerLoader  = (IVSMDDesignerLoader)designerService.CreateDesignerLoader(LoaderName);

                try
                {
                    designerLoader.Initialize(_oleServiceProvider, vsHierarchy, (int)itemid, (IVsTextLines)textBuffer);
                    pbstrEditorCaption = designerLoader.GetEditorCaption((int)readOnlyStatus);

                    var designer = designerService.CreateDesigner(_oleServiceProvider, designerLoader);
                    ppunkDocView = Marshal.GetIUnknownForObject(designer.View);
                    pguidCmdUI   = designer.CommandGuid;
                }
                catch
                {
                    designerLoader.Dispose();
                    throw;
                }

                break;

            case "Code":

                var codeWindow = _editorAdaptersFactoryService.CreateVsCodeWindowAdapter(_oleServiceProvider);
                codeWindow.SetBuffer((IVsTextLines)textBuffer);

                codeWindow.GetEditorCaption(readOnlyStatus, out pbstrEditorCaption);

                ppunkDocView = Marshal.GetIUnknownForObject(codeWindow);
                pguidCmdUI   = VSConstants.GUID_TextEditorFactory;

                break;

            default:

                return(VSConstants.E_INVALIDARG);
            }

            ppunkDocData = Marshal.GetIUnknownForObject(textBuffer);

            return(VSConstants.S_OK);
        }
        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;
        }
Beispiel #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);
        }