private string GetStringFromCommandID(CommandID commandID) { if (commandID == null) { throw new ArgumentNullException("commandID"); } //v-oscca: //The services resourceManager and dte will be null during installation phase, this is becuase the component is not sited. //This is by design. IVsResourceManager resourceManager = (IVsResourceManager)GetService(typeof(SVsResourceManager)); if (resourceManager != null) { int localeId = CultureInfo.CurrentCulture.LCID; DTE dte = (DTE)GetService(typeof(DTE)); if (dte != null) { localeId = dte.LocaleID; } string valueAsString = null; Guid guid = commandID.Guid; resourceManager.LoadResourceString(ref guid, localeId, "#" + commandID.ID, out valueAsString); return(valueAsString); } return(null); }
private bool TryGetResourceManager(out IVsResourceManager resourceManager) { if (_resourceManager == null) { _resourceManager = _serviceProvider.GetService(typeof(SVsResourceManager)) as IVsResourceManager; } resourceManager = _resourceManager; return (resourceManager != null); }
private bool TryGetResourceManager(out IVsResourceManager resourceManager) { if (_resourceManager == null) { _resourceManager = _serviceProvider.GetService(typeof(SVsResourceManager)) as IVsResourceManager; } resourceManager = _resourceManager; return(resourceManager != null); }
public static string GetResourceString(string resourceName) { string resourceValue; IVsResourceManager resourceManager = (IVsResourceManager)GetGlobalService(typeof(SVsResourceManager)); Guid packageGuid = typeof(VSPackage).GUID; int hr = resourceManager.LoadResourceString(ref packageGuid, -1, resourceName, out resourceValue); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); return(resourceValue); }
/// <summary> /// This method loads a localized string based on the specified resource. /// </summary> /// <param name="resourceName">Resource to load</param> /// <returns>String loaded for the specified resource</returns> public string GetResourceString(string resourceName) { IVsResourceManager resourceManager = (IVsResourceManager)GetService(typeof(SVsResourceManager)); if (resourceManager == null) { throw new InvalidOperationException("Could not get SVsResourceManager service. Make sure the package is Sited before calling this method"); } Guid packageGuid = this.GetType().GUID; int hr = resourceManager.LoadResourceString(ref packageGuid, -1, resourceName, out string resourceValue); ErrorHandler.ThrowOnFailure(hr); return(resourceValue); }
internal static string GetResourceString(string resourceName) { string resourceValue; IVsResourceManager resourceManager = (IVsResourceManager)GetGlobalService(typeof(SVsResourceManager)); if (resourceManager == null) { throw new InvalidOperationException("Could not get SVsResourceManager service. Make sure the package is Sited before calling this method."); } Guid packageGuid = typeof(TBEdit).GUID; int hr = resourceManager.LoadResourceString(ref packageGuid, -1, resourceName, out resourceValue); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); return(resourceValue); }
/// <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)); }
private static bool TryGetResourceManager(out IVsResourceManager resourceManager) { if (_resourceManager == null) { _resourceManager = JToolsPackage.GetGlobalService(typeof(SVsResourceManager)) as IVsResourceManager; } resourceManager = _resourceManager; return (resourceManager != null); }