| internalclassaTreeViewEditorServiceContext:IWindowsFormsEditorService, |
| ITypeDescriptorContext,IServiceProvider |
| { |
| IComponentChangeService_componentChangeService; |
| ComponentDesigner_designer; |
| PropertyDescriptor_targetProperty; |
|
| internalaTreeViewEditorServiceContext(ComponentDesignerdesigner) |
| { |
| this._designer=designer; |
| } |
|
| internalaTreeViewEditorServiceContext(ComponentDesignerdesigner,PropertyDescriptorprop) |
| { |
| this._designer=designer; |
| this._targetProperty=prop; |
| if(prop==null) |
| { |
| prop=TypeDescriptor.GetDefaultProperty(designer.Component); |
| if((prop!=null)&&typeof(ICollection).IsAssignableFrom(prop.PropertyType)) |
| { |
| this._targetProperty=prop; |
| } |
| } |
| } |
|
| internalaTreeViewEditorServiceContext(ComponentDesignerdesigner,PropertyDescriptorprop,stringverbText) |
| :this(designer,prop) |
| { |
| this._designer.Verbs.Add(newDesignerVerb(verbText,newEventHandler(this.OnEditItems))); |
| } |
|
| publicstaticobjectEditValue(ComponentDesignerdesigner,objectobjectToChange,stringpropName) |
| { |
| try |
| { |
| PropertyDescriptorprop=TypeDescriptor.GetProperties(objectToChange)[propName]; |
| aTreeViewEditorServiceContextcontext= |
| newaTreeViewEditorServiceContext(designer,prop); |
| UITypeEditoreditor=prop.GetEditor(typeof(UITypeEditor))asUITypeEditor; |
| objectobj1=prop.GetValue(objectToChange); |
objectobj2=editor.EditValue(context,context,obj1);//Error occurs here.
|
| //MessageBox.Show(((aTreeNodeCollection)obj2)[0].Text.ToString()); |
| if(obj2!=obj1) |
| { |
| try |
| { |
| prop.SetValue(objectToChange,obj2); |
| } |
| catch(CheckoutException) |
| { |
| } |
| } |
| returnobj2; |
| } |
| catch(Exceptionex) |
| { |
| MessageBox.Show(ex.Message); |
| } |
| returnnull; |
| } |
|
| privatevoidOnEditItems(objectsender,EventArgse) |
| { |
| try |
| { |
| objectcomponent=this._targetProperty.GetValue(this._designer.Component); |
| if(component!=null) |
| { |
| CollectionEditoreditor=TypeDescriptor.GetEditor(component,typeof(UITypeEditor))asCollectionEditor; |
| if(editor!=null) |
| { |
| editor.EditValue(this,this,component); |
| } |
| } |
| } |
| catch(Exceptionex) |
| { |
| MessageBox.Show(ex.Message); |
| } |
| } |
|
| privateIComponentChangeServiceChangeService |
| { |
| get |
| { |
| if(this._componentChangeService==null) |
| { |
| this._componentChangeService= |
| (IComponentChangeService)((IServiceProvider)this).GetService(typeof(IComponentChangeService)); |
| } |
| return_componentChangeService; |
| } |
| } |
|
| #regionIWindowsFormsEditorService |
| voidIWindowsFormsEditorService.CloseDropDown() |
| { |
| } |
|
| voidIWindowsFormsEditorService.DropDownControl(Controlcontrol) |
| { |
| } |
|
| DialogResultIWindowsFormsEditorService.ShowDialog(Formdialog) |
| { |
|
| IUIServiceservice=(IUIService)((IServiceProvider)this).GetService(typeof(IUIService)); |
| if(service!=null) |
| { |
| returnservice.ShowDialog(dialog); |
| } |
| returndialog.ShowDialog(this._designer.ComponentasIWin32Window); |
|
| } |
| #endregion |
|
| #regionITypeDescriptorContext |
|
| objectIServiceProvider.GetService(TypeserviceType) |
| { |
| if((serviceType==typeof(ITypeDescriptorContext))||(serviceType==typeof(IWindowsFormsEditorService))) |
| { |
| returnthis; |
| } |
| if(this._designer.Component.Site!=null) |
| { |
| returnthis._designer.Component.Site.GetService(serviceType); |
| } |
| returnnull; |
| } |
|
| boolITypeDescriptorContext.OnComponentChanging() |
| { |
| try |
| { |
| this.ChangeService.OnComponentChanging(this._designer.Component,this._targetProperty); |
| } |
| catch(CheckoutExceptionexception) |
| { |
| if(exception!=CheckoutException.Canceled) |
| { |
| throw; |
| } |
| returnfalse; |
| } |
| returntrue; |
| } |
|
| voidITypeDescriptorContext.OnComponentChanged() |
| { |
| this.ChangeService.OnComponentChanged(this._designer.Component,this._targetProperty,null,null); |
| } |
|
| IContainerITypeDescriptorContext.Container |
| { |
| get |
| { |
| if(this._designer.Component.Site!=null) |
| { |
| returnthis._designer.Component.Site.Container; |
| } |
| returnnull; |
| } |
| } |
|
| objectITypeDescriptorContext.Instance |
| { |
| get |
| { |
| returnthis._designer.Component; |
| } |
| } |
|
| PropertyDescriptorITypeDescriptorContext.PropertyDescriptor |
| { |
| get |
| { |
| returnthis._targetProperty; |
| } |
| } |
|
| #endregion |
|
| } |