示例#1
0
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid           = codeWindowType.GUID;
            Guid clsid          = typeof(VsCodeWindowClass).GUID;
            var  compModel      = _package.AsVsServiceProvider().GetComponentModel();
            var  adapterService = compModel.GetService <IVsEditorAdaptersFactoryService>();

            var window = adapterService.CreateVsCodeWindowAdapter(_serviceProvider.TryGetOleServiceProvider());

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                if (_promptEncodingOnLoad)
                {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            cmdUI = VSConstants.GUID_TextEditorFactory;
            return(window);
        }
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid           = codeWindowType.GUID;
            Guid clsid          = typeof(VsCodeWindowClass).GUID;
            var  compModel      = (IComponentModel) new VsServiceProviderWrapper(_package).GetService(typeof(SComponentModel));
            var  adapterService = compModel.GetService <IVsEditorAdaptersFactoryService>();

            var window = adapterService.CreateVsCodeWindowAdapter((IOleServiceProvider)_serviceProvider.GetService(typeof(IOleServiceProvider)));

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                if (PromptEncodingOnLoad)
                {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            cmdUI = VSConstants.GUID_TextEditorFactory;

            var componentModel      = (IComponentModel) new VsServiceProviderWrapper(Package).GetService(typeof(SComponentModel));
            var bufferEventListener = new TextBufferEventListener(componentModel, textLines, _languageServiceId);

            if (!createdDocData)
            {
                // we have a pre-created buffer, go ahead and initialize now as the buffer already
                // exists and is initialized
                bufferEventListener.OnLoadCompleted(0);
            }

            return(window);
        }