Merge pull request #11 from Bletch1971/DiscordPluginChanges

Discord plugin changes
This commit is contained in:
Brett Hewitson 2021-12-03 11:29:18 +10:00 committed by GitHub
commit 763094bebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 386 additions and 71 deletions

View file

@ -18,6 +18,7 @@ using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;
@ -312,6 +313,7 @@ namespace ServerManagerTool
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
PluginHelper.Instance.LoadPlugins(installPath, true);
PluginHelper.Instance.SetFetchProfileCallback(FetchProfiles);
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
// check if we are starting ASM for the old server restart - no longer supported
if (e.Args.Any(a => a.StartsWith(Constants.ARG_AUTORESTART, StringComparison.OrdinalIgnoreCase)))
@ -458,6 +460,11 @@ namespace ServerManagerTool
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void OnResourceDictionaryChanged(string languageCode)
{
PluginHelper.Instance.OnResourceDictionaryChanged(languageCode);
}
public static void ReconfigureLogging()
{
string logDir = Path.Combine(Config.Default.DataDir, Config.Default.LogsDir);

View file

@ -306,6 +306,8 @@ namespace ServerManagerTool
CurrentConfig.CultureName = AvailableLanguages.Instance.SelectedLanguage;
PopulateWindowsStatesComboBox();
App.Instance.OnResourceDictionaryChanged(CurrentConfig.CultureName);
}
private void StyleSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)

View file

@ -17,6 +17,7 @@ using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using WPFSharp.Globalizer;
@ -304,6 +305,7 @@ namespace ServerManagerTool
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
PluginHelper.Instance.LoadPlugins(installPath, true);
PluginHelper.Instance.SetFetchProfileCallback(FetchProfiles);
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
// check if we are starting server manager for server shutdown
if (e.Args.Any(a => a.StartsWith(Constants.ARG_AUTOSHUTDOWN1, StringComparison.OrdinalIgnoreCase)))
@ -438,6 +440,11 @@ namespace ServerManagerTool
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void OnResourceDictionaryChanged(string languageCode)
{
PluginHelper.Instance.OnResourceDictionaryChanged(languageCode);
}
public static void ReconfigureLogging()
{
string logDir = Path.Combine(Config.Default.DataPath, Config.Default.LogsRelativePath);

View file

@ -315,6 +315,8 @@ namespace ServerManagerTool
Config.CultureName = AvailableLanguages.Instance.SelectedLanguage;
PopulateWindowsStatesComboBox();
App.Instance.OnResourceDictionaryChanged(Config.CultureName);
}
private void StyleSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)

View file

