Esempio n. 1
0
        public override Colorizer GetColorizer(IVsTextLines buffer)
        {
            // Clear font cache
            // http://social.msdn.microsoft.com/Forums/office/en-US/54064c52-727d-4015-af70-c72e44d116a7/vs2012-fontandcolors-text-editor-category-for-language-service-colors?forum=vsx
            IVsFontAndColorStorage storage;
            Guid textMgrIID = new Guid(
//#if VISUALSTUDIO_11_0
		            "{E0187991-B458-4F7E-8CA9-42C9A573B56C}" /* 'Text Editor Language Services Items' category discovered in the registry. Resetting TextEditor has no effect. */
//#else
//		            FontsAndColorsCategory.TextEditor
//#endif
	        );
	        if (null != (storage = GetService(typeof(IVsFontAndColorStorage)) as IVsFontAndColorStorage) &&
		        VSConstants.S_OK == storage.OpenCategory(ref textMgrIID, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)))
	        {
		        bool missingColor = false;
		        try
		        {
			        ColorableItemInfo[] info = new ColorableItemInfo[1];
                    for (int i = 0; i < m_colorableItems.Length; ++i)
                    {
                        string colorName;
                        m_colorableItems[i].GetDisplayName(out colorName);
				        if (ErrorHandler.Failed(storage.GetItem(colorName, info)))
				        {
					        missingColor = true;
					        break;
				        }
			        }
		        }
		        finally
		        {
			        storage.CloseCategory();
		        }
		        if (missingColor)
		        {
			        IOleServiceProvider oleProvider;
			        // The service and interface guids are different, so we need to go to the OLE layer to get the service
			        Guid iid = typeof(IVsFontAndColorCacheManager).GUID;
			        Guid sid = typeof(SVsFontAndColorCacheManager).GUID;
			        IntPtr pCacheManager;
			        if (null != (oleProvider = GetService(typeof(IOleServiceProvider)) as IOleServiceProvider) &&
				        VSConstants.S_OK == oleProvider.QueryService(ref sid, ref iid, out pCacheManager) &&
				        pCacheManager != IntPtr.Zero)
			        {
				        try
				        {
					        IVsFontAndColorCacheManager cacheManager = (IVsFontAndColorCacheManager)Marshal.GetObjectForIUnknown(pCacheManager);
					        cacheManager.ClearCache(ref textMgrIID);
				        }
				        finally
				        {
					        Marshal.Release(pCacheManager);
				        }
			        }
		        }
            }

            return base.GetColorizer(buffer);
        }
Esempio n. 2
0
        public override void Initialize()
        {
            _serviceprovider_sys = this.Site;
            IVsFontAndColorCacheManager mgr = this.GetService(typeof(SVsFontAndColorCacheManager)) as IVsFontAndColorCacheManager;

            mgr.ClearAllCaches();
        }
Esempio n. 3
0
        public void TryClearFontAndColorCache()
        {
            SafeExecute(() =>
            {
                IVsFontAndColorCacheManager cacheManager =
                    ServiceProvider.GetService(typeof(SVsFontAndColorCacheManager)) as IVsFontAndColorCacheManager;

                cacheManager.ClearCache(ref VSCFontAndColorCategoryGuid);
            });
        }
Esempio n. 4
0
        // Changes to ProvideFontAndColorsCategory will not be registered until this method is run.
        // This is only useful when developing the extension, so make sure to guard this call with #if DEBUG.
        internal static void ClearFontAndColorCache(IServiceProvider serviceProvider)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsFontAndColorCacheManager cacheManager = (IVsFontAndColorCacheManager)
                                                       serviceProvider.GetService(typeof(SVsFontAndColorCacheManager));

            Assumes.Present(cacheManager);
            var categoryGuid = Constants.FontAndColorsCategoryGuid;

            cacheManager.ClearCache(ref categoryGuid);
        }
 public TextInformationManager(IServiceProvider serviceProvider, IComponentModel componentModel)
 {
     this.serviceProvider = serviceProvider;
     this.componentModel = componentModel;
     fontAndColorStorage = (IVsFontAndColorStorage) serviceProvider.GetService(typeof (SVsFontAndColorStorage));
     fontAndColorUtilities = fontAndColorStorage as IVsFontAndColorUtilities;
     fontAndColorCache = (IVsFontAndColorCacheManager)serviceProvider.GetService(typeof(SVsFontAndColorCacheManager));
     textManager = (IVsTextManager) serviceProvider.GetService(typeof (SVsTextManager));
     editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
     textStructureNavigatorSelectorService = componentModel.GetService<ITextStructureNavigatorSelectorService>();
     classicationFormatMapService = componentModel.GetService<IClassificationFormatMapService>();
     classificationAggregatorService = componentModel.GetService<IClassifierAggregatorService>();
 }
