示例#1
0
        public void ChangeName(string newName)
        {
            LocalVariable lv = this.ClassPointer as LocalVariable;

            _name = newName;
            lv.SetName(_name);
            SetLabelText(_name);
            IList <MethodDiagramViewer> lst = MethodViewer.GetViewer();

            foreach (MethodDiagramViewer dv in lst)
            {
                for (int i = 0; i < dv.Controls.Count; i++)
                {
                    ActionViewerConstructor avc = dv.Controls[i] as ActionViewerConstructor;
                    if (avc != null)
                    {
                        AB_Constructor     bc  = avc.ActionObject as AB_Constructor;
                        ConstructorPointer cp  = bc.ActionData.ActionMethod as ConstructorPointer;
                        LocalVariable      lv2 = cp.Owner as LocalVariable;
                        if (lv2.IsSameObjectRef(lv))
                        {
                            lv2.SetName(_name);
                            avc.ActionName = "Create " + _name;
                            break;
                        }
                    }
                }
            }
        }
        protected override void OnActionNameChanged()
        {
            AB_Constructor ab = this.ActionObject as AB_Constructor;

            if (ab != null && ab.ActionData != null)
            {
                ConstructorPointer cp = ab.ActionData.ActionMethod as ConstructorPointer;
                if (cp.ReturnReceiver != null)
                {
                    _displayData = "Create " + cp.ReturnReceiver.Name;
                }
                else
                {
                    _displayData = "Create " + cp.TypeString;
                }
            }
        }
        protected override void OnCreateContextMenu(ContextMenu cm)
        {
            AB_Constructor     av = this.ActionObject as AB_Constructor;
            ConstructorPointer cp = av.ActionData.ActionMethod as ConstructorPointer;
            LocalVariable      lv = cp.Owner as LocalVariable;

            ConstructorInfo[] cis = lv.ObjectType.GetConstructors();
            if (cis.Length > 1)
            {
                MenuItem mi;
                //
                mi = new MenuItemWithBitmap("Select Constructor", miSelectConstructor_Click, Resources._dialog.ToBitmap());
                cm.MenuItems.Add(mi);
                //
                mi = new MenuItem("-");
                cm.MenuItems.Add(mi);
            }
        }
        void miSelectConstructor_Click(object sender, EventArgs e)
        {
            MethodDiagramViewer mv = this.Parent as MethodDiagramViewer;

            if (mv != null)
            {
                AB_Constructor           av  = this.ActionObject as AB_Constructor;
                IConstructor             cp  = av.ActionData.ActionMethod as IConstructor;
                LocalVariable            lv  = cp.Owner as LocalVariable;
                dlgConstructorParameters dlg = new dlgConstructorParameters();
                dlg.SetMethod(mv.DesignerHolder.Method);
                dlg.LoadData(lv);
                dlg.LocateConstructor(cp);
                if (dlg.ShowDialog(this.FindForm()) == DialogResult.OK)
                {
                    cp.CopyFrom(dlg.Ret);
                    mv.Changed = true;
                }
            }
        }