当前位置: 首页>>代码示例>>C#>>正文


C# IVsTextBuffer.InitializeContent方法代码示例

本文整理汇总了C#中IVsTextBuffer.InitializeContent方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextBuffer.InitializeContent方法的具体用法?C# IVsTextBuffer.InitializeContent怎么用?C# IVsTextBuffer.InitializeContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IVsTextBuffer的用法示例。


在下文中一共展示了IVsTextBuffer.InitializeContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCodeWindow

    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);
      }
    }
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:39,代码来源:VSCodeEditor.cs

示例2: InitializeEditor

        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);
        }
开发者ID:GeertVL,项目名称:SnippetDesigner,代码行数:35,代码来源:CodeWindow.cs

示例3: CreateCodeWindow

        /// <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));
                }
            }
        }
开发者ID:necora,项目名称:ank_git,代码行数:75,代码来源:TheVSTextEditor.cs

示例4: CreateVsCodeWindow

        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;
        }
开发者ID:Predelnik,项目名称:CppFormatter,代码行数:58,代码来源:CodeWindow.xaml.cs

示例5: InitializeEditor

        // ----------------------------------------------------------------------------------
        /// <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);
        }
开发者ID:gencer,项目名称:git-tools,代码行数:33,代码来源:MyToolWindow.cs

示例6: CreateHostedEditor

        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;
        }
开发者ID:ryanmolden,项目名称:ModalDialogHostedEditor,代码行数:33,代码来源:MyModalDialog.cs


注:本文中的IVsTextBuffer.InitializeContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。