private void addParamButton_Click(object sender, EventArgs e)
        {
            Debug.Check(_method != null);

            if (_method != null)
            {
                if (_method.MemberType == MemberType.Task && _method.Params.Count >= 3)
                {
                    MessageBox.Show(Resources.EventParametersInfo, Resources.Warning, MessageBoxButtons.OK);
                    return;
                }

                if (_method.Params.Count >= 8)
                {
                    MessageBox.Show(Resources.MethodParametersInfo, Resources.Warning, MessageBoxButtons.OK);
                    return;
                }

                MethodDef.Param param = new MethodDef.Param("", null, "", "", "");
                _method.Params.Add(param);

                RowControl row = addRowControl(param);
                row.NameTextBox.Focus();

                this.IsModified = true;
            }
        }
Example #2
0
        void createParamEditor(MethodDef method, bool enable, bool bReadonlyParent)
        {
            List <MethodDef.Param> parameters = method.Params;

            foreach (MethodDef.Param p in parameters)
            {
                Type   editorType    = typeof(DesignerParameterComboEnumEditor);
                string arugmentsName = "    " + p.DisplayName;
                bool   bReadonly     = bReadonlyParent | p.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly);
                Label  label         = propertyGrid.AddProperty(arugmentsName, editorType, bReadonly);

                label.MouseEnter += new EventHandler(label_MouseEnter);

                DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag;

                if (p.Type.Name == "IList")
                {
                    lastListParam = p;
                }

                if (p.Type.Name == "System_Object" && lastListParam != null)
                {
                    p.ListParam = lastListParam;
                }

                editor.Enabled = enable;
                editor.SetParameter(p, _selectedObject, bReadonly);

                editor.ValueWasAssigned();
                editor.MouseEnter            += editor_MouseEnter;
                editor.DescriptionWasChanged += editor_DescriptionWasChanged;
                editor.ValueWasChanged       += editor_ValueWasChanged;
                //editor.ValueType = p.Attribute.ValueType;

                MethodDef.Param arrayIndexElement = null;

                if (p.Value is VariableDef)
                {
                    VariableDef var = p.Value as VariableDef;
                    arrayIndexElement = var.ArrayIndexElement;
                }
                else if (p.Value is RightValueDef)
                {
                    RightValueDef varRV = p.Value as RightValueDef;

                    if (varRV.Var != null)
                    {
                        arrayIndexElement = varRV.Var.ArrayIndexElement;
                    }
                }

                if (arrayIndexElement != null)
                {
                    createArrayIndexEditor("        ", arrayIndexElement);
                }
            }
        }
Example #3
0
        void createArrayIndexEditor(string preBlank, MethodDef.Param arrayIndex)
        {
            Type   editorType    = typeof(DesignerParameterComboEnumEditor);
            string arugmentsName = preBlank + "Index";
            bool   bReadonly     = false;
            Label  label         = propertyGrid.AddProperty(arugmentsName, editorType, bReadonly);

            label.MouseEnter += new EventHandler(label_MouseEnter);

            DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag;

            editor.Enabled = true;
            editor.SetParameter(arrayIndex, _selectedObject, bReadonly);
            editor.ValueWasAssigned();
            editor.MouseEnter            += editor_MouseEnter;
            editor.DescriptionWasChanged += editor_DescriptionWasChanged;
            editor.ValueWasChanged       += editor_ValueWasChanged;
        }
Example #4
0
        public VariableDef(VariableDef other)
        {
            if (other == null)
            {
                Value = null;
            }
            else
            {
                _property = null;

                if (other._property != null)
                {
                    if (other._property.IsPar && other._property is ParInfo)
                    { _property = new ParInfo(other._property as ParInfo); }

                    else
                    { _property = new PropertyDef(other._property); }
                }

                _value = Plugin.CloneValue(other._value);
                ValueClass = other._valueClass;

                if (other.m_arrayIndexElement != null)
                { m_arrayIndexElement = new MethodDef.Param(other.m_arrayIndexElement); }
            }
        }
