2015-09-08 1 views
0

Fondamentalement, est-il possible d'ajouter un classificateur à un volet OutputWindow personnalisé?Ajout d'un classificateur à un volet OutputWindow personnalisé

je peux ajouter un nouveau volet à la fenêtre de sortie avec le code suivant:

 IVsOutputWindow outputWindow = null; 
    outputWindow = ServiceProvider.GlobalProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; 
    if (outputWindow.CreatePane(ref GuidList.guidDebugOutputFilteredPane, "FilteredOutput", 1, 1) == Microsoft.VisualStudio.VSConstants.S_OK) 
    { 
     if (outputWindow.GetPane(ref GuidList.guidDebugOutputFilteredPane, out filteredPane) == Microsoft.VisualStudio.VSConstants.S_OK) 
     { 
      filteredPane.OutputString("Created filtered pane. Need to add a classifier..."); 
     } 
    } 

Mais je suis à une perte quant à la façon d'ajouter un classificateur à lui. J'ai ajouté un classificateur au volet Débogage de la fenêtre de sortie et je voulais faire un peu de reformatage et de filtrage avant d'afficher dans le volet FilteredOutput avec une coloration syntaxique supplémentaire.

J'ai créer un classificateur FilteredOutput avec son propre ContentTypeDefinition (MSDN):

internal sealed class Components 
{ 
    [Export] 
    [Name("FilteredOutput")] 
    [BaseDefinition("Output")] 
    internal static ContentTypeDefinition FilteredOutputContentTypeDefinition; 
} 

J'ai ensuite utilisé cette option pour créer une nouvelle IClassiferProvider:

[ContentType("FilteredOutput")] 
[Export(typeof(IClassifierProvider))] 
public class FilteredOutputClassifierProvider : IClassifierProvider 
{ 
    [Import] 
    internal IClassificationTypeRegistryService ClassificationRegistry; 
    public static FilteredOutputClassifier FilteredOutputClassifier { get; private set; } 
    public IClassifier GetClassifier(ITextBuffer textBuffer) 
    { 
     return FilteredOutputClassifier ?? (FilteredOutputClassifier = new FilteredOutputClassifier(ClassificationRegistry)); 
    } 
} 

GetClassifier() devient appelé à DebugOutput , mais n'est pas appelé pour FilteredOutput. Est-ce faisable même en utilisant une extension de type VSPackage? C'est dans VS2013 en utilisant le dernier VSSDK.

Répondre

0

J'ai trouvé la solution par accident en creusant dans les documents; utilisez CreatePane2() depuis l'interface IVsOutputWindow3, ce qui vous permet de spécifier un type de contenu par son nom. Quelque chose comme:

IVsOutputWindow outputWindow = null; 
IVsOutputWindow3 outputWindow3 = null; 
outputWindow = ServiceProvider.GlobalProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; 
outputWindow3 = ServiceProvider.GlobalProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow3; 
if (outputWindow3.CreatePane2(ref GuidList.guidDebugOutputFilteredPane, "Filtered Output", 1, 1, "FilteredOutput", PredefinedTextViewRoles.Debuggable) == Microsoft.VisualStudio.VSConstants.S_OK) 
{ 
    if (outputWindow.GetPane(ref GuidList.guidDebugOutputFilteredPane, out filteredPane) == Microsoft.VisualStudio.VSConstants.S_OK) 
    { 
     filteredPane.OutputString("Created filtered pane. Need to add a classifier..."); 
    } 
}