示例#1
0
            private Control GetControlForSetting(PropertyInfo property, PluginSetting setting)
            {
                if (property.PropertyType == typeof(string))
                {
                    var textbox = new TextBox
                    {
                        Text = setting.GetValue <string>()
                    };
                    textbox.TextChanged += (sender, e) => setting.SetValue(textbox.Text);
                    return(textbox);
                }
                else if (property.PropertyType == typeof(bool))
                {
                    string description = property.Name;
                    if (property.GetCustomAttribute <BooleanPropertyAttribute>() is BooleanPropertyAttribute attribute)
                    {
                        description = attribute.Description;
                    }

                    var checkbox = new CheckBox
                    {
                        Text    = description,
                        Checked = setting.GetValue <bool>()
                    };
                    checkbox.CheckedChanged += (sender, e) => setting.SetValue((bool)checkbox.Checked);
                    return(checkbox);
                }
                else if (property.PropertyType == typeof(float))
                {
                    var tb = new TextBox
                    {
                        Text = $"{setting.GetValue<float>()}"
                    };
                    tb.TextChanged += (sender, e) => setting.SetValue(float.TryParse(tb.Text, out var val) ? val : 0f);

                    if (property.GetCustomAttribute <SliderPropertyAttribute>() is SliderPropertyAttribute sliderAttr)
                    {
                        // TODO: replace with slider when possible (https://github.com/picoe/Eto/issues/1772)
                        tb.ToolTip         = $"Minimum: {sliderAttr.Min}, Maximum: {sliderAttr.Max}";
                        tb.PlaceholderText = $"{sliderAttr.DefaultValue}";
                        if (setting.Value == null)
                        {
                            setting.SetValue(sliderAttr.DefaultValue);
                        }
                    }
                    return(tb);
                }
                else if (GenericallyConvertableTypes.Contains(property.PropertyType))
                {
                    var tb = new TextBox
                    {
                        Text = $"{setting.GetValue(property.PropertyType)}"
                    };
                    tb.TextChanged += (sender, e) => setting.SetValue(Convert.ChangeType(tb.Text, property.PropertyType) ?? 0);
                    return(tb);
                }
                throw new NotSupportedException($"'{property.PropertyType}' is not supported by {nameof(PluginSettingStoreEditor)}");
            }
示例#2
0
        public static string Format(this PluginSetting setting)
        {
            if (setting == null)
            {
                return(null);
            }

            return($"{{ {setting.Property}: {setting.GetValue(typeof(object))} }}");
        }
            private static MaskedTextBox <T> GetMaskedTextBox <T>(PropertyInfo property, PluginSetting setting)
            {
                var tb = new MaskedTextBox <T>
                {
                    Value = setting.GetValue <T>()
                };

                tb.ValueChanged += (sender, e) => setting.SetValue(tb.Value);
                return(tb);
            }
 private static T GetSetting <T>(PropertyInfo property, PluginSetting setting)
 {
     if (setting.HasValue)
     {
         return(setting.GetValue <T>());
     }
     else
     {
         if (property.GetCustomAttribute <DefaultPropertyValueAttribute>() is DefaultPropertyValueAttribute defaults)
         {
             try
             {
                 return((T)defaults.Value);
             }
             catch (Exception e)
             {
                 Log.Write("UX", $"Failed to get custom default of {property.Name}: {e.Message}");
             }
         }
         return(default);