Exemplo n.º 1
0
        public BaseEditor GetEditor(PropertyDescriptor pd, GridRow parentRow)
        {
            //try to find a custom editor
            //TODO: Find a way to provide a IWindowsFormsEditorService so this can work directly
            //for now, substitute GTK#-based editors
            /*
            UITypeEditor UITypeEd = (UITypeEditor) pd.GetEditor(typeof (System.Drawing.Design.UITypeEditor));//first, does it have custom editors?
            if (UITypeEd != null)
                if (surrogates.Contains(UITypeEd.GetType ()))
                    return instantiateEditor((Type) surrogates[UITypeEd.GetType()], parentRow);
            */

            //does a registered GTK# editor support this natively?
            Type editType = pd.PropertyType;
            if (editors.Contains (editType))
                return instantiateEditor ((Type) editors[editType], parentRow);

            //editors that edit derived types
            foreach (DictionaryEntry de in inheritingEditors)
                if (editType.IsSubclassOf((Type) de.Key))
                    return instantiateEditor ((Type) de.Value, parentRow);

            //special cases
            if (editType.IsEnum)
                return new EnumEditor (parentRow);

            //collections with items of single type that aren't just objects
            if(editType.GetInterface ("IList") != null) {
                PropertyInfo member = editType.GetProperty ("Item");
                if (member != null)
                    if (member.PropertyType != typeof (object))
                        return new CollectionEditor (parentRow, member.PropertyType);
            }
            //TODO: support simple SWF collection editor derivatives that just override Types available
            // and reflect protected Type[] NewItemTypes {get;} to get types
            //if (UITypeEd is System.ComponentModel.Design.CollectionEditor)
            //	((System.ComponentModel.Design.CollectionEditor)UITypeEd).

            //can we use a type converter with a built-in editor?
            TypeConverter tc = pd.Converter;

            //TODO: build this functionality into the grid
            if (tc.GetType () == typeof (ExpandableObjectConverter)) {
                return new ExpandableObjectEditor (parentRow);
            }

            //This is a temporary workaround *and* and optimisation
            //First, most unknown types will be most likely to convert to/from strings
            //Second, System.Web.UI.WebControls/UnitConverter.cs dies on non-strings
            if (tc.CanConvertFrom (typeof (string)) && tc.CanConvertTo (typeof(string)))
                return new StringEditor (parentRow);

            foreach (DictionaryEntry editor in editors)
                if (tc.CanConvertFrom((Type) editor.Key) && tc.CanConvertTo((Type) editor.Key))
                    return instantiateEditor((Type) editor.Value, parentRow);

            foreach (DictionaryEntry de in inheritingEditors)
                if (tc.CanConvertFrom((Type) de.Key) && tc.CanConvertTo((Type) de.Key))
                    return instantiateEditor((Type) de.Value, parentRow);

            //nothing found - just display type
            return new DefaultEditor (parentRow);
        }
Exemplo n.º 2
0
 public EnumEditor(GridRow parentRow)
     : base(parentRow)
 {
     if (!parentRow.PropertyDescriptor.PropertyType.IsEnum)
         throw new Exception ("property is not an enum");
 }
Exemplo n.º 3
0
 private BaseEditor instantiateEditor(Type type, GridRow parentRow)
 {
     ConstructorInfo ctor = type.GetConstructor( new Type[] { typeof (GridRow) });
     return (BaseEditor) ctor.Invoke(new object[] { parentRow });
 }
 public PropertyValueChangedEventArgs(GridRow changedItem, object oldValue, object newValue)
 {
     this.changedItem = changedItem;
     this.oldValue = oldValue;
     this.newValue = newValue;
 }