Example #5
0
        private static void LoadCustomMembers(List<Nodes.Node.ErrorCheck> result, XmlNode rootNode)
        {
            if (rootNode == null)
            { return; }

            // Set the default base agent.
            if (Plugin.AgentTypes.Count == 0) {
                AgentType agent = new AgentType(typeof(Agent), "Agent", false, "Agent", "");
                Plugin.AgentTypes.Add(agent);
            }

            foreach(XmlNode xmlNode in rootNode.ChildNodes) {
                if (xmlNode.Name == "agent") {
                    string agentName = GetAttribute(xmlNode, "type");
                    string agentBase = GetAttribute(xmlNode, "base");
                    int baseIndex = -1;

                    for (int i = 0; i < Plugin.AgentTypes.Count; ++i) {
                        if (Plugin.AgentTypes[i].AgentTypeName == agentBase) {
                            baseIndex = i;
                            break;
                        }
                    }

                    string agentDisp = GetAttribute(xmlNode, "disp");
                    string agentDesc = GetAttribute(xmlNode, "desc");

                    if (string.IsNullOrEmpty(agentDisp))
                    { agentDisp = agentName; }

                    AgentType agent = Plugin.GetAgentType(agentName);

                    if (agent == null) {
                        agent = new AgentType(agentName, (baseIndex > -1) ? Plugin.AgentTypes[baseIndex] : null, agentDisp, agentDesc);
                        Plugin.AgentTypes.Add(agent);
                    }

                    foreach(XmlNode bbNode in xmlNode) {
                        if (bbNode.Name == "properties") {
                            foreach(XmlNode propNode in bbNode) {
                                if (propNode.Name == "property") {
                                    string propName = GetAttribute(propNode, "name");

                                    string isStatic = GetAttribute(propNode, "static");
                                    bool bStatic = false;

                                    if (!string.IsNullOrEmpty(isStatic) && isStatic == "true")
                                    { bStatic = true; }

                                    string isPublic = GetAttribute(propNode, "public");
                                    bool bPublic = false;

                                    if (string.IsNullOrEmpty(isPublic) || isPublic == "true")
                                    { bPublic = true; }

                                    string isReadonly = GetAttribute(propNode, "readonly");
                                    bool bReadonly = false;

                                    if (!string.IsNullOrEmpty(isReadonly) && isReadonly == "true")
                                    { bReadonly = true; }

                                    string propType = GetAttribute(propNode, "type");
                                    Type type = Plugin.GetTypeFromName(propType);

                                    string classname = GetAttribute(propNode, "classname");

                                    if (string.IsNullOrEmpty(classname))
                                    { classname = agent.AgentTypeName; }

                                    string propDisp = GetAttribute(propNode, "disp");

                                    if (string.IsNullOrEmpty(propDisp))
                                    { propDisp = propName; }

                                    string propDesc = GetAttribute(propNode, "desc");

                                    PropertyDef prop = new PropertyDef(agent, type, classname, propName, propDisp, propDesc);
                                    prop.IsStatic = bStatic;
                                    prop.IsPublic = bPublic;
                                    prop.IsReadonly = bReadonly;

                                    string defaultValue = GetAttribute(propNode, "defaultvalue");

                                    if (!string.IsNullOrEmpty(defaultValue)) {
                                        prop.Variable = new VariableDef(null);
                                        Plugin.InvokeTypeParser(result, type, defaultValue, (object value) => prop.Variable.Value = value, null);
                                    }

                                    agent.AddProperty(prop);
                                }
                            }

                        } else if (bbNode.Name == "methods") {
                            foreach(XmlNode methodNode in bbNode) {
                                if (methodNode.Name == "method") {
                                    string methodName = GetAttribute(methodNode, "name");
                                    Type returnType = Plugin.GetTypeFromName(GetAttribute(methodNode, "returntype"));

                                    string isStatic = GetAttribute(methodNode, "static");
                                    bool bStatic = false;

                                    if (!string.IsNullOrEmpty(isStatic) && isStatic == "true")
                                    { bStatic = true; }

                                    string isPublic = GetAttribute(methodNode, "public");
                                    bool bPublic = false;

                                    if (string.IsNullOrEmpty(isPublic) || isPublic == "true")
                                    { bPublic = true; }

                                    string classname = GetAttribute(methodNode, "classname");

                                    if (string.IsNullOrEmpty(classname))
                                    { classname = agent.AgentTypeName; }

                                    string methodDisp = GetAttribute(methodNode, "disp");

                                    if (string.IsNullOrEmpty(methodDisp))
                                    { methodDisp = methodName; }

                                    string methodDesc = GetAttribute(methodNode, "desc");

                                    bool istask = (GetAttribute(methodNode, "istask") == "true");
                                    //bool isevent = (GetAttribute(methodNode, "isevent") == "true");

                                    MemberType memberType = MemberType.Method;

                                    if (istask) {
                                        memberType = MemberType.Task;
                                    }

                                    methodName = string.Format("{0}::{1}", agent.AgentTypeName, methodName);

                                    MethodDef method = new MethodDef(agent, memberType, classname, methodName, methodDisp, methodDesc, "", returnType);
                                    method.IsStatic = bStatic;
                                    method.IsPublic = bPublic;

                                    agent.AddMethod(method);

                                    foreach(XmlNode paramNode in methodNode) {
                                        string paramName = GetAttribute(paramNode, "name");
                                        Type paramType = Plugin.GetTypeFromName(GetAttribute(paramNode, "type"));
                                        bool isOut = (GetAttribute(paramNode, "isout") == "true");
                                        bool isRef = (GetAttribute(paramNode, "isref") == "true");
                                        string nativeType = Plugin.GetNativeTypeName(paramType);

                                        string paramDisp = GetAttribute(paramNode, "disp");

                                        if (string.IsNullOrEmpty(paramDisp))
                                        { paramDisp = paramName; }

                                        string paramDesc = GetAttribute(paramNode, "desc");

                                        MethodDef.Param param = new MethodDef.Param(paramName, paramType, nativeType, paramDisp, paramDesc);
                                        param.IsOut = isOut;
                                        param.IsRef = isRef;

                                        method.Params.Add(param);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private RowControl addRowControl(MethodDef.Param param)
        {
            Debug.Check(param != null);
            if (param != null)
            {
                RowControl rowControl = new RowControl();
                _rowControls.Add(rowControl);

                int rowIndex = _rowControls.Count;

                rowControl.Param = param;

                rowControl.SelectCheckBox           = new System.Windows.Forms.CheckBox();
                rowControl.SelectCheckBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.SelectCheckBox.ForeColor = System.Drawing.Color.LightGray;
                rowControl.SelectCheckBox.FlatAppearance.MouseDownBackColor = Color.DarkGray;
                rowControl.SelectCheckBox.FlatAppearance.MouseOverBackColor = Color.DarkGray;
                //rowControl.SelectCheckBox.Dock = System.Windows.Forms.DockStyle.Fill;
                rowControl.SelectCheckBox.CheckAlign = ContentAlignment.MiddleCenter;
                rowControl.SelectCheckBox.Margin     = new System.Windows.Forms.Padding(0);
                this.tableLayoutPanel.Controls.Add(rowControl.SelectCheckBox, 0, rowIndex);

                rowControl.NameTextBox              = new System.Windows.Forms.TextBox();
                rowControl.NameTextBox.BackColor    = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.NameTextBox.ForeColor    = System.Drawing.Color.LightGray;
                rowControl.NameTextBox.BorderStyle  = BorderStyle.None;
                rowControl.NameTextBox.Dock         = System.Windows.Forms.DockStyle.Fill;
                rowControl.NameTextBox.Margin       = new System.Windows.Forms.Padding(3);
                rowControl.NameTextBox.Text         = param.Name;
                rowControl.NameTextBox.TextChanged += new EventHandler(NameTextBox_TextChanged);
                this.tableLayoutPanel.Controls.Add(rowControl.NameTextBox, 1, rowIndex);

                bool isParamArray = Plugin.IsArrayType(param.Type);
                Type paramType    = isParamArray ? param.Type.GetGenericArguments()[0] : param.Type;

                rowControl.TypeComboBox               = new System.Windows.Forms.ComboBox();
                rowControl.TypeComboBox.BackColor     = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.TypeComboBox.ForeColor     = System.Drawing.Color.LightGray;
                rowControl.TypeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                rowControl.TypeComboBox.FlatStyle     = FlatStyle.Popup;
                rowControl.TypeComboBox.Dock          = System.Windows.Forms.DockStyle.Fill;
                rowControl.TypeComboBox.Margin        = new System.Windows.Forms.Padding(0);
                setParamTypes(rowControl.TypeComboBox);
                rowControl.TypeComboBox.Text = Plugin.GetMemberValueTypeName(paramType);
                rowControl.TypeComboBox.SelectedIndexChanged += new EventHandler(TypeComboBox_SelectedIndexChanged);
                this.tableLayoutPanel.Controls.Add(rowControl.TypeComboBox, 2, rowIndex);

                rowControl.IsArrayCheckBox           = new System.Windows.Forms.CheckBox();
                rowControl.IsArrayCheckBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.IsArrayCheckBox.ForeColor = System.Drawing.Color.LightGray;
                rowControl.IsArrayCheckBox.FlatAppearance.MouseDownBackColor = Color.DarkGray;
                rowControl.IsArrayCheckBox.FlatAppearance.MouseOverBackColor = Color.DarkGray;
                //rowControl.IsArrayCheckBox.Dock = System.Windows.Forms.DockStyle.Fill;
                rowControl.IsArrayCheckBox.CheckAlign      = ContentAlignment.MiddleCenter;
                rowControl.IsArrayCheckBox.Margin          = new System.Windows.Forms.Padding(0);
                rowControl.IsArrayCheckBox.Enabled         = (paramType != null);
                rowControl.IsArrayCheckBox.Checked         = isParamArray;
                rowControl.IsArrayCheckBox.CheckedChanged += new EventHandler(IsArrayCheckBox_CheckedChanged);
                this.tableLayoutPanel.Controls.Add(rowControl.IsArrayCheckBox, 3, rowIndex);

                rowControl.ByReferrenceCheckBox           = new System.Windows.Forms.CheckBox();
                rowControl.ByReferrenceCheckBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.ByReferrenceCheckBox.ForeColor = System.Drawing.Color.LightGray;
                rowControl.ByReferrenceCheckBox.FlatAppearance.MouseDownBackColor = Color.DarkGray;
                rowControl.ByReferrenceCheckBox.FlatAppearance.MouseOverBackColor = Color.DarkGray;
                //rowControl.ByReferrenceCheckBox.Dock = System.Windows.Forms.DockStyle.Fill;
                rowControl.ByReferrenceCheckBox.CheckAlign      = ContentAlignment.MiddleCenter;
                rowControl.ByReferrenceCheckBox.Margin          = new System.Windows.Forms.Padding(0);
                rowControl.ByReferrenceCheckBox.Enabled         = (paramType != null);
                rowControl.ByReferrenceCheckBox.Checked         = param.IsRef;
                rowControl.ByReferrenceCheckBox.CheckedChanged += new EventHandler(ByReferrenceCheckBox_CheckedChanged);
                this.tableLayoutPanel.Controls.Add(rowControl.ByReferrenceCheckBox, 4, rowIndex);

                rowControl.IsConstCheckBox           = new System.Windows.Forms.CheckBox();
                rowControl.IsConstCheckBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.IsConstCheckBox.ForeColor = System.Drawing.Color.LightGray;
                rowControl.IsConstCheckBox.FlatAppearance.MouseDownBackColor = Color.DarkGray;
                rowControl.IsConstCheckBox.FlatAppearance.MouseOverBackColor = Color.DarkGray;
                //rowControl.IsConstCheckBox.Dock = System.Windows.Forms.DockStyle.Fill;
                rowControl.IsConstCheckBox.CheckAlign      = ContentAlignment.MiddleCenter;
                rowControl.IsConstCheckBox.Margin          = new System.Windows.Forms.Padding(0);
                rowControl.IsConstCheckBox.Enabled         = (paramType != null && Workspace.Current.Language == "cpp");
                rowControl.IsConstCheckBox.Checked         = param.IsConst;
                rowControl.IsConstCheckBox.CheckedChanged += new EventHandler(IsConstCheckBox_CheckedChanged);
                this.tableLayoutPanel.Controls.Add(rowControl.IsConstCheckBox, 5, rowIndex);

                rowControl.DisplayNameTextBox              = new System.Windows.Forms.TextBox();
                rowControl.DisplayNameTextBox.BackColor    = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65)))));
                rowControl.DisplayNameTextBox.ForeColor    = System.Drawing.Color.LightGray;
                rowControl.DisplayNameTextBox.BorderStyle  = BorderStyle.None;
                rowControl.DisplayNameTextBox.Dock         = System.Windows.Forms.DockStyle.Fill;
                rowControl.DisplayNameTextBox.Margin       = new System.Windows.Forms.Padding(3);
                rowControl.DisplayNameTextBox.Text         = param.DisplayName;
                rowControl.DisplayNameTextBox.TextChanged += new EventHandler(DisplayNameTextBox_TextChanged);
                this.tableLayoutPanel.Controls.Add(rowControl.DisplayNameTextBox, 6, rowIndex);

                this.tableLayoutPanel.RowCount++;
                this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));

                return(rowControl);
            }

            return(null);
        }
        public void Initialize(bool canBeEdit, AgentType agent, MethodDef method, MemberType memberType)
        {
            _initialized = false;

            _isModified = false;
            _shouldCheckMembersInWorkspace = false;
            _isNew          = (method == null);
            _agent          = agent;
            _originalMethod = method;

            setReturnTypes();

            if (memberType == MemberType.Task)
            {
                this.Text = _isNew ? Resources.AddTask : Resources.EditTask;
            }
            else if (memberType == MemberType.Method)
            {
                this.Text = _isNew ? Resources.AddMethod : Resources.EditMethod;
            }

            bool isCppLanguage = (Workspace.Current.Language == "cpp");

            if (_isNew)
            {
                string nativeReturnType = "void";
                Type   returnType       = typeof(void);
                _method = new MethodDef(agent, memberType, agent.Name, "", "", "", nativeReturnType, returnType);

                _method.IsPublic = !isCppLanguage;
            }
            else
            {
                _method         = new MethodDef(method);
                _method.OldName = method.Name;

                this.dispTextBox.Text = _method.DisplayName;
                this.descTextBox.Text = _method.BasicDescription;

                this.tableLayoutPanel.Hide();

                deleteAllRowControls();

                for (int i = 0; i < _method.Params.Count; ++i)
                {
                    MethodDef.Param param = _method.Params[i];
                    addRowControl(param);
                }

                this.tableLayoutPanel.Show();
            }

            _isArray = Plugin.IsArrayType(_method.ReturnType);
            Type type = _isArray ? _method.ReturnType.GetGenericArguments()[0] : _method.ReturnType;

            this.nameTextBox.Text         = _method.BasicName;
            this.returnTypeComboBox.Text  = Plugin.GetMemberValueTypeName(type);
            this.arrayCheckBox.Checked    = _isArray;
            this.isStaticCheckBox.Checked = _method.IsStatic;
            this.isPublicCheckBox.Checked = _method.IsPublic;

            this.nameTextBox.Enabled        = canBeEdit;
            this.returnTypeComboBox.Enabled = (memberType != MemberType.Task) ? (canBeEdit || _method.IsChangeableType) : false;
            this.arrayCheckBox.Enabled      = this.returnTypeComboBox.Enabled;
            this.isStaticCheckBox.Enabled   = canBeEdit;
            this.isPublicCheckBox.Enabled   = canBeEdit && isCppLanguage;
            this.dispTextBox.Enabled        = canBeEdit;
            this.descTextBox.Enabled        = canBeEdit;
            this.addParamButton.Enabled     = canBeEdit;
            this.removeParamButton.Enabled  = canBeEdit;
            this.tableLayoutPanel.Enabled   = canBeEdit || _method.IsChangeableType; // parameters

            this.nameTextBox.Focus();

            if (this.nameTextBox.TextLength > 0)
            {
                this.nameTextBox.SelectionStart = this.nameTextBox.TextLength;
            }
            else
            {
                this.nameTextBox.Select();
            }

            _initialized = true;
        }
Example #8
0
        public static string GetPropertyNativeType(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement)
        {
            string nativeType = CsExporter.GetGeneratedNativeType(property.NativeType);

            return(nativeType);
        }
Example #9
0
        public static string GetPropertyBasicName(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement)
        {
            if (property != null)
            {
                string propName = property.BasicName;

                if (property.IsArrayElement && arrayIndexElement != null)
                {
                    propName = propName.Replace("[]", "");
                }

                return(propName);
            }

            return("");
        }
Example #10
0
        private static MethodDef CreateAction(AgentType agentType, Type delegateType, string owner, string typeName, string typeDisplayName, bool isNamedEvent, bool isActionMethodOnly, out string displayName) {
            System.Reflection.MethodInfo method = AgentType.GetMethodInfo(delegateType);
            System.Reflection.ParameterInfo[] parameters = AgentType.GetMethodParams(method);

            bool isChangeableType = false;
            bool isPublic = false;
            bool isStatic = false;
            string name = typeName + "::" + delegateType.Name;
            string nativeReturnType = "void";
            displayName = name;
            string description = name;
            Attribute[] attributes = (Attribute[])delegateType.GetCustomAttributes(typeof(Behaviac.Design.MethodDescAttribute), false);

            if (attributes.Length > 0) {
                MethodDescAttribute methodAttr = (MethodDescAttribute)attributes[0];

                isChangeableType = methodAttr.IsChangeableType;
                isPublic = methodAttr.IsPublic;
                isStatic = methodAttr.IsStatic;
                nativeReturnType = methodAttr.NativeReturnType;
                displayName = typeDisplayName + "::" + methodAttr.DisplayName;
                description = methodAttr.Description;
            }

            MethodDef methodDef = new MethodDef(agentType, isNamedEvent ? MemberType.Task : MemberType.Method, isChangeableType, isPublic, isStatic, typeName, owner, name, displayName, description, nativeReturnType, method.ReturnType, isActionMethodOnly, new List<MethodDef.Param>());

            string category = "Arguments";
            foreach(System.Reflection.ParameterInfo par in parameters) {
                Attribute[] paramAttributes = (Attribute[])par.GetCustomAttributes(typeof(Behaviac.Design.ParamDescAttribute), false);
                string paramNativeType = Plugin.GetNativeTypeName(par.ParameterType);
                string paramDisplayName = par.Name;
                string paramDescription = paramDisplayName;
                string defaultValue = "";
                bool isOut = false;
                bool isRef = false;
                float rangeMin = float.MinValue;
                float rangeMax = float.MaxValue;

                if (paramAttributes.Length > 0) {
                    ParamDescAttribute paramDescAttr = ((ParamDescAttribute)paramAttributes[0]);
                    paramNativeType = paramDescAttr.NativeType;
                    paramDisplayName = paramDescAttr.DisplayName;
                    paramDescription = paramDescAttr.Description;
                    defaultValue = paramDescAttr.DefaultValue;
                    isOut = paramDescAttr.IsOut;
                    isRef = paramDescAttr.IsRef;
                    rangeMin = paramDescAttr.RangeMin;
                    rangeMax = paramDescAttr.RangeMax;
                }

                //object value = par.ParameterType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null);
                object value = Plugin.DefaultValue(par.ParameterType, defaultValue);
                MethodDef.Param p = new MethodDef.Param(category, par, value, paramNativeType, paramDisplayName, paramDescription, isOut, isRef, rangeMin, rangeMax);
                methodDef.Params.Add(p);
            }

            return methodDef;
        }
Example #11
0
        public void Initialize(AgentType agent, MethodDef method, MemberType memberType)
        {
            _initialized    = false;
            _isModified     = false;
            _isNew          = (method == null);
            _agent          = agent;
            _originalMethod = method;

            setReturnTypes();

            if (memberType == MemberType.Task)
            {
                this.Text = _isNew ? Resources.AddTask : Resources.EditTask;
            }
            else if (memberType == MemberType.Method)
            {
                this.Text = _isNew ? Resources.AddMethod : Resources.EditMethod;
            }

            if (_isNew)
            {
                string nativeReturnType = "void";
                Type   returnType       = typeof(void);
                _method = new MethodDef(agent, memberType, agent.AgentTypeName, "", "", "", nativeReturnType, returnType);
            }
            else
            {
                _method         = new MethodDef(method);
                _method.OldName = method.Name;

                this.dispTextBox.Text = _method.DisplayName;
                this.descTextBox.Text = _method.BasicDescription;

                this.tableLayoutPanel.Hide();

                deleteAllRowControls();
                for (int i = 0; i < _method.Params.Count; ++i)
                {
                    MethodDef.Param param = _method.Params[i];
                    addRowControl(param);
                }

                this.tableLayoutPanel.Show();
            }

            _isArray = Plugin.IsArrayType(_method.ReturnType);
            Type type = _isArray ? _method.ReturnType.GetGenericArguments()[0] : _method.ReturnType;

            this.nameTextBox.Text         = _method.BasicName;
            this.returnTypeComboBox.Text  = Plugin.GetMemberValueTypeName(type);
            this.arrayCheckBox.Checked    = _isArray;
            this.isStaticCheckBox.Checked = _method.IsStatic;
            this.isPublicCheckBox.Checked = _method.IsPublic;

            this.nameTextBox.Enabled        = _method.IsCustomized;
            this.returnTypeComboBox.Enabled = (memberType != MemberType.Task) ? _method.IsCustomized : false;
            this.arrayCheckBox.Enabled      = (memberType != MemberType.Task) ? _method.IsCustomized : false;
            this.isStaticCheckBox.Enabled   = _method.IsCustomized;
            this.isPublicCheckBox.Enabled   = _method.IsCustomized;
            this.dispTextBox.Enabled        = _method.IsCustomized;
            this.descTextBox.Enabled        = _method.IsCustomized;
            this.addParamButton.Enabled     = _method.IsCustomized;
            this.removeParamButton.Enabled  = _method.IsCustomized;
            this.tableLayoutPanel.Enabled   = _method.IsCustomized;

            _initialized = true;
        }
Example #12
0
        //private void UpdateProperties(IList<DesignerPropertyInfo> properties, List<MethodDef.Param> parameters, string parametersCategory)
        private void UpdateProperties(IList <DesignerPropertyInfo> properties)
        {
            DefaultObject obj = SelectedObject as DefaultObject;

            if (obj != null)
            {
                uiPolicy = obj.CreateUIPolicy();
                uiPolicy.Initialize(obj);
            }

            List <string> categories = new List <string>();

            foreach (DesignerPropertyInfo property in properties)
            {
                if (uiPolicy.ShouldAddProperty(property) &&
                    !property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) &&
                    (property.Attribute.CategoryResourceString != "CategoryVersion" || Settings.Default.ShowVersionInfo) &&
                    !categories.Contains(property.Attribute.CategoryResourceString))
                {
                    categories.Add(property.Attribute.CategoryResourceString);
                }
            }

            categories.Sort(new CategorySorter());

            foreach (string category in categories)
            {
                propertyGrid.AddCategory(Plugin.GetResourceString(category), true);

                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) &&
                        property.Attribute.CategoryResourceString == category)
                    {
                        if (uiPolicy != null && !uiPolicy.ShouldAddProperty(property))
                        {
                            continue;
                        }

                        object             value_         = property.Property.GetValue(_selectedObject, null);
                        Type               type           = property.Attribute.GetEditorType(value_);
                        DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum;

                        if (propertyMethod != null)
                        {
                            if ((propertyMethod.MethodType & MethodType.Task) == MethodType.Task)
                            {
                                type = typeof(DesignerMethodEnumEditor);
                            }
                        }

                        string displayName = property.Attribute.DisplayName;

                        if (uiPolicy != null)
                        {
                            displayName = uiPolicy.GetLabel(property);
                        }

                        Label label = propertyGrid.AddProperty(displayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly));

                        // register description showing
                        label.MouseEnter += new EventHandler(label_MouseEnter);

                        // when we found an editor we connect it to the object
                        if (type != null)
                        {
                            DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag;
                            editor.SetRootNode((Nodes.Node) this._rootBehavior);
                            editor.SetProperty(property, _selectedObject);
                            editor.ValueWasAssigned();
                            editor.MouseEnter            += editor_MouseEnter;
                            editor.DescriptionWasChanged += editor_DescriptionWasChanged;
                            editor.ValueWasChanged       += editor_ValueWasChanged;

                            if (uiPolicy != null)
                            {
                                uiPolicy.AddEditor(editor);
                            }
                        }

                        MethodDef method             = null;
                        bool      methodEditorEnable = true;

                        if (propertyMethod != null)
                        {
                            if (propertyMethod.MethodType != MethodType.Status)
                            {
                                method = value_ as MethodDef;
                                //methodEditorEnable = (propertyMethod.MethodType != MethodType.Event);
                            }
                        }
                        else
                        {
                            DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum;

                            if (propertyRV != null)
                            {
                                RightValueDef rv = value_ as RightValueDef;

                                if (rv != null && rv.IsMethod)
                                {
                                    method = rv.Method;
                                }
                            }
                        }

                        if (property.Attribute != null)
                        {
                            if (method != null)
                            {
                                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplayOnProperty))
                                {
                                    //don't dipslay on the property panel
                                }
                                else
                                {
                                    bool bReadonly = property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnlyParams);

                                    createParamEditor(method, methodEditorEnable, bReadonly);
                                }
                            }
                            else
                            {
                                MethodDef.Param arrayIndexElement = null;

                                if (value_ is VariableDef)
                                {
                                    VariableDef var = value_ as VariableDef;
                                    arrayIndexElement = var.ArrayIndexElement;
                                }
                                else if (value_ is RightValueDef)
                                {
                                    RightValueDef varRV = value_ as RightValueDef;

                                    if (varRV.Var != null)
                                    {
                                        arrayIndexElement = varRV.Var.ArrayIndexElement;
                                    }
                                }

                                if (arrayIndexElement != null)
                                {
                                    createArrayIndexEditor("    ", arrayIndexElement);
                                }
                            }
                        }
                    }
                }
            }

            if (uiPolicy != null)
            {
                uiPolicy.Update(null, new DesignerPropertyInfo());
            }
        }
