Пример #1
0
 public BlendingCell(object obj, string propName)
 {
     Layout       = new HBoxLayout();
     MinMaxHeight = 20;
     Anchors      = Anchors.LeftRightTopBottom;
     property     = new Property <BlendingOption>(obj, propName);
     AddButton    = new ThemedAddButton {
         Anchors    = Anchors.Center,
         Clicked    = () => property.Value = new BlendingOption(),
         LayoutCell = new LayoutCell {
             Alignment = Alignment.Center
         }
     };
     RemoveButton = new ThemedTabCloseButton {
         Clicked = () => property.Value = null
     };
     Nodes.Add(AddButton);
     AddChangeWatcher(() => property.Value, (v) => {
         Nodes.Clear();
         if (v == null)
         {
             Nodes.Add(AddButton);
         }
         else
         {
             new BlendingPropertyEditor(new PropertyEditorParams(this, obj, propName)
             {
                 ShowLabel = false
             });
             Nodes.Add(RemoveButton);
         }
     });
 }
Пример #2
0
        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);
        }