Ejemplo n.º 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;
            }
        }
Ejemplo n.º 3
0
        private void AddNewValueHelper(Func <IVsWritableSettingsStore, string, string, int> setter)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var subCollection = GetSelectedSubCollection();

            if (subCollection != null && subCollection.TryGetWritableSettingsStore(out var settingsStore))
            {
                var newPropertyName = subCollection.GenerateNewPropertyName();
                if (ErrorHandler.Succeeded(setter(settingsStore, newPropertyName, subCollection.Path)))
                {
                    var type = settingsStore.GetPropertyType(subCollection.Path, newPropertyName);

                    // Update the view model.
                    var newProperty = SettingsStoreProperty.CreateInstance(subCollection, newPropertyName, type);
                    subCollection.Properties.Add(newProperty);

                    // Move focus to the newly-created value and start in-place editing of the name.
                    _control.SetListViewSelection(newProperty);

                    Telemetry.Client.TrackEvent("AddNewProperty", new Dictionary <string, string> {
                        ["Type"] = type.ToString()
                    });

                    InPlaceEditPropertyName(newProperty, settingsStore);
                }
            }
        }
Ejemplo n.º 4
0
 public EditIntegerDialog(string title, IntegerToStringConverter converter, SettingsStoreProperty property)
 {
     Title      = title;
     _converter = converter;
     _property  = property;
     InitializeComponent();
     DataContext = new { property.Name, Value = _converter.ToString(property.Value, ValueFormat, CultureInfo.CurrentUICulture) };
 }
 public void InPlaceEditListViewItem(SettingsStoreProperty item, string initialText, Action <string> onAcceptEdit)
 {
     // Find the control for the given item.
     if (listView.ItemContainerGenerator.ContainerFromItem(item) is ListViewItem listViewItem)
     {
         listViewItem.BringIntoView();
         listViewItem.Focus();
         listViewItem.InPlaceEdit(initialText, SetIsInPlaceEditing, onAcceptEdit);
     }
 }
        public void SetListViewSelection(SettingsStoreProperty item)
        {
            if (!listView.IsFocused)
            {
                listView.Focus();
            }

            if (listView.ItemContainerGenerator.ContainerFromItem(item) is ListViewItem listViewItem)
            {
                listViewItem.BringIntoView();
                listViewItem.Focus();
            }
            else
            {
                // This may be a newly-created item, so it hasn't been generated yet.
                // Try again after the next render.
#pragma warning disable VSTHRD001 // Avoid legacy thread switching APIs
                Dispatcher.Invoke(() => SetListViewSelection(item), DispatcherPriority.Render);
#pragma warning restore VSTHRD001 // Avoid legacy thread switching APIs
            }
        }
        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");
            });
        }
        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;
            }
        }
 public EditBinaryDialog(SettingsStoreProperty property)
 {
     _property = property;
     InitializeComponent();
     DataContext = new { property.Name, property.Value };
 }