Ejemplo n.º 1
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && provider != null && context.Instance != null)
     {
         MathematicExpression me = context.Instance as MathematicExpression;
         if (me != null)
         {
             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             if (edSvc != null)
             {
                 Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 MathExpEditor.ExcludeProjectItem = true;
                 IMathEditor dlg = me.CreateEditor(rc);
                 MathExpEditor.ExcludeProjectItem = false;
                 MathNodeRoot r = new MathNodeRoot();
                 r.SetWriter(me.GetWriter());
                 r.SetReader(me.GetReader());
                 try
                 {
                     XmlDocument doc = new XmlDocument();
                     doc.LoadXml(me.Formula.Xml);
                     if (doc.DocumentElement != null)
                     {
                         r.Load(doc.DocumentElement);
                     }
                 }
                 catch
                 {
                 }
                 dlg.MathExpression            = r;
                 dlg.MathExpression.EnableUndo = true;
                 try
                 {
                     if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                     {
                         r = (MathNodeRoot)dlg.MathExpression;
                         r.FindAllInputVariables();
                         XmlDocument doc      = new XmlDocument();
                         XmlNode     rootNode = doc.CreateElement(MathematicExpression.XML_Root);
                         doc.AppendChild(rootNode);
                         r.SetWriter(me.GetWriter());
                         r.SetReader(me.GetReader());
                         r.Save(rootNode);
                         value = new FormulaProperty(doc.OuterXml);
                         PropertyGrid pg   = null;
                         Type         t    = edSvc.GetType();
                         PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                         if (pif0 != null)
                         {
                             object g = pif0.GetValue(edSvc, null);
                             pg = g as PropertyGrid;
                             if (pg != null)
                             {
                                 me.SetPropertyGrid(pg);
                             }
                         }
                     }
                 }
                 catch (Exception err2)
                 {
                     MessageBox.Show(MathException.FormExceptionText(null, err2), "Math Expression Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
     }
     return(value);
 }