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)
                {
                    MethodClass scopeMethod = context.Instance as MethodClass;
                    if (scopeMethod != null)
                    {
                        //this version only edit FinalActions
                        ILimnorDesignPane dp = scopeMethod.Project.GetTypedData <ILimnorDesignPane>(scopeMethod.RootPointer.ClassId);
                        if (dp != null)
                        {
                            //save the method contents
                            BranchList           bl         = scopeMethod.ActionList;
                            string               methodName = scopeMethod.MethodName;
                            ParameterClass       returnType = scopeMethod.ReturnValue;
                            List <ComponentIcon> icons      = scopeMethod.ComponentIconList;

                            //switch method contents
                            scopeMethod.ActionList = scopeMethod.FinalActions.Actions;
                            scopeMethod.SetName("FinalActions");
                            List <ComponentIcon> icons2 = new List <ComponentIcon>();
                            foreach (ComponentIcon ic in icons)
                            {
                                icons2.Add((ComponentIcon)ic.Clone());
                            }
                            foreach (ComponentIconSubscopeVariable ic in scopeMethod.FinalActions.ComponentIconList)
                            {
                                icons2.Add((ComponentIcon)ic.Clone());
                            }
                            scopeMethod.SetComponentIcons(icons2);
                            //
                            Rectangle rc = new Rectangle(Cursor.Position, new Size(32, 232));
                            if (scopeMethod.Owner == null)
                            {
                                scopeMethod.Owner = dp.Loader.GetRootId();
                            }
                            DlgMethod dlg = scopeMethod.CreateBlockScopeMethodEditor(rc, 1);
                            try
                            {
                                dlg.LoadMethod(scopeMethod, EnumParameterEditType.ReadOnly);
                                dlg.Text = string.Format(CultureInfo.InvariantCulture, "Specify final actionsfor {0}", methodName);
                                if (edSvc.ShowDialog(dlg) == DialogResult.OK)
                                {
                                    scopeMethod.FinalActions.Actions = scopeMethod.ActionList;
                                    List <ComponentIconSubscopeVariable> lst = new List <ComponentIconSubscopeVariable>();
                                    foreach (ComponentIcon ic in scopeMethod.ComponentIconList)
                                    {
                                        ComponentIconSubscopeVariable sv = ic as ComponentIconSubscopeVariable;
                                        if (sv != null)
                                        {
                                            lst.Add(sv);
                                        }
                                    }
                                    scopeMethod.FinalActions.ComponentIconList = lst;
                                    XmlObjectWriter xw = dp.Loader.Writer;
                                    xw.WriteObject(scopeMethod.FinalActions.DataXmlNode, scopeMethod.FinalActions, null);
                                    value = scopeMethod.FinalActions;
                                }
                            }
                            catch (Exception err)
                            {
                                MathNode.LogError(DesignerException.FormExceptionText(err));
                            }
                            finally
                            {
                                //restore method contents
                                scopeMethod.SetName(methodName);
                                scopeMethod.ActionList = bl;
                                scopeMethod.SetComponentIcons(icons);
                                scopeMethod.ExitEditor();
                            }
                        }
                    }
                }
            }
            return(value);
        }
示例#2
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)
                {
                    ExceptionHandlerList.PropertyDescriptorExceptionHandler pd = context.PropertyDescriptor as ExceptionHandlerList.PropertyDescriptorExceptionHandler;
                    if (pd == null)
                    {
                        throw new DesignerException("Property descriptor [{0}] is not a PropertyDescriptorExceptionHandler", context.PropertyDescriptor == null ? "null" : context.PropertyDescriptor.GetType().FullName);
                    }
                    ExceptionHandler     eh       = pd.Handler;
                    BranchList           branches = eh.ActionList;
                    ExceptionHandlerList ehs      = context.Instance as ExceptionHandlerList;
                    if (ehs != null)
                    {
                        MethodClass scopeMethod = ehs.OwnerMethod;
                        if (scopeMethod != null)
                        {
                            if (branches == null)
                            {
                                branches = new BranchList(eh, new List <ActionBranch>());
                            }

                            ILimnorDesignPane dp = scopeMethod.Project.GetTypedData <ILimnorDesignPane>(scopeMethod.RootPointer.ClassId);
                            if (dp != null)
                            {
                                //save the method contents
                                BranchList           bl         = scopeMethod.ActionList;
                                string               methodName = scopeMethod.MethodName;
                                ParameterClass       returnType = scopeMethod.ReturnValue;
                                List <ComponentIcon> icons      = scopeMethod.ComponentIconList;

                                //switch method contents
                                scopeMethod.ActionList = branches;
                                scopeMethod.SetName(string.Format(CultureInfo.InvariantCulture, "HandlerFor{0}", eh.ExceptionType.Name));
                                scopeMethod.ReturnValue = null;
                                List <ComponentIcon> icons2 = new List <ComponentIcon>();
                                foreach (ComponentIcon ic in icons)
                                {
                                    icons2.Add((ComponentIcon)ic.Clone());
                                }
                                foreach (ComponentIconSubscopeVariable ic in eh.ComponentIconList)
                                {
                                    icons2.Add((ComponentIcon)ic.Clone());
                                }
                                icons2.Add(eh.ExceptionObject);
                                scopeMethod.SetComponentIcons(icons2);
                                //
                                Rectangle rc = new Rectangle(Cursor.Position, new Size(32, 232));
                                if (scopeMethod.Owner == null)
                                {
                                    scopeMethod.Owner = dp.Loader.GetRootId();
                                }
                                DlgMethod dlg = scopeMethod.CreateBlockScopeMethodEditor(rc, eh.ExceptionType.MemberId);
                                try
                                {
                                    dlg.LoadMethod(scopeMethod, EnumParameterEditType.ReadOnly);
                                    dlg.Text = string.Format(CultureInfo.InvariantCulture, "Create exception handler for {0}", eh.ExceptionType.Name);
                                    if (edSvc.ShowDialog(dlg) == DialogResult.OK)
                                    {
                                        bool delete = false;
                                        eh.ActionList = scopeMethod.ActionList;
                                        if (eh.ActionList.Count == 0)
                                        {
                                            if (MessageBox.Show(string.Format(CultureInfo.CurrentUICulture, "Do you want to remove this exception [{0}]?", eh.ExceptionType.Name), "Capture exception", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                            {
                                                delete = true;
                                            }
                                        }
                                        if (delete)
                                        {
                                            scopeMethod.RemoveExceptionCapture(eh);
                                        }
                                        else
                                        {
                                            List <ComponentIconSubscopeVariable> lst = new List <ComponentIconSubscopeVariable>();
                                            foreach (ComponentIcon ic in scopeMethod.ComponentIconList)
                                            {
                                                ComponentIconSubscopeVariable sv = ic as ComponentIconSubscopeVariable;
                                                if (sv != null)
                                                {
                                                    lst.Add(sv);
                                                }
                                            }
                                            eh.ComponentIconList = lst;
                                            scopeMethod.RootPointer.SaveMethod(scopeMethod, eh);
                                        }
                                    }
                                }
                                catch (Exception err)
                                {
                                    MathNode.LogError(DesignerException.FormExceptionText(err));
                                }
                                finally
                                {
                                    //restore method contents
                                    scopeMethod.SetName(methodName);
                                    scopeMethod.ActionList  = bl;
                                    scopeMethod.ReturnValue = returnType;
                                    scopeMethod.SetComponentIcons(icons);
                                    scopeMethod.ExitEditor();
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }