Ejemplo n.º 1
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 });
        }