Esempio n. 6
0
        private void ValidateFontAndColorCacheManagerIsUpToDate()
        {
            IVsFontAndColorCacheManager cacheManager =
                (IVsFontAndColorCacheManager)GetService(typeof(SVsFontAndColorCacheManager));

            if (cacheManager == null)
            {
                return;
            }

            bool alreadyInitialized = false;

            try
            {
                const string registryValueName = "InstalledVersion";
                string       expectedVersion   = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                using (RegistryKey rootKey = UserRegistryRoot)
                    using (RegistryKey ourKey = rootKey.CreateSubKey("NShader"))
                    {
                        if (ourKey != null)
                        {
                            object registryValue      = ourKey.GetValue(registryValueName);
                            string initializedVersion = Convert.ToString(registryValue, CultureInfo.InvariantCulture);
                            alreadyInitialized = (initializedVersion == expectedVersion);
                            ourKey.SetValue(registryValueName, expectedVersion, RegistryValueKind.String);
                        }
                    }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {
                // Ignore any errors since it's not a big deal if we can't read
                // this setting. We just always refresh the cache in that case.
            }

            // Actually refresh the Fonts and Colors cache now if we detected we have
            // to do so.
            if (alreadyInitialized)
            {
                return;
            }

            ErrorHandler.ThrowOnFailure(cacheManager.ClearAllCaches());
            Guid categoryGuid = Guid.Empty;

            ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
            categoryGuid = new Guid("a27b4e24-a735-4d1d-b8e7-9716e1e3d8e0");
            ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
        }
Esempio n. 7
0
        private void ValidateFontAndColorCacheManagerIsUpToDate()
        {
            // The Fonts and Colors cache has to be refreshed after each marker change
            // (during development) and of course after install/uninstall.

            // To identify when we have to refresh the cache we store a custom value
            // in the Visual Studio registry hive. Downsides of this approach:
            //
            //     1. The cache is not refreshed until the package is loaded for the
            //        first time. That means that our text markers don't show up in
            //        the Fonts and Colors settings after install. They will only
            //        show up after the first solution has been opened.
            //
            //     2. Since this code is part of the package we can't execute it
            //        after uninstall. That means that the user will see our markers
            //        in the Fonts and Colors settings dialog even after he has
            //        uninstalled the package. That is very ugly!

            IVsFontAndColorCacheManager cacheManager = (IVsFontAndColorCacheManager)GetService(typeof(SVsFontAndColorCacheManager));

            if (cacheManager == null)
            {
                return;
            }

            // We need to know whether we already refreshed the fonts and colors
            // cache to reflect the text markers we registered. We have to do this
            // on a per-user basis.
            bool alreadyInitialized = false;

            try
            {
                string registryValueName = "InstalledVersion";
                string expectedVersion   = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                using (RegistryKey rootKey = UserRegistryRoot)
                    using (RegistryKey ourKey = rootKey.CreateSubKey(ProductName))
                    {
                        object registryValue      = ourKey.GetValue(registryValueName);
                        string initializedVersion = Convert.ToString(registryValue, CultureInfo.InvariantCulture);

                        alreadyInitialized = (initializedVersion == expectedVersion);

                        ourKey.SetValue(registryValueName, expectedVersion, RegistryValueKind.String);
                    }
            }
            catch
            {
                // Ignore any errors since it's not a big deal if we can't read
                // this setting. We just always refresh the cache in that case.
            }

            // Actually refresh the Fonts and Colors cache now if we detected we have
            // to do so.
            if (!alreadyInitialized)
            {
                ErrorHandler.ThrowOnFailure(cacheManager.ClearAllCaches());

                Guid categoryGuid = Guid.Empty;
                ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
                categoryGuid = Guids.GuidFontsAndColorsTextEditor;
                ErrorHandler.ThrowOnFailure(cacheManager.RefreshCache(ref categoryGuid));
            }
        }