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");
            });
        }
        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);
            }
        }