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);
}