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


C# IVsTextView.SetBuffer方法代码示例

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


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

示例1: DisplayPreview

        public void DisplayPreview(IVsTextView view) {
            EnsureTempFile();

            // transfer the analyzer to the underlying buffer so we tokenize with the correct version of the language
            var model = (IComponentModel)_engine._serviceProvider.GetService(typeof(SComponentModel));
            var adapterFactory = model.GetService<IVsEditorAdaptersFactoryService>();
            var buffer = adapterFactory.GetDocumentBuffer(_buffer);
            if (buffer.Properties.ContainsProperty(typeof(VsProjectAnalyzer))) {
                buffer.Properties.RemoveProperty(typeof(VsProjectAnalyzer));
            }
            buffer.Properties.AddProperty(typeof(VsProjectAnalyzer), this.Engine._analyzer);

            view.SetBuffer(_buffer);
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:14,代码来源:FilePreviewItem.cs

示例2: DisplayPreview

        /// <summary>
        ///     Display the refactoring preview for a selected preview changes node.
        /// </summary>
        /// <param name="vsTextView">The text view to show the file contents.</param>
        /// <param name="fileChange">All changes in one file.</param>
        /// <param name="node">The selected PreviewChangesNode.</param>
        public void DisplayPreview(IVsTextView vsTextView, FileChange fileChange, PreviewChangesNode node)
        {
            ArgumentValidation.CheckForNullReference(vsTextView, "vsTextView");
            ArgumentValidation.CheckForNullReference(node, "previewChangeNode");

            if (fileChange != null)
            {
                // Get the temp file for this file extension, and copy all file content to the temp file text buffer
                PreviewTempFile tempFile = null;
                try
                {
                    tempFile = GetPreviewTempFile(Path.GetExtension(fileChange.FileName));
                }
                catch (InvalidOperationException)
                {
                    // Failed to get text buffer, just set the text view to nothing.
                    NativeMethods.ThrowOnFailure(vsTextView.SetBuffer(_bufferForNoChanges));
                    return;
                }

                // Copy the content of source file to that temp file text buffer
                CopyFileToBuffer(fileChange.FileName, tempFile.TextBuffer);

                // Create text markers on all changes on this file
                RefactoringOperationBase.ApplyChangesToOneFile(fileChange, tempFile.TextBuffer, true, node.ChangeProposal);

                // Set language service ID
                // Get Language service ID on this change node
                var languageServiceID = node.LanguageServiceID;
                if (languageServiceID == Guid.Empty
                    && node.ChildList != null
                    && node.ChildList.Count > 0)
                {
                    // If can not get the language service ID, check if it has child nodes
                    // if so, get the language service ID for first change in this file node.
                    languageServiceID = node.ChildList[0].LanguageServiceID;
                }
                if (languageServiceID != Guid.Empty)
                {
                    NativeMethods.ThrowOnFailure(tempFile.TextBuffer.SetLanguageServiceID(ref languageServiceID));
                }

                // Set the vsTextView with textBuffer
                NativeMethods.ThrowOnFailure(vsTextView.SetBuffer(tempFile.TextBuffer));

                // Ensure visible of first line and set the caret to position (0,0)
                ScrollInView(vsTextView, 0, 0, 0, 1);

                // If there is ChangeProposal, make sure that change is visible in the text view.
                // If ChangeProposal is null, that might be file node, make the first chagne visible.
                // Here we will only work with Text based change proposal.
                var visibleChange = node.ChangeProposal as TextChangeProposal;
                if (visibleChange == null)
                {
                    // Try to get first change in this file
                    if (node.ChildList != null
                        && node.ChildList.Count > 0)
                    {
                        visibleChange = node.ChildList[0].ChangeProposal as TextChangeProposal;
                    }
                }

                if (visibleChange != null)
                {
                    // There are some changes, create TextSpan for first change, 
                    // and make the cursor position to that TextSpan.
                    ScrollInView(
                        vsTextView, visibleChange.StartLine, visibleChange.StartColumn,
                        visibleChange.EndLine, visibleChange.EndColumn);
                }

                // Save the state, this will be used to refresh the text view when preview request
                // changed, such as check/uncheck
                _lastTextView = vsTextView;
                _lastDisplayedFileChange = fileChange;
                _lastDisplayedNode = node;
            }
            else
            {
                // No related file to this node, set nothing for the text view.
                NativeMethods.ThrowOnFailure(vsTextView.SetBuffer(_bufferForNoChanges));
            }
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:89,代码来源:PreviewBuffer.cs


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