Esempio n. 1
0
        public void OnBlockCreated(ITextBuffer editorBuffer, LanguageProjectionBuffer projectionBuffer)
        {
            WindowHelpers.WaitFor(delegate
            {
                var textView = TextViewConnectionListener.GetFirstViewForBuffer(editorBuffer);
                if (textView == null)
                {
                    return(false);
                }
                // Add the inner buffer's EditorDocument to the outer buffer before
                // broken editor code tries to create a new EditorDocument from the
                // outer buffer.
                var editorDocument = JSONEditorDocument.FromTextBuffer(projectionBuffer.IProjectionBuffer);
                ServiceManager.AddService(editorDocument, textView.TextBuffer);
                editorDocument.Closing += delegate { ServiceManager.RemoveService <JSONEditorDocument>(textView.TextBuffer); };

                // JSONIndenter uses TextView.TextBuffer, and therefore operates on the
                // entire Markdown buffer, breaking everything.  I manually force it to
                // use the inner projection buffer instead. Beware that this breaks its
                // ViewCaret property, and I can't fix that unless I mock its TextView.
                var indenter = ServiceManager.GetService <ISmartIndent>(textView);
                indenter.GetType().GetField("_textBuffer", BindingFlags.Instance | BindingFlags.NonPublic)
                .SetValue(indenter, projectionBuffer.IProjectionBuffer);
                return(true);
            });
        }
Esempio n. 2
0
        public void OnBlockCreated(ITextBuffer editorBuffer, LanguageProjectionBuffer projectionBuffer)
        {
            var componentModel = (IComponentModel)ServiceProvider.GetService(typeof(SComponentModel));

            var workspace = editorBuffer.Properties.GetOrCreateSingletonProperty(() =>
                                                                                 new MarkdownWorkspace(MefV1HostServices.Create(componentModel.DefaultExportProvider))
                                                                                 );

            var contentType = projectionBuffer.IProjectionBuffer.ContentType.DisplayName;
            var projectId   = editorBuffer.Properties.GetOrCreateSingletonProperty(contentType, () =>
            {
                var newProject = workspace.CurrentSolution
                                 .AddProject(contentType + " Markdown Project", "Markdown", contentTypeLanguages[contentType])
                                 .AddMetadataReferences(
                    DefaultReferences.Select(name => VSWorkspace.CreatePortableExecutableReference(
                                                 Path.Combine(referenceAssemblyPath, name + ".dll"),
                                                 MetadataReferenceProperties.Assembly
                                                 ))
                    );
                workspace.TryApplyChanges(newProject.Solution);
                return(newProject.Id);
            });

            workspace.CreateDocument(projectId, projectionBuffer.IProjectionBuffer);
            WindowHelpers.WaitFor(delegate
            {
                var textView = TextViewConnectionListener.GetFirstViewForBuffer(editorBuffer);
                if (textView == null)
                {
                    return(false);
                }
                InstallCommandTarget(textView, projectionBuffer.IProjectionBuffer);
                return(true);
            });
        }
 public void OnBlockCreated(ITextBuffer editorBuffer, LanguageProjectionBuffer projectionBuffer)
 {
     WindowHelpers.WaitFor(delegate
     {
         var textView = TextViewConnectionListener.GetFirstViewForBuffer(editorBuffer);
         if (textView == null)
         {
             return(false);
         }
         // Attach the inner buffer's Document to the outer
         // buffer so that it can be found from the TextView
         var editorDocument = JSONEditorDocument.FromTextBuffer(projectionBuffer.IProjectionBuffer)
                              ?? JSONEditorDocument.Attach(projectionBuffer.IProjectionBuffer);
         ServiceManager.AddService(editorDocument, editorBuffer);
         editorDocument.Closing += delegate { ServiceManager.RemoveService <JSONEditorDocument>(textView.TextBuffer); };
         return(true);
     });
 }
Esempio n. 4
0
        protected override void OnNavigate(EventArgs e)
        {
            if (_source.TextBuffer != null && _item.Line > 0 && _item.Column > 0)
            {
                var textView = TextViewConnectionListener.GetFirstViewForBuffer(_source.TextBuffer);
                if (textView != null)
                {
                    var snapshot = textView.TextBuffer.CurrentSnapshot;
                    try {
                        int start = snapshot.GetLineFromLineNumber(_item.Line - 1).Start + _item.Column - 1;
                        int end   = start + _item.Length;

                        var endLine = snapshot.GetLineFromPosition(end);

                        var textManager = VsAppShell.Current.GetGlobalService <IVsTextManager>(typeof(SVsTextManager));
                        var textLines   = textView.TextBuffer.GetBufferAdapter <IVsTextLines>();

                        textManager.NavigateToLineAndColumn(textLines, VSConstants.LOGVIEWID_TextView,
                                                            _item.Line - 1, _item.Column - 1,
                                                            endLine.LineNumber, end - endLine.Start);
                    } catch (Exception) { }
                }
            }
        }
Esempio n. 5
0
 public static ITextView GetFirstView(this ITextBuffer textBuffer)
 {
     return(TextViewConnectionListener.GetFirstViewForBuffer(textBuffer));
 }