Example #1
0
        private void InPlaceEditPropertyName(SettingsStoreProperty property, IVsWritableSettingsStore settingsStore)
        {
            _control.InPlaceEditListViewItem(property, property.Name, newName =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                // Allow renaming to blank to support the (Default) value, but only for strings.
                if (newName.Length == 0 && property.Type != __VsSettingsType.SettingsType_String)
                {
                    ShowErrorMessage("Error renaming property", "Only a string property may have a blank name. Try again with a different name.");
                    return;
                }

                // Check for duplicate names.
                if (settingsStore.PropertyExists(property.CollectionPath, newName))
                {
                    var message = newName.Length == 0 ?
                                  "There is already a (Default) property. Delete it first and try again or use a different name." :
                                  $"There is already a property called '{newName}'. Try again with a different name.";

                    ShowErrorMessage("Error renaming property", message);
                    return;
                }

                // Clone the property then delete the original.
                settingsStore.CopyProperty(property, newName);
                ErrorHandler.ThrowOnFailure(settingsStore.DeleteProperty(property.CollectionPath, property.Name));

                // Update the view model (keeping the selection the same)
                property.Rename(newName);

                Telemetry.Client.TrackEvent("RenameProperty");
            });
        }
        public static void CopyProperty(this IVsWritableSettingsStore store, SettingsStoreProperty from, string toName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var fromName       = from.Name;
            var collectionPath = from.CollectionPath;

            switch (from.Type)
            {
            case __VsSettingsType.SettingsType_String:
                ErrorHandler.ThrowOnFailure(store.GetString(collectionPath, fromName, out var stringValue));
                ErrorHandler.ThrowOnFailure(store.SetString(collectionPath, toName, stringValue));
                break;

            case __VsSettingsType.SettingsType_Int:
                ErrorHandler.ThrowOnFailure(store.GetInt(collectionPath, fromName, out var intValue));
                ErrorHandler.ThrowOnFailure(store.SetInt(collectionPath, toName, intValue));
                break;

            case __VsSettingsType.SettingsType_Int64:
                ErrorHandler.ThrowOnFailure(store.GetInt64(collectionPath, fromName, out var longValue));
                ErrorHandler.ThrowOnFailure(store.SetInt64(collectionPath, toName, longValue));
                break;

            case __VsSettingsType.SettingsType_Binary:
                uint[] actualByteLength = { 0 };
                ErrorHandler.ThrowOnFailure(store.GetBinary(collectionPath, fromName, 0, null, actualByteLength));
                byte[] bytes = new byte[actualByteLength[0]];
                ErrorHandler.ThrowOnFailure(store.GetBinary(collectionPath, fromName, actualByteLength[0], bytes, actualByteLength));
                ErrorHandler.ThrowOnFailure(store.SetBinary(collectionPath, toName, actualByteLength[0], bytes));
                break;
            }
        }
