public void SaveToXmlNode(XmlNode node)
        {
            SaveLocations();
            mathExp.Save(node);
            Form f = this.FindForm();

            if (f != null)
            {
                XmlSerialization.SetAttribute(node, XmlSerialization.XMLATT_EDITORRECT, f.Bounds);
            }
            _changed = false;
        }
Beispiel #2
0
        private string createXmlString()
        {
            XmlDocument doc      = new XmlDocument();
            XmlNode     rootNode = doc.CreateElement(XML_Root);

            doc.AppendChild(rootNode);
            _root.SetWriter(_writer);
            _root.Save(rootNode);
            if (_variables != null && _variables.Count > 0)
            {
                XmlNode nodeVars = XmlUtil.CreateSingleNewElement(doc.DocumentElement, XML_Variables);
                nodeVars.RemoveAll();
                foreach (KeyValuePair <string, MathPropertyPointer> kv in _variables)
                {
                    XmlNode node = nodeVars.OwnerDocument.CreateElement(XML_Item);
                    nodeVars.AppendChild(node);
                    XmlUtil.SetNameAttribute(node, kv.Key);
                    MathPropertyPointer top = kv.Value.Top;
                    top.SaveToXml(node);
                }
            }
            return(doc.OuterXml);
        }
Beispiel #3
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);
 }