本文整理汇总了C#中IVsTextBuffer.SetLanguageServiceID方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextBuffer.SetLanguageServiceID方法的具体用法?C# IVsTextBuffer.SetLanguageServiceID怎么用?C# IVsTextBuffer.SetLanguageServiceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextBuffer
的用法示例。
在下文中一共展示了IVsTextBuffer.SetLanguageServiceID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateVsCodeWindow
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);
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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;
}