Example #3
0
        /// <summary>
        /// Save a list of UIContext items in the settings store.
        /// </summary>
        /// <param name="settingsStore"></param>
        /// <param name="list"></param>
        /// <param name="name"></param>
        private void SaveContextIDList(IVsWritableSettingsStore settingsStore, ObservableCollection <UIContextInformation> list, string name)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string collectionRoot = SettingsRoot + "\\" + name;

            // rewrite the collection
            settingsStore.DeleteCollection(collectionRoot);
            settingsStore.CreateCollection(collectionRoot);

            for (int iContext = 0; iContext < list.Count; iContext++)
            {
                string guidString = list[iContext].Guid.ToString();
                settingsStore.SetString(collectionRoot, guidString, list[iContext].Name);
            }
        }
        public static void CopyProperties(this IVsWritableSettingsStore writableSettingsStore, SettingsStoreSubCollection from, SettingsStoreSubCollection to)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var fromStore = from.Root.SettingsStore;
            var fromPath  = from.Path;
            var toPath    = to.Path;

            for (uint index = 0; ; index++)
            {
                if (ErrorHandler.Failed(fromStore.GetPropertyName(fromPath, index, out var name)))
                {
                    break;
                }

                if (ErrorHandler.Failed(fromStore.GetPropertyType(fromPath, name, out var type)))
                {
                    break;
                }

                switch ((__VsSettingsType)type)
                {
                case __VsSettingsType.SettingsType_String:
                    ErrorHandler.ThrowOnFailure(fromStore.GetString(fromPath, name, out var stringValue));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetString(toPath, name, stringValue));
                    break;

                case __VsSettingsType.SettingsType_Int:
                    ErrorHandler.ThrowOnFailure(fromStore.GetInt(fromPath, name, out var intValue));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetInt(toPath, name, intValue));
                    break;

                case __VsSettingsType.SettingsType_Int64:
                    ErrorHandler.ThrowOnFailure(fromStore.GetInt64(fromPath, name, out var longValue));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetInt64(toPath, name, longValue));
                    break;

                case __VsSettingsType.SettingsType_Binary:
                    uint[] actualByteLength = { 0 };
                    ErrorHandler.ThrowOnFailure(fromStore.GetBinary(fromPath, name, 0, null, actualByteLength));
                    byte[] bytes = new byte[actualByteLength[0]];
                    ErrorHandler.ThrowOnFailure(fromStore.GetBinary(fromPath, name, actualByteLength[0], bytes, actualByteLength));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetBinary(toPath, name, actualByteLength[0], bytes));
                    break;
                }
            }
        }
        public static void CopyTree(this IVsWritableSettingsStore writableSettingsStore, SettingsStoreSubCollection from, SettingsStoreSubCollection to)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            writableSettingsStore.CopyProperties(from, to);

            var fromStore = from.Root.SettingsStore;
            var fromPath  = from.Path;

            for (uint index = 0; ; index++)
            {
                if (ErrorHandler.Failed(fromStore.GetSubCollectionName(fromPath, index, out var name)))
                {
                    break;
                }

                var newSubCollection = new SettingsStoreSubCollection(to, name);
                ErrorHandler.ThrowOnFailure(writableSettingsStore.CreateCollection(newSubCollection.Name));

                writableSettingsStore.CopyTree(new SettingsStoreSubCollection(from, name), newSubCollection);
            }
        }
        private void InPlaceEditPropertyName(SettingsStoreProperty property, IVsWritableSettingsStore settingsStore)
        {
            _control.InPlaceEditListViewItem(property, property.Name, newName =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                // Allow renaming to blank to support the (Default) value, but only for strings.
                if (newName.Length == 0 && property.Type != __VsSettingsType.SettingsType_String)
                {
                    var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                    ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming property", "Only a string property may have a blank name. Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result));
                    return;
                }

                // Check for duplicate names.
                if (settingsStore.PropertyExists(property.CollectionPath, newName))
                {
                    var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                    var message = newName.Length == 0 ?
                                  "There is already a (Default) property. Delete it first and try again or use a different name." :
                                  $"There is already a property called '{newName}'. Try again with a different name.";

                    ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming property", message, null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result));
                    return;
                }

                // Clone the property then delete the original.
                settingsStore.CopyProperty(property, newName);
                ErrorHandler.ThrowOnFailure(settingsStore.DeleteProperty(property.CollectionPath, property.Name));

                // Update the view model (keeping the selection the same)
                property.Rename(newName);

                Telemetry.Client.TrackEvent("RenameProperty");
            });
        }
Example #7
0
 public int GetWritableSettingsStore(uint scope, out IVsWritableSettingsStore writableStore) {
     writableStore = Store;
     return VSConstants.S_OK;
 }
