Exemplo n.º 1
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 }));
        }
Exemplo n.º 2
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 }));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private static String GetArgumentName(FieldAndPropertyWrapper argument)
        {
            ActionArgumentAttribute argAttr = argument.GetArgumentAttribute();

            return(argAttr.DisplayName ?? argument.Name);
        }
Exemplo n.º 5
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 });
        }