Example #1
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             IMethod m = value as IMethod;
             IActionMethodPointer im     = null;
             MethodPointer        method = value as MethodPointer;
             if (m == null)
             {
                 IMethodPointerHolder mh = context.Instance as IMethodPointerHolder;
                 if (mh != null)
                 {
                     im = mh.GetMethodPointer();
                     if (im != null)
                     {
                         m = im.MethodPointed;
                     }
                 }
             }
             MethodClass  scopeMethod = null;
             Type         t           = edSvc.GetType();
             PropertyInfo pif0        = t.GetProperty("OwnerGrid");
             if (pif0 != null)
             {
                 object           g  = pif0.GetValue(edSvc, null);
                 MathPropertyGrid pg = g as MathPropertyGrid;
                 if (pg != null)
                 {
                     scopeMethod = pg.ScopeMethod as MethodClass;
                 }
             }
             if (scopeMethod == null)
             {
                 IAction ia = context.Instance as IAction;
                 if (ia != null)
                 {
                     scopeMethod = ia.ScopeMethod as MethodClass;
                 }
             }
             FrmObjectExplorer dlg = DesignUtil.CreateSelectMethodDialog(scopeMethod, m);
             if (edSvc.ShowDialog(dlg) == DialogResult.OK)
             {
                 IAction act = null;
                 if (method != null)
                 {
                     act = method.Action;
                 }
                 if (act == null)
                 {
                     if (im != null)
                     {
                         act = im.Action;
                     }
                 }
                 IPropertyEx p = dlg.SelectedObject as IPropertyEx;
                 if (p != null)
                 {
                     value = p.CreateSetterMethodPointer(act);
                 }
                 else
                 {
                     MethodPointer mp = dlg.SelectedObject as MethodPointer;
                     if (mp != null)
                     {
                         mp.Action = act;
                         value     = mp;
                     }
                     else
                     {
                         CustomMethodPointer cmp = dlg.SelectedObject as CustomMethodPointer;
                         if (cmp != null)
                         {
                             cmp.Action = act;
                             value      = cmp;
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         ParameterValue pv = context.Instance as ParameterValue;
         if (pv == null)
         {
             MapItem item = context.Instance as MapItem;
             if (item != null)
             {
                 pv = item.Item.Value as ParameterValue;
             }
         }
         if (pv == null)
         {
             pv = value as ParameterValue;
         }
         if (pv != null)
         {
             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             if (edSvc != null)
             {
                 IMathExpression mew = value as IMathExpression;
                 if (mew == null)
                 {
                     mew = pv.MathExpression;
                     if (mew == null)
                     {
                         MathNodeRoot r = new MathNodeRoot();
                         r.Name = pv.Name;
                         mew    = r;
                     }
                 }
                 System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 IMathEditor dlg = mew.CreateEditor(rc);
                 //
                 MathPropertyGrid pg   = null;
                 Type             t    = edSvc.GetType();
                 PropertyInfo     pif0 = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object g = pif0.GetValue(edSvc, null);
                     pg = g as MathPropertyGrid;
                 }
                 IMethod imScope = pv.ScopeMethod;
                 if (imScope == null)
                 {
                     imScope = mew.ScopeMethod;
                     if (imScope == null)
                     {
                         if (pg != null)
                         {
                             imScope = pg.ScopeMethod;
                         }
                     }
                 }
                 //
                 dlg.ActionContext = pv.ActionContext;
                 dlg.SetScopeMethod(imScope);
                 dlg.VariableMapTargetType      = typeof(ParameterValue);
                 dlg.MathExpression             = (IMathExpression)mew.Clone();
                 dlg.MathExpression.ScopeMethod = imScope;
                 dlg.MathExpression.EnableUndo  = true;
                 if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                 {
                     mew = dlg.MathExpression;
                     if (value != pv)
                     {
                         value = mew;
                         pv.SetValue(value);
                     }
                     else
                     {
                         pv.SetValue(mew);
                     }
                     if (pg != null)
                     {
                         pg.OnValueChanged(mew, EventArgs.Empty);
                     }
                 }
             }
         }
     }
     return(value);
 }
Example #3
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (service != null)
         {
             IObjectPointer mm = value as IObjectPointer;
             if (mm == null)
             {
                 PropertyPointer pp = new PropertyPointer();
                 IDataScope      dv = context.Instance as IDataScope;
                 if (dv != null)
                 {
                     pp.Scope = dv.ScopeDataType;
                     pp.Owner = dv.ScopeOwner;
                 }
                 mm = pp;
             }
             if (mm != null)
             {
                 IMethod      imScope = null;
                 Type         t       = service.GetType();
                 PropertyInfo pif0    = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object           pv = pif0.GetValue(service, null);
                     MathPropertyGrid pg = pv as MathPropertyGrid;
                     if (pg != null)
                     {
                         imScope = pg.ScopeMethod;
                     }
                 }
                 if (imScope == null)
                 {
                     IScopeMethodHolder mh = context.Instance as IScopeMethodHolder;
                     if (mh != null)
                     {
                         imScope = mh.GetScopeMethod();
                     }
                 }
                 DataTypePointer scope = null;
                 IOwnerScope     ios   = context.Instance as IOwnerScope;
                 if (ios != null)
                 {
                     scope = ios.OwnerScope;
                 }
                 if (scope == null)
                 {
                     ParameterValue pv = context.Instance as ParameterValue;
                     if (pv != null && pv.DataType != null && pv.DataType.BaseClassType != null)
                     {
                         if (typeof(Delegate).IsAssignableFrom(pv.DataType.BaseClassType))
                         {
                             scope = pv.DataType;
                         }
                     }
                 }
                 FrmObjectExplorer dlg = DesignUtil.GetPropertySelector(mm, imScope, scope);
                 if (dlg != null)
                 {
                     OnDialogCreated(dlg);
                     if (service.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                     {
                         bool   isValid = true;
                         string msg     = string.Empty;
                         if (MethodEditContext.IsWebPage)
                         {
                             IObjectPointer iop = dlg.SelectedObject as IObjectPointer;
                             if (iop != null)
                             {
                                 if (MethodEditContext.UseClientPropertyOnly)
                                 {
                                     if (iop.RunAt == EnumWebRunAt.Server)
                                     {
                                         isValid = false;
                                         msg     = "Server value is not allowed";
                                     }
                                 }
                                 else if (MethodEditContext.UseServerPropertyOnly)
                                 {
                                     if (iop.RunAt == EnumWebRunAt.Client)
                                     {
                                         isValid = false;
                                         msg     = "Client value is not allowed";
                                     }
                                 }
                             }
                         }
                         if (!isValid)
                         {
                             MessageBox.Show(msg, "Select value", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                         else
                         {
                             value = dlg.SelectedObject;
                             if (context.PropertyDescriptor.IsReadOnly)
                             {
                                 //manually set it
                                 PropertyInfo pif = context.Instance.GetType().GetProperty(context.PropertyDescriptor.Name);
                                 pif.SetValue(context.Instance, value, new object[] { });
                             }
                         }
                     }
                     dlg.ResetSelectLValue();
                 }
             }
         }
     }
     return(value);
 }