@ -15,6 +15,7 @@ namespace ServerManagerTool.Plugin.Common
{
private const string PLUGINFILE_FOLDER = "Plugins";
private const string PLUGINFILE_EXTENSION = "dll";
public const string LANGUAGECODE_FALLBACK = "en-US";
private static volatile PluginHelper _instance;
private static readonly object _syncLock = new object();
@ -27,6 +28,7 @@ namespace ServerManagerTool.Plugin.Common
private PluginHelper()
{
BetaEnabled = false;
LanguageCode = LANGUAGECODE_FALLBACK;
Plugins = new ObservableCollection<PluginItem>();
}
@ -61,6 +63,12 @@ namespace ServerManagerTool.Plugin.Common
set;
}
public string LanguageCode
{
get;
set;
}
public ObservableCollection<PluginItem> Plugins
{
get;
@ -236,6 +244,11 @@ namespace ServerManagerTool.Plugin.Common
}
}
public void OnResourceDictionaryChanged(string languageCode)
{
LanguageCode = languageCode;
}
internal void OpenConfigForm(string pluginCode, Window owner)
{
if (Plugins == null)

View file

@ -1,5 +1,10 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace ServerManagerTool.Plugin.Common
{
@ -21,5 +26,111 @@ namespace ServerManagerTool.Plugin.Common
}
return null;
}
public static void RemoveExceptResourceDictionary(Window window, string dictionaryName)
{
if (window == null || string.IsNullOrWhiteSpace(dictionaryName))
return;
var dictionariesToRemove = window.Resources.MergedDictionaries.Where(d => !d.Source.OriginalString.Contains(dictionaryName)).ToList();
if (dictionariesToRemove != null)
{
foreach (var dictionaryToRemove in dictionariesToRemove)
{
window.Resources.MergedDictionaries.Remove(dictionaryToRemove);
}
}
}
public static void RemoveExceptResourceDictionary(UserControl control, string dictionaryName)
{
if (control == null || string.IsNullOrWhiteSpace(dictionaryName))
return;
var dictionariesToRemove = control.Resources.MergedDictionaries.Where(d => !d.Source.OriginalString.Contains(dictionaryName)).ToList();
if (dictionariesToRemove != null)
{
foreach (var dictionaryToRemove in dictionariesToRemove)
{
control.Resources.MergedDictionaries.Remove(dictionaryToRemove);
}
}
}
public static void RemoveResourceDictionary(Window window, string dictionaryName)
{
if (window == null || string.IsNullOrWhiteSpace(dictionaryName))
return;
var dictionaryToRemove = window.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Contains(dictionaryName));
if (dictionaryToRemove != null)
{
window.Resources.MergedDictionaries.Remove(dictionaryToRemove);
}
}
public static void RemoveResourceDictionary(UserControl control, string dictionaryName)
{
if (control == null || string.IsNullOrWhiteSpace(dictionaryName))
return;
var dictionaryToRemove = control.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Contains(dictionaryName));
if (dictionaryToRemove != null)
{
control.Resources.MergedDictionaries.Remove(dictionaryToRemove);
}
}
public static void UpdateResourceDictionary(Window window, string languageCode)
{
if (window == null)
return;
RemoveExceptResourceDictionary(window, PluginHelper.LANGUAGECODE_FALLBACK);
var assembly = Assembly.GetCallingAssembly();
var resourcePath = assembly.GetManifestResourceNames().FirstOrDefault(r => r.EndsWith($"{languageCode}.xaml"));
if (string.IsNullOrWhiteSpace(resourcePath))
return;
using (Stream stream = assembly.GetManifestResourceStream(resourcePath))
{
using (StreamReader reader = new StreamReader(stream))
{
var resourceDictionary = XamlReader.Load(reader.BaseStream) as ResourceDictionary;
if (resourceDictionary != null)
{
window.Resources.MergedDictionaries.Add(resourceDictionary);
}
}
}
}
public static void UpdateResourceDictionary(UserControl control, string languageCode)
{
if (control == null)
return;
RemoveExceptResourceDictionary(control, PluginHelper.LANGUAGECODE_FALLBACK);
var assembly = Assembly.GetCallingAssembly();
var resourcePath = assembly.GetManifestResourceNames().FirstOrDefault(r => r.EndsWith($"{languageCode}.xaml"));
if (string.IsNullOrWhiteSpace(resourcePath))
return;
using (Stream stream = assembly.GetManifestResourceStream(resourcePath))
{
using (StreamReader reader = new StreamReader(stream))
{
var resourceDictionary = XamlReader.Load(reader.BaseStream) as ResourceDictionary;
if (resourceDictionary != null)
{
control.Resources.MergedDictionaries.Add(resourceDictionary);
}
}
}
}
}
}

View file

@ -305,6 +305,32 @@ namespace Plugin.Discord.UnitTests
Assert.IsTrue(true);
}
[TestMethod]
public void DiscordPlugin_OpenConfigForm_WithDifferentLanguage()
{
// Arrange
ServerManagerTool.Plugin.Common.PluginHelper.Instance.SetFetchProfileCallback(FetchProfiles);
var plugin = new DiscordPlugin();
plugin.BetaEnabled = true;
plugin.Initialize();
// Act
plugin.OpenConfigForm(null);
// Assert
Assert.IsTrue(true);
// Arrange
ServerManagerTool.Plugin.Common.PluginHelper.Instance.OnResourceDictionaryChanged("zh-CN");
// Act
plugin.OpenConfigForm(null);
// Assert
Assert.IsTrue(true);
}
private IList<Profile> FetchProfiles()
{
return new List<Profile>()

View file

@ -59,6 +59,28 @@ namespace ServerManagerTool.Plugin.Discord
public bool HasConfigForm => true;
public string LanguageCode
{
get
{
var assembly = typeof(PluginHelper).Assembly;
if (assembly != null)
{
var pluginHelperType = assembly.GetType(typeof(PluginHelper).FullName, false, true);
if (pluginHelperType != null)
{
var property = pluginHelperType.GetProperty(nameof(LanguageCode));
if (property != null)
{
return property.GetValue(PluginHelper.Instance).ToString();
}
}
}
return "en-US";
}
}
private async Task CallHomeAsync()
{
try

View file

@ -4,6 +4,18 @@
xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
<!--#region Alert Types -->
<sys:String x:Key="AlertType_Backup">Backup</sys:String>
<sys:String x:Key="AlertType_Error">Error</sys:String>
<sys:String x:Key="AlertType_ModUpdateDetected">Mod Update Detected</sys:String>
<sys:String x:Key="AlertType_Shutdown">Shutdown</sys:String>
<sys:String x:Key="AlertType_ShutdownMessage">Shutdown Message</sys:String>
<sys:String x:Key="AlertType_ShutdownReason">Shutdown Reason</sys:String>
<sys:String x:Key="AlertType_ServerStatusChange">Server Status Change</sys:String>
<sys:String x:Key="AlertType_Startup">Startup</sys:String>
<sys:String x:Key="AlertType_UpdateResults">Update Results</sys:String>
<!--#endregion-->
<!--#region Global -->
<sys:String x:Key="Global_CancelButtonLabel">Cancel</sys:String>
<sys:String x:Key="Global_CloseButtonLabel">Close</sys:String>

View file

@ -2,7 +2,7 @@
namespace ServerManagerTool.Plugin.Discord
{
public class ComboBoxItemList : ObservableCollection<ComboBoxItem>
public class ComboBoxItemList : SortableObservableCollection<ComboBoxItem>
{
public ComboBoxItemList()
{

View file

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace ServerManagerTool.Plugin.Discord
{
/// <summary>
/// Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed and allows sorting.
/// </summary>
/// <typeparam name="T">The type of elements in the collection.</typeparam>
public class SortableObservableCollection<T> : ObservableCollection<T>
{
public SortableObservableCollection()
{
}
public SortableObservableCollection(List<T> list)
: base(list)
{
}
public SortableObservableCollection(IEnumerable<T> collection)
: base(collection)
{
}
/// <summary>
/// Sorts the items of the collection in ascending order according to a key.
/// </summary>
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam>
/// <param name="keySelector">A function to extract a key from an item.</param>
public void Sort<TKey>(Func<T, TKey> keySelector)
{
InternalSort(Items.OrderBy(keySelector));
}
/// <summary>
/// Sorts the items of the collection in ascending order according to a key.
/// </summary>
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam>
/// <param name="keySelector">A function to extract a key from an item.</param>
/// <param name="comparer">An <see cref="IComparer{T}"/> to compare keys.</param>
public void Sort<TKey>(Func<T, TKey> keySelector, IComparer<TKey> comparer)
{
InternalSort(Items.OrderBy(keySelector, comparer));
}
/// <summary>
/// Sorts the items of the collection in descending order according to a key.
/// </summary>
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam>
/// <param name="keySelector">A function to extract a key from an item.</param>
public void SortDescending<TKey>(Func<T, TKey> keySelector)
{
InternalSort(Items.OrderByDescending(keySelector));
}
/// <summary>
/// Sorts the items of the collection in descending order according to a key.
/// </summary>
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam>
/// <param name="keySelector">A function to extract a key from an item.</param>
/// <param name="comparer">An <see cref="IComparer{T}"/> to compare keys.</param>
public void SortDescending<TKey>(Func<T, TKey> keySelector, IComparer<TKey> comparer)
{
InternalSort(Items.OrderByDescending(keySelector, comparer));
}
/// <summary>
/// Moves the items of the collection so that their orders are the same as those of the items provided.
/// </summary>
/// <param name="sortedItems">An <see cref="IEnumerable{T}"/> to provide item orders.</param>
private void InternalSort(IEnumerable<T> sortedItems)
{
var sortedItemsList = sortedItems.ToList();
foreach (var item in sortedItemsList)
{
Move(IndexOf(item), sortedItemsList.IndexOf(item));
}
}
}
}

View file

@ -65,10 +65,8 @@
<Resource Include="Art\Edit.ico" />
<Resource Include="Art\favicon.ico" />
<Resource Include="Globalization\en-US\en-US.xaml" />
<Resource Include="Globalization\pt-BR\pt-BR.xaml">
<Generator></Generator>
</Resource>
<Resource Include="Globalization\zh-CN\zh-CN.xaml" />
<EmbeddedResource Include="Globalization\pt-BR\pt-BR.xaml" />
<EmbeddedResource Include="Globalization\zh-CN\zh-CN.xaml" />
</ItemGroup>
<ItemGroup>
<Compile Update="Config.Designer.cs">

View file

@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.17.2")]
[assembly: AssemblyFileVersion("1.0.17.2")]
[assembly: AssemblyVersion("1.0.18.1")]
[assembly: AssemblyFileVersion("1.0.18.1")]

View file

@ -1,4 +1,4 @@
using System.Linq;
using ServerManagerTool.Plugin.Common;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@ -8,27 +8,37 @@ namespace ServerManagerTool.Plugin.Discord
{
public static class WindowUtils
{
public static void RemoveDefaultResourceDictionary(Window window, string defaultDictionary)
public static void UpdateResourceDictionary(Window window, string languageCode)
{
if (window == null)
return;
var dictToRemove = window.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Contains(defaultDictionary));
if (dictToRemove != null)
var assembly = typeof(ResourceUtils).Assembly;
if (assembly != null)
{
window.Resources.MergedDictionaries.Remove(dictToRemove);
var resourceUtilsType = assembly.GetType(typeof(ResourceUtils).FullName, false, true);
if (resourceUtilsType != null)
{
var method = resourceUtilsType.GetMethod(nameof(UpdateResourceDictionary), new System.Type[] { typeof(Window), typeof(string) });
if (method != null)
{
method.Invoke(null, new object[] { window, languageCode });
}
}
}
}
public static void RemoveDefaultResourceDictionary(UserControl control, string defaultDictionary)
public static void UpdateResourceDictionary(UserControl control, string languageCode)
{
if (control == null)
return;
var dictToRemove = control.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Contains(defaultDictionary));
if (dictToRemove != null)
var assembly = typeof(ResourceUtils).Assembly;
if (assembly != null)
{
control.Resources.MergedDictionaries.Remove(dictToRemove);
var resourceUtilsType = assembly.GetType(typeof(ResourceUtils).FullName, false, true);
if (resourceUtilsType != null)
{
var method = resourceUtilsType.GetMethod(nameof(UpdateResourceDictionary), new System.Type[] { typeof(UserControl), typeof(string) });
if (method != null)
{
method.Invoke(null, new object[] { control, languageCode });
}
}
}
}

View file

@ -5,7 +5,30 @@
<title>Discord Plugin Version Feed</title>
<subtitle>This is the Discord Plugin release version feed.</subtitle>
<link href="" />
<updated>2020-07-13T00:00:00Z</updated>
<updated>2021-12-03T00:00:00Z</updated>
<entry>
<id>urn:uuid:C01A4AA0-D839-4732-9814-301DAC6EB094</id>
<title>1.0.18 (1.0.18.1)</title>
<summary>1.0.18.1</summary>
<link href="" />
<updated>2021-12-03T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Have enabled globalization support for the plugin.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:D8974ABF-8444-4D40-A594-D4443921B3B8</id>

View file

@ -5,44 +5,21 @@
<title>Discord Plugin Version Feed</title>
<subtitle>This is the Discord Plugin beta version feed.</subtitle>
<link href="" />
<updated>2020-07-12T02:00:00Z</updated>
<updated>2021-12-03T00:00:00Z</updated>
<entry>
<id>urn:uuid:4750D17C-2C8F-4D8C-AA17-B3512F002170</id>
<title>1.0.17 (1.0.17.2)</title>
<summary>1.0.17.2</summary>
<id>urn:uuid:C01A4AA0-D839-4732-9814-301DAC6EB094</id>
<title>1.0.18 (1.0.18.1)</title>
<summary>1.0.18.1</summary>
<link href="" />
<updated>2020-07-12T02:00:00Z</updated>
<updated>2021-12-03T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Added drag/drop feature to the config window.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:D8974ABF-8444-4D40-A594-D4443921B3B8</id>
<title>1.0.17 (1.0.17.1)</title>
<summary>1.0.17.1</summary>
<link href="" />
<updated>2020-07-12T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Profile name has been converted to a droplist and is now populated with the Server Manager Profile Names for selection.</li>
<li>Have enabled globalization support for the plugin.</li>
</ul>
</p>
</div>

View file

@ -1,11 +1,11 @@
<Window x:Class="ServerManagerTool.Plugin.Discord.Windows.ConfigProfileWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:pc="clr-namespace:ServerManagerTool.Plugin.Common;assembly=ServerManager.Plugin.Common"
Name="ConfigProfileUI" Title="{DynamicResource ConfigProfileWindow_Title}"
Icon="/ServerManager.Plugin.Discord;component/Art/favicon.ico"
Width="640" Height="520" MinWidth="640" MinHeight="480" ResizeMode="CanResizeWithGrip" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" Closing="ConfigProfileWindow_Closing">
Width="640" Height="520" MinWidth="640" MinHeight="480" ResizeMode="CanResizeWithGrip" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
Closing="ConfigProfileWindow_Closing">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@ -18,12 +18,6 @@
<GradientStop Color="#FFEAE8E6"/>
</LinearGradientBrush>
<ObjectDataProvider x:Key="AlertTypes" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="pc:AlertType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<Style x:Key="GroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
<Setter Property="BorderBrush" Value="{StaticResource BeigeBorder}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
@ -212,7 +206,7 @@
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="False" ItemsSource="{Binding Source={StaticResource AlertTypes}}" SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
<ComboBox IsEditable="False" ItemsSource="{Binding AlertTypeList, ElementName=ConfigProfileUI}" SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

View file

@ -16,26 +16,35 @@ namespace ServerManagerTool.Plugin.Discord.Windows
/// </summary>
public partial class ConfigProfileWindow : Window
{
private static readonly DependencyProperty AlertsListProperty = DependencyProperty.Register(nameof(AlertTypeList), typeof(ComboBoxItemList), typeof(ConfigProfileWindow));
private static readonly DependencyProperty ProfileProperty = DependencyProperty.Register(nameof(Profile), typeof(ConfigProfile), typeof(ConfigProfileWindow));
private static readonly DependencyProperty ProfileListProperty = DependencyProperty.Register(nameof(ProfileList), typeof(ComboBoxItemList), typeof(ConfigProfileWindow));
internal ConfigProfileWindow(DiscordPlugin plugin, ConfigProfile profile)
{
InitializeComponent();
WindowUtils.UpdateResourceDictionary(this, plugin.LanguageCode);
this.Plugin = plugin ?? new DiscordPlugin();
this.OriginalProfile = profile;
this.Profile = profile.Clone();
this.Profile.CommitChanges();
RefreshAlertTypeList();
RefreshProfileList();
InitializeComponent();
if (plugin.BetaEnabled)
Title = $"{Title} {ResourceUtils.GetResourceString(this.Resources, "Global_BetaModeLabel")}";
this.DataContext = this;
}
private ComboBoxItemList AlertTypeList
{
get { return GetValue(AlertsListProperty) as ComboBoxItemList; }
set { SetValue(AlertsListProperty, value); }
}
private ConfigProfile OriginalProfile
{
get;
@ -277,6 +286,23 @@ namespace ServerManagerTool.Plugin.Discord.Windows
expression?.UpdateSource();
}
private void RefreshAlertTypeList()
{
var newList = new ComboBoxItemList();
foreach (AlertType alertType in Enum.GetValues(typeof(AlertType)))
{
newList.Add(new ComboBoxItem
{
ValueMember = alertType.ToString(),
DisplayMember = ResourceUtils.GetResourceString(this.Resources, $"AlertType_{alertType}") ?? alertType.ToString(),
});
}
newList.Sort(i => i.DisplayMember);
this.AlertTypeList = newList;
}
private void RefreshProfileList()
{
var newList = new ComboBoxItemList();
@ -297,7 +323,7 @@ namespace ServerManagerTool.Plugin.Discord.Windows
});
}
}
catch
catch (Exception)
{
// do nothing, most likely they are using an older version of a server manager
}

View file

@ -20,11 +20,12 @@ namespace ServerManagerTool.Plugin.Discord.Windows
internal ConfigWindow(DiscordPlugin plugin, DiscordPluginConfig pluginConfig)
{
InitializeComponent();
WindowUtils.UpdateResourceDictionary(this, plugin.LanguageCode);
this.Plugin = plugin ?? new DiscordPlugin();
this.PluginConfig = pluginConfig ?? new DiscordPluginConfig();
InitializeComponent();
if (plugin.BetaEnabled)
Title = $"{Title} {ResourceUtils.GetResourceString(this.Resources, "Global_BetaModeLabel")}";

View file

@ -2,9 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ServerManagerTool.Plugin.Discord"
xmlns:pc="clr-namespace:ServerManagerTool.Plugin.Common;assembly=ServerManager.Plugin.Common"
MinWidth="400" MinHeight="400" Width="640" Height="480" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" ResizeMode="CanResizeWithGrip"
Loaded="Window_Loaded"
Loaded="VersionFeedWindow_Loaded"
Icon="../Art/favicon.ico" Title="{DynamicResource VersionFeedWindow_Title}">
<Window.Resources>
<ResourceDictionary>

View file

@ -18,11 +18,12 @@ namespace ServerManagerTool.Plugin.Discord.Windows
public VersionFeedWindow(DiscordPlugin plugin, string feedUri)
{
InitializeComponent();
WindowUtils.UpdateResourceDictionary(this, plugin.LanguageCode);
this.Plugin = plugin ?? new DiscordPlugin();
this.feedUri = feedUri;
InitializeComponent();
this.DataContext = this;
}
@ -44,7 +45,7 @@ namespace ServerManagerTool.Plugin.Discord.Windows
set { SetValue(SelectedFeedEntryProperty, value); }
}
private void Window_Loaded(object sender, RoutedEventArgs e)
private void VersionFeedWindow_Loaded(object sender, RoutedEventArgs e)
{
try
{