예제 #1
0
        /// <inheritdoc/>
        /// <remarks>
        /// <para>When a text view is created, this method first checks if the content type of the underlying
        /// <see cref="ITextBuffer"/> matches a content type associated with any of the
        /// <see cref="CommenterProviders"/>. If so, <see cref="ICommenterProvider.TryCreateCommenter"/> is called to
        /// obtain the <see cref="ICommenter"/> to associate with the text buffer for the view. The commenter is then
        /// used to initialize a <see cref="CommenterFilter"/> that provides support for the comment and uncomment
        /// commands for the text view.</para>
        ///
        /// <para>
        /// If any of these operations fails, no changes are applied to the text view.
        /// </para>
        ///
        /// <note type="note">
        /// <para>The current implementation does not support projection buffer scenarios involving multiple content
        /// types. However, the <see cref="ICommenterProvider"/> and <see cref="ICommenter"/> interfaces do not prevent
        /// such a feature from being implemented in a future release.</para>
        /// </note>
        /// </remarks>
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ITextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            var provider = CommenterProviders.FirstOrDefault(providerInfo => providerInfo.Metadata.ContentTypes.Any(contentType => textView.TextBuffer.ContentType.IsOfType(contentType)));

            if (provider == null)
            {
                return;
            }

            var commenter = provider.Value.TryCreateCommenter(textView.TextBuffer);

            if (commenter == null)
            {
                return;
            }

            IEditorOperations editorOperations = EditorOperationsFactoryService.GetEditorOperations(textView);

            CommenterFilter filter = new CommenterFilter(textViewAdapter, textView, commenter, editorOperations, TextUndoHistoryRegistry);

            filter.Enabled = true;
            textView.Properties.AddProperty(typeof(CommenterFilter), filter);
        }
예제 #2
0
        /// <inheritdoc/>
        /// <remarks>
        /// <para>When a text view is created, this method first checks if the content type of the underlying
        /// <see cref="ITextBuffer"/> matches a content type associated with any of the
        /// <see cref="CommenterProviders"/>. If so, <see cref="ICommenterProvider.TryCreateCommenter"/> is called to
        /// obtain the <see cref="ICommenter"/> to associate with the text buffer for the view. The commenter is then
        /// used to initialize a <see cref="CommenterFilter"/> that provides support for the comment and uncomment
        /// commands for the text view.</para>
        ///
        /// <para>
        /// If any of these operations fails, no changes are applied to the text view.
        /// </para>
        ///
        /// <note type="note">
        /// <para>The current implementation does not support projection buffer scenarios involving multiple content
        /// types. However, the <see cref="ICommenterProvider"/> and <see cref="ICommenter"/> interfaces do not prevent
        /// such a feature from being implemented in a future release.</para>
        /// </note>
        /// </remarks>
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ITextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            if (textView == null)
                return;

            var provider = CommenterProviders.FirstOrDefault(providerInfo => providerInfo.Metadata.ContentTypes.Any(contentType => textView.TextBuffer.ContentType.IsOfType(contentType)));
            if (provider == null)
                return;

            var commenter = provider.Value.TryCreateCommenter(textView.TextBuffer);
            if (commenter == null)
                return;

            IEditorOperations editorOperations = EditorOperationsFactoryService.GetEditorOperations(textView);

            CommenterFilter filter = new CommenterFilter(textViewAdapter, textView, commenter, editorOperations, TextUndoHistoryRegistry);
            filter.Enabled = true;
            textView.Properties.AddProperty(typeof(CommenterFilter), filter);
        }