Example #1
0
 public DGNodeRefPropertyCommand(D dgNode, T thing,
                                 RefToValue <P> rtv, string property, P newValue,
                                 bool extendable)
     : base(dgNode, thing, property, newValue, extendable)
 {
     this.mRTV = rtv;
 }
Example #2
0
            public override object ConvertTo(ITypeDescriptorContext context,
                                             System.Globalization.CultureInfo culture, object value,
                                             Type destinationType)
            {
                RefToValue <T> rtv = value as RefToValue <T>;

                if (rtv == null || !typeof(string).Equals(destinationType))
                {
                    return(base.ConvertTo(context, culture, value,
                                          destinationType));
                }
                if (rtv.mValue == null)
                {
                    return("");
                }
                StateMachine sm = rtv.mScene.StateMachine;
                int          i  = (int)rtv.mCountProperty.GetValue(sm, null);

                if (i == 0)
                {
                    return("[?] " + rtv.mValue.Name);
                }
                T[] values = rtv.mArrayProperty.GetValue(sm, null) as T[];
                for (i = values.Length - 1; i >= 0; i--)
                {
                    if (rtv.mValue == values[i])
                    {
                        break;
                    }
                }
                string result;
                int    j = values.Length.ToString("X").Length;

                if (i < 0)
                {
                    result = string.Concat("[", new string('?', j), "] ");
                }
                else
                {
                    result = string.Concat("[", i.ToString("X" + j), "] ");
                }
                return(result + rtv.mValue.Name);
            }
Example #3
0
            public override object EditValue(ITypeDescriptorContext context,
                                             IServiceProvider provider, object value)
            {
                if (provider == null)
                {
                    return(value);
                }
                RefToValue <T>             rtv = value as RefToValue <T>;
                IWindowsFormsEditorService edSvc
                    = (IWindowsFormsEditorService)provider.GetService(
                          typeof(IWindowsFormsEditorService));

                if (rtv == null || edSvc == null)
                {
                    return(value);
                }
                StateMachine sm    = rtv.mScene.StateMachine;
                int          index = (int)rtv.mCountProperty.GetValue(sm, null);

                string[] items = new string[index + 1];
                items[0] = "";
                T[] values = rtv.mArrayProperty.GetValue(sm, null) as T[];
                if (index > 0)
                {
                    int    i   = index.ToString("X").Length;
                    string fmt = "[{0:X" + i + "}] ";
                    if (rtv.mValue == null)
                    {
                        for (i = index - 1; i >= 0; i--)
                        {
                            items[i + 1] = string.Format(fmt, i)
                                           + values[i].Name;
                        }
                        index = 0;
                    }
                    else
                    {
                        index = -1;
                        T val;
                        for (i = values.Length - 1; i >= 0; i--)
                        {
                            val = values[i];
                            if (rtv.mValue == val)
                            {
                                index = i + 1;
                            }
                            items[i + 1] = string.Format(fmt, i) + val.Name;
                        }
                    }
                }
                else
                {
                    index = rtv.mValue == null ? 0 : -1;
                }

                ListBox lb = new ListBox();
                TextBox tb = new TextBox();

                tb.AutoSize  = true;
                tb.Font      = lb.Font;
                tb.Margin    = new Padding(0);
                tb.Multiline = true;
                tb.Lines     = items;
                tb.PerformLayout();

                lb.IntegralHeight = false;
                lb.Margin         = new Padding(0);
                lb.Size           = tb.PreferredSize;
                lb.Tag            = edSvc;
                lb.Items.AddRange(items);
                lb.PerformLayout();

                if (index >= 0)
                {
                    lb.SelectedIndex = index;
                }
                lb.SelectedIndexChanged +=
                    new EventHandler(lb_SelectedIndexChanged);
                edSvc.DropDownControl(lb);

                index = lb.SelectedIndex;
                if (index == 0)
                {
                    rtv.mValue = null;
                }
                else if (index > 0)
                {
                    rtv.mValue = values[index];
                }
                return(value);
            }