Пример #1
0
        public AutoLoadPackage(Guid packageGuid, Guid contextGuid, string contextName, bool isRuleBasedUIContext, string contextTerms, SettingsStore configurationStore)
        {
            PackageGuid          = packageGuid;
            AutoLoadContextGuid  = contextGuid;
            AutoLoadContextName  = contextName;
            IsRuleBasedUIContext = isRuleBasedUIContext;
            UIContextTerms       = contextTerms;

            string packageInfoPath           = Path.Combine(_packagesPath, packageGuid.ToString("B"));
            string autoLoadConfigurationPath = Path.Combine(_autoLoadPackagesPath, contextGuid.ToString("B"));

            if (configurationStore.CollectionExists(packageInfoPath))
            {
                PackageName = configurationStore.GetString(packageInfoPath, string.Empty, "Unknown").Split(',')[0];
                string moduleName = configurationStore.GetString(packageInfoPath, "Class", null) ?? Path.GetFileName(configurationStore.GetString(packageInfoPath, "InProcServer32", string.Empty));
                ModuleName     = moduleName.Split(',')[0];
                IsAsyncPackage = configurationStore.GetBoolean(packageInfoPath, "AllowsBackgroundLoad", false);
            }

            if (configurationStore.CollectionExists(autoLoadConfigurationPath))
            {
                uint autoLoadFlags = (uint)PackageAutoLoadFlags.None;
                try
                {
                    autoLoadFlags = configurationStore.GetUInt32(autoLoadConfigurationPath, packageGuid.ToString("B"), 0);
                }
                catch (Exception)
                {
                    //Do not do anyting. Use none as flag
                    // Apparently user feed package "bb4bf712-fcf7-4d17-83bb-93e6478b4e5d" specified a string in the pkgdef..
                }

                bool backgroundLoad = ((autoLoadFlags & (uint)PackageAutoLoadFlags.BackgroundLoad) == (uint)PackageAutoLoadFlags.BackgroundLoad);

                IsAsyncForUIContext = IsAsyncPackage && backgroundLoad;
            }
        }
        /// <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;
            }
        }
Пример #3
0
 public int GetUnsignedInt([ComAliasName("OLE.LPCOLESTR")] string collectionPath, [ComAliasName("OLE.LPCOLESTR")] string propertyName, [ComAliasName("OLE.DWORD")] out uint value)
 {
     value = inner.GetUInt32(collectionPath, propertyName);
     return(0);
 }