From 91734d3f9d84eb0a252bbe811d071c9ed2041af9 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 30 Oct 2023 11:29:08 -0700 Subject: [PATCH] fixed editor --- .../SelectedChildrenPropertyEditor.cs | 98 +++--- .../DesignTools/StringPropertyEditor.cs | 292 +++++++++--------- Submodules/MatterSlice | 2 +- 3 files changed, 194 insertions(+), 198 deletions(-) diff --git a/MatterControlLib/DesignTools/SelectedChildrenPropertyEditor.cs b/MatterControlLib/DesignTools/SelectedChildrenPropertyEditor.cs index dc7f8fb8f..d6cf7d2de 100644 --- a/MatterControlLib/DesignTools/SelectedChildrenPropertyEditor.cs +++ b/MatterControlLib/DesignTools/SelectedChildrenPropertyEditor.cs @@ -45,68 +45,66 @@ namespace MatterHackers.MatterControl.DesignTools { public GuiWidget CreateEditor(PropertyEditor propertyEditor, EditableProperty property, EditorContext context) { - var childSelector = property.Source as SelectedChildren; - if (childSelector != null) + if (property.Value is SelectedChildren childSelector) { - // we passed the wrong type - throw new Exception("Passed the wrong type to the SelectedChildrenEditor"); - } + var theme = propertyEditor.Theme; + var undoBuffer = propertyEditor.UndoBuffer; + var contextItem = context.Item; + var contextObject3D = contextItem as IObject3D; + var propertyIObject3D = property.Source as IObject3D; + var propertyGridModifier = property.Source as IPropertyGridModifier; - var theme = propertyEditor.Theme; - var undoBuffer = propertyEditor.UndoBuffer; - var contextItem = context.Item; - var contextObject3D = contextItem as IObject3D; - var propertyIObject3D = property.Source as IObject3D; - var propertyGridModifier = property.Source as IPropertyGridModifier; - - GuiWidget rowContainer; - { - if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() is ShowAsListAttribute showAsList) + GuiWidget rowContainer; { - UIField field = new ChildrenSelectorListField(property, theme); + if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() is ShowAsListAttribute showAsList) + { + UIField field = new ChildrenSelectorListField(property, theme); - field.Initialize(0); - PropertyEditor.RegisterValueChanged(property, undoBuffer, context, - field, - (valueString) => - { - var childrenSelector = new SelectedChildren(); - foreach (var child in valueString.Split(',')) + field.Initialize(0); + PropertyEditor.RegisterValueChanged(property, undoBuffer, context, + field, + (valueString) => { - childrenSelector.Add(child); + var childrenSelector = new SelectedChildren(); + foreach (var child in valueString.Split(',')) + { + childrenSelector.Add(child); + } + + return childrenSelector; + }); + + rowContainer = propertyEditor.CreateSettingsRow(property, field.Content, theme); + } + else // show the subtract editor for boolean subtract and subtract and replace + { + rowContainer = PropertyEditor.CreateSettingsColumn(property); + if (property.Source is OperationSourceContainerObject3D sourceContainer) + { + Action selected = null; + var showUpdate = contextItem.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() as ShowUpdateButtonAttribute; + if (showUpdate == null + || !showUpdate.SuppressPropertyChangeUpdates) + { + selected = () => + { + propertyIObject3D?.Invalidate(new InvalidateArgs(contextObject3D, InvalidateType.Properties)); + }; } - return childrenSelector; - }); - - rowContainer = propertyEditor.CreateSettingsRow(property, field.Content, theme); - } - else // show the subtract editor for boolean subtract and subtract and replace - { - rowContainer = PropertyEditor.CreateSettingsColumn(property); - if (property.Source is OperationSourceContainerObject3D sourceContainer) - { - Action selected = null; - var showUpdate = contextItem.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() as ShowUpdateButtonAttribute; - if (showUpdate == null - || !showUpdate.SuppressPropertyChangeUpdates) - { - selected = () => - { - propertyIObject3D?.Invalidate(new InvalidateArgs(contextObject3D, InvalidateType.Properties)); - }; + rowContainer.AddChild(CreateSourceChildSelector(childSelector, sourceContainer, theme, selected)); + } + else + { + rowContainer.AddChild(CreateSelector(childSelector, propertyIObject3D, theme)); } - - rowContainer.AddChild(CreateSourceChildSelector(childSelector, sourceContainer, theme, selected)); - } - else - { - rowContainer.AddChild(CreateSelector(childSelector, propertyIObject3D, theme)); } } + + return rowContainer; } - return rowContainer; + return null; } public static GuiWidget CreateSourceChildSelector(SelectedChildren childSelector, OperationSourceContainerObject3D sourceContainer, ThemeConfig theme, Action selectionChanged) diff --git a/MatterControlLib/DesignTools/StringPropertyEditor.cs b/MatterControlLib/DesignTools/StringPropertyEditor.cs index 06a9d89f0..b5a7771fb 100644 --- a/MatterControlLib/DesignTools/StringPropertyEditor.cs +++ b/MatterControlLib/DesignTools/StringPropertyEditor.cs @@ -48,178 +48,176 @@ namespace MatterHackers.MatterControl.DesignTools { public GuiWidget CreateEditor(PropertyEditor propertyEditor, EditableProperty property, EditorContext context) { - var stringValue = property.Source as string; - if (stringValue != null) + if (property.Value is string stringValue) { - // we passed the wrong type - throw new Exception("Passed the wrong type to the SelectedChildrenEditor"); - } + var theme = propertyEditor.Theme; + var undoBuffer = propertyEditor.UndoBuffer; - var theme = propertyEditor.Theme; - var undoBuffer = propertyEditor.UndoBuffer; + var contextItem = context.Item; + var contextObject3D = contextItem as IObject3D; + var propertyIObject3D = property.Source as IObject3D; + var propertyGridModifier = property.Source as IPropertyGridModifier; - var contextItem = context.Item; - var contextObject3D = contextItem as IObject3D; - var propertyIObject3D = property.Source as IObject3D; - var propertyGridModifier = property.Source as IPropertyGridModifier; + GuiWidget rowContainer = null; - GuiWidget rowContainer = null; - - if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null) - { - rowContainer = NewImageSearchWidget(theme); - } - else if (propertyIObject3D is AssetObject3D assetObject - && property.PropertyInfo.Name == "AssetPath") - { - // This is the AssetPath property of an asset object, add a button to set the AssetPath from a file - // Change button - var changeButton = new ThemedTextButton(property.Description, theme) + if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null) { - BackgroundColor = theme.MinimalShade, - Margin = 3 - }; - - rowContainer = new SettingsRow(property.DisplayName, - null, - changeButton, - theme); - - - changeButton.Click += (sender, e) => + rowContainer = NewImageSearchWidget(theme); + } + else if (propertyIObject3D is AssetObject3D assetObject + && property.PropertyInfo.Name == "AssetPath") { - UiThread.RunOnIdle(() => + // This is the AssetPath property of an asset object, add a button to set the AssetPath from a file + // Change button + var changeButton = new ThemedTextButton(property.Description, theme) { - ImageObject3D.ShowOpenDialog(assetObject); - }); - }; - } - else - { - var readOnly = property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null; + BackgroundColor = theme.MinimalShade, + Margin = 3 + }; - if (readOnly) - { - WrappedTextWidget wrappedTextWidget = null; - if (!string.IsNullOrEmpty(property.DisplayName)) + rowContainer = new SettingsRow(property.DisplayName, + null, + changeButton, + theme); + + + changeButton.Click += (sender, e) => { - rowContainer = new GuiWidget() + UiThread.RunOnIdle(() => { - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit, - Margin = 9 - }; - - var displayName = rowContainer.AddChild(new TextWidget(property.DisplayName, - textColor: theme.TextColor, - pointSize: 10) - { - VAnchor = VAnchor.Center, + ImageObject3D.ShowOpenDialog(assetObject); }); - - var wrapContainer = new GuiWidget() - { - Margin = new BorderDouble(displayName.Width + displayName.Margin.Width + 15, 3, 3, 3), - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit - }; - wrappedTextWidget = new WrappedTextWidget(stringValue, textColor: theme.TextColor, pointSize: 10) - { - HAnchor = HAnchor.Stretch - }; - wrappedTextWidget.TextWidget.HAnchor = HAnchor.Right; - wrapContainer.AddChild(wrappedTextWidget); - rowContainer.AddChild(wrapContainer); - } - else - { - rowContainer = wrappedTextWidget = new WrappedTextWidget(stringValue, - textColor: theme.TextColor, - pointSize: 10) - { - Margin = 9 - }; - } - - void RefreshField(object s, InvalidateArgs e) - { - if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues)) - { - wrappedTextWidget.Text = property.Value.ToString(); - } - } - - if (propertyIObject3D != null) - { - propertyIObject3D.Invalidated += RefreshField; - wrappedTextWidget.Closed += (s, e) => propertyIObject3D.Invalidated -= RefreshField; - } + }; } - else // normal edit row + else { - if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null) - { - // create a a multi-line string editor - var field = new MultilineStringField(theme, property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null); - field.Initialize(0); - field.SetValue(stringValue, false); - field.ClearUndoHistory(); - field.Content.HAnchor = HAnchor.Stretch; - field.Content.Descendants().FirstOrDefault().MaximumSize = new Vector2(double.MaxValue, 200); - field.Content.Descendants().FirstOrDefault().Parent.VAnchor = VAnchor.Top; - field.Content.MinimumSize = new Vector2(0, 100 * GuiWidget.DeviceScale); - field.Content.Margin = new BorderDouble(0, 0, 0, 5); - PropertyEditor.RegisterValueChanged(property, undoBuffer, context, field, (valueString) => valueString); - rowContainer = PropertyEditor.CreateSettingsColumn(property, field, fullWidth: true); - } - else - { - // create a string editor - var field = new TextField(theme); - field.Initialize(0); - field.SetValue(stringValue, false); - field.ClearUndoHistory(); - field.Content.HAnchor = HAnchor.Stretch; - PropertyEditor.RegisterValueChanged(property, undoBuffer, context, field, (valueString) => valueString); - rowContainer = propertyEditor.CreateSettingsRow(property, field.Content, theme, true); + var readOnly = property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null; - // check for DirectoryPathAttribute - var directoryPathAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault(); - if (directoryPathAttribute != null) + if (readOnly) + { + WrappedTextWidget wrappedTextWidget = null; + if (!string.IsNullOrEmpty(property.DisplayName)) { - // add a browse button - var browseButton = new ThemedIconButton(StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png"), 16, 16).GrayToColor(theme.TextColor), theme) + rowContainer = new GuiWidget() { - ToolTipText = "Select Folder".Localize(), + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit, + Margin = 9 }; - browseButton.Click += (s, e) => + + var displayName = rowContainer.AddChild(new TextWidget(property.DisplayName, + textColor: theme.TextColor, + pointSize: 10) { - UiThread.RunOnIdle(() => + VAnchor = VAnchor.Center, + }); + + var wrapContainer = new GuiWidget() + { + Margin = new BorderDouble(displayName.Width + displayName.Margin.Width + 15, 3, 3, 3), + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit + }; + wrappedTextWidget = new WrappedTextWidget(stringValue, textColor: theme.TextColor, pointSize: 10) + { + HAnchor = HAnchor.Stretch + }; + wrappedTextWidget.TextWidget.HAnchor = HAnchor.Right; + wrapContainer.AddChild(wrappedTextWidget); + rowContainer.AddChild(wrapContainer); + } + else + { + rowContainer = wrappedTextWidget = new WrappedTextWidget(stringValue, + textColor: theme.TextColor, + pointSize: 10) + { + Margin = 9 + }; + } + + void RefreshField(object s, InvalidateArgs e) + { + if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues)) + { + wrappedTextWidget.Text = property.Value.ToString(); + } + } + + if (propertyIObject3D != null) + { + propertyIObject3D.Invalidated += RefreshField; + wrappedTextWidget.Closed += (s, e) => propertyIObject3D.Invalidated -= RefreshField; + } + } + else // normal edit row + { + if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null) + { + // create a a multi-line string editor + var field = new MultilineStringField(theme, property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() != null); + field.Initialize(0); + field.SetValue(stringValue, false); + field.ClearUndoHistory(); + field.Content.HAnchor = HAnchor.Stretch; + field.Content.Descendants().FirstOrDefault().MaximumSize = new Vector2(double.MaxValue, 200); + field.Content.Descendants().FirstOrDefault().Parent.VAnchor = VAnchor.Top; + field.Content.MinimumSize = new Vector2(0, 100 * GuiWidget.DeviceScale); + field.Content.Margin = new BorderDouble(0, 0, 0, 5); + PropertyEditor.RegisterValueChanged(property, undoBuffer, context, field, (valueString) => valueString); + rowContainer = PropertyEditor.CreateSettingsColumn(property, field, fullWidth: true); + } + else + { + // create a string editor + var field = new TextField(theme); + field.Initialize(0); + field.SetValue(stringValue, false); + field.ClearUndoHistory(); + field.Content.HAnchor = HAnchor.Stretch; + PropertyEditor.RegisterValueChanged(property, undoBuffer, context, field, (valueString) => valueString); + rowContainer = propertyEditor.CreateSettingsRow(property, field.Content, theme, true); + + // check for DirectoryPathAttribute + var directoryPathAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault(); + if (directoryPathAttribute != null) + { + // add a browse button + var browseButton = new ThemedIconButton(StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png"), 16, 16).GrayToColor(theme.TextColor), theme) { - AggContext.FileDialogs.SelectFolderDialog( - new SelectFolderDialogParams(directoryPathAttribute.Message) - { - ActionButtonLabel = directoryPathAttribute.ActionLabel, - Title = ApplicationController.Instance.ProductName + " - " + "Select A Folder".Localize(), - RootFolder = SelectFolderDialogParams.RootFolderTypes.Specify, - FolderPath = stringValue - }, - (openParams) => - { - if (!string.IsNullOrEmpty(openParams.FolderPath)) + ToolTipText = "Select Folder".Localize(), + }; + browseButton.Click += (s, e) => + { + UiThread.RunOnIdle(() => + { + AggContext.FileDialogs.SelectFolderDialog( + new SelectFolderDialogParams(directoryPathAttribute.Message) { - field.SetValue(openParams.FolderPath, true); - } - }); - }); - }; - rowContainer.AddChild(browseButton); + ActionButtonLabel = directoryPathAttribute.ActionLabel, + Title = ApplicationController.Instance.ProductName + " - " + "Select A Folder".Localize(), + RootFolder = SelectFolderDialogParams.RootFolderTypes.Specify, + FolderPath = stringValue + }, + (openParams) => + { + if (!string.IsNullOrEmpty(openParams.FolderPath)) + { + field.SetValue(openParams.FolderPath, true); + } + }); + }); + }; + rowContainer.AddChild(browseButton); + } } } } + + return rowContainer; } - return rowContainer; + return null; } public static GuiWidget NewImageSearchWidget(ThemeConfig theme, string postPend = "silhouette") diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 00b99afed..7ed8dca97 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 00b99afed26b58d9c3a25eafa891fcef0dfd89de +Subproject commit 7ed8dca97eab5e850a0031b71cea55c19b826f39