private void PropertyGrid_AutoGeneratingPropertyGridItem(object sender, Syncfusion.Windows.PropertyGrid.AutoGeneratingPropertyGridItemEventArgs e)
        {
            if (e.OriginalSource is PropertyItem {
            } propertyItem)
            {
                if (DataContext is RedCollectionEditorViewModel viewModel)
                {
                    var propertyType = propertyItem.PropertyType;
                    var propertyName = propertyItem.DisplayName;

                    ITypeEditor customEditor = null;

                    if (propertyType == typeof(object) && propertyName.Equals("Element"))
                    {
                        var type = viewModel.SelectedElement.Element.GetType();
                        customEditor = PropertyGridEditors.GetPropertyEditor(type);
                    }
                    else
                    {
                        customEditor = PropertyGridEditors.GetPropertyEditor(propertyItem.PropertyType);
                    }

                    if (customEditor is not null)
                    {
                        propertyItem.Editor = customEditor;
                        e.ExpandMode        = PropertyExpandModes.FlatMode;
                    }
                }
            }
        }
Beispiel #2
0
        // Get Type Editor UserControl from the parameter name and type
        private UserControl GetTypeEditor(string parameterName, Type t)
        {
            // Search the existing type editor user controls
            if (_typeEditorControls.Keys.Contains(parameterName + t.ToString()))
            {
                return(_typeEditorControls[parameterName + t.ToString()]);
            }

            // Search for the ITypeEditor with EditorType t
            ITypeEditor editor = _host.TypeEditors.Where(x => x.EditorType == t).FirstOrDefault();

            if (editor == null) // None found
            {
                _host.LogText(_searchUIAddOn, "Unable to locate ITypeEditor with EditorType of " + t.ToString());
                return(null);
            }

            editor.GetControl(out var ctrl);

            if (ctrl == null)
            {
                _host.LogText(_searchUIAddOn, "ITypeEditor " + editor.GetType().ToString() + " failed to initialize UserControl");
                return(null);
            }

            _typeEditorControls.Add(parameterName + t.ToString(), ctrl);
            return(ctrl);
        }
