public override bool Edit(UInt32 actionBranchId, Rectangle rcStart, ILimnorDesignerLoader loader, Form caller)
 {
     if (Owner == null)
     {
         Owner = loader.GetRootId();
     }
     try
     {
         _origiContext = VPLUtil.CurrentRunContext;
         if (loader.Project.IsWebApplication)
         {
             if (this.RunAt == EnumWebRunAt.Client)
             {
                 VPLUtil.CurrentRunContext = EnumRunContext.Client;
             }
             else
             {
                 VPLUtil.CurrentRunContext = EnumRunContext.Server;
             }
         }
         else
         {
             VPLUtil.CurrentRunContext = EnumRunContext.Server;
         }
         DlgMethod dlg = this.CreateMethodEditor(rcStart);
         dlg.LoadMethod(this, EnumParameterEditType.ReadOnly);
         if (dlg.EditSubAction(caller))
         {
             IsNewMethod = false;
             loader.GetRootId().SaveAction(this, loader.Writer);
             loader.NotifyChanges();
             return(true);
         }
     }
     catch (Exception err)
     {
         MathNode.Log(caller, err);
     }
     finally
     {
         ExitEditor();
         VPLUtil.CurrentRunContext = _origiContext;
     }
     return(false);
 }
        protected override object OnEditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, System.Windows.Forms.Design.IWindowsFormsEditorService service, object value)
        {
            IWithProject mc = context.Instance as IWithProject;

            if (mc != null)
            {
                if (mc.Project == null)
                {
                    MathNode.Log(TraceLogClass.GetForm(provider), new DesignerException("Project not set for {0} [{1}]", mc, mc.GetType()));
                }
                else
                {
                    GetterClass          val      = value as GetterClass;
                    System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                    rc.X = curPoint.X;
                    rc.Y = curPoint.Y;
                    DlgMethod dlg = val.CreateMethodEditor(rc);
                    try
                    {
                        dlg.SetNameReadOnly();
                        dlg.LoadMethod(val, EnumParameterEditType.ReadOnly);
                        dlg.Text = val.ToString();
                        if (service.ShowDialog(dlg) == DialogResult.OK)
                        {
                            value = val;
                            ILimnorDesignerLoader l = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader;
                            if (l != null)
                            {
                                //save the property and hence save the getter
                                DesignUtil.SaveCustomProperty(LimnorProject.ActiveDesignerLoader.Node, l.Writer, val.Property);
                                //save actions
                                List <IAction> actions = val.GetActions();
                                if (actions != null)
                                {
                                    foreach (IAction a in actions)
                                    {
                                        l.GetRootId().SaveAction(a, l.Writer);
                                    }
                                }
                                LimnorProject.ActiveDesignerLoader.NotifyChanges();
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        MathNode.Log(TraceLogClass.GetForm(provider), err);
                    }
                    finally
                    {
                        val.ExitEditor();
                    }
                }
            }
            return(value);
        }
Esempio n. 3
0
 public void OnFinishEdit(UInt32 actionBranchId, ILimnorDesignerLoader loader)
 {
     try
     {
         ILimnorDesignPane dp = loader.DesignPane;
         if (dp == null)
         {
             throw new DesignerException("ILimnorDesignPane not found for class {0}", loader.GetRootId());
         }
         IEvent       ep = _event;
         EventAction  ea = null;                //event-actions mapping
         ClassPointer a  = loader.GetRootId();
         if (a != null)
         {
             List <EventAction> lst = a.EventHandlers;
             if (lst != null)
             {
                 foreach (EventAction e in lst)
                 {
                     if (e.GetAssignActionId() == actionBranchId && e.Event.IsSameObjectRef(ep))
                     {
                         ea = e;
                         break;
                     }
                 }
             }
         }
         if (ea == null)
         {
             ea       = new EventAction();
             ea.Event = ep;
             if (actionBranchId != 0)
             {
                 ea.SetAssignActionId(actionBranchId);
             }
         }
         _handlerOwner = ea;
         ea.AddAction(this);
         a.SaveEventHandler(ea);
         dp.OnNotifyChanges();
         dp.OnAssignAction(ea);
     }
     catch (Exception err)
     {
         MathNode.Log(TraceLogClass.MainForm, err);
     }
     finally
     {
         this.ExitEditor();
     }
 }
Esempio n. 4
0
        public DlgMethod GetEditDialog(Rectangle rcStart, ILimnorDesignerLoader loader)
        {
            if (Owner == null)
            {
                MathNode.Log(loader.DesignPane.Window as Form, new DesignerException("Calling EventHandlerMethod.Edit with null method owner"));
            }
            if (this.Owner == null)
            {
                this.Owner = loader.GetRootId();
            }
            DlgMethod dlg = this.CreateMethodEditor(rcStart);

            if (Parameters != null && Parameters.Count > 0)
            {
                if (typeof(object).Equals(Parameters[0].ObjectType) && string.CompareOrdinal(Parameters[0].Name, "sender") == 0)
                {
                    Parameters[0]          = new ParameterClass(this.Event.Owner.ObjectType, "sender", this);
                    Parameters[0].ReadOnly = true;
                }
                if (Parameters.Count > 1)
                {
                    if (typeof(EventArgs).Equals(Parameters[1].ObjectType) && string.CompareOrdinal(Parameters[1].Name, "e") == 0)
                    {
                        ICustomEventMethodDescriptor ce = this.Event.Owner.ObjectInstance as ICustomEventMethodDescriptor;
                        if (ce != null)
                        {
                            Type pType = ce.GetEventArgumentType(this.Event.Name);
                            if (pType != null)
                            {
                                Parameters[1]          = new ParameterClass(pType, "e", this);
                                Parameters[1].ReadOnly = true;
                            }
                        }
                    }
                }
            }
            dlg.LoadMethod(this, EnumParameterEditType.ReadOnly);
            return(dlg);
        }
Esempio n. 5
0
        public override object OnGetDropDownControl(ITypeDescriptorContext context, IServiceProvider provider, IWindowsFormsEditorService service, object value)
        {
            ComponentPointer cp = (ComponentPointer)value;
            IComponent       h  = context.Instance as IComponent;

            if (h == null || h.Site == null)
            {
                h = VPL.VPLUtil.GetObject(context.Instance) as IComponent;
            }
            if (h == null || h.Site == null)
            {
                ClassPointer root = context.Instance as ClassPointer;
                if (root != null)
                {
                    h = root.ObjectInstance as IComponent;
                }
            }
            if (h == null || h.Site == null)
            {
                IObjectPointer op = context.Instance as IObjectPointer;
                if (op != null)
                {
                    ClassPointer root = op.RootPointer;
                    if (root != null)
                    {
                        h = root.ObjectInstance as IComponent;
                    }
                }
            }
            if (h != null && h.Site != null)
            {
                ListBox list = new ListBox();
                list.Tag       = service;
                list.Click    += new EventHandler(list_Click);
                list.KeyPress += new KeyPressEventHandler(list_KeyPress);
                foreach (IComponent ic in h.Site.Container.Components)
                {
                    if (ic is T)
                    {
                        list.Items.Add(new ComponentName(ic));
                    }
                    else
                    {
                        Type t = VPL.VPLUtil.GetObjectType(ic);
                        if (typeof(T).IsAssignableFrom(t))
                        {
                            int n = list.Items.Add(new ComponentName(ic));
                            if (cp != null && list.SelectedIndex < 0 && ic.Site != null)
                            {
                                if (cp.Name == ic.Site.Name)
                                {
                                    list.SelectedIndex = n;
                                }
                            }
                        }
                    }
                }
                if (list.Items.Count > 0)
                {
                    service.DropDownControl(list);
                    if (list.SelectedIndex >= 0)
                    {
                        ComponentName c = list.Items[list.SelectedIndex] as ComponentName;
                        if (c != null)
                        {
                            ILimnorDesignerLoader loader = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader;
                            UInt32 memberId = loader.ObjectMap.GetObjectID(c.Component);
                            if (memberId != 0)
                            {
                                XmlNode nodeCr = SerializeUtil.GetClassRefNodeByObjectId(loader.Node, memberId);
                                if (nodeCr != null)
                                {
                                    loader.Reader.ResetErrors();
                                    ClassInstancePointer cr = loader.Reader.ReadObject <ClassInstancePointer>(nodeCr, loader.GetRootId());
                                    if (loader.Reader.HasErrors)
                                    {
                                        MathNode.Log(loader.Reader.Errors);
                                    }
                                    ComponentPointer pt = new ComponentPointer(cr);
                                    value = pt;
                                }
                                else
                                {
                                    MemberComponentId cid = new MemberComponentId(loader.GetRootId(), c.Component, memberId);
                                    ComponentPointer  pt  = new ComponentPointer(cid);
                                    value = pt;
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }
        public override bool Edit(UInt32 actionBranchId, Rectangle rcStart, ILimnorDesignerLoader loader, Form caller)
        {
            if (this.Owner == null)
            {
                this.Owner = loader.GetRootId();
            }
            DlgMethod dlg = this.CreateMethodEditor(rcStart);

            try
            {
                _origiContext = VPLUtil.CurrentRunContext;
                if (loader.Project.IsWebApplication)
                {
                    if (this.RunAt == EnumWebRunAt.Client)
                    {
                        VPLUtil.CurrentRunContext = EnumRunContext.Client;
                    }
                    else
                    {
                        VPLUtil.CurrentRunContext = EnumRunContext.Server;
                    }
                }
                else
                {
                    VPLUtil.CurrentRunContext = EnumRunContext.Server;
                }
                dlg.LoadMethod(this, EnumParameterEditType.Edit);
                if (dlg.ShowDialog(caller) == DialogResult.OK)
                {
                    _display = null;
                    XmlNode nodeMethodCollection = loader.Node.SelectSingleNode(XmlTags.XML_CONSTRUCTORS);
                    if (nodeMethodCollection == null)
                    {
                        nodeMethodCollection = loader.Node.OwnerDocument.CreateElement(XmlTags.XML_CONSTRUCTORS);
                        loader.Node.AppendChild(nodeMethodCollection);
                    }
                    XmlNode nodeMethod = nodeMethodCollection.SelectSingleNode(
                        string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                      "{0}[@{1}='{2}']",
                                      XmlTags.XML_Item, XmlTags.XMLATT_MethodID, MemberId));
                    if (nodeMethod == null)
                    {
                        nodeMethod = nodeMethodCollection.OwnerDocument.CreateElement(XmlTags.XML_Item);
                        nodeMethodCollection.AppendChild(nodeMethod);
                    }
                    XmlUtil.SetAttribute(nodeMethod, XmlTags.XMLATT_MethodID, MemberId);
                    XmlUtil.SetAttribute(nodeMethod, XmlTags.XMLATT_NAME, Name);
                    XmlObjectWriter wr = loader.Writer;
                    wr.WriteObjectToNode(nodeMethod, this);
                    if (wr.HasErrors)
                    {
                        MathNode.Log(wr.ErrorCollection);
                    }
                    ILimnorDesignPane pane = loader.Project.GetTypedData <ILimnorDesignPane>(loader.ObjectMap.ClassId);

                    pane.OnNotifyChanges();
                    return(true);
                }
            }
            catch (Exception err)
            {
                MathNode.Log(caller, err);
            }
            finally
            {
                ExitEditor();
                VPLUtil.CurrentRunContext = _origiContext;
            }
            return(false);
        }