public Task InitializeAsync() { OleMenuCommandService commandService = _serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService == null) { _logger.WriteLine("OleMenuCommandService was not resolved"); return(Task.CompletedTask); } var id = 1; foreach (var iconType in ExtensionCatalogue.IconTypes) { var names = Enum.GetNames(iconType); var values = Enum.GetValues(iconType); for (var idx = 0; idx < names.Length; idx++) { var cmdidMyDynamicStartCommand = id * 100; var value = (int)values.GetValue(idx); var icon = new ExtensionMethodIcon(iconType, value); CommandID dynamicItemRootId = new CommandID(guidDynamicCommandsSet.SetId, cmdidMyDynamicStartCommand); var existing = commandService.FindCommand(dynamicItemRootId); if (existing != null) { commandService.RemoveCommand(existing); } var matchingMethods = _extensionsCacheService.ExtensionsForIcon(icon); if (matchingMethods.Any()) { DynamicItemMenuCommand dynamicMenuCommand = new DynamicItemMenuCommand( _extensionsCacheService, _invocationService, dynamicItemRootId, cmdidMyDynamicStartCommand, matchingMethods ) { Visible = false }; commandService.AddCommand(dynamicMenuCommand); } id++; } } return(Task.CompletedTask); }
ExtensionMethodIcon ToResourceIcon(ExtensionMethodIcon extensionIcon) { if (extensionIcon.IconType == typeof(TopLevelIcon)) { switch ((TopLevelIcon)extensionIcon.IconValue) { case TopLevelIcon.Translate: return(RemixIcon.RiAliensFill); case TopLevelIcon.BitStream: return(SimpleIcons.SiLaunchpad); case TopLevelIcon.Program: return(Ionicons5.IoHardwareChipSharp); case TopLevelIcon.Generic: return(Grommet_Icons.GrTools); } } return(extensionIcon); }
public object Resolve(ExtensionMethodIcon extensionIcon) { extensionIcon = ToResourceIcon(extensionIcon); var assembly = Assembly.GetExecutingAssembly(); var resources = assembly.GetManifestResourceNames(); var iconIndex = extensionIcon.IconValue; var collectionName = extensionIcon.IconType.Name; var maxPerCollection = 255; var partIndex = iconIndex / 255; var iconPosition = iconIndex % 255; var startIndex = partIndex * maxPerCollection; var collectionPartName = $"{extensionIcon.IconType.Name}_{startIndex}_{startIndex + maxPerCollection - 1}"; var resourceName = resources.Single(r => r.Contains(collectionPartName)); var pngStream = assembly.GetManifestResourceStream(resourceName); using (var image = new Bitmap(pngStream)) { using (var icon = new Bitmap(16, 16)) { for (var row = 0; row < 16; row++) { for (var col = 0; col < 16; col++) { var key = EnvironmentColors.ToolWindowTextBrushKey; var color = VSColorTheme.GetThemedColor(key); var isBright = color.GetBrightness() > 0.5; var pixel = image.GetPixel(iconPosition * 16 + col, row); var inverted = Color.FromArgb(pixel.ToArgb() ^ 0xFFFFFF); icon.SetPixel(col, row, isBright ? inverted : pixel); } } return(BitmapToImageSource(icon)); } } }
public DynamicItemMenuCommandFactory( ExtensionDeps deps, IExtensionInvocationService invocationService, IExtensionsCacheService extensionsCacheService, Guid commandsSetId, int cmdidMyDynamicStartCommand, ExtensionMethodIcon icon ) : base(deps) { _invocationService = invocationService; _extensionsCacheService = extensionsCacheService; _commandsSetId = commandsSetId; _cmdidMyDynamicStartCommand = cmdidMyDynamicStartCommand; _icon = icon; _ens.OnExtensionsReloaded += (s, a) => { Reload(); }; }
public List <ExtensionMethodInfo> ExtensionsForIcon(ExtensionMethodIcon icon) { _mapIconToExtensions.TryGetValue(icon.ToString(), out var result); return(result ?? new List <ExtensionMethodInfo>()); }