Ejemplo n.º 1
0
 void AddContextName(string contextGuidString, string contextName, string packageGuidString)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (Guid.TryParse(contextGuidString, out Guid contextGuid) && ErrorHandler.Succeeded(selectionMonitor.GetCmdUIContextCookie(ref contextGuid, out uint guidCookie)))
     {
         contextIDNames.TryGetValue(guidCookie, out UIContextInformation info);
         if (info == null)
         {
             contextIDNames[guidCookie] = new UIContextInformation(guidCookie, contextName, contextGuid.ToString("B"), packageGuidString);
         }
         else
         {
             if (info.Name == NoNameProvided)
             {
                 info.Name = contextName;
             }
         }
     }
 }
Ejemplo n.º 2
0
 public UIContextLogItem(bool activate, UIContextInformation info)
 {
     Activate    = activate;
     ContextInfo = info;
     Time        = DateTime.Now;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// When the CmdUIContext changes, find the real name of the context.  If it looks like a package resource, look up the real name.
        /// Mark our internal data to be active or inactive and add this event to the log.
        /// </summary>
        /// <param name="dwCmdUICookie"></param>
        /// <param name="fActive"></param>
        /// <returns></returns>
        public int OnCmdUIContextChanged(uint dwCmdUICookie, int fActive)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (contextIDNames.ContainsKey(dwCmdUICookie))
            {
                UIContextInformation ci = contextIDNames[dwCmdUICookie];

                if (fActive != 0)
                {
                    // Before we add this guy, check to see if its name starts with a '#'
                    // Then look it up in its package now since it will be loaded
                    if (!string.IsNullOrEmpty(ci.Package))
                    {
                        if (ci.Name.StartsWith("#"))
                        {
                            Guid packageGuid             = new Guid(ci.Package);
                            IVsResourceManager resources = Package.GetGlobalService(typeof(SVsResourceManager)) as IVsResourceManager;
                            if (ErrorHandler.Succeeded(resources.LoadResourceString(ref packageGuid, 0, ci.Name, out var newName)))
                            {
                                ci.Name = newName;
                            }
                            // Also try without the "#" in the name
                            else if (ErrorHandler.Succeeded(resources.LoadResourceString(ref packageGuid, 0, ci.Name.Substring(1), out newName)))
                            {
                                ci.Name = newName;
                            }
                        }
                    }
                    else if (ci.Name.StartsWith("resource="))
                    {
                        // Ad7 engines
                        StringBuilder newName            = new StringBuilder(255);
                        int           resourceIDPosition = ci.Name.IndexOf('#');
                        string        resourceIDString   = ci.Name.Substring(resourceIDPosition);
                        string        resourceDLL        = ci.Name.Substring("resource=".Length, ci.Name.Length - resourceIDPosition);
                        if (uint.TryParse(resourceIDString.Substring(1), out var resourceID))
                        {
                            if (!string.IsNullOrEmpty(resourceDLL))
                            {
                                IntPtr hModule = IntPtr.Zero;
                                try
                                {
                                    hModule = NativeMethods.LoadLibrary(resourceDLL);
                                    if (hModule != IntPtr.Zero)
                                    {
                                        NativeMethods.LoadString(hModule, resourceID, newName, newName.Capacity + 1);
                                        ci.Name = newName.ToString();
                                    }
                                }
                                finally
                                {
                                    if (hModule != IntPtr.Zero)
                                    {
                                        NativeMethods.FreeLibrary(hModule);
                                    }
                                }
                            }
                        }
                    }

                    LiveContexts.Add(ci);
                    ci.Enabled = true;
                }
                else
                {
                    LiveContexts.Remove(ci);
                    ci.Enabled = false;
                }

                UIContextLog.Insert(0, new UIContextLogItem(fActive == 1, ci));
            }