/// <summary> /// Populates the maps that map from name -> scope info and GUID -> scope info /// </summary> private void PopulateScopeMaps() { ShellSettingsManager settingsManager = new ShellSettingsManager(this.serviceProvider); SettingsStore settingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration); // First build map of all registered scopes if (settingsStore.CollectionExists(KeyBindingTableRegKeyName)) { int itemCount = settingsStore.GetSubCollectionCount(KeyBindingTableRegKeyName); foreach (string str in settingsStore.GetSubCollectionNames(KeyBindingTableRegKeyName)) { string collectionName = Path.Combine(KeyBindingTableRegKeyName, str); Guid scopeId; if (!Guid.TryParse(str, out scopeId)) { continue; } Guid owningPackage; uint resourceId; bool allowNavKeyBinding = false; if (scopeId == VSConstants.GUID_VSStandardCommandSet97) { owningPackage = CLSID_VsEnvironmentPackage; resourceId = ID_Intl_Base + 18; } else { if (!settingsStore.PropertyExists(collectionName, PackageRegPropertyName)) { continue; } if (!Guid.TryParse(settingsStore.GetString(collectionName, PackageRegPropertyName), out owningPackage)) { continue; } string resIdString = settingsStore.GetString(collectionName, string.Empty); if (resIdString.StartsWith("#")) { resIdString = resIdString.Substring(1); } if (!uint.TryParse(resIdString, out resourceId)) { continue; } if (settingsStore.PropertyExists(collectionName, AllowNavKeyBindingPropertyName)) { allowNavKeyBinding = settingsStore.GetUInt32(collectionName, AllowNavKeyBindingPropertyName) == 0 ? false : true; } } string scopeName; if (!ErrorHandler.Succeeded(Shell.LoadPackageString(ref owningPackage, resourceId, out scopeName))) { continue; } KeybindingScope scopeInfo = new KeybindingScope(scopeName, scopeId, allowNavKeyBinding); this.scopeGuidToScopeInfoMap[scopeId] = scopeInfo; this.scopeNameToScopeInfoMap[scopeName] = scopeInfo; } } IVsEnumGuids scopeEnum = UIShell.EnumKeyBindingScopes(); // Random GUID the shell also skips ("Source Code Text Editor" scope) Guid toSkip = new Guid("{72F42A10-B1C5-11d0-A8CD-00A0C921A4D2}"); Guid[] scopes = new Guid[1]; uint fetched = 0; while (scopeEnum.Next((uint)scopes.Length, scopes, out fetched) == VSConstants.S_OK && fetched != 0) { // We already have info for this scope if (scopeGuidToScopeInfoMap.ContainsKey(scopes[0])) { continue; } // The shell skips this as a possible binding scope if (scopes[0] == toSkip) { continue; } string path = Path.Combine("Editors", scopes[0].ToString("B")); // If it isn't a registered scope, see if it is an editor factory if (!settingsStore.CollectionExists(path)) { continue; } if (!settingsStore.PropertyExists(path, PackageRegPropertyName)) { continue; } Guid packageGuid; if (!Guid.TryParse(settingsStore.GetString(path, PackageRegPropertyName), out packageGuid)) { continue; } if (!settingsStore.PropertyExists(path, DisplayNameRegPropertyName)) { continue; } string displayNameResIdStr = settingsStore.GetString(path, DisplayNameRegPropertyName); if (displayNameResIdStr.StartsWith("#")) { displayNameResIdStr = displayNameResIdStr.Substring(1); } uint displayNameResId; if (!uint.TryParse(displayNameResIdStr, out displayNameResId)) { continue; } string displayName; if (!ErrorHandler.Succeeded(shell.LoadPackageString(ref packageGuid, displayNameResId, out displayName))) { continue; } // NOTE: Is false the right default value? KeybindingScope scopeInfo = new KeybindingScope(displayName, scopes[0], allowNavKeyBinding: false); this.scopeGuidToScopeInfoMap[scopes[0]] = scopeInfo; this.scopeNameToScopeInfoMap[displayName] = scopeInfo; } }
public int GetSubCollectionCount([ComAliasName("OLE.LPCOLESTR")] string collectionPath, [ComAliasName("OLE.DWORD")] out uint subCollectionCount) { subCollectionCount = (uint)inner.GetSubCollectionCount(collectionPath); return(0); }