Example #1
0
        private void CbOnCheckedChanged(object sender, EventArgs eventArgs)
        {
            CheckBox cb = (CheckBox)sender;
            FieldAndPropertyWrapper arg = (FieldAndPropertyWrapper)cb.Tag;

            arg.Set(this.ThisAction, cb.Checked);
        }
Example #2
0
        private EventHandler GetLeaveHandler(FieldAndPropertyWrapper arg)
        {
            ActionArgumentAttribute argAttr = arg.GetArgumentAttribute();

            if (argAttr.OnLeaveHandlerName == null)
            {
                return(null);
            }
            Type       actionType = ThisAction.GetType();
            MethodInfo method     = actionType.GetMethod(argAttr.OnLeaveHandlerName);

            return((sender, e) => method.Invoke(ThisAction, new[] { sender, e }));
        }
Example #3
0
        private EventHandler GetChangedHandler(FieldAndPropertyWrapper arg)
        {
            ActionArgumentAttribute argAttr = arg.GetArgumentAttribute();

            if (argAttr.OnChangedHandlerName == null)
            {
                if (argAttr.OnLeaveHandlerName == null)
                {
                    return(this.attrValue_TextChanged);
                }
                return(delegate { });
            }
            MethodInfo method = arg.DeclaringType.GetMethod(argAttr.OnChangedHandlerName);

            return((sender, e) => method.Invoke(ThisAction, new[] { sender, e }));
        }
Example #4
0
        /// <summary>
        /// Populate members from the given Xml Element.
        /// </summary>
        /// <remarks>
        /// Should be implemented if <see cref="Action.AddToXmlElement" /> is
        /// non-trivially overridden.
        /// </remarks>
        /// <param name="element">The XmlElement describing the action</param>
        protected virtual void PopulateMembersFromXml(XPathNavigator element)
        {
            Type actionType = GetType();

            //element.Attributes.RemoveNamedItem(@"Assembly");

            foreach (XPathNavigator attribute in element.Select(@"./@*"))
            {
                if (attribute.Name == @"Assembly")
                {
                    continue;
                }
                FieldAndPropertyWrapper field = (FieldAndPropertyWrapper)actionType.GetMember(attribute.Name).First();
                MethodInfo parseMethod        = field.MemberType.GetMethod(@"Parse", new[] { typeof(String) });
                field.Set(this,
                          parseMethod != null
                              ? parseMethod.Invoke(field, new object[] { attribute.Value })
                              : attribute.Value);
            }
        }
Example #5
0
        private void attrValue_TextChanged(object sender, EventArgs e)
        {
            TextBoxBase attrValue = sender as TextBoxBase;

            if (attrValue == null)
            {
                return;
            }
            FieldAndPropertyWrapper f = (FieldAndPropertyWrapper)attrValue.Tag;

            if (f == null)
            {
                return;
            }
            ActionArgumentAttribute argInfo = f.GetArgumentAttribute();

            object     value  = f.Get <Object>(ThisAction);
            MethodInfo parser = f.MemberType.GetMethod(@"Parse", new[] { typeof(String) });

            if (parser != null)
            {
                try
                {
                    value = parser.Invoke(f, new object[] { attrValue.Text });
                }
                catch (Exception)
                {
                    MessageBox.Show(this, String.Format("Invalid Value entered in {0}.{1}: {2}",
                                                        ThisAction.Name, argInfo.DisplayName, attrValue.Text));
                }
            }
            else
            {
                value = attrValue.Text;
            }


            f.Set(ThisAction, value);
        }
Example #6
0
        private static String GetArgumentName(FieldAndPropertyWrapper argument)
        {
            ActionArgumentAttribute argAttr = argument.GetArgumentAttribute();

            return(argAttr.DisplayName ?? argument.Name);
        }
Example #7
0
        /// <summary>
        /// Create label and value control for argument <paramref name="arg"/>
        /// </summary>
        /// <param name="arg">A <see cref="FieldAndPropertyWrapper"/>for the given argument</param>
        /// <returns>An array of <see cref="Control"/>s containing {<see cref="Label">label</see>, control}.</returns>
        protected Control[] GenerateFieldControls(FieldAndPropertyWrapper arg)
        {
            ActionArgumentAttribute attrData = arg.GetArgumentAttribute();
            var attrLabel = new Label {
                Text = GetArgumentName(arg), Dock = DockStyle.Fill
            };

            if (!string.IsNullOrEmpty(attrData.Usage))
            {
                ArgumentTooltips.SetToolTip(attrLabel, attrData.Usage);
            }
            Control attrValue;

            {
                switch (arg.GetFieldTypeCategory())
                {
                case FieldAndPropertyWrapper.FieldType.Boolean:
                    CheckBox cb = new CheckBox
                    {
                        Anchor  = AnchorStyles.Top | AnchorStyles.Left,
                        Checked = arg.Get <Boolean>(ThisAction)
                    };
                    cb.CheckedChanged += this.CbOnCheckedChanged;
                    cb.CheckedChanged += SetDirty;
                    attrValue          = cb;

                    break;

                //case FieldAndPropertyWrapper.FieldType.Other:
                //case FieldAndPropertyWrapper.FieldType.String:
                //case FieldAndPropertyWrapper.FieldType.Numeric:
                default:
                    if (attrData.Literal)
                    {
                        attrValue = new TextBox
                        {
                            ShortcutsEnabled = true,
                            ContextMenu      = null
                        };
                    }
                    else
                    {
                        attrValue = new TextBox     //RichTextBox
                        {
                            BackColor        = SystemColors.Info,
                            Multiline        = false,
                            Height           = 20,
                            ShortcutsEnabled = true,
                            ContextMenu      = null
                        };
                        // ((RichTextBox)attrValue).TextChanged += NonLiteralOnTextChanged;
                    }
                    attrValue.Anchor      = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    attrValue.ContextMenu = null;


                    object obj = arg.Get <Object>(ThisAction); //.ToString();
                    attrValue.Text         = (obj ?? "").ToString();
                    attrValue.TextChanged += GetChangedHandler(arg);
                    attrValue.TextChanged += SetDirty;
                    break;
                }

                attrValue.Tag    = arg;
                attrValue.Leave += GetLeaveHandler(arg);
            }

            attrLabel.Margin = new Padding
            {
                Top    = (attrValue.Height - attrLabel.Height) / 2,
                Bottom = attrLabel.Margin.Bottom,
                Left   = attrLabel.Margin.Left,
                Right  = attrLabel.Margin.Right
            };

            return(new[] { attrLabel, attrValue });
        }