locked
Inherit the background color of the General OutputWindowPane of Visual Studio RRS feed

  • Question

  • Hello,

    I'm trying to make the background color of one of our VSpackage automatically follow the general OutputWindowPane. I found out that inplementing the IVsFontAndColorEvents interface is the way.

    My main issue come with defining OnFontChanged(Guid, FontInfo[], LOGFONTW[], UInt32) and OnItemChanged(Guid, String, Int32, ColorableItemInfo[], UInt32, UInt32) methods.

    Outside of the Guid, i don't know how to find the remaining parameters for each method.

    Please can you explain to me where to find thoses parameter concerning the OutputWindowPane or any example of implementation of this interface??

    Thanks in advance

    Wednesday, February 17, 2016 3:37 PM

All replies

  • Hi Chairman Fabrice,

    >>I'm trying to make the background color of one of our VSpackage automatically follow the general OutputWindowPane.

    I suggest you use TextManagerEvents to do it. Link below is for your reference.
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/8db35420-61f3-4f9d-9fd5-04687a914f75/vs-package-receiving-option-fonts-and-color-change-events

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 22, 2016 9:32 AM
  • Thanks for the answer Li Wang. 

    I think using TextManagerEvents detects changes only to the Visual Studio textEditor Font and Colors. Since i want to extend the General OutputWindow I`m not sure how to make that code work for my case.

    Monday, February 22, 2016 6:55 PM
  • Hi, 

    I was able to write the method. (I forgot it was call back method so i didn`t really need to know the parameters values in advance.) 

    My issue now is  the method is never called when i modify the outputWidow colors.

    Do I have to suscribe the methods to something somewhere?

    Thanks in advance

    Monday, February 22, 2016 7:02 PM
  • You can use the IEditorFormatMapService and IEditorFormatMap to do this. The trick is in knowing/guessing what strings to pass retrieve the proper IEditorFormatMap, and resource dictionary.

    For example: (from a simple VS2015 package I just wrote to test this)

    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;
    
    using Microsoft.VisualStudio.ComponentModelHost;
    using Microsoft.VisualStudio.Text.Classification;
    
    namespace OutputWindowTest
    {
        [ProvideAutoLoad(UIContextGuids.SolutionExists)]
        [ProvideAutoLoad(UIContextGuids.NoSolution)]
        [PackageRegistration(UseManagedResourcesOnly = true)]
        [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
        [Guid(OWTestPackage.PackageGuidString)]
        [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
        public sealed class OWTestPackage : Package 
        {
            public const string PackageGuidString = "7807978f-9faf-4ae8-8f17-19898537cf8e";
    
            public OWTestPackage() {}
    
            private IEditorFormatMapService editorFormatMapService = null;
            private IEditorFormatMap editorFormatMap = null;
    
            protected override void Initialize()
            {
                base.Initialize();
    
                // wait until the IDE is completely initialized
                KnownUIContexts.ShellInitializedContext.WhenActivated(() =>
                {
                    System.Diagnostics.Debug.WriteLine("OWTestPackage initalizing...");
    
                    IComponentModel componentModel = (IComponentModel)GetService(typeof(SComponentModel));
                    this.editorFormatMapService = componentModel.GetService<IEditorFormatMapService>();
                    this.editorFormatMap = editorFormatMapService.GetEditorFormatMap("output");
    
                    var resourceDictionary = editorFormatMap.GetProperties("TextView Background");
                    System.Diagnostics.Debug.WriteLine(resourceDictionary["BackgroundColor"].ToString());
    
                    // track changes
                    this.editorFormatMap.FormatMappingChanged += OnFormatMappingChanged;
                });
            }
    
            private void OnFormatMappingChanged(object sender, FormatItemsEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("Output window format changed!!!");
    
                IEditorFormatMap editorFormatMap = (IEditorFormatMap)sender;
                var resourceDictionary = editorFormatMap.GetProperties("TextView Background");
                System.Diagnostics.Debug.WriteLine(resourceDictionary["BackgroundColor"].ToString());
            }
        }
    }

    Sincerely,


    Ed Dore

    Monday, February 22, 2016 10:54 PM
  • Thanks for the answer Ed,

    I apologize for the delay.  I was trying to understand what i was doing wrong regarding the IVsFontAndColorEvents implementation. I still don,t understand why its not working that way, unless may be there is a bug with this interface on MS side?

    I tried to adapt your example to my package but I'm missing  the

    Microsoft.VisualStudio.Text.Classification.dll (i'm using visual studio 2013).

    where am I supposed to get this dll from please?

    Bests Regards,

    Mataani

    Monday, March 14, 2016 3:55 PM
  • Hi Mataani,

    With respect to the old IVsFontAndColorEvents interface, I'm not certain. To be honest, I haven't poked around in that part of VS for close to 10 years.

    There were some quirks around implementing IVsFontAndColorEvents, and to be honest I've only ever seen it used in conjunction with a custom font and color category implementation. But these old articles might shed some light on the matter.

       https://blogs.msdn.microsoft.com/dr._ex/2005/06/03/have-you-had-fun-with-fonts-and-colors-yet/

       http://microsoft.public.vstudio.extensibility.narkive.com/cw6bTJ5t/how-to-use-ivsfontandcolorevents-interface  

       http://stackoverflow.com/questions/31269241/how-to-use-ivsfontandcolorevents

    The suggestion to use the IEditorFormatMap.FormatMappingChanged event came from one of the editor dev's that I happen to sit next to :-)

    I'll see if I can do something similar with VS 2013 and post back the results to this thread. I did test that code against VS 2015, though I'm pretty sure that assembly exists for VS 2013 as well. But I'll double check.

    Ed...


    Ed Dore

    Tuesday, March 15, 2016 3:45 AM
  • Hi Ed,

    Thanks for the explanations.  I found the missing dll. It was Microsoft.VisualStudio.Text.Logic.dll. Even after adding all the missing .dll we ran to the following issue:

    1-       KnownUIContexts.ShellInitializedContext

    ShellInitializedContext is not in Microsoft.VisualStudio.Shell.12.0 (VS 2013) its only in Microsoft.VisualStudio.Shell.14.0 (VS 2015). We are actually using VS 2013   ( in a few month we will support both VS2013 and VS2015) so we would like the solution to be valid in both IDE

    2-      EditorFrotmatMap and EditorFormatMapService return and error saying that both does not exist in the actual context

    bes   Bests Regards,



    Thursday, March 17, 2016 1:41 PM
  • Hi Mataani,

    Didn't realize that particular contextUI guid wasn't available in 2013. Looks like that particular activation context is new to VS 2015.

    As an alternative, you can use the IVsShellPropertyEvents.OnShellPropertyChanged event instead, and wait for the VSSPROPID_ShellInitialized property to be set. The following blog entry has an example of how to go about doing this. (just ignore the fact that it's talking about the isolated shell, the interface and property work the exact same way in the VS IDE as well.

       How to change solution icon in the Visual Studio Isolated Shell

    Sincerely,


    Ed Dore

    Wednesday, March 23, 2016 8:43 PM
  • Hi Ed, 

    Many thanks for your help. We ended up upgrading our environement to VS2015. So i was able to adapt your example code to our Package. And indeed I'm able to get the Text Editor background color when the theme changes. Can we please have the list of keys used for the defaults RessourcesDictionary  for IEditorFormatMap properties please?  We will definitely need to apply more that the Text Editor Background.

    Regards, 

    Mataani


     


    Thursday, April 7, 2016 4:37 PM