Exemplo n.º 1
0
        /// <summary>
        /// Load a list of UIContext items from the settings store.
        /// </summary>
        /// <param name="settingsStore"></param>
        /// <param name="list"></param>
        /// <param name="name"></param>
        private void LoadContextIDList(IVsSettingsStore settingsStore, ObservableCollection <UIContextInformation> list, string name)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string collectionRoot = SettingsRoot + "\\" + name;

            settingsStore.CollectionExists(collectionRoot, out var exists);
            if (exists != 0)
            {
                settingsStore.GetPropertyCount(collectionRoot, out var contextCount);
                for (uint iContext = 0; iContext < contextCount; iContext++)
                {
                    if (ErrorHandler.Succeeded(settingsStore.GetPropertyName(collectionRoot, iContext, out var guidString)))
                    {
                        Guid contextGuid = new Guid(guidString);
                        if (ErrorHandler.Succeeded(selectionMonitor.GetCmdUIContextCookie(ref contextGuid, out var contextID)))
                        {
                            if (contextIDNames.ContainsKey(contextID))
                            {
                                list.Add(contextIDNames[contextID]);
                                if (contextIDNames[contextID].Name.StartsWith("#") ||
                                    contextIDNames[contextID].Name.StartsWith("resource="))
                                {
                                    // if the name is a resource, use the name we found from the last session
                                    if (ErrorHandler.Succeeded(settingsStore.GetString(collectionRoot, guidString, out var contextName)))
                                    {
                                        contextIDNames[contextID].Name = contextName;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public static IEnumerable <string> GetPropertyNames(this IVsSettingsStore store, string collectionPath)
        {
            for (uint index = 0; ; index++)
            {
                string name;
                try
                {
                    if (ErrorHandler.Failed(store.GetPropertyName(collectionPath, index, out name)))
                    {
                        break;
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    break;
                }

                yield return(name);
            }
        }