Added a log level droplist

This commit is contained in:
Brett Hewitson 2021-12-16 23:08:31 +10:00
parent 708031dcbb
commit 430bfe7bbb
21 changed files with 224 additions and 59 deletions

View file

@ -32,6 +32,7 @@ namespace ServerManagerTool
public static readonly DependencyProperty AppInstanceProperty = DependencyProperty.Register(nameof(AppInstance), typeof(App), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty IsAdministratorProperty = DependencyProperty.Register(nameof(IsAdministrator), typeof(bool), typeof(GlobalSettingsControl), new PropertyMetadata(false));
public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty DiscordBotLogLevelsProperty = DependencyProperty.Register(nameof(DiscordBotLogLevels), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelist>), typeof(GlobalSettingsControl), new PropertyMetadata(null));
public GlobalSettingsControl()
@ -42,7 +43,11 @@ namespace ServerManagerTool
this.IsAdministrator = SecurityUtils.IsAdministrator();
this.Version = GetDeployedVersion();
InitializeComponent();
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
PopulateWindowsStatesComboBox();
PopulateDiscordBotLogLevelsComboBox();
DiscordBotWhitelist = new List<DiscordBotWhitelist>();
if (Config.DiscordBotWhitelist != null)
@ -53,9 +58,6 @@ namespace ServerManagerTool
}
}
InitializeComponent();
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
this.DataContext = this;
}
@ -95,6 +97,12 @@ namespace ServerManagerTool
set;
}
public ComboBoxItemList DiscordBotLogLevels
{
get { return (ComboBoxItemList)GetValue(DiscordBotLogLevelsProperty); }
set { SetValue(DiscordBotLogLevelsProperty, value); }
}
public List<DiscordBotWhitelist> DiscordBotWhitelist
{
get { return (List<DiscordBotWhitelist>)GetValue(DiscordBotWhitelistProperty); }
@ -500,6 +508,24 @@ namespace ServerManagerTool
}
}
private void PopulateDiscordBotLogLevelsComboBox()
{
var selectedValue = this.DiscordBotLogLevelComboBox?.SelectedValue ?? Config.DiscordBotLogLevel;
var comboBoxList = new ComboBoxItemList();
foreach (DiscordBot.Enums.LogLevel logLevel in Enum.GetValues(typeof(DiscordBot.Enums.LogLevel)))
{
var displayMember = _globalizer.GetResourceString($"DiscordBotLogLevel_{logLevel}") ?? logLevel.ToString();
comboBoxList.Add(new Common.Model.ComboBoxItem(logLevel.ToString(), displayMember));
}
this.DiscordBotLogLevels = comboBoxList;
if (this.DiscordBotLogLevelComboBox != null)
{
this.DiscordBotLogLevelComboBox.SelectedValue = selectedValue;
}
}
#region Discord Bot Whitelist
private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
{