public DictionaryPropertyEditor(IPropertyEditorParams editorParams, Func <Type, PropertyEditorParams, Widget, object, IEnumerable <IPropertyEditor> > populateEditors) : base(editorParams) { if (EditorParams.Objects.Skip(1).Any()) { EditorContainer.AddNode(new Widget() { Layout = new HBoxLayout(), Nodes = { new ThemedSimpleText { Text = "Edit of dictionary properties isn't supported for multiple selection.", ForceUncutText = false } }, Presenter = new WidgetFlatFillPresenter(Theme.Colors.WarningBackground) }); return; } this.populateEditors = populateEditors; dictionary = PropertyValue(EditorParams.Objects.First()).GetValue(); var addButton = new ThemedAddButton { Clicked = () => { if (dictionary == null) { var pi = EditorParams.PropertyInfo; var o = EditorParams.Objects.First(); pi.SetValue(o, dictionary = Activator.CreateInstance <TDictionary>()); } if (dictionary.ContainsKey(keyValueToAdd.Key)) { AddWarning($"Key \"{keyValueToAdd.Key}\" already exists.", ValidationResult.Warning); return; } using (Document.Current.History.BeginTransaction()) { InsertIntoDictionary <TDictionary, string, TValue> .Perform(dictionary, keyValueToAdd.Key, keyValueToAdd.Value); ExpandableContent.Nodes.Add(CreateDefaultKeyValueEditor(keyValueToAdd.Key, keyValueToAdd.Value)); Document.Current.History.CommitTransaction(); } keyValueToAdd.Value = DefaultValue; keyValueToAdd.Key = string.Empty; }, LayoutCell = new LayoutCell(Alignment.LeftCenter), }; var keyEditorContainer = CreateKeyEditor(editorParams, keyValueToAdd, s => keyValueToAdd.Key = s, addButton); ExpandableContent.Nodes.Add(keyEditorContainer); ExpandableContent.Nodes.Add(CreateValueEditor(editorParams, keyValueToAdd, populateEditors)); Rebuild(); EditorContainer.Tasks.AddLoop(() => { if (dictionary != null && ((ICollection)dictionary).Count != pairs.Count) { Rebuild(); } }); var current = PropertyValue(EditorParams.Objects.First()); ContainerWidget.AddChangeWatcher(() => current.GetValue(), d => { dictionary = d; Rebuild(); }); }
protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams) { EditorContainer.AddNode(new Widget { Layout = new HBoxLayout(), Nodes = { (editor = editorParams.EditBoxFactory()), Spacer.HSpacer(4), (button = new ThemedButton { Text = "...", MinMaxWidth = 20, LayoutCell = new LayoutCell(Alignment.Center) }) } }); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Submitted += text => SetComponent(text); bool textValid = true; editor.AddChangeWatcher(() => editor.Text, text => textValid = IsValid(text)); editor.CompoundPostPresenter.Add(new SyncDelegatePresenter <EditBox>(editBox => { if (!textValid) { editBox.PrepareRendererState(); Renderer.DrawRect(Vector2.Zero, editBox.Size, Color4.Red.Transparentify(0.8f)); } })); button.Clicked += () => { var dlg = new FileDialog { AllowedFileTypes = allowedFileTypes, Mode = FileDialogMode.Open, InitialDirectory = Directory.Exists(LastOpenedDirectory) ? LastOpenedDirectory : Project.Current.GetSystemDirectory(Document.Current.Path), }; if (dlg.RunModal()) { SetFilePath(dlg.FileName); LastOpenedDirectory = Project.Current.GetSystemDirectory(dlg.FileName); } }; ExpandableContent.Padding = new Thickness(24, 10, 2, 2); var prefixEditor = new StringPropertyEditor(new PropertyEditorParams(ExpandableContent, prefix, nameof(PrefixData.Prefix)) { LabelWidth = 180 }); prefix.Prefix = GetLongestCommonPrefix(GetPaths()); ContainerWidget.AddChangeWatcher(() => prefix.Prefix, v => { string oldPrefix = GetLongestCommonPrefix(GetPaths()); if (oldPrefix == v) { return; } SetPathPrefix(oldPrefix, v); prefix.Prefix = v.Trim('/'); }); }
protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams) { ThemedButton button; this.allowedFileTypes = allowedFileTypes; EditorContainer.AddNode(new Widget { Layout = new HBoxLayout(), Nodes = { (editor = editorParams.EditBoxFactory()), Spacer.HSpacer(4), (button = new ThemedButton { Text = "...", MinMaxWidth = 20, LayoutCell = new LayoutCell(Alignment.Center) }) } }); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Submitted += text => SetComponent(text); button.Clicked += OnSelectClicked; ExpandableContent.Padding = new Thickness(24, 10, 2, 2); var prefixEditor = new StringPropertyEditor(new PropertyEditorParams(ExpandableContent, prefix, nameof(PrefixData.Prefix)) { LabelWidth = 180 }); prefix.Prefix = GetLongestCommonPrefix(GetPaths()); ContainerWidget.AddChangeWatcher(() => prefix.Prefix, v => { string oldPrefix = GetLongestCommonPrefix(GetPaths()); if (oldPrefix == v) { return; } SetPathPrefix(oldPrefix, v); prefix.Prefix = v.Trim('/'); }); ContainerWidget.AddChangeWatcher(() => ShowPrefix, show => { Expanded = show && Expanded; ExpandButton.Visible = show; }); var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = ValueToStringConverter(v.Value) ?? ""); ManageManyValuesOnFocusChange(editor, current); }
public ListPropertyEditor(IPropertyEditorParams editorParams, Func <PropertyEditorParams, Widget, IList, IEnumerable <IPropertyEditor> > onAdd) : base(editorParams) { this.onAdd = onAdd; if (EditorParams.Objects.Skip(1).Any()) { // Dont create editor interface if > 1 objects are selected EditorContainer.AddNode(new Widget() { Layout = new HBoxLayout(), Nodes = { new ThemedSimpleText { Text = "Edit of list properties isnt supported for multiple selection.", ForceUncutText = false } }, // TODO: move color to theme Presenter = new WidgetFlatFillPresenter(Theme.Colors.WarningBackground) }); return; } ExpandableContent.Padding = new Thickness(left: 4.0f, right: 0.0f, top: 4.0f, bottom: 4.0f); list = (IList)EditorParams.PropertyInfo.GetValue(EditorParams.Objects.First()); var addButton = new ThemedAddButton() { Clicked = () => { Expanded = true; if (list == null) { var pi = EditorParams.PropertyInfo; var o = EditorParams.Objects.First(); pi.SetValue(o, list = new TList()); } var newElement = typeof(TElement) == typeof(string) ? (TElement)(object)string.Empty : Activator.CreateInstance <TElement>(); using (Document.Current.History.BeginTransaction()) { int newIndex = list.Count; InsertIntoList.Perform(list, newIndex, newElement); Document.Current.History.CommitTransaction(); } } }; EditorContainer.AddNode(addButton); ContainerWidget.Updating += _ => removeCallback?.Invoke(); ContainerWidget.AddChangeWatcher(() => list?.Count ?? 0, Build); }
public ColorGradientPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { if (editorParams.Objects.Count() > 1) { ExpandButton.Visible = false; EditorContainer.AddNode(new ThemedSimpleText { Text = "Unable to edit multiple gradients", VAlignment = VAlignment.Center, LayoutCell = new LayoutCell(Alignment.Center, stretchX: 0), }); return; } gradientControlWidget = new TransactionalGradientControlWidget(EditorParams.History) { MinMaxHeight = 35f, Height = 35f, LayoutCell = new LayoutCell(Alignment.LeftCenter), Padding = new Thickness { Right = 5f, Bottom = 5f } }; var gradientProperty = CoalescedPropertyValue(new ColorGradient(Color4.White, Color4.Black)).DistinctUntilChanged(); gradientControlWidget.Gradient = gradientProperty.GetValue(); ContainerWidget.AddChangeWatcher(gradientProperty, g => gradientControlWidget.Gradient = g); gradientControlWidget.SelectionChanged += SelectPoint; EditorContainer.AddNode(gradientControlWidget); EditorContainer.AddNode(CreatePipetteButton()); ExpandableContent.Padding = new Thickness { Left = 25f, Right = 25f, Top = 5f }; ExpandableContent.AddNode(new Widget { Layout = new HBoxLayout { Spacing = 10f }, Nodes = { new ThemedSimpleText { Text = nameof(GradientControlPoint.Position), MinWidth = 150 }, (positionEditor = EditorParams.NumericEditBoxFactory()) }, Padding = new Thickness(0, 3f) }); ExpandableContent.AddNode(new Widget { Layout = new HBoxLayout { Spacing = 10f }, Nodes = { new ThemedSimpleText { Text = nameof(GradientControlPoint.Color), MinWidth = 150 }, (colorEditor = EditorParams.EditBoxFactory()) }, Padding = new Thickness(0, 3f) }); positionEditor.Step = 0.005f; colorEditor.Submitted += SetColor; positionEditor.Submitted += SetPosition; colorPanel = new ColorPickerPanel(); ExpandableContent.AddNode(colorPanel.Widget); var padding = colorPanel.Widget.Padding; padding.Right = 12; colorPanel.Widget.Padding = padding; colorPanel.DragStarted += () => EditorParams.History?.BeginTransaction(); gradientControlWidget.DragStarted += () => EditorParams.History?.BeginTransaction(); gradientControlWidget.DragEnded += () => { EditorParams.History?.CommitTransaction(); EditorParams.History?.EndTransaction(); }; colorPanel.DragEnded += () => { EditorParams.History?.CommitTransaction(); EditorParams.History?.EndTransaction(); }; colorPanel.Changed += () => { EditorParams.History?.RollbackTransaction(); Core.Operations.SetProperty.Perform(selectedControlPoint, nameof(GradientControlPoint.Color), colorPanel.Color); }; SelectPoint(selectedControlPoint); }