internal SelectionData() { ThreadHelper.ThrowIfNotOnUIThread(); selectionMonitor = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; InitializeSelectionItems(); InitializeContextDictionary(); IVsSettingsManager userSettings = Package.GetGlobalService(typeof(SVsSettingsManager)) as IVsSettingsManager; userSettings.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out var settingsStore); LoadContextIDList(settingsStore, FavoriteContexts, "Favorites"); // at the point where we are created, we don't know what contexts are live so we need to look // for all of them that we know about. foreach (uint contextID in contextIDNames.Keys) { if (ErrorHandler.Succeeded(selectionMonitor.IsCmdUIContextActive(contextID, out var active)) && active != 0) { // Add the item to the live contexts LiveContexts.Add(contextIDNames[contextID]); contextIDNames[contextID].Enabled = true; } } selectionMonitor.AdviseSelectionEvents(this, out selectionEventsCookie); }
public TerminalOptionPage() { ThreadHelper.ThrowIfNotOnUIThread(); IVsSettingsManager settingsManager = (IVsSettingsManager)ServiceProvider.GlobalProvider.GetService(typeof(SVsSettingsManager)); this.model = new TerminalOptionsModel(settingsManager); }
private async Task <Guid> GetCurrentThemeAsync(CancellationToken cancellationToken) { const string COLLECTION_NAME = @"ApplicationPrivateSettings\Microsoft\VisualStudio"; const string PROPERTY_NAME = "ColorTheme"; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); IVsSettingsManager manager = (IVsSettingsManager)await VS.Services.GetSettingsManagerAsync(); SettingsStore store = new ShellSettingsManager(manager).GetReadOnlySettingsStore(SettingsScope.UserSettings); if (store.CollectionExists(COLLECTION_NAME)) { if (store.PropertyExists(COLLECTION_NAME, PROPERTY_NAME)) { // The value is made up of three parts, separated // by a star. The third part is the GUID of the theme. string[] parts = store.GetString(COLLECTION_NAME, PROPERTY_NAME).Split('*'); if (parts.Length == 3) { if (Guid.TryParse(parts[2], out Guid value)) { return(value); } } } } return(Guid.Empty); }
public bool SaveOption(IEditorOptions options, string optionName) { if (options == null) { throw new ArgumentNullException("options"); } while (true) { if (options.IsOptionDefined(optionName, true)) { break; } options = options.Parent; if (options == null) { return(false); //Unable to save option. } } IVsSettingsManager manager = this.SettingsManagerService; IVsWritableSettingsStore store; Marshal.ThrowExceptionForHR(manager.GetWritableSettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out store)); string result = options.GetOptionValue(optionName).ToString(); Marshal.ThrowExceptionForHR(store.SetString("Text Editor", optionName, result)); return(true); }
public static IVsSettingsManager Create() { IVsSettingsManager sm = Substitute.For <IVsSettingsManager>(); string s; sm.GetApplicationDataFolder(Arg.Any <uint>(), out s).ReturnsForAnyArgs(x => { x[1] = Path.GetTempPath(); return(VSConstants.S_OK); }); IVsSettingsStore store; sm.GetReadOnlySettingsStore(Arg.Any <uint>(), out store).ReturnsForAnyArgs(x => { x[1] = VsSettingsStoreMock.Create(); return(VSConstants.S_OK); }); IVsWritableSettingsStore writable; sm.GetWritableSettingsStore(Arg.Any <uint>(), out writable).ReturnsForAnyArgs(x => { x[1] = VsSettingsStoreMock.Create(); return(VSConstants.S_OK); }); return(sm); }
/// <summary> /// Retrieves the supported item extensions from the package settings /// </summary> /// <param name="settingsManager">The settings manager for the project</param> /// <returns>A list of supported item extensions</returns> public static IEnumerable <string> GetSupportedItemExtensions(IVsSettingsManager settingsManager) { if (supportedItemExtensions == null) { supportedItemExtensions = GetSupportedExtensions(settingsManager, SupportedProjectExtensionsKey); } return(supportedItemExtensions); }
/// <summary> /// Constructor for the SettingsManager class. It requires Service Provider to reach IVsSettingsManager /// which is the interop COM interface of the service that provides the Settings related functionalities. /// </summary> /// <param name="serviceProvider">Service provider of the VS.</param> public ShellSettingsManager(IServiceProvider serviceProvider) { HelperMethods.CheckNullArgument(serviceProvider, "serviceProvider"); this.settingsManager = serviceProvider.GetService(typeof(SVsSettingsManager)) as IVsSettingsManager; if (this.settingsManager == null) { throw new NotSupportedException(typeof(SVsSettingsManager).FullName); } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); this.AddService(typeof(STerminalService), CreateServiceAsync, promote: true); await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); this.settingsManager = (IVsSettingsManager)await this.GetServiceAsync(typeof(SVsSettingsManager)); await TermWindowCommand.InitializeCommandAsync(this); }
private static IEnumerable <string> GetSupportedExtensions(IVsSettingsManager settingsManager, string rootKey) { ErrorHandler.ThrowOnFailure(settingsManager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_Configuration, out IVsSettingsStore settings)); ErrorHandler.ThrowOnFailure(settings.GetSubCollectionCount(rootKey, out uint count)); List <string> supportedExtensions = new List <string>(); for (uint i = 0; i != count; ++i) { ErrorHandler.ThrowOnFailure(settings.GetSubCollectionName(rootKey, i, out string keyName)); supportedExtensions.Add(keyName); } return(supportedExtensions); }
private string[] GetSupportedExtensions(string rootKey) { IVsSettingsManager settingsManager = (IVsSettingsManager)GetService(typeof(SVsSettingsManager)); IVsSettingsStore settings; ErrorHandler.ThrowOnFailure(settingsManager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_Configuration, out settings)); uint count = 0; ErrorHandler.ThrowOnFailure(settings.GetSubCollectionCount(rootKey, out count)); string[] supportedExtensions = new string[count]; for (uint i = 0; i != count; ++i) { string keyName; ErrorHandler.ThrowOnFailure(settings.GetSubCollectionName(rootKey, i, out keyName)); supportedExtensions[i] = keyName; } return(supportedExtensions); }
public void InitializeViewModel(IVsSettingsManager vsSettingsManager, ISettingsManager roamingSettingsManager) => DataContext = new SettingsStoreViewModel(vsSettingsManager, roamingSettingsManager);
public bool LoadOption(IEditorOptions options, string optionName) { if (options == null) { throw new ArgumentNullException("options"); } EditorOptionDefinition optionDefinition = null; while (true) { optionDefinition = GetMatchingOption(options, optionName); if (optionDefinition != null) { break; } options = options.Parent; if (options == null) { return(false); //Unable to load option. } } IVsSettingsManager manager = this.SettingsManagerService; IVsSettingsStore store; Marshal.ThrowExceptionForHR(manager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out store)); string result; Marshal.ThrowExceptionForHR(store.GetStringOrDefault("Text Editor", optionName, string.Empty, out result)); if (result == string.Empty) { //No corresponding entry in the registery. Save the option to make it finable and editable. this.SaveOption(options, optionName); } else { try { if (optionDefinition.ValueType == typeof(bool)) { options.SetOptionValue(optionName, bool.Parse(result)); return(true); } else if (optionDefinition.ValueType == typeof(int)) { options.SetOptionValue(optionName, int.Parse(result)); return(true); } else if (optionDefinition.ValueType == typeof(double)) { options.SetOptionValue(optionName, double.Parse(result)); return(true); } else if (optionDefinition.ValueType == typeof(string)) { options.SetOptionValue(optionName, result); return(true); } else if (optionDefinition.ValueType == typeof(Color)) { //Color's saved by Color.ToString() have a leading # sign ... strip that off before we parse. uint argb = uint.Parse(result.Substring(1), NumberStyles.AllowHexSpecifier); options.SetOptionValue(optionName, Color.FromArgb((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)argb)); return(true); } } catch (System.FormatException) { //If we get a format exception, then the data for the option is invalid: overwrite it with something in the correct format. this.SaveOption(options, optionName); } } return(false); }
public OptionsModel(IVsSettingsManager settingsManager) { this.settingsManager = new ShellSettingsManager(settingsManager); this.LoadData(); }
public TerminalOptionsModel(IVsSettingsManager settingsManager) : base(settingsManager) { }
public int GetGeneratorInformation(string wszProgId, out int pbGeneratesDesignTimeSource, out int pbGeneratesSharedDesignTimeSource, out int pbUseTempPEFlag, out Guid pguidGenerator) { pbGeneratesDesignTimeSource = 0; pbGeneratesSharedDesignTimeSource = 0; pbUseTempPEFlag = 0; pguidGenerator = Guid.Empty; if (wszProgId == null || string.IsNullOrWhiteSpace(wszProgId)) { return(VSConstants.E_INVALIDARG); } // Get the guid of the project UIThreadHelper.VerifyOnUIThread(); var projectGuid = _projectIntegrationService.ProjectTypeGuid; if (projectGuid.Equals(Guid.Empty)) { return(VSConstants.E_FAIL); } IVsSettingsManager manager = _serviceProvider.GetService <IVsSettingsManager, SVsSettingsManager>(); HResult hr = manager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_Configuration, out IVsSettingsStore store); if (!hr.Succeeded) { return(hr); } var key = $"Generators\\{projectGuid.ToString("B")}\\{wszProgId}"; hr = store.CollectionExists(key, out int exists); if (!hr.Succeeded) { return(hr); } if (exists != 1) { return(VSConstants.E_FAIL); } // The clsid value is the only required value. The other 3 are optional hr = store.PropertyExists(key, CLSIDKey, out exists); if (!hr.Succeeded) { return(hr); } if (exists != 1) { return(VSConstants.E_FAIL); } hr = store.GetString(key, CLSIDKey, out string clsidString); if (hr.Failed) { return(hr); } if (string.IsNullOrWhiteSpace(clsidString) || !Guid.TryParse(clsidString, out pguidGenerator)) { return(VSConstants.E_FAIL); } // Explicitly convert anything that's not 1 to 0. These aren't required keys, so we don't explicitly fail here. store.GetIntOrDefault(key, DesignTimeSourceKey, 0, out pbGeneratesDesignTimeSource); pbGeneratesDesignTimeSource = pbGeneratesDesignTimeSource == 1 ? 1 : 0; store.GetIntOrDefault(key, SharedDesignTimeSourceKey, 0, out pbGeneratesSharedDesignTimeSource); pbGeneratesSharedDesignTimeSource = pbGeneratesSharedDesignTimeSource == 1 ? 1 : 0; store.GetIntOrDefault(key, DesignTimeCompilationFlagKey, 0, out pbUseTempPEFlag); pbUseTempPEFlag = pbUseTempPEFlag == 1 ? 1 : 0; return(VSConstants.S_OK); }
public DteService(IVsSettingsManager provider) { m_environment = Package.GetGlobalService(typeof(EnvDTE.DTE)) as DTE2; m_provider = provider; }
public SettingsManagerWrapper(IServiceProvider serviceProvider) { _settingsManager = (IVsSettingsManager)serviceProvider.GetService(typeof(SVsSettingsManager)); Debug.Assert(_settingsManager != null); }
public SettingsStore(IVsSettingsManager manager, IEditorOptions options) { _options = options; manager.GetWritableSettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out _store); }
private WebResourcePublishCommand(AsyncPackage package, OleMenuCommandService commandService, IVsSettingsManager vsSettingsManager) { m_token = new CancellationToken(); m_pane = new Guid("A8E3D03E-28C9-4900-BD48-CEEDEC35E7E6"); m_service = new DteService(vsSettingsManager); m_package = package ?? throw new ArgumentNullException(nameof(package)); m_telemetry = new TelemetryWrapper(m_service.Version, VersionHelper.GetVersionFromManifest()); if (commandService != null) { var deployMenuCommandID = new CommandID(CommandSet, DeployCommandId); var deployMenuItem = new OleMenuCommand(DeployMenuItemCallback, deployMenuCommandID); deployMenuItem.BeforeQueryStatus += HandleDeployMenuState; commandService.AddCommand(deployMenuItem); var initializeMenuCommandId = new CommandID(CommandSet, InitCommandId); var initMenuItem = new OleMenuCommand(InitMenuItemCallback, initializeMenuCommandId); initMenuItem.BeforeQueryStatus += HandleInitMenuState; commandService.AddCommand(initMenuItem); var singeDeplotMenuCommandId = new CommandID(CommandSet, SingleDeployCommandId); var initSingleDeploy = new OleMenuCommand(SingleDeployMenuItemCallback, singeDeplotMenuCommandId); initSingleDeploy.BeforeQueryStatus += HandleSingleDeployMenuState; commandService.AddCommand(initSingleDeploy); // Fix for enable/disable states HandleInitMenuState(initMenuItem, null); HandleDeployMenuState(deployMenuItem, null); } }
public void InitializeViewModel(IVsSettingsManager settingsManager) => DataContext = new SettingsStoreViewModel(settingsManager);