Example #8
0
 public int GetWritableSettingsStore(uint scope, out IVsWritableSettingsStore writableStore)
 {
     throw new NotImplementedException();
 }
 public WritableSettingsStoreWrapper(IVsWritableSettingsStore store)
     : base(store)
 {
     _store = store;
 }
 /// <summary>
 /// Internal constructor that takes the COM interface that provides the functionality of this class.
 /// </summary>
 /// <param name="writableSettingsStore">COM interface wrapped by this class.</param>
 internal ShellWritableSettingsStore(IVsWritableSettingsStore writableSettingsStore)
 {
     HelperMethods.CheckNullArgument(writableSettingsStore, "writableSettingsStore");
     this.writableSettingsStore = writableSettingsStore;
     this.settingsStore = new ShellSettingsStore(this.writableSettingsStore);
 }
        private void WriteUserSettingsString(string key, string propertyName, string value)
        {
            IVsWritableSettingsStore store = ReadWriteUserSettings;

            Marshal.ThrowExceptionForHR(store.SetString(key, propertyName, value));
        }
        public static void ShowModifyPropertyDialog(SettingsStoreProperty property, IVsWritableSettingsStore writableStore)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            switch (property.Type)
            {
            case __VsSettingsType.SettingsType_String:
            {
                Telemetry.Client.TrackPageView(nameof(EditStringDialog));
                var dialog = new EditStringDialog(property);
                if (dialog.ShowModal() == true)
                {
                    ErrorHandler.ThrowOnFailure(writableStore.SetString(property.CollectionPath, property.Name, (string)property.Value));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            case __VsSettingsType.SettingsType_Int:
            {
                Telemetry.Client.TrackPageView(nameof(EditIntegerDialog) + "(32)");
                var dialog = new EditIntegerDialog("Edit DWORD (32-bit) Value", DwordToStringConverter.Instance, property);
                if (dialog.ShowModal() == true)
                {
                    ErrorHandler.ThrowOnFailure(writableStore.SetUnsignedInt(property.CollectionPath, property.Name, (uint)property.Value));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            case __VsSettingsType.SettingsType_Int64:
            {
                Telemetry.Client.TrackPageView(nameof(EditIntegerDialog) + "(64)");
                var dialog = new EditIntegerDialog("Edit QWORD (64-bit) Value", QwordToStringConverter.Instance, property);
                if (dialog.ShowModal() == true)
                {
                    ErrorHandler.ThrowOnFailure(writableStore.SetUnsignedInt64(property.CollectionPath, property.Name, (ulong)property.Value));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            case __VsSettingsType.SettingsType_Binary:
            {
                Telemetry.Client.TrackPageView(nameof(EditBinaryDialog));
                var dialog = new EditBinaryDialog(property);
                if (dialog.ShowModal() == true)
                {
                    var binary = (byte[])property.Value;
                    ErrorHandler.ThrowOnFailure(writableStore.SetBinary(property.CollectionPath, property.Name, (uint)binary.Length, binary));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            default:
                break;
            }
        }
Example #13
0
 public SettingsStore(string collectionName, IVsWritableSettingsStore writableSettingsStore)
 {
     _collectionName        = collectionName;
     _writableSettingsStore = writableSettingsStore;
 }
Example #14
0
 public int GetWritableSettingsStore([ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSSETTINGSSCOPE")] uint scope, out IVsWritableSettingsStore writableStore)
 {
     writableStore = (IVsWritableSettingsStore)inner.GetReadOnlySettingsStore((SettingsScope)scope);
     return(0);
 }
Example #15
0
 public int GetWritableSettingsStore(uint scope, out IVsWritableSettingsStore writableStore) {
     throw new NotImplementedException();
 }
Example #16
0
 public int GetWritableSettingsStore(uint scope, out IVsWritableSettingsStore writableStore)
 {
     writableStore = Store;
     return(VSConstants.S_OK);
 }
Example #17
0
 public WritableSettingsStoreWrapper(IVsWritableSettingsStore store)
     : base(store)
 {
     _store = store;
 }
 /// <summary>
 /// Internal constructor that takes the COM interface that provides the functionality of this class.
 /// </summary>
 /// <param name="writableSettingsStore">COM interface wrapped by this class.</param>
 internal ShellWritableSettingsStore(IVsWritableSettingsStore writableSettingsStore)
 {
     HelperMethods.CheckNullArgument(writableSettingsStore, "writableSettingsStore");
     this.writableSettingsStore = writableSettingsStore;
     this.settingsStore         = new ShellSettingsStore(this.writableSettingsStore);
 }
Example #19
0
        private void InPlaceEditSubCollectionName(SettingsStoreSubCollection subCollection, IVsWritableSettingsStore settingsStore)
        {
            _control.InPlaceEditTreeViewItem(subCollection, subCollection.Name, newName =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                if (newName.Length == 0)
                {
                    ShowErrorMessage("Error renaming collection", $"A collection name cannot be blank. Try again with a different name.");
                    return;
                }

                if (newName.IndexOfAny(s_invalidCollectionNameChars) >= 0)
                {
                    ShowErrorMessage("Error renaming collection", $"A collection name cannot contain a backslash character (\\). Try again with a different name.");
                    return;
                }

                // Create a sibling and check for duplicate names.
                var parent = subCollection.Parent;
                var renamedSubCollection = new SettingsStoreSubCollection(parent, newName);
                if (settingsStore.CollectionExists(renamedSubCollection.Path))
                {
                    ShowErrorMessage("Error renaming collection", $"There is already a collection called '{newName}'. Try again with a different name.");
                    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");
            });
        }
Example #20
0
 public int GetWritableSettingsStore([ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSSETTINGSSCOPE")]uint scope, out IVsWritableSettingsStore writableStore)
 {
     writableStore = (IVsWritableSettingsStore)inner.GetReadOnlySettingsStore((SettingsScope)scope);
     return 0;
 }
        public static bool TryGetWritableSettingsStore(this SettingsStoreItem settingsStoreItem, out IVsWritableSettingsStore writableSettingsStore)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!(ServiceProvider.GlobalProvider.GetService(typeof(SVsSettingsManager)) is IVsSettingsManager settingsManager))
            {
                writableSettingsStore = null;
                return(false);
            }

            return(ErrorHandler.Succeeded(settingsManager.GetWritableSettingsStore((uint)settingsStoreItem.Root.EnclosingScope, out writableSettingsStore)));
        }