Example #13
0
        private void addParamButton_Click(object sender, EventArgs e)
        {
            Debug.Check(_method != null);

            if (_method.MemberType == MemberType.Task && _method.Params.Count >= 3)
            {
                MessageBox.Show(Resources.EventParametersInfo, Resources.Warning, MessageBoxButtons.OK);
                return;
            }

            if (_method.Params.Count >= 8)
            {
                MessageBox.Show(Resources.MethodParametersInfo, Resources.Warning, MessageBoxButtons.OK);
                return;
            }

            MethodDef.Param param = new MethodDef.Param("", null, "", "", "");
            _method.Params.Add(param);

            RowControl row = addRowControl(param);
            row.NameTextBox.Focus();
        }
Example #14
0
        private static void LoadCustomMembers(List<Nodes.Node.ErrorCheck> result, XmlNode rootNode)
        {
            try
            {
                if (rootNode == null)
                { return; }

                // Set the default base agent.
                if (Plugin.AgentTypes.Count == 0)
                {
                    AgentType agent = new AgentType(typeof(Agent), "Agent", false, false, "Agent", "", false);
                    Plugin.AgentTypes.Add(agent);
                }

                string agentName;

                // first pass, to load all the agents as it might be used as a property of another agent
                foreach (XmlNode xmlNode in rootNode.ChildNodes)
                {
                    if (xmlNode.Name == "agent")
                    {
                        LoadAgentType(xmlNode, out agentName);
                    }
                }


                foreach (XmlNode xmlNode in rootNode.ChildNodes)
                {
                    if (xmlNode.Name == "agent")
                    {
                        AgentType agent = LoadAgentType(xmlNode, out agentName); 
                        
                        foreach (XmlNode bbNode in xmlNode)
                        {
                            if (bbNode.Name == "properties")
                            {
                                foreach (XmlNode propNode in bbNode)
                                {
                                    if (propNode.Name == "property")
                                    {
                                        string propName = GetAttribute(propNode, "name");
                                        try
                                        {
                                            string isStatic = GetAttribute(propNode, "static");
                                            bool bStatic = false;

                                            if (!string.IsNullOrEmpty(isStatic) && isStatic == "true")
                                            { bStatic = true; }

                                            string isPublic = GetAttribute(propNode, "public");
                                            bool bPublic = false;

                                            if (string.IsNullOrEmpty(isPublic) || isPublic == "true")
                                            { bPublic = true; }

                                            string isReadonly = GetAttribute(propNode, "readonly");
                                            bool bReadonly = false;

                                            if (!string.IsNullOrEmpty(isReadonly) && isReadonly == "true")
                                            { bReadonly = true; }

                                            string propType = GetAttribute(propNode, "type");
                                            Type type = Plugin.GetTypeFromName(propType);

                                            string classname = GetAttribute(propNode, "classname");

                                            if (string.IsNullOrEmpty(classname))
                                            { classname = agent.AgentTypeName; }

                                            string propDisp = GetAttribute(propNode, "disp");

                                            if (string.IsNullOrEmpty(propDisp))
                                            { propDisp = propName; }

                                            string propDesc = GetAttribute(propNode, "desc");

                                            PropertyDef prop = new PropertyDef(agent, type, classname, propName, propDisp, propDesc);
                                            prop.IsStatic = bStatic;
                                            prop.IsPublic = bPublic;
                                            prop.IsReadonly = bReadonly;

                                            string defaultValue = GetAttribute(propNode, "defaultvalue");

                                            if (!string.IsNullOrEmpty(defaultValue))
                                            {
                                                prop.Variable = new VariableDef(null);
                                                Plugin.InvokeTypeParser(result, type, defaultValue, (object value) => prop.Variable.Value = value, null);
                                            }

                                            agent.AddProperty(prop);
                                        }
                                        catch (Exception)
                                        {
                                            string errorInfo = string.Format("error when loading Agent '{0}' Member '{1}'", agentName, propName);
                                            MessageBox.Show(errorInfo, "Loading Custom Meta", MessageBoxButtons.OK);
                                        }
                                    }
                                }

                            }
                            else if (bbNode.Name == "methods")
                            {
                                foreach (XmlNode methodNode in bbNode)
                                {
                                    if (methodNode.Name == "method")
                                    {
                                        string methodName = GetAttribute(methodNode, "name");
                                        try
                                        {
                                            Type returnType = Plugin.GetTypeFromName(GetAttribute(methodNode, "returntype"));

                                            string isStatic = GetAttribute(methodNode, "static");
                                            bool bStatic = false;

                                            if (!string.IsNullOrEmpty(isStatic) && isStatic == "true")
                                            { bStatic = true; }

                                            string isPublic = GetAttribute(methodNode, "public");
                                            bool bPublic = false;

                                            if (string.IsNullOrEmpty(isPublic) || isPublic == "true")
                                            { bPublic = true; }

                                            string classname = GetAttribute(methodNode, "classname");

                                            if (string.IsNullOrEmpty(classname))
                                            { classname = agent.AgentTypeName; }

                                            string methodDisp = GetAttribute(methodNode, "disp");

                                            if (string.IsNullOrEmpty(methodDisp))
                                            { methodDisp = methodName; }

                                            string methodDesc = GetAttribute(methodNode, "desc");

                                            bool istask = (GetAttribute(methodNode, "istask") == "true");
                                            //bool isevent = (GetAttribute(methodNode, "isevent") == "true");

                                            MemberType memberType = MemberType.Method;

                                            if (istask)
                                            {
                                                memberType = MemberType.Task;
                                            }

                                            methodName = string.Format("{0}::{1}", agent.AgentTypeName, methodName);

                                            MethodDef method = new MethodDef(agent, memberType, classname, methodName, methodDisp, methodDesc, "", returnType);
                                            method.IsStatic = bStatic;
                                            method.IsPublic = bPublic;

                                            agent.AddMethod(method);

                                            foreach (XmlNode paramNode in methodNode)
                                            {
                                                string paramName = GetAttribute(paramNode, "name");
                                                Type paramType = Plugin.GetTypeFromName(GetAttribute(paramNode, "type"));
                                                bool isOut = (GetAttribute(paramNode, "isout") == "true");
                                                bool isRef = (GetAttribute(paramNode, "isref") == "true");
                                                string nativeType = Plugin.GetNativeTypeName(paramType);

                                                string paramDisp = GetAttribute(paramNode, "disp");

                                                if (string.IsNullOrEmpty(paramDisp))
                                                { paramDisp = paramName; }

                                                string paramDesc = GetAttribute(paramNode, "desc");

                                                MethodDef.Param param = new MethodDef.Param(paramName, paramType, nativeType, paramDisp, paramDesc);
                                                param.IsOut = isOut;
                                                param.IsRef = isRef;

                                                method.Params.Add(param);
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            string errorInfo = string.Format("error when loading Agent '{0}' Method '{1}'", agentName, methodName);
                                            MessageBox.Show(errorInfo, "Loading Custom Meta", MessageBoxButtons.OK);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                string errorInfo = string.Format("error when loading custom members");

                MessageBox.Show(errorInfo, "Loading Custom Meta", MessageBoxButtons.OK);
            }
        }