public StringSettingControl(StringSetting stringSetting)
        {
            StringSetting = stringSetting;
            InitializeComponent();
            TitleTextBox.Text = stringSetting.Name;
            HelpTextBox.Text  = stringSetting.Help;
            ValueTextBox.Text = StringSetting.Value;

            if (StringSetting.Width > 0)
            {
                ValueTextBox.Width = StringSetting.Width;
            }

            if (StringSetting.Type != "folder" && StringSetting.Type != "color")
            {
                Button.Visibility = Visibility.Hidden;
            }

            Link.SetURL(StringSetting.URL);

            if (string.IsNullOrEmpty(stringSetting.URL))
            {
                LinkTextBlock.Visibility = Visibility.Collapsed;
            }
        }
Example #2
0
        public static List <SettingBase> LoadSettings(string content)
        {
            TomlTable table;

            using (StringReader reader = new StringReader(content))
                table = TOML.Parse(reader);
            List <SettingBase> settingsList = new List <SettingBase>();

            foreach (TomlTable setting in table["settings"])
            {
                SettingBase baseSetting = null;

                if (setting.HasKey("options"))
                {
                    OptionSetting optionSetting = new OptionSetting();
                    baseSetting              = optionSetting;
                    optionSetting.Default    = setting["default"];
                    optionSetting.Value      = optionSetting.Default;
                    optionSetting.StartValue = optionSetting.Default;

                    foreach (TomlTable option in setting["options"])
                    {
                        var opt = new OptionSettingOption();
                        opt.Name = option["name"];
                        if (option.HasKey("help"))
                        {
                            opt.Help = option["help"];
                        }
                        if (option.HasKey("text"))
                        {
                            opt.Text = option["text"];
                        }
                        else if (opt.Name == optionSetting.Default)
                        {
                            opt.Text = opt.Name + " (Default)";
                        }
                        opt.OptionSetting = optionSetting;
                        optionSetting.Options.Add(opt);
                    }
                }
                else
                {
                    StringSetting stringSetting = new StringSetting();
                    baseSetting           = stringSetting;
                    stringSetting.Default = setting.HasKey("default") ? setting["default"].ToString() : "";
                }

                baseSetting.Name   = setting["name"];
                baseSetting.Filter = setting["filter"];

                if (setting.HasKey("help"))
                {
                    baseSetting.Help = setting["help"];
                }
                if (setting.HasKey("helpurl"))
                {
                    baseSetting.HelpURL = setting["helpurl"];
                }
                if (setting.HasKey("width"))
                {
                    baseSetting.Width = setting["width"];
                }
                if (setting.HasKey("type"))
                {
                    baseSetting.Type = setting["type"];
                }

                settingsList.Add(baseSetting);
            }
            return(settingsList);
        }
Example #3
0
        public static List <SettingBase> LoadSettings(string filepath)
        {
            TomlTable table;

            using (StreamReader reader = new StreamReader(File.OpenRead(filepath)))
                table = TOML.Parse(reader);
            List <SettingBase> settingsList = new List <SettingBase>();

            foreach (TomlTable setting in table["settings"])
            {
                SettingBase baseSetting = null;

                if (setting.HasKey("options"))
                {
                    OptionSetting optionSetting = new OptionSetting();
                    baseSetting           = optionSetting;
                    optionSetting.Default = setting["default"];
                    optionSetting.Value   = optionSetting.Default;

                    foreach (TomlTable option in setting["options"])
                    {
                        var opt = new OptionSettingOption();
                        opt.Name = option["name"];
                        if (option.HasKey("help"))
                        {
                            opt.Help = option["help"];
                        }
                        if (option.HasKey("text"))
                        {
                            opt.Text = option["text"];
                        }
                        else if (opt.Name == optionSetting.Default)
                        {
                            opt.Text = opt.Name + " (Default)";
                        }
                        opt.OptionSetting = optionSetting;
                        optionSetting.Options.Add(opt);
                    }
                }
                else if (setting["default"].IsString)
                {
                    StringSetting stringSetting = new StringSetting();
                    baseSetting           = stringSetting;
                    stringSetting.Default = setting["default"];
                    if (setting.HasKey("folder"))
                    {
                        stringSetting.IsFolder = true;
                    }
                }

                baseSetting.Name   = setting["name"];
                baseSetting.Filter = setting["filter"];
                if (setting.HasKey("help"))
                {
                    baseSetting.Help = setting["help"];
                }
                if (setting.HasKey("helpurl"))
                {
                    baseSetting.HelpURL = setting["helpurl"];
                }
                if (setting.HasKey("alias"))
                {
                    baseSetting.Alias = setting["alias"];
                }
                if (setting.HasKey("width"))
                {
                    baseSetting.Width = setting["width"];
                }
                settingsList.Add(baseSetting);
            }
            return(settingsList);
        }