public IEnumerable <AutoLoadPackage> GetAutoLoadPackages() { foreach (string autoLoadContextGuidString in _configurationStore.GetSubCollectionNames(_autoLoadPackagesPath)) { //Each path here is a context GUID Guid contextGuid = Guid.Empty; if (!Guid.TryParse(autoLoadContextGuidString, out contextGuid)) { continue; } string packagesPath = Path.Combine(_autoLoadPackagesPath, autoLoadContextGuidString); string contextName = GetUIContextName(autoLoadContextGuidString); bool isRuleBasedUIContext = IsRuleBasedUIContext(autoLoadContextGuidString); string uiContextExpression = string.Empty; if (isRuleBasedUIContext) { string rulePath = Path.Combine(_uIContextRulesPath, autoLoadContextGuidString); var expression = new StringBuilder(); foreach (string expressionName in _configurationStore.GetPropertyNames(rulePath)) { if (expressionName != "" && expressionName != "Expression" && expressionName != "Delay") { expression.Append(_configurationStore.GetString(rulePath, expressionName) + "|"); } } uiContextExpression = expression.ToString(); } foreach (string packageGuidString in _configurationStore.GetPropertyNames(packagesPath)) { Guid packageGuid = Guid.Empty; if (Guid.TryParse(packageGuidString, out packageGuid)) { yield return(new AutoLoadPackage(packageGuid, contextGuid, contextName, isRuleBasedUIContext, uiContextExpression, _configurationStore)); } } } }
/// <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; } }
private IPythonInterpreterFactoryProvider[] LoadProviders( SettingsStore store, IServiceProvider serviceProvider ) { var seen = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var catalog = new List <ComposablePartCatalog>(); if (store.CollectionExists(SuppressFactoryProvidersCollection)) { return(new IPythonInterpreterFactoryProvider[0]); } if (store.CollectionExists(FactoryProvidersCollection)) { foreach (var idStr in store.GetSubCollectionNames(FactoryProvidersCollection)) { var key = FactoryProvidersCollection + "\\" + idStr; LoadOneProvider( store.GetString(key, FactoryProviderCodeBaseSetting, ""), seen, catalog, _activityLog ); } } foreach (var baseKey in new[] { Registry.CurrentUser, Registry.LocalMachine }) { using (var key = baseKey.OpenSubKey(FactoryProvidersRegKey)) { if (key != null) { foreach (var idStr in key.GetSubKeyNames()) { using (var subkey = key.OpenSubKey(idStr)) { if (subkey != null) { LoadOneProvider( subkey.GetValue(FactoryProviderCodeBaseSetting, "") as string, seen, catalog, _activityLog ); } } } } } } if (!catalog.Any()) { LoadOneProvider( typeof(CPythonInterpreterFactoryConstants).Assembly.Location, seen, catalog, _activityLog ); } const string FailedToImportMessage = "Failed to import factory providers"; var providers = new List <IPythonInterpreterFactoryProvider>(); var serviceProviderProvider = new MockExportProvider(); if (serviceProvider != null) { serviceProviderProvider.SetExport(typeof(SVsServiceProvider), () => serviceProvider); } foreach (var part in catalog) { var container = new CompositionContainer(part, serviceProviderProvider); try { foreach (var provider in container.GetExports <IPythonInterpreterFactoryProvider>()) { if (provider.Value != null) { providers.Add(provider.Value); } } } catch (CompositionException ex) { LogException(_activityLog, FailedToImportMessage, null, ex, ex.Errors); } catch (ReflectionTypeLoadException ex) { LogException(_activityLog, FailedToImportMessage, null, ex, ex.LoaderExceptions); } catch (Exception ex) { LogException(_activityLog, FailedToImportMessage, null, ex); } } return(providers.ToArray()); }
private IPythonInterpreterFactoryProvider[] LoadProviders( SettingsStore store, IServiceProvider serviceProvider ) { var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase); var catalog = new List<ComposablePartCatalog>(); if (store.CollectionExists(SuppressFactoryProvidersCollection)) { return new IPythonInterpreterFactoryProvider[0]; } if (store.CollectionExists(FactoryProvidersCollection)) { foreach (var idStr in store.GetSubCollectionNames(FactoryProvidersCollection)) { var key = FactoryProvidersCollection + "\\" + idStr; LoadOneProvider( store.GetString(key, FactoryProviderCodeBaseSetting, ""), seen, catalog, _activityLog ); } } foreach (var baseKey in new[] { Registry.CurrentUser, Registry.LocalMachine }) { using (var key = baseKey.OpenSubKey(FactoryProvidersRegKey)) { if (key != null) { foreach (var idStr in key.GetSubKeyNames()) { using (var subkey = key.OpenSubKey(idStr)) { if (subkey != null) { LoadOneProvider( subkey.GetValue(FactoryProviderCodeBaseSetting, "") as string, seen, catalog, _activityLog ); } } } } } } if (!catalog.Any()) { LoadOneProvider( typeof(CPythonInterpreterFactoryConstants).Assembly.Location, seen, catalog, _activityLog ); } const string FailedToImportMessage = "Failed to import factory providers"; var providers = new List<IPythonInterpreterFactoryProvider>(); var serviceProviderProvider = new MockExportProvider(); if (serviceProvider != null) { serviceProviderProvider.SetExport(typeof(SVsServiceProvider), () => serviceProvider); } foreach (var part in catalog) { var container = new CompositionContainer(part, serviceProviderProvider); try { foreach (var provider in container.GetExports<IPythonInterpreterFactoryProvider>()) { if (provider.Value != null) { providers.Add(provider.Value); } } } catch (CompositionException ex) { LogException(_activityLog, FailedToImportMessage, null, ex, ex.Errors); } catch (ReflectionTypeLoadException ex) { LogException(_activityLog, FailedToImportMessage, null, ex, ex.LoaderExceptions); } catch (Exception ex) { LogException(_activityLog, FailedToImportMessage, null, ex); } } return providers.ToArray(); }
public int GetSubCollectionName([ComAliasName("OLE.LPCOLESTR")] string collectionPath, [ComAliasName("OLE.DWORD")] uint index, out string subCollectionName) { subCollectionName = inner.GetSubCollectionNames(collectionPath).ElementAt((int)index); return(0); }