public AcuminatorThemeChangedEventArgs(IVsFontAndColorStorage fontAndColorStorage, IClassificationTypeRegistryService classificationTypeRegistry, IClassificationFormatMap formatMap) { FontAndColorStorage = fontAndColorStorage.CheckIfNull(nameof(fontAndColorStorage)); ClassificationTypeRegistry = classificationTypeRegistry.CheckIfNull(nameof(classificationTypeRegistry)); FormatMap = formatMap; }
public FindResultsClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService, DTE2 dte) : base( settingsService, vsEventsService, typeRegistryService, formatMapService, fontAndColorStorageService, "find results") { this.Dte = dte; IsEnabled = true; AddClassificationType(ClassificationNames.FindResultsOutputMatch); OutputWindowTextClassificationOverride = ClassificationNames.OutputText; ShouldOverrideOutputWindowTextClassification = true; RefreshClassifications(); }
FontInfo?GetTextEditorFontInfo() { IVsFontAndColorStorage fontStorage = (IVsFontAndColorStorage)VSAsmPackage.GetGlobalService(typeof(SVsFontAndColorStorage)); if (fontStorage == null) { return(null); } if (fontStorage.OpenCategory(TextEditorFontGuid, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) != VSConstants.S_OK) { return(null); } FontInfo[] info = new FontInfo[1]; int result = fontStorage.GetFont(null, info); fontStorage.CloseCategory(); if (result != VSConstants.S_OK) { return(null); } return(info[0]); }
public FindResultsClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService, DTE2 dte) : base(settingsService, vsEventsService, typeRegistryService, formatMapService, fontAndColorStorageService, "find results") { this.Dte = dte; IsEnabled = true; AddClassificationType(ClassificationNames.FindResultsOutputMatch); OutputWindowTextClassificationOverride = ClassificationNames.OutputText; ShouldOverrideOutputWindowTextClassification = true; RefreshClassifications(); }
internal static void AdjustFontSize(IServiceProvider serviceProvider, Guid category, short change) { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)serviceProvider.GetService(typeof(SVsFontAndColorStorage)); IVsFontAndColorUtilities utilities = storage as IVsFontAndColorUtilities; LOGFONTW[] pLOGFONT = new LOGFONTW[1]; FontInfo[] pInfo = new FontInfo[1]; ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES))); try { if (!ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo))) { return; } pInfo[0].wPointSize = checked ((ushort)(pInfo[0].wPointSize + change)); ErrorHandler.ThrowOnFailure(storage.SetFont(pInfo)); ErrorHandler.ThrowOnFailure(utilities.FreeFontInfo(pInfo)); } finally { storage.CloseCategory(); } }
private void EnsureFontsAndColors() { if (this.fontsAndColors == null) { this.fontsAndColors = this.packageState.GetService <IVsFontAndColorStorage>(); } }
public PresentationModeFontChanger(IPresentationModeState state) { this.packageState = state; this.enabled = false; this.settings = SettingsContext.GetSettings(); this.categories = GetCategories(); this.fontsAndColors = state.GetService <IVsFontAndColorStorage>(); }
public PresentationModeFontChanger(IPresentationModeState state) { this.packageState = state; this.enabled = false; this.settings = SettingsContext.GetSettings(); this.categories = GetCategories(); this.fontsAndColors = state.GetService<IVsFontAndColorStorage>(); }
protected ClassificationColorManager(IServiceProvider serviceProvider) { fontAndColorStorage = serviceProvider.GetService(typeof(SVsFontAndColorStorage)) as IVsFontAndColorStorage; fontAndColorUtilities = serviceProvider.GetService(typeof(SVsFontAndColorStorage)) as IVsFontAndColorUtilities; // Initialize theme engine themeEngine = new VisualStudioThemeEngine(serviceProvider); themeEngine.OnThemeChanged += themeEngine_OnThemeChanged; }
public FontAndColorProvider() { ThreadHelper.ThrowIfNotOnUIThread(); _storage = (IVsFontAndColorStorage)GetGlobalService(typeof(SVsFontAndColorStorage)); Assumes.Present(_storage); ErrorHandler.ThrowOnFailure(_storage.OpenCategory(Constants.FontAndColorsCategoryGuid, _storageFlags)); _service = (FontAndColorService)GetGlobalService(typeof(FontAndColorService)); _service.ItemsChanged += FontAndColorItemsChanged; FontAndColorState = new FontAndColorState(this); }
private async Task LoadSystemTextSettingsAsync(CancellationToken cancellationToken) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { #pragma warning disable SA1129 // Do not use default value type constructor LOGFONTW[] fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] info = new FontInfo[] { new FontInfo() }; #pragma warning restore SA1129 // Do not use default value type constructor if (storage.GetFont(fnt, info) == Microsoft.VisualStudio.VSConstants.S_OK) { var fontSize = info[0].wPointSize; if (fontSize > 0) { ResourceAdornmentManager.TextSize = fontSize; } } } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; // Get the color value configured for regular string display if (storage.GetItem("String", info) == Microsoft.VisualStudio.VSConstants.S_OK) { var win32Color = (int)info[0].crForeground; int r = win32Color & 0x000000FF; int g = (win32Color & 0x0000FF00) >> 8; int b = (win32Color & 0x00FF0000) >> 16; var textColor = Color.FromRgb((byte)r, (byte)g, (byte)b); ResourceAdornmentManager.TextForegroundColor = textColor; } } } catch (Exception exc) { ExceptionHelper.Log(exc, "Error in LoadSystemTextSettingsAsync"); } }
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>(); }
public ClassificationFormatManager(System.IServiceProvider serviceProvider) { this.storage = (IVsFontAndColorStorage)serviceProvider.GetService(typeof(SVsFontAndColorStorage)); this.storage2 = (IVsFontAndColorStorage2)this.storage; if (this.storage == null) { throw new InvalidOperationException("Unable to obtain an IVsFontAndColorStorage."); } // Note: textManager also implements IVsTextManager2 in case we need to call ResetColorableItems. IConnectionPointContainer textManager = (IConnectionPointContainer)serviceProvider.GetService(typeof(SVsTextManager)); Guid interfaceGuid = typeof(IVsTextManagerEvents).GUID; textManager.FindConnectionPoint(ref interfaceGuid, out IConnectionPoint connectionPoint); if (connectionPoint == null) { throw new InvalidOperationException("The connection point was null."); } connectionPoint.Advise(this, out uint cookie); // Find all ClassificationFormatBase-derived types in this assembly, get their category GUIDs and names, and // save them for when we need to refresh a category's fonts and colors. IEnumerable <TypeInfo> formatTypes = typeof(ClassificationFormatManager).Assembly.DefinedTypes .Where(t => !t.IsNestedPrivate && t.IsSubclassOf(typeof(ClassificationFormatBase))); foreach (TypeInfo formatType in formatTypes) { // See if the format type or any of its containing types has an associated category. TypeInfo categoryType = formatType; while (categoryType != null) { var category = categoryType.GetCustomAttribute <ClassificationFormatCategoryAttribute>(); if (category != null && category.Category != VsFormatCategory.TextEditor) { // We found a non-TextEditor category, so store it along with the format name. NameAttribute name = formatType.GetCustomAttribute <NameAttribute>(); if (name != null) { string formatName = name.Name; this.formatNameToCategoryMap.Add(formatName, category.Guid); } break; } // Keep walking up the chain of declaring/containing types. categoryType = categoryType.DeclaringType?.GetTypeInfo(); } } }
static void InCategory(IVsFontAndColorStorage storage, Guid category, Action callback) { var hresult = storage.OpenCategory(ref category, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS)); try { if (hresult == 0) callback(); } finally { storage.CloseCategory(); } }
public OutputWindowPaneClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService, string classificationMapName) : base(settingsService, vsEventsService, typeRegistryService, formatMapService, fontAndColorStorageService, classificationMapName) { }
public OutputWindowPaneClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService, string classificationMapName) : base( settingsService, vsEventsService, typeRegistryService, formatMapService, fontAndColorStorageService, classificationMapName) { }
static void InCategory(IVsFontAndColorStorage storage, Guid category, Action callback) { var hresult = storage.OpenCategory(ref category, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS)); try { if (hresult == 0) { callback(); } } finally { storage.CloseCategory(); } }
private static void SaveColor(IVsFontAndColorStorage vsStorage, ColorKey colorKey, Color color) { var colorableItemInfo = new ColorableItemInfo(); if (colorKey.IsForeground) { colorableItemInfo.bForegroundValid = 1; colorableItemInfo.crForeground = (uint)ColorTranslator.ToWin32(color); } else { colorableItemInfo.bBackgroundValid = 1; colorableItemInfo.crBackground = (uint)ColorTranslator.ToWin32(color); } ErrorHandler.ThrowOnFailure(vsStorage.SetItem(colorKey.Name, new[] { colorableItemInfo })); }
private static void SaveColor(IVsFontAndColorStorage vsStorage, ColorKey colorKey, System.Drawing.Color color) { Debug.WriteLine($"GeneralOptions.SaveColoR keyName={colorKey.Name} color={color}"); ThreadHelper.ThrowIfNotOnUIThread(); ColorableItemInfo[] arr = new ColorableItemInfo[1]; ErrorHandler.ThrowOnFailure(vsStorage.GetItem(colorKey.Name, arr)); if (colorKey.IsForeground) { arr[0].bForegroundValid = 1; arr[0].crForeground = (uint)ColorTranslator.ToWin32(color); } else { arr[0].bBackgroundValid = 1; arr[0].crBackground = (uint)ColorTranslator.ToWin32(color); } ErrorHandler.ThrowOnFailure(vsStorage.SetItem(colorKey.Name, arr)); }
private Color FromColorRef(IVsFontAndColorStorage vsStorage, uint colorValue) { var vsUtil = (IVsFontAndColorUtilities)vsStorage; int type; ErrorHandler.ThrowOnFailure(vsUtil.GetColorType(colorValue, out type)); switch ((__VSCOLORTYPE)type) { case __VSCOLORTYPE.CT_SYSCOLOR: case __VSCOLORTYPE.CT_RAW: return(ColorTranslator.FromWin32((int)colorValue)); case __VSCOLORTYPE.CT_COLORINDEX: { var array = new COLORINDEX[1]; ErrorHandler.ThrowOnFailure(vsUtil.GetEncodedIndex(colorValue, array)); uint rgb; ErrorHandler.ThrowOnFailure(vsUtil.GetRGBOfIndex(array[0], out rgb)); return(ColorTranslator.FromWin32((int)rgb)); }; case __VSCOLORTYPE.CT_VSCOLOR: { var vsUIShell = (IVsUIShell2)GetService(typeof(SVsUIShell)); int index; ErrorHandler.ThrowOnFailure(vsUtil.GetEncodedVSColor(colorValue, out index)); uint rgbValue; ErrorHandler.ThrowOnFailure(vsUIShell.GetVSSysColorEx(index, out rgbValue)); return(ColorTranslator.FromWin32((int)rgbValue)); }; case __VSCOLORTYPE.CT_AUTOMATIC: case __VSCOLORTYPE.CT_TRACK_BACKGROUND: case __VSCOLORTYPE.CT_TRACK_FOREGROUND: case __VSCOLORTYPE.CT_INVALID: // These values should never show up because we passed the FCSF_NOAUTOCOLORS flag. Everything // should be CT_RAW / CT_SYSCOLOR throw new Exception("Invalid color value"); default: Contract.GetInvalidEnumException((__VSCOLORTYPE)type); return(default(Color)); } }
private void LoadColorsCore(IVsFontAndColorStorage vsStorage) { foreach (var colorKey in ColorKeyList) { ColorInfo colorInfo; try { var color = LoadColor(vsStorage, colorKey); colorInfo = new ColorInfo(colorKey, color); } catch (Exception ex) { VimTrace.TraceError(ex); colorInfo = new ColorInfo(colorKey, Color.Black, isValid: false); } _colorMap[colorKey] = colorInfo; } }
public VscClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService, string mapName) { this.SettingsService = settingsService; this.VisualStudioEventsService = vsEventsService; this.ClassificationTypeRegistryService = typeRegistryService; this.ClassificationFormatMapService = formatMapService; this.FontAndColorStorageService = fontAndColorStorageService; this.ClassificationMapName = mapName; vsEventsService.AfterVisualStudioThemeChanged += (s, e) => RefreshClassifications(); vsEventsService.AfterTextColorSettingsChanged += (s, e) => RefreshClassifications(); vsEventsService.AfterVSCommandsColorSettingsChanged += (s, e) => RefreshClassifications(); }
public VscClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService, string mapName) { this.SettingsService = settingsService; this.VisualStudioEventsService = vsEventsService; this.ClassificationTypeRegistryService = typeRegistryService; this.ClassificationFormatMapService = formatMapService; this.FontAndColorStorageService = fontAndColorStorageService; this.ClassificationMapName = mapName; vsEventsService.AfterVisualStudioThemeChanged += (s, e) => RefreshClassifications(); vsEventsService.AfterTextColorSettingsChanged += (s, e) => RefreshClassifications(); vsEventsService.AfterVSCommandsColorSettingsChanged += (s, e) => RefreshClassifications(); }
private static System.Drawing.Color LoadColor(IServiceProvider Site, IVsFontAndColorStorage vsStorage, ColorKey colorKey) { ThreadHelper.ThrowIfNotOnUIThread(); var arr = new ColorableItemInfo[1]; ErrorHandler.ThrowOnFailure(vsStorage.GetItem(colorKey.Name, arr)); var isValid = colorKey.IsForeground ? arr[0].bForegroundValid : arr[0].bBackgroundValid; if (isValid == 0) { throw new Exception(); } var colorRef = colorKey.IsForeground ? arr[0].crForeground : arr[0].crBackground; var color = FromColorRef(Site, vsStorage, colorRef); Debug.WriteLine($"GeneralOptions.LoadColoR keyName={colorKey.Name} color={color}"); return(color); }
private void LoadColorsCore(IServiceProvider Site, IVsFontAndColorStorage vsStorage) { ThreadHelper.ThrowIfNotOnUIThread(); foreach (var colorKey in s_colorKeyList) { ColorInfo colorInfo; try { var color = LoadColor(Site, vsStorage, colorKey); colorInfo = new ColorInfo(colorKey, color); } catch (Exception ex) { Debug.WriteLine($"PeasyMotion exception in Options.LoadColorsCore: {ex.ToString()}"); colorInfo = new ColorInfo(colorKey, System.Drawing.Color.Black, isValid: false); } colorMap[colorKey] = colorInfo; } }
public HighlightWordFormatDefinition() { // Default the BackgroundColor to a transparent grey BackgroundColor = Color.FromArgb(127, 170, 170, 170); DisplayName = "Highlight Word"; ZOrder = 5; // If possible, set the Background color to match the Highlighted Reference color IVsFontAndColorStorage colorStorage = ServiceProvider.GlobalProvider.GetService(typeof(IVsFontAndColorStorage)) as IVsFontAndColorStorage; ColorableItemInfo[] itemInfoOut = new ColorableItemInfo[1]; if (colorStorage.OpenCategory(ref _textEditorCategory, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VSConstants.S_OK) { if (colorStorage.GetItem(_itemName, itemInfoOut) == VSConstants.S_OK) { uint hexColor = itemInfoOut[0].crBackground; BackgroundColor = Color.FromArgb(255, (byte)hexColor, (byte)(hexColor >> 8), (byte)(hexColor >> 16)); } colorStorage.CloseCategory(); } }
private Color LoadColor(IVsFontAndColorStorage vsStorage, ColorKey colorKey) { var array = new ColorableItemInfo[1]; ErrorHandler.ThrowOnFailure(vsStorage.GetItem(colorKey.Name, array)); int isValid = colorKey.IsForeground ? array[0].bForegroundValid : array[0].bBackgroundValid; if (isValid == 0) { throw new Exception(); } uint colorRef = colorKey.IsForeground ? array[0].crForeground : array[0].crBackground; return(FromColorRef(vsStorage, colorRef)); }
static Tuple <Color?, Color?> TryGetItem(IVsFontAndColorStorage storage, string item) { Tuple <Color?, Color?> result = null; // load specific category to prevent our own format classifications being loaded InCategory(storage, Microsoft.VisualStudio.Editor.DefGuidList.guidTextEditorFontCategory, () => { ColorableItemInfo[] colors = new ColorableItemInfo[1]; var hresult = storage.GetItem(item, colors); if (hresult == 0) { result = Tuple.Create <Color?, Color?>(ParseColor(colors[0].crForeground), ParseColor(colors[0].crBackground)); } else { result = Tuple.Create <Color?, Color?>(null, null); } }); return(result); }
public OutputClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService) : base( settingsService, vsEventsService, typeRegistryService, formatMapService, fontAndColorStorageService, "output") { IsEnabled = true; // TODO: get from actual configuration and react to any changes var Config = new Configuration(); AddClassificationType(ClassificationNames.OutputError, Config.OutputErrorClassificationPattern); AddClassificationType(ClassificationNames.OutputWarning, Config.OutputWarningClassificationPattern); AddClassificationType(ClassificationNames.OutputInformation, Config.OutputInformationClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummarySuccess, Config.BuildOutputBuildSummarySuccessClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummaryFailed, Config.BuildOutputBuildSummaryFailedClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputCodeContractsInformation, Config.BuildOutputCodeContractsInformationClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputProjectBuildStart, Config.BuildOutputProjectBuildStartClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummary, Config.BuildOutputBuildSummaryClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummaryTotal, Config.BuildOutputBuildSummaryTotalClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputProjectBuildSkipped, Config.BuildOutputProjectBuildSkippedClassificationPattern); AddClassificationType(ClassificationNames.TfsOutputError, Config.TfsOutputErrorClassificationPattern); AddClassificationType(ClassificationNames.TfsOutputWarning, Config.TfsOutputWarningClassificationPattern); AddClassificationType(ClassificationNames.TfsOutputSuccess, Config.TfsOutputSuccessClassificationPattern); OutputWindowTextClassificationOverride = ClassificationNames.OutputText; ShouldOverrideOutputWindowTextClassification = true; RefreshClassifications(); }
public OutputClassifier( IVscSettingsService settingsService, IVisualStudioEventsService vsEventsService, IClassificationTypeRegistryService typeRegistryService, IClassificationFormatMapService formatMapService, IVsFontAndColorStorage fontAndColorStorageService) : base(settingsService, vsEventsService, typeRegistryService, formatMapService, fontAndColorStorageService, "output") { IsEnabled = true; // TODO: get from actual configuration and react to any changes var Config = new Configuration(); AddClassificationType(ClassificationNames.OutputError, Config.OutputErrorClassificationPattern); AddClassificationType(ClassificationNames.OutputWarning, Config.OutputWarningClassificationPattern); AddClassificationType(ClassificationNames.OutputInformation, Config.OutputInformationClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummarySuccess, Config.BuildOutputBuildSummarySuccessClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummaryFailed, Config.BuildOutputBuildSummaryFailedClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputCodeContractsInformation, Config.BuildOutputCodeContractsInformationClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputProjectBuildStart, Config.BuildOutputProjectBuildStartClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummary, Config.BuildOutputBuildSummaryClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputBuildSummaryTotal, Config.BuildOutputBuildSummaryTotalClassificationPattern); AddClassificationType(ClassificationNames.BuildOutputProjectBuildSkipped, Config.BuildOutputProjectBuildSkippedClassificationPattern); AddClassificationType(ClassificationNames.TfsOutputError, Config.TfsOutputErrorClassificationPattern); AddClassificationType(ClassificationNames.TfsOutputWarning, Config.TfsOutputWarningClassificationPattern); AddClassificationType(ClassificationNames.TfsOutputSuccess, Config.TfsOutputSuccessClassificationPattern); OutputWindowTextClassificationOverride = ClassificationNames.OutputText; ShouldOverrideOutputWindowTextClassification = true; RefreshClassifications(); }
private static System.Drawing.Color FromColorRef(IServiceProvider Site, IVsFontAndColorStorage vsStorage, uint colorValue) { ThreadHelper.ThrowIfNotOnUIThread(); var vsUtil = (IVsFontAndColorUtilities)vsStorage; ErrorHandler.ThrowOnFailure(vsUtil.GetColorType(colorValue, out int type)); switch ((__VSCOLORTYPE)type) { case __VSCOLORTYPE.CT_SYSCOLOR: case __VSCOLORTYPE.CT_RAW: return(ColorTranslator.FromWin32((int)colorValue)); case __VSCOLORTYPE.CT_COLORINDEX: { var array = new COLORINDEX[1]; ErrorHandler.ThrowOnFailure(vsUtil.GetEncodedIndex(colorValue, array)); ErrorHandler.ThrowOnFailure(vsUtil.GetRGBOfIndex(array[0], out uint rgb)); return(ColorTranslator.FromWin32((int)rgb)); }; case __VSCOLORTYPE.CT_VSCOLOR: { var vsUIShell = (IVsUIShell2)Site.GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(vsUtil.GetEncodedVSColor(colorValue, out int index)); ErrorHandler.ThrowOnFailure(vsUIShell.GetVSSysColorEx(index, out uint rgbValue)); return(ColorTranslator.FromWin32((int)rgbValue)); }; case __VSCOLORTYPE.CT_AUTOMATIC: case __VSCOLORTYPE.CT_TRACK_BACKGROUND: case __VSCOLORTYPE.CT_TRACK_FOREGROUND: case __VSCOLORTYPE.CT_INVALID: return(System.Drawing.Color.Transparent); default: return(System.Drawing.Color.Black); } }
private static void GetSize() { try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)Package.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = (int)Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; storage.GetItem("Plain Text", info); _backgroundColor = ConvertFromWin32Color((int)info[0].crBackground); } } catch { } }
public static async Task AdjustFontSizeAsync(string categoryGuid, short change) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsFontAndColorStorage storage = await VS.Shell.GetFontAndColorStorageAsync(); Assumes.Present(storage); // ReSharper disable once SuspiciousTypeConversion.Global var utilities = storage as IVsFontAndColorUtilities; if (utilities == null) { return; } var pLOGFONT = new LOGFONTW[1]; var pInfo = new FontInfo[1]; var category = new Guid(categoryGuid); ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES))); try { if (!ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo))) { return; } pInfo[0].wPointSize = checked ((ushort)(pInfo[0].wPointSize + change)); ErrorHandler.ThrowOnFailure(storage.SetFont(pInfo)); ErrorHandler.ThrowOnFailure(utilities.FreeFontInfo(pInfo)); } finally { storage.CloseCategory(); } }
private async void HandleOpenSolution(object sender = null, EventArgs e = null) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(); //Use nested methods to avoid prompt (and need) for multiple MainThead checks/switches IEnumerable <ProjectItem> RecurseProjectItems(ProjectItems projItems) { if (projItems != null) { foreach (ProjectItem item in projItems) { foreach (var subItem in RecurseProjectItem(item)) { yield return(subItem); } } } } IEnumerable <ProjectItem> RecurseProjectItem(ProjectItem item) { yield return(item); foreach (var subItem in RecurseProjectItems(item.ProjectItems)) { yield return(subItem); } } IEnumerable <ProjectItem> GetProjectFiles(Project proj) { foreach (ProjectItem item in RecurseProjectItems(proj.ProjectItems)) { yield return(item); } } // TODO: handle res files being removed or added to a project - currently will be ignored. Issue #2 // Get all resource files from the solution // Do this now, rather than in adornment manager for performance and to avoid thread issues if (await this.GetServiceAsync(typeof(DTE)) is DTE dte) { foreach (var project in dte.Solution.Projects) { foreach (var solFile in GetProjectFiles((Project)project)) { var filePath = solFile.FileNames[0]; var fileExt = System.IO.Path.GetExtension(filePath); // Only interested in resx files if (fileExt.Equals(".resx")) { // Only want neutral language ones, not locale specific versions if (!System.IO.Path.GetFileNameWithoutExtension(filePath).Contains(".")) { ResourceAdornmentManager.ResourceFiles.Add(filePath); } } } } IVsFontAndColorStorage storage = (IVsFontAndColorStorage)VSPackage.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); // Seem like reasonabel defaults as should be visible on light & dark theme int _fontSize = 10; Color _textColor = Colors.Gray; if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; // Get the color value configured for regular string display storage.GetItem("String", info); var win32Color = (int)info[0].crForeground; int r = win32Color & 0x000000FF; int g = (win32Color & 0x0000FF00) >> 8; int b = (win32Color & 0x00FF0000) >> 16; _textColor = Color.FromRgb((byte)r, (byte)g, (byte)b); } ResourceAdornmentManager.TextSize = _fontSize; ResourceAdornmentManager.TextForegroundColor = _textColor; var plural = ResourceAdornmentManager.ResourceFiles.Count > 1 ? "s" : string.Empty; (await this.GetServiceAsync(typeof(DTE)) as DTE).StatusBar.Text = $"String Resource Visualizer initialized with {ResourceAdornmentManager.ResourceFiles.Count} resource file{plural}."; } }
private Color FromColorRef(IVsFontAndColorStorage vsStorage, uint colorValue) { var vsUtil = (IVsFontAndColorUtilities)vsStorage; int type; ErrorHandler.ThrowOnFailure(vsUtil.GetColorType(colorValue, out type)); switch ((__VSCOLORTYPE)type) { case __VSCOLORTYPE.CT_SYSCOLOR: case __VSCOLORTYPE.CT_RAW: return ColorTranslator.FromWin32((int)colorValue); case __VSCOLORTYPE.CT_COLORINDEX: { var array = new COLORINDEX[1]; ErrorHandler.ThrowOnFailure(vsUtil.GetEncodedIndex(colorValue, array)); uint rgb; ErrorHandler.ThrowOnFailure(vsUtil.GetRGBOfIndex(array[0], out rgb)); return ColorTranslator.FromWin32((int)rgb); }; case __VSCOLORTYPE.CT_VSCOLOR: { var vsUIShell = (IVsUIShell2)GetService(typeof(SVsUIShell)); int index; ErrorHandler.ThrowOnFailure(vsUtil.GetEncodedVSColor(colorValue, out index)); uint rgbValue; ErrorHandler.ThrowOnFailure(vsUIShell.GetVSSysColorEx(index, out rgbValue)); return ColorTranslator.FromWin32((int)rgbValue); }; case __VSCOLORTYPE.CT_AUTOMATIC: case __VSCOLORTYPE.CT_TRACK_BACKGROUND: case __VSCOLORTYPE.CT_TRACK_FOREGROUND: case __VSCOLORTYPE.CT_INVALID: // These values should never show up because we passed the FCSF_NOAUTOCOLORS flag. Everything // should be CT_RAW / CT_SYSCOLOR throw new Exception("Invalid color value"); default: Contract.GetInvalidEnumException((__VSCOLORTYPE)type); return default(Color); } }
private Color LoadColor(IVsFontAndColorStorage vsStorage, ColorKey colorKey) { var array = new ColorableItemInfo[1]; ErrorHandler.ThrowOnFailure(vsStorage.GetItem(colorKey.Name, array)); int isValid = colorKey.IsForeground ? array[0].bForegroundValid : array[0].bBackgroundValid; if (isValid == 0) { throw new Exception(); } uint colorRef = colorKey.IsForeground ? array[0].crForeground : array[0].crBackground; return FromColorRef(vsStorage, colorRef); }
private void LoadColorsCore(IVsFontAndColorStorage vsStorage) { foreach (var colorKey in ColorKeyList) { ColorInfo colorInfo; try { var color = LoadColor(vsStorage, colorKey); colorInfo = new ColorInfo(colorKey, color); } catch (Exception ex) { VimTrace.TraceError(ex); colorInfo = new ColorInfo(colorKey, Color.Black, isValid: false); } _colorMap[colorKey] = colorInfo; } }
static Tuple<Color?, Color?> TryGetItem(IVsFontAndColorStorage storage, string item) { Tuple<Color?, Color?> result = null; // load specific category to prevent our own format classifications being loaded InCategory(storage, Microsoft.VisualStudio.Editor.DefGuidList.guidTextEditorFontCategory, () => { ColorableItemInfo[] colors = new ColorableItemInfo[1]; var hresult = storage.GetItem(item, colors); if (hresult == 0) { result = Tuple.Create<Color?, Color?>(ParseColor(colors[0].crForeground), ParseColor(colors[0].crBackground)); } else { result = Tuple.Create<Color?, Color?>(null, null); } }); return result; }
public FontAndColorsResourceDictionary(IVsFontAndColorStorage fncStorage) { this.fncStorage = fncStorage; }
private void EnsureStorage() { if (!myStorageOpen) { if (myStorage == null) { myStorage = (IVsFontAndColorStorage)myServiceProvider.GetService(typeof(IVsFontAndColorStorage)); } ErrorHandler.ThrowOnFailure(myStorage.OpenCategory(ref myCategoryGuid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS))); myStorageOpen = true; } }
private static void SaveColor(IVsFontAndColorStorage vsStorage, ColorKey colorKey, Color color) { var colorableItemInfo = new ColorableItemInfo(); if (colorKey.IsForeground) { colorableItemInfo.bForegroundValid = 1; colorableItemInfo.crForeground = (uint)ColorTranslator.ToWin32(color); } else { colorableItemInfo.bBackgroundValid = 1; colorableItemInfo.crBackground = (uint)ColorTranslator.ToWin32(color); } ErrorHandler.ThrowOnFailure(vsStorage.SetItem(colorKey.Name, new[] { colorableItemInfo })); }
public FontAndColorsHelper() { fncStorage = (IVsFontAndColorStorage)Package.GetGlobalService(typeof(SVsFontAndColorStorage)); fncUtils = (IVsFontAndColorUtilities)Package.GetGlobalService(typeof(SVsFontAndColorStorage)); }