示例#1
0
        public OptionList(GCSVTable csv, Func<IData, Options, string> getDefault, Func<string, Options> getList, Utilities.VariableBin var, Func<IData, bool> selector)
        {
            Var = var;
            Options = new List<Option>();

            foreach (var line in csv)
            {
                if (!selector(line))
                    continue;

                var o = new Option();
                o.Parent = this;
                o.Caption = line["caption"];
                o.ID = line["id"];
                o.Active = line["active"].ToBool();
                var l = getList(line["list"]);
                o.Values = l.ToList();
                o.Default = getDefault(line, o.Values);
                o.Initialize();

                if (!var.Str.ContainsKey(o.ID))
                    var.Str[o.ID] = o.Default;

                if (var.Str.ContainsKey(o.ID))
                    o.ComboBox.SelectedIndex = o.Values.FindIndex(p => p.Key == var.Str[o.ID]);

                Options.Add(o);
            }
        }
示例#2
0
        public OptionList(GCSVTable csv, IGCSVCollection csvs, Utilities.VariableBin var, Func<IData,bool> selector)
        {
            Var = var;
            Options = new List<Option>();

            foreach (var line in csv)
            {
                if (!selector(line))
                    continue;

                var o = new Option();
                o.Parent = this;
                o.Caption = line["caption"];
                o.ID = line["id"];
                o.Active = line["active"].ToBool();

                o.Default = line["default"];
                var l = csvs[line["list"]];
                o.Values = l.Where(m => !m.ContainsKey("active") || m["active"].ToBool()).Select(m => new KeyValuePair<string, string>(m[line["value"]], m[line["text"]])).ToList();
                o.Initialize();

                if (!var.Str.ContainsKey(o.ID) || !o.Active) // set defaults if variable is not set or option is not active
                    var.Str[o.ID] = o.Default;

                if (var.Str.ContainsKey(o.ID))
                    o.ComboBox.SelectedIndex = o.Values.FindIndex(p => p.Key == var.Str[o.ID]);

                Options.Add(o);
            }
        }