Ejemplo n.º 1
0
        public ConfigItemBase(SettingsPropertyAttribute attr, Func <T> loadCallback, Action <T> saveCallback)
        {
            _attr         = attr;
            _saveCallback = saveCallback;
            _loadCallback = loadCallback;

            Value = _loadCallback();
        }
        public EnumConfigItemViewModel(SettingsPropertyAttribute attr, Func <int> loadCallback, Action <int> saveCallback, Type enumType) : base(attr, loadCallback, saveCallback)
        {
            _enumType = enumType;
            var values = Enum.GetValues(enumType);

            EnumList = new List <string>();
            enumMap  = new Dictionary <string, int>();
            foreach (object v in values)
            {
                enumMap.Add(GetDescription(v), (int)v);
                EnumList.Add(GetDescription(v));
            }
        }
        public ConfigurationViewModel()
        {
            DisplayName = "Settings";

            FeaturesEnum features = Features.AsEnum;

            settings = Logic.Instance.settings;
            var props = settings.GetType().GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(SettingsPropertyAttribute)));

            props.ToList().ForEach(p =>
            {
                SettingsPropertyAttribute attr = p.GetAttributes <SettingsPropertyAttribute>(false).First();
                PropertyInfo property          = p;

                if (!features.HasFlag(attr.requiredFeatures))
                {
                    return;
                }

                var TargetCollection = attr is SettingsAdvancedPropertyAttribute ? ConfigAdvancedItems : ConfigItems;

                switch (attr.Type)
                {
                case ConfigItemType.Bool:
                    TargetCollection.Add(new BoolConfigItemViewModel(attr, () => (bool)property.GetValue(settings, null), (value) => property.SetValue(settings, value, null)));
                    break;

                case ConfigItemType.Path:
                    TargetCollection.Add(new PathConfigItemViewModel(attr, () => (string)property.GetValue(settings, null), (value) => property.SetValue(settings, value, null)));
                    break;

                case ConfigItemType.String:
                    TargetCollection.Add(new StringConfigItemViewModel(attr, () => (string)property.GetValue(settings, null), (value) => property.SetValue(settings, value, null)));
                    break;

                case ConfigItemType.Enum:
                    Type enumType = p.PropertyType;
                    TargetCollection.Add(new EnumConfigItemViewModel(attr, () => (int)property.GetValue(settings, null), (value) => property.SetValue(settings, value, null), enumType));
                    break;

                case ConfigItemType.Action:
                    TargetCollection.Add(new ButtonConfigItemViewModel(attr, () => { ((System.Action)property.GetValue(settings))(); }));
                    break;
                }
            });
        }
Ejemplo n.º 4
0
 public StringConfigItemViewModel(SettingsPropertyAttribute attr, Func <string> loadCallback, Action <string> saveCallback) : base(attr, loadCallback, saveCallback)
 {
 }
Ejemplo n.º 5
0
 public ButtonConfigItemViewModel(SettingsPropertyAttribute attr, System.Action callback)
 {
     ActionText  = attr.Caption;
     DisplayName = attr.DisplayName;
     _callback   = callback;
 }
 public BoolConfigItemViewModel(SettingsPropertyAttribute attr, Func <bool> loadCallback, Action <bool> saveCallback) : base(attr, loadCallback, saveCallback)
 {
 }