Exemplo n.º 5
0
        public BaseEditor GetEditor(PropertyDescriptor pd, GridRow parentRow)
        {
            //try to find a custom editor
            //TODO: Find a way to provide a IWindowsFormsEditorService so this can work directly
            //for now, substitute GTK#-based editors

            /*
             * UITypeEditor UITypeEd = (UITypeEditor) pd.GetEditor(typeof (System.Drawing.Design.UITypeEditor));//first, does it have custom editors?
             * if (UITypeEd != null)
             *      if (surrogates.Contains(UITypeEd.GetType ()))
             *              return instantiateEditor((Type) surrogates[UITypeEd.GetType()], parentRow);
             */

            //does a registered GTK# editor support this natively?
            Type editType = pd.PropertyType;

            if (editors.Contains(editType))
            {
                return(instantiateEditor((Type)editors[editType], parentRow));
            }

            //editors that edit derived types
            foreach (DictionaryEntry de in inheritingEditors)
            {
                if (editType.IsSubclassOf((Type)de.Key))
                {
                    return(instantiateEditor((Type)de.Value, parentRow));
                }
            }

            //special cases
            if (editType.IsEnum)
            {
                return(new EnumEditor(parentRow));
            }

            //collections with items of single type that aren't just objects
            if (editType.GetInterface("IList") != null)
            {
                PropertyInfo member = editType.GetProperty("Item");
                if (member != null)
                {
                    if (member.PropertyType != typeof(object))
                    {
                        return(new CollectionEditor(parentRow, member.PropertyType));
                    }
                }
            }
            //TODO: support simple SWF collection editor derivatives that just override Types available
            // and reflect protected Type[] NewItemTypes {get;} to get types
            //if (UITypeEd is System.ComponentModel.Design.CollectionEditor)
            //	((System.ComponentModel.Design.CollectionEditor)UITypeEd).

            //can we use a type converter with a built-in editor?
            TypeConverter tc = pd.Converter;

            //TODO: build this functionality into the grid
            if (tc.GetType() == typeof(ExpandableObjectConverter))
            {
                return(new ExpandableObjectEditor(parentRow));
            }

            //This is a temporary workaround *and* and optimisation
            //First, most unknown types will be most likely to convert to/from strings
            //Second, System.Web.UI.WebControls/UnitConverter.cs dies on non-strings
            if (tc.CanConvertFrom(typeof(string)) && tc.CanConvertTo(typeof(string)))
            {
                return(new StringEditor(parentRow));
            }

            foreach (DictionaryEntry editor in editors)
            {
                if (tc.CanConvertFrom((Type)editor.Key) && tc.CanConvertTo((Type)editor.Key))
                {
                    return(instantiateEditor((Type)editor.Value, parentRow));
                }
            }

            foreach (DictionaryEntry de in inheritingEditors)
            {
                if (tc.CanConvertFrom((Type)de.Key) && tc.CanConvertTo((Type)de.Key))
                {
                    return(instantiateEditor((Type)de.Value, parentRow));
                }
            }

            //nothing found - just display type
            return(new DefaultEditor(parentRow));
        }
Exemplo n.º 6
0
        private BaseEditor instantiateEditor(Type type, GridRow parentRow)
        {
            ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(GridRow) });

            return((BaseEditor)ctor.Invoke(new object[] { parentRow }));
        }
Exemplo n.º 7
0
        private Table BuildTable(ArrayList arr)
        {
            //create new table
            Table table = new Table (Convert.ToUInt32 (arr.Count), 2, false);
            table.ColumnSpacing = 1;
            table.RowSpacing = 1;
            table.BorderWidth = 0;

            UInt32 currentRow = 0;

            for (int i = 0; i < arr.Count; i++) {
            PropertyDescriptor pd = (PropertyDescriptor) arr[i];

            //create item
            //TODO: expand children of expandable objects with no editor. Use ExpandableObjectConverter?
            GridRow newRow = new GridRow (this, pd);

            if (newRow.IsValidProperty) {
                table.Attach (newRow.LabelWidget, 0, 1, currentRow, currentRow + 1, AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                table.Attach (newRow.ValueWidget, 1, 2, currentRow, currentRow + 1, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                currentRow += 1;
                Rows.Add (newRow);

                if (newRow.PropertyDescriptor == SelectedTab.GetDefaultProperty (this.CurrentObject))
                    this.SelectedRow = newRow;
            }

            }
            return table;
        }
Exemplo n.º 8
0
 public void OnPropertyValueChanged(GridRow changedItem, object oldValue, object newValue)
 {
     if (PropertyValueChanged != null)
     PropertyValueChanged (this, new PropertyValueChangedEventArgs (changedItem, oldValue, newValue));
 }