Beispiel #3
0
        public ITypeEditor GetEditor(PropertyItem pd)
        {
            ITypeEditor editor = pd.PropertyDescriptor.GetEditor(typeof(ITypeEditor)) as ITypeEditor;

            if (editor != null && pd.Editor == null)
            {
                return(editor);
            }
            EditorAttribute attribute = this.GetAttribute <EditorAttribute>(pd.PropertyDescriptor);

            if (attribute != null)
            {
                Type type = !(pd.DiaplayName == "Display_ColorBlend") ? Type.GetType(attribute.EditorTypeName) : Type.GetType("CocoStudio.Model.Editor.ColorsEditor, CocoStudio.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
                type.GetConstructors();
                if (Activator.CreateInstance(type) is ITypeEditor)
                {
                    object instance = Activator.CreateInstance(type, new object[1] {
                        (object)pd
                    });
                    pd.WidgetDate = ((ITypeEditor)instance).ResolveEditor((PropertyItem)null);
                    pd.TypeEditor = (ITypeEditor)instance;
                    return((ITypeEditor)null);
                }
            }
            return(this.GetEditorType(pd.PropertyDescriptor, pd) ?? (ITypeEditor) new DefaultEditor());
        }
        internal FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem)
        {
            FrameworkElement editorElement      = null;
            DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition;
            object      definitionKey           = null;
            Type        definitionKeyAsType     = definitionKey as Type;
            ITypeEditor editor = null;

            if (editor == null)
            {
                editor = pd.CreateAttributeEditor();
            }

            if (editor != null)
            {
                editorElement = editor.ResolveEditor(propertyItem);
            }


            if (editorElement == null && definitionKey == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyDescriptor.Name, propertyItem);
            }

            if (editorElement == null && definitionKeyAsType == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyType, propertyItem);
            }

            foreach (var edef in this.PropertyContainer.EditorDefinitions.Where(x => x.HasAttribute != null))
            {
                if (propertyItem.PropertyDescriptor.Attributes.Cast <Attribute>().Any(x => x.GetType() == edef.HasAttribute))
                {
                    return(edef.GenerateEditingElementInternal(propertyItem));
                }
            }

            if (editorElement == null)
            {
                if (pd.IsReadOnly)
                {
                    editor = new TextBlockEditor();
                }

                // Fallback: Use a default type editor.
                if (editor == null)
                {
                    editor = (definitionKeyAsType != null)
          ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null)
          : pd.CreateDefaultEditor();
                }

                Debug.Assert(editor != null);

                editorElement = editor.ResolveEditor(propertyItem);
            }

            return(editorElement);
        }
        internal FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem)
        {
            FrameworkElement editorElement      = null;
            DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition;
            object      definitionKey           = null;
            Type        definitionKeyAsType     = definitionKey as Type;
            ITypeEditor editor = null;

            if (editor == null)
            {
                editor = pd.CreateAttributeEditor();
            }

            if (editor != null)
            {
                editorElement = editor.ResolveEditor(propertyItem);
            }


            if ((editorElement == null) && (definitionKey == null) && (propertyItem.PropertyDescriptor != null))
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyDescriptor.Name, propertyItem);
            }

            if (editorElement == null && definitionKeyAsType == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyType, propertyItem);
            }

            if (editorElement == null)
            {
                if (propertyItem.IsReadOnly &&
                    !ListUtilities.IsListOfItems(propertyItem.PropertyType) &&
                    !ListUtilities.IsCollectionOfItems(propertyItem.PropertyType) &&
                    !ListUtilities.IsDictionaryOfItems(propertyItem.PropertyType))
                {
                    editor = new TextBlockEditor((propertyItem.PropertyDescriptor != null) ? propertyItem.PropertyDescriptor.Converter : null);
                }

                // Fallback: Use a default type editor.
                if (editor == null)
                {
                    editor = (definitionKeyAsType != null)
          ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null, propertyItem)
          : pd.CreateDefaultEditor(propertyItem);
                }

                Debug.Assert(editor != null);

                editorElement = editor.ResolveEditor(propertyItem);
            }

            return(editorElement);
        }
        private FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem)
        {
            FrameworkElement editorElement      = null;
            DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition;
            object      definitionKey           = null;
            Type        definitionKeyAsType     = definitionKey as Type;
            ITypeEditor editor = null;

            if (pd.IsReadOnly)
            {
                editor = new TextBlockEditor();
            }

            if (editor == null)
            {
                editor = pd.CreateAttributeEditor();
            }

            if (editor != null)
            {
                editorElement = editor.ResolveEditor(propertyItem);
            }


            if (editorElement == null && definitionKey == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyDescriptor.Name, propertyItem);
            }

            if (editorElement == null && definitionKeyAsType == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyType, propertyItem);
            }

            if (editorElement == null)
            {
                // Fallback: Use a default type editor.
                if (editor == null)
                {
                    editor = (definitionKeyAsType != null)
                    ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null)
                    : pd.CreateDefaultEditor();
                }

                Debug.Assert(editor != null);

                if (editor != null)
                {
                    editorElement = editor.ResolveEditor(propertyItem);
                }
            }

            return(editorElement);
        }
Beispiel #7
0
        public FrameworkElement GenerateEditorElement(PropertyItem propertyItem)
        {
            FrameworkElement editorElement = null;

            // Priority #1: CustomEditors based on the Attribute.
            ITypeEditor editor = GetAttributeEditor();

            if (editor != null)
            {
                editorElement = editor.ResolveEditor(propertyItem);
            }

            if (_propertyParent.EditorDefinitions != null)
            {
                // Priority #2: Custom Editors based on the name (same for all PropertyDescriptors).
                if (editorElement == null)
                {
                    editorElement = CreateCustomEditor(_propertyParent.EditorDefinitions[GetPropertyName()]);
                }

                // Priority #3: Custom Editors based on the type (same for all PropertyDescriptors).
                if (editorElement == null)
                {
                    editorElement = CreateCustomEditor(_propertyParent.EditorDefinitions[GetPropertyType()]);
                }
            }

            if (editorElement == null)
            {
                // Priority #4: Default Editor. Read-only properties use a TextBox.
                if (IsPropertyDescriptorReadOnly())
                {
                    editor = new TextBlockEditor();
                }

                // Fallback: Use a default type editor.
                if (editor == null)
                {
                    editor = CreateDefaultEditor();
                }

                Debug.Assert(editor != null);

                editorElement = editor.ResolveEditor(propertyItem);
            }

            return(editorElement);
        }
Beispiel #8
0
        internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter, PropertyItem propertyItem)
        {
            ITypeEditor editor = null;

            var context = new EditorTypeDescriptorContext(null, propertyItem.Instance, propertyItem.PropertyDescriptor);

            if ((typeConverter != null) &&
                typeConverter.GetStandardValuesSupported(context) &&
                typeConverter.GetStandardValuesExclusive(context) &&
                (propertyType != typeof(bool)) && (propertyType != typeof(bool?)))   //Bool type always have a BooleanConverter with standardValues : True/False.
            {
                var items = typeConverter.GetStandardValues(context);
                editor = new SourceComboBoxEditor(items, typeConverter);
            }
            else if (propertyType == typeof(string))
            {
                editor = new TextBoxEditor();
            }
            else if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyType == typeof(double) || propertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyType == typeof(int) || propertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyType == typeof(short) || propertyType == typeof(short?))
            {
                editor = new ShortUpDownEditor();
            }
            else if (propertyType == typeof(long) || propertyType == typeof(long?))
            {
                editor = new LongUpDownEditor();
            }
            else if (propertyType == typeof(float) || propertyType == typeof(float?))
            {
                editor = new SingleUpDownEditor();
            }
            else if (propertyType == typeof(byte) || propertyType == typeof(byte?))
            {
                editor = new ByteUpDownEditor();
            }
            else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?))
            {
                editor = new SByteUpDownEditor();
            }
            else if (propertyType == typeof(uint) || propertyType == typeof(uint?))
            {
                editor = new UIntegerUpDownEditor();
            }
            else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
            {
                editor = new ULongUpDownEditor();
            }
            else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?))
            {
                editor = new UShortUpDownEditor();
            }
            else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyType == typeof(Color)) || (propertyType == typeof(Color?)))
            {
                editor = new ColorEditor();
            }
            else if (propertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyType == typeof(TimeSpan) || propertyType == typeof(TimeSpan?))
            {
                editor = new TimeSpanUpDownEditor();
            }
            else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?))
            {
                editor = new MaskedTextBoxEditor()
                {
                    ValueDataType = propertyType, Mask = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
                }
            }
            ;
            else if (propertyType == typeof(char) || propertyType == typeof(char?))
            {
                editor = new MaskedTextBoxEditor()
                {
                    ValueDataType = propertyType, Mask = "&"
                }
            }
            ;
            else if (propertyType == typeof(object))
            {
                // If any type of object is possible in the property, default to the TextBoxEditor.
                // Useful in some case (e.g., Button.Content).
                // Can be reconsidered but was the legacy behavior on the PropertyGrid.
                editor = new TextBoxEditor();
            }
            else
            {
                var listType = ListUtilities.GetListItemType(propertyType);

                // A List of T
                if (listType != null)
                {
                    if (!listType.IsPrimitive && !listType.Equals(typeof(String)) && !listType.IsEnum)
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    var dictionaryType = ListUtilities.GetDictionaryItemsType(propertyType);
                    var collectionType = ListUtilities.GetCollectionItemType(propertyType);
                    // A dictionary of T or a Collection of T or an ICollection
                    if ((dictionaryType != null) || (collectionType != null) || typeof(ICollection).IsAssignableFrom(propertyType))
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        // If the type is not supported, check if there is a converter that supports
                        // string conversion to the object type. Use TextBox in theses cases.
                        // Otherwise, return a TextBlock editor since no valid editor exists.
                        editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                          ? (ITypeEditor) new TextBoxEditor()
                          : (ITypeEditor) new TextBlockEditor();
                    }
                }
            }

            return(editor);
        }
Beispiel #9
0
        internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter)
        {
            ITypeEditor editor = null;

            if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyType == typeof(double) || propertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyType == typeof(int) || propertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyType == typeof(short) || propertyType == typeof(short?))
            {
                editor = new ShortUpDownEditor();
            }
            else if (propertyType == typeof(long) || propertyType == typeof(long?))
            {
                editor = new LongUpDownEditor();
            }
            else if (propertyType == typeof(float) || propertyType == typeof(float?))
            {
                editor = new SingleUpDownEditor();
            }
            else if (propertyType == typeof(byte) || propertyType == typeof(byte?))
            {
                editor = new ByteUpDownEditor();
            }
            else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?))
            {
                editor = new UpDownEditor <SByteUpDown, sbyte?>();
            }
            else if (propertyType == typeof(uint) || propertyType == typeof(uint?))
            {
                editor = new UpDownEditor <UIntegerUpDown, uint?>();
            }
            else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
            {
                editor = new UpDownEditor <ULongUpDown, ulong?>();
            }
            else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?))
            {
                editor = new UpDownEditor <UShortUpDown, ushort?>();
            }
            else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyType == typeof(Color)))
            {
                editor = new ColorEditor();
            }
            else if (propertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyType == typeof(TimeSpan))
            {
                editor = new TimeSpanEditor();
            }
            else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else if (propertyType == typeof(object))
            {
                // If any type of object is possible in the property, default to the TextBoxEditor.
                // Useful in some case (e.g., Button.Content).
                // Can be reconsidered but was the legacy behavior on the PropertyGrid.
                editor = new TextBoxEditor();
            }
            else
            {
                Type listType = CollectionControl.GetListItemType(propertyType);

                if (listType != null)
                {
                    if (!listType.IsPrimitive && !listType.Equals(typeof(String)))
                    {
                        editor = new Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    // If the type is not supported, check if there is a converter that supports
                    // string conversion to the object type. Use TextBox in theses cases.
                    // Otherwise, return a TextBlock editor since no valid editor exists.
                    editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                                          ? (ITypeEditor) new TextBoxEditor()
                                          : (ITypeEditor) new TextBlockEditor();
                }
            }

            return(editor);
        }
Beispiel #10
0
        internal static FrameworkElement CreateDefaultEditor(PropertyItem propertyItem)
        {
            ITypeEditor editor = null;

            if (propertyItem.IsReadOnly)
            {
                editor = new TextBlockEditor();
            }
            else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyItem.PropertyType == typeof(Color)))
            {
                editor = new ColorEditor();
            }
            else if (propertyItem.PropertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyItem.PropertyType == typeof(TimeSpan))
            {
                editor = new TimeSpanEditor();
            }
            else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else if (propertyItem.PropertyType.IsGenericType)
            {
                if (propertyItem.PropertyType.GetInterface("IList") != null)
                {
                    var t = propertyItem.PropertyType.GetGenericArguments()[0];
                    if (!t.IsPrimitive && !t.Equals(typeof(String)))
                    {
                        editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    editor = new TextBlockEditor();
                }
            }
            else
            {
                editor = new TextBoxEditor();
            }

            return(editor.ResolveEditor(propertyItem));
        }
        internal static FrameworkElement CreateDefaultEditor(PropertyItem propertyItem)
        {
            ITypeEditor editor = null;


            if (propertyItem.IsReadOnly)
            {
                editor = new TextBlockEditor();
            }
            else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal? ))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime? ))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyItem.PropertyType == typeof(Color)))
            {
                editor = new ColorEditor();
            }
            else if (propertyItem.PropertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyItem.PropertyType == typeof(TimeSpan))
            {
                editor = new TimeSpanEditor();
            }
            else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else
            {
                Type listType = CollectionEditor.GetListItemType(propertyItem.PropertyType);

                if (listType != null)
                {
                    if (!listType.IsPrimitive && !listType.Equals(typeof(String)))
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    editor = new TextBoxEditor();
                }
            }

            return(editor.ResolveEditor(propertyItem));
        }
Beispiel #12
0
 public SODAMethodBuilder(ITypeEditor editor)
 {
     _editor = editor;
     BuildMethodReferences();
 }
Beispiel #13
0
        private PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid)
        {
            PropertyItem propertyItem = new PropertyItem(instance, property, grid);

            var binding = new Binding(property.Name)
            {
                Source = instance,
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true,
                Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay
            };

            if (instance is ICustomTypeDescriptor)
            {
                binding.Source = (instance as ICustomTypeDescriptor).GetPropertyOwner(property);
            }
            propertyItem.SetBinding(PropertyItem.ValueProperty, binding);

            ITypeEditor editor = null;

            foreach (Attribute attr in propertyItem.PropertyDescriptor.Attributes)
            {
                if (attr is EditorAttribute)
                {
                    editor = Activator.CreateInstance(Type.GetType((attr as EditorAttribute).EditorTypeName)) as ITypeEditor;
                    if (editor != null)
                    {
                        editor.Attach(propertyItem);
                        propertyItem.Editor = editor.ResolveEditor();

                        if (property is CustomizePropertyDescriptor)
                        {
                            propertyItem.Editor.IsEnabled = (property as CustomizePropertyDescriptor).IsEnabled;
                        }
                        return(propertyItem);
                    }
                }
            }
            //check for custom editor
            if (CustomTypeEditors.Count > 0)
            {
                //first check if the custom editor is type based
                ICustomTypeEditor customEditor = CustomTypeEditors[propertyItem.PropertyType];
                if (customEditor == null)
                {
                    //must be property based
                    customEditor = CustomTypeEditors[propertyItem.Name];
                }

                if (customEditor != null)
                {
                    editor = customEditor.Editor;
                }
            }

            try
            {
                //no custom editor found
                if (editor == null)
                {
                    if (propertyItem.IsReadOnly)
                    {
                        editor = new TextBlockEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?))
                    {
                        editor = new CheckBoxEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?))
                    {
                        editor = new DecimalUpDownEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?))
                    {
                        editor = new DoubleUpDownEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?))
                    {
                        editor = new IntegerUpDownEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?))
                    {
                        editor = new DateTimeUpDownEditor();
                    }
                    else if ((propertyItem.PropertyType == typeof(Color)))
                    {
                        editor = new ColorEditor();
                    }
                    else if (propertyItem.PropertyType.IsEnum)
                    {
                        editor = new EnumEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))
                    {
                        editor = new FontComboBoxEditor();
                    }
                    else if (propertyItem.PropertyType.IsGenericType)
                    {
                        if (propertyItem.PropertyType.GetInterface("IList") != null)
                        {
                            var t = propertyItem.PropertyType.GetGenericArguments()[0];
                            if (!t.IsPrimitive && !t.Equals(typeof(String)))
                            {
                                editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor();
                            }
                            else
                            {
                                editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                            }
                        }
                        else
                        {
                            editor = new TextBlockEditor();
                        }
                    }
                    else
                    {
                        editor = new TextBoxEditor();
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: handle this some how
            }

            editor.Attach(propertyItem);
            propertyItem.Editor = editor.ResolveEditor();
            if (property is CustomizePropertyDescriptor)
            {
                propertyItem.Editor.IsEnabled = (property as CustomizePropertyDescriptor).IsEnabled;
            }
            return(propertyItem);
        }
Beispiel #14
0
        private EventBox CreateTable(string calegory, List <PropertyItem> propertyItem)
        {
            EventBox eventBox = new EventBox();
            Table    table    = new Table((uint)(propertyItem.Count + 1), 2u, false);
            Label    label    = new Label();

            label.HeightRequest = 16;
            table.Attach(label, 1u, 2u, 0u, 1u, AttachOptions.Expand, AttachOptions.Fill, 0u, 0u);
            label.Show();
            uint num = 1u;

            foreach (PropertyItem current in propertyItem)
            {
                ITypeEditor editor = this.em.GetEditor(current);
                Widget      widget;
                if (editor == null)
                {
                    widget = current.WidgetDate;
                }
                else
                {
                    current.TypeEditor = editor;
                    widget             = editor.ResolveEditor(current);
                }
                if (current.DiaplayName == "grid_sudoku_size" || current.DiaplayName == "Fill_color")
                {
                    if (widget == null)
                    {
                        num += 1u;
                    }
                    else
                    {
                        if (widget is Entry)
                        {
                            Entry entry = widget as Entry;
                            table.Add(entry);
                            entry.Show();
                        }
                        else
                        {
                            table.Add(widget);
                        }
                        widget.Show();
                        Table.TableChild tableChild = (Table.TableChild)table[widget];
                        tableChild.LeftAttach   = 0u;
                        tableChild.RightAttach  = 2u;
                        tableChild.TopAttach    = num;
                        tableChild.BottomAttach = num + 1u;
                        tableChild.XOptions     = (AttachOptions.Expand | AttachOptions.Fill);
                        tableChild.YOptions     = AttachOptions.Fill;
                        num += 1u;
                    }
                }
                else
                {
                    ContentLabel contentLabel = new ContentLabel(90);
                    contentLabel.SetLabelText(LanguageOption.GetValueBykey(current.DiaplayName));
                    table.Add(contentLabel);
                    contentLabel.Show();
                    Table.TableChild tableChild2 = (Table.TableChild)table[contentLabel];
                    tableChild2.TopAttach    = num;
                    tableChild2.BottomAttach = num + 1u;
                    tableChild2.XOptions     = AttachOptions.Fill;
                    tableChild2.YOptions     = AttachOptions.Fill;
                    if (widget == null)
                    {
                        num += 1u;
                    }
                    else
                    {
                        Alignment alignment = new Alignment(0.5f, 0.5f, 1f, 1f);
                        if (widget is Entry)
                        {
                            Entry entry = widget as Entry;
                            alignment.BottomPadding = 16u;
                            alignment.Add(entry);
                            entry.Show();
                            alignment.Show();
                            table.Add(alignment);
                        }
                        else
                        {
                            if (widget is INumberEntry)
                            {
                                if ((widget as INumberEntry).GetMenuVisble())
                                {
                                    alignment.BottomPadding = 8u;
                                }
                                else
                                {
                                    alignment.BottomPadding = 16u;
                                }
                            }
                            else
                            {
                                alignment.BottomPadding = 16u;
                            }
                            alignment.Add(widget);
                            widget.Show();
                            alignment.Show();
                            table.Add(alignment);
                        }
                        Table.TableChild tableChild = (Table.TableChild)table[alignment];
                        tableChild.LeftAttach   = 1u;
                        tableChild.RightAttach  = 2u;
                        tableChild.TopAttach    = num;
                        tableChild.BottomAttach = num + 1u;
                        tableChild.XOptions     = (AttachOptions.Expand | AttachOptions.Fill);
                        tableChild.YOptions     = AttachOptions.Fill;
                        num += 1u;
                    }
                }
            }
            table.ColumnSpacing = 10u;
            eventBox.Add(table);
            table.Show();
            eventBox.CanFocus = false;
            return(eventBox);
        }
Beispiel #15
0
		public SODAMethodBuilder(ITypeEditor editor)
		{
			_editor = editor;
			BuildMethodReferences();
		}