locked
Cannot implement IVsProvideColorableItems properly (nothing shown in Color and Fonts dialog) RRS feed

  • Question

  • Here you see minimalistic package that must provide one ColorableItem to Font and Colors dialog box in options. But it doesn't!!!

    What is wrong? VS 2010, tested on reseted Experimental Hive with Usual F5

    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio;
    using Microsoft.VisualStudio.Package;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.TextManager.Interop;
    
    namespace Company.testofcoloritem {
    	[PackageRegistration(UseManagedResourcesOnly = true)]
    	[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
    	[Guid(GuidList.guidtestofcoloritemPkgString)]
    	[ProvideService(typeof (TestColorProvider))]
    	[ProvideLanguageService(typeof(TestColorProvider), "TestColorProvider", 104, RequestStockColors=false)]
    	public sealed class TestofcoloritemPackage : Package {
    	}
    
    	public class TestColorProvider : IVsLanguageInfo, IVsProvideColorableItems {
    		
    		
    		public int GetItemCount(out int piCount)
    		{
    			piCount = 1;
    			return VSConstants.S_OK;
    		}
    
    		public int GetColorableItem(int iIndex, out IVsColorableItem ppItem)
    		{
    			ppItem = new ColorableItem("TestColorProvider", "TestColorProvider", COLORINDEX.CI_BLUE,
    									   COLORINDEX.CI_SYSPLAINTEXT_BK, Color.Empty, Color.Empty, FONTFLAGS.FF_DEFAULT);
    			return VSConstants.S_OK;
    		}
    
    
    		public int GetLanguageName(out string bstrName) {
    			bstrName = "TestColorProvider";
    			return VSConstants.S_OK;
    		}
    
    		public int GetFileExtensions(out string pbstrExtensions) {
    			pbstrExtensions = ".TestColorProvider";
    			return VSConstants.S_OK;
    		}
    
    		public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer) {
    			ppColorizer = new STUB();
    			return VSConstants.S_OK;
    		}
    
    		public int GetCodeWindowManager(IVsCodeWindow pCodeWin, out IVsCodeWindowManager ppCodeWinMgr) {
    			ppCodeWinMgr = new STUB();
    			return VSConstants.S_OK;
    		}
    
    		
    
    		
    	}
    
    
    	public class STUB : IVsColorizer, IVsCodeWindowManager {
    		#region IVsCodeWindowManager Members
    
    		public int AddAdornments() {
    			throw new NotImplementedException();
    		}
    
    		public int RemoveAdornments() {
    			throw new NotImplementedException();
    		}
    
    		public int OnNewView(IVsTextView pView) {
    			throw new NotImplementedException();
    		}
    
    		#endregion
    
    		#region IVsColorizer Members
    
    		public int GetStateMaintenanceFlag(out int pfFlag) {
    			throw new NotImplementedException();
    		}
    
    		public int GetStartState(out int piStartState) {
    			throw new NotImplementedException();
    		}
    
    		public int ColorizeLine(int iLine, int iLength, IntPtr pszText, int iState, uint[] pAttributes) {
    			throw new NotImplementedException();
    		}
    
    		public int GetStateAtEndOfLine(int iLine, int iLength, IntPtr pText, int iState) {
    			throw new NotImplementedException();
    		}
    
    		public void CloseColorizer() {
    			throw new NotImplementedException();
    		}
    
    		#endregion
    	}
    }

    • Changed type fagim Tuesday, April 24, 2012 9:12 AM error in first definition
    • Moved by Abolmasov Dmitry Tuesday, April 24, 2012 9:24 AM (From:Работа в среде Visual Studio)
    Tuesday, April 24, 2012 9:11 AM

Answers

  • Eurica!!!!

    VS caches Font-Color dialog and keeps it in registry.

    I don't know for auto cache cleaning, but if I see that F-C don't match actual Extension set, I cleanup registry and restart Hive

    all work well.

    At my system key was : HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0Exp\FontAndColors

    • Marked as answer by fagim Thursday, April 26, 2012 8:51 AM
    Thursday, April 26, 2012 8:51 AM

All replies

  • OK. I have found that i not implement IOleComponent, so my language service was not started.

    Thought that it is performed automatically in base Initialize method


    • Edited by fagim Tuesday, April 24, 2012 12:24 PM
    • Marked as answer by fagim Tuesday, April 24, 2012 12:30 PM
    • Unmarked as answer by fagim Tuesday, April 24, 2012 6:28 PM
    Tuesday, April 24, 2012 12:17 PM
  • It was just start of battle.

    It ONCE populate list of Colors but after rebuild and reseting hive (without changing of code) it not works again.

    Interface itself works - I CAN COLORIZE CODE. But i cannot REDEFINE COLORS in Fonts and Colors dialog box!

    VS visits my IVsProvideColorableItems interfaces, but not ADDED them to list!!!!

    What's happend? Who can answer me....?

    Tuesday, April 24, 2012 6:28 PM
  • Hi fagim,

    Thank you for your question.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 26, 2012 8:28 AM
  • Eurica!!!!

    VS caches Font-Color dialog and keeps it in registry.

    I don't know for auto cache cleaning, but if I see that F-C don't match actual Extension set, I cleanup registry and restart Hive

    all work well.

    At my system key was : HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0Exp\FontAndColors

    • Marked as answer by fagim Thursday, April 26, 2012 8:51 AM
    Thursday, April 26, 2012 8:51 AM