private void LoadOption <T>(EditorOptionKey <T> key) { string collection = GetCollectionName(key.Name); string property = GetPropertyName(key.Name); int ivalue = 0; if (VSConstants.S_OK == _store.CollectionExists(collection, out ivalue)) { ivalue = 2; } string svalue; if (VSConstants.S_OK == _store.GetString(collection, property, out svalue)) { if (typeof(T) == typeof(bool)) { bool value = bool.Parse(svalue); _options.SetOptionValue(key.Name, value); } else if (typeof(T) == typeof(uint)) { uint argb = uint.Parse(svalue); _options.SetOptionValue(key.Name, argb); } } }
public void WriteString(string name, string value) { if (_settingsStore == null) { return; } int exists; _settingsStore.CollectionExists(SettingsRoot, out exists); if (exists != 1) { _settingsStore.CreateCollection(SettingsRoot); } _settingsStore.SetString(SettingsRoot, name, value); }
public void Save(string name, object data) { int exists = 0; _writableSettingsStore.CollectionExists(_collectionName, out exists); if (exists != 1) { _writableSettingsStore.CreateCollection(_collectionName); } BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, data); _writableSettingsStore.SetBinary(_collectionName, name, (uint)memoryStream.Length, memoryStream.ToArray()); }
private void InPlaceEditSubCollectionName(SettingsStoreSubCollection subCollection, IVsWritableSettingsStore settingsStore) { _control.InPlaceEditTreeViewItem(subCollection, subCollection.Name, newName => { ThreadHelper.ThrowIfNotOnUIThread(); if (newName.Length == 0) { var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming collection", $"A collection name cannot be blank. Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result)); return; } if (newName.IndexOfAny(s_invalidCollectionNameChars) >= 0) { var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming collection", $"A collection name cannot contain a backslash character (\\). Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result)); return; } // Create a sibling and check for duplicate names. var parent = subCollection.Parent; var renamedSubCollection = new SettingsStoreSubCollection(parent, newName); if (settingsStore.CollectionExists(renamedSubCollection.Path)) { var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming collection", $"There is already a collection called '{newName}'. Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result)); return; } // Clone and recreate the entire tree beneath this collection and then delete the original. ErrorHandler.ThrowOnFailure(settingsStore.CreateCollection(renamedSubCollection.Path)); settingsStore.CopyTree(subCollection, renamedSubCollection); ErrorHandler.ThrowOnFailure(settingsStore.DeleteCollection(subCollection.Path)); // Update the view model. subCollection.Rename(newName); // Select the newly-renamed sub-collection. _control.SetTreeViewSelection(subCollection); Telemetry.Client.TrackEvent("RenameSubCollection"); }); }