mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
Globalisation Changes
This commit is contained in:
parent
4a80b089b4
commit
034d7401d1
15 changed files with 410 additions and 51 deletions
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ServerManagerTool.Plugin.Common.Events
|
||||||
|
{
|
||||||
|
public class ResourceDictionaryChangedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public ResourceDictionaryChangedEventArgs(string languageCode)
|
||||||
|
{
|
||||||
|
LanguageCode = languageCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LanguageCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using ServerManagerTool.Plugin.Common.Delegates;
|
using ServerManagerTool.Plugin.Common.Delegates;
|
||||||
|
using ServerManagerTool.Plugin.Common.Events;
|
||||||
using ServerManagerTool.Plugin.Common.Lib;
|
using ServerManagerTool.Plugin.Common.Lib;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -15,6 +16,7 @@ namespace ServerManagerTool.Plugin.Common
|
||||||
{
|
{
|
||||||
private const string PLUGINFILE_FOLDER = "Plugins";
|
private const string PLUGINFILE_FOLDER = "Plugins";
|
||||||
private const string PLUGINFILE_EXTENSION = "dll";
|
private const string PLUGINFILE_EXTENSION = "dll";
|
||||||
|
public const string LANGUAGECODE_FALLBACK = "en-US";
|
||||||
|
|
||||||
private static volatile PluginHelper _instance;
|
private static volatile PluginHelper _instance;
|
||||||
private static readonly object _syncLock = new object();
|
private static readonly object _syncLock = new object();
|
||||||
|
|
@ -24,9 +26,12 @@ namespace ServerManagerTool.Plugin.Common
|
||||||
private FetchProfilesDelegate _fetchProfilesCallback;
|
private FetchProfilesDelegate _fetchProfilesCallback;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
|
||||||
|
public EventHandler<ResourceDictionaryChangedEventArgs> ResourceDictionaryChanged;
|
||||||
|
|
||||||
private PluginHelper()
|
private PluginHelper()
|
||||||
{
|
{
|
||||||
BetaEnabled = false;
|
BetaEnabled = false;
|
||||||
|
LanguageCode = LANGUAGECODE_FALLBACK;
|
||||||
Plugins = new ObservableCollection<PluginItem>();
|
Plugins = new ObservableCollection<PluginItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,6 +66,12 @@ namespace ServerManagerTool.Plugin.Common
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string LanguageCode
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableCollection<PluginItem> Plugins
|
public ObservableCollection<PluginItem> Plugins
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|
@ -236,6 +247,12 @@ namespace ServerManagerTool.Plugin.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnResourceDictionaryChanged(string languageCode)
|
||||||
|
{
|
||||||
|
LanguageCode = languageCode;
|
||||||
|
ResourceDictionaryChanged?.Invoke(this, new ResourceDictionaryChangedEventArgs(languageCode));
|
||||||
|
}
|
||||||
|
|
||||||
internal void OpenConfigForm(string pluginCode, Window owner)
|
internal void OpenConfigForm(string pluginCode, Window owner)
|
||||||
{
|
{
|
||||||
if (Plugins == null)
|
if (Plugins == null)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Markup;
|
||||||
|
|
||||||
namespace ServerManagerTool.Plugin.Common
|
namespace ServerManagerTool.Plugin.Common
|
||||||
{
|
{
|
||||||
|
|
@ -21,5 +26,111 @@ namespace ServerManagerTool.Plugin.Common
|
||||||
}
|
}
|
||||||
return null;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,32 @@ namespace Plugin.Discord.UnitTests
|
||||||
Assert.IsTrue(true);
|
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()
|
private IList<Profile> FetchProfiles()
|
||||||
{
|
{
|
||||||
return new List<Profile>()
|
return new List<Profile>()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,18 @@
|
||||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
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 -->
|
<!--#region Global -->
|
||||||
<sys:String x:Key="Global_CancelButtonLabel">Cancel</sys:String>
|
<sys:String x:Key="Global_CancelButtonLabel">Cancel</sys:String>
|
||||||
<sys:String x:Key="Global_CloseButtonLabel">Close</sys:String>
|
<sys:String x:Key="Global_CloseButtonLabel">Close</sys:String>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace ServerManagerTool.Plugin.Discord
|
namespace ServerManagerTool.Plugin.Discord
|
||||||
{
|
{
|
||||||
public class ComboBoxItemList : ObservableCollection<ComboBoxItem>
|
public class ComboBoxItemList : SortableObservableCollection<ComboBoxItem>
|
||||||
{
|
{
|
||||||
public ComboBoxItemList()
|
public ComboBoxItemList()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
84
src/Plugin.Discord/Models/SortableObservableCollection.cs
Normal file
84
src/Plugin.Discord/Models/SortableObservableCollection.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -65,10 +65,8 @@
|
||||||
<Resource Include="Art\Edit.ico" />
|
<Resource Include="Art\Edit.ico" />
|
||||||
<Resource Include="Art\favicon.ico" />
|
<Resource Include="Art\favicon.ico" />
|
||||||
<Resource Include="Globalization\en-US\en-US.xaml" />
|
<Resource Include="Globalization\en-US\en-US.xaml" />
|
||||||
<Resource Include="Globalization\pt-BR\pt-BR.xaml">
|
<EmbeddedResource Include="Globalization\pt-BR\pt-BR.xaml" />
|
||||||
<Generator></Generator>
|
<EmbeddedResource Include="Globalization\zh-CN\zh-CN.xaml" />
|
||||||
</Resource>
|
|
||||||
<Resource Include="Globalization\zh-CN\zh-CN.xaml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Config.Designer.cs">
|
<Compile Update="Config.Designer.cs">
|
||||||
|
|
|
||||||
|
|
@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.0.17.2")]
|
[assembly: AssemblyVersion("1.0.18.1")]
|
||||||
[assembly: AssemblyFileVersion("1.0.17.2")]
|
[assembly: AssemblyFileVersion("1.0.18.1")]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Linq;
|
using System.Windows;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
|
@ -8,30 +6,6 @@ namespace ServerManagerTool.Plugin.Discord
|
||||||
{
|
{
|
||||||
public static class WindowUtils
|
public static class WindowUtils
|
||||||
{
|
{
|
||||||
public static void RemoveDefaultResourceDictionary(Window window, string defaultDictionary)
|
|
||||||
{
|
|
||||||
if (window == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var dictToRemove = window.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Contains(defaultDictionary));
|
|
||||||
if (dictToRemove != null)
|
|
||||||
{
|
|
||||||
window.Resources.MergedDictionaries.Remove(dictToRemove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveDefaultResourceDictionary(UserControl control, string defaultDictionary)
|
|
||||||
{
|
|
||||||
if (control == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var dictToRemove = control.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Contains(defaultDictionary));
|
|
||||||
if (dictToRemove != null)
|
|
||||||
{
|
|
||||||
control.Resources.MergedDictionaries.Remove(dictToRemove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds a parent of a given item on the visual tree.
|
/// Finds a parent of a given item on the visual tree.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
<Window x:Class="ServerManagerTool.Plugin.Discord.Windows.ConfigProfileWindow"
|
<Window x:Class="ServerManagerTool.Plugin.Discord.Windows.ConfigProfileWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
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"
|
xmlns:pc="clr-namespace:ServerManagerTool.Plugin.Common;assembly=ServerManager.Plugin.Common"
|
||||||
Name="ConfigProfileUI" Title="{DynamicResource ConfigProfileWindow_Title}"
|
Name="ConfigProfileUI" Title="{DynamicResource ConfigProfileWindow_Title}"
|
||||||
Icon="/ServerManager.Plugin.Discord;component/Art/favicon.ico"
|
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>
|
<Window.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
|
@ -18,12 +18,6 @@
|
||||||
<GradientStop Color="#FFEAE8E6"/>
|
<GradientStop Color="#FFEAE8E6"/>
|
||||||
</LinearGradientBrush>
|
</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}}">
|
<Style x:Key="GroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||||
<Setter Property="BorderBrush" Value="{StaticResource BeigeBorder}"/>
|
<Setter Property="BorderBrush" Value="{StaticResource BeigeBorder}"/>
|
||||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
|
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
|
||||||
|
|
@ -212,7 +206,7 @@
|
||||||
</DataGridTemplateColumn.Header>
|
</DataGridTemplateColumn.Header>
|
||||||
<DataGridTemplateColumn.CellTemplate>
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<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>
|
</DataTemplate>
|
||||||
</DataGridTemplateColumn.CellTemplate>
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
</DataGridTemplateColumn>
|
</DataGridTemplateColumn>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using ServerManagerTool.Plugin.Common;
|
using ServerManagerTool.Plugin.Common;
|
||||||
|
using ServerManagerTool.Plugin.Common.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
@ -16,26 +17,43 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class ConfigProfileWindow : Window
|
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 ProfileProperty = DependencyProperty.Register(nameof(Profile), typeof(ConfigProfile), typeof(ConfigProfileWindow));
|
||||||
private static readonly DependencyProperty ProfileListProperty = DependencyProperty.Register(nameof(ProfileList), typeof(ComboBoxItemList), typeof(ConfigProfileWindow));
|
private static readonly DependencyProperty ProfileListProperty = DependencyProperty.Register(nameof(ProfileList), typeof(ComboBoxItemList), typeof(ConfigProfileWindow));
|
||||||
|
|
||||||
internal ConfigProfileWindow(DiscordPlugin plugin, ConfigProfile profile)
|
internal ConfigProfileWindow(DiscordPlugin plugin, ConfigProfile profile)
|
||||||
{
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceUtils.UpdateResourceDictionary(this, PluginHelper.Instance.LanguageCode);
|
||||||
|
PluginHelper.Instance.ResourceDictionaryChanged += OnResourceDictionaryChanged;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
|
||||||
this.Plugin = plugin ?? new DiscordPlugin();
|
this.Plugin = plugin ?? new DiscordPlugin();
|
||||||
this.OriginalProfile = profile;
|
this.OriginalProfile = profile;
|
||||||
this.Profile = profile.Clone();
|
this.Profile = profile.Clone();
|
||||||
this.Profile.CommitChanges();
|
this.Profile.CommitChanges();
|
||||||
|
|
||||||
|
RefreshAlertTypeList();
|
||||||
RefreshProfileList();
|
RefreshProfileList();
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
if (plugin.BetaEnabled)
|
if (plugin.BetaEnabled)
|
||||||
Title = $"{Title} {ResourceUtils.GetResourceString(this.Resources, "Global_BetaModeLabel")}";
|
Title = $"{Title} {ResourceUtils.GetResourceString(this.Resources, "Global_BetaModeLabel")}";
|
||||||
|
|
||||||
this.DataContext = this;
|
this.DataContext = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ComboBoxItemList AlertTypeList
|
||||||
|
{
|
||||||
|
get { return GetValue(AlertsListProperty) as ComboBoxItemList; }
|
||||||
|
set { SetValue(AlertsListProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
private ConfigProfile OriginalProfile
|
private ConfigProfile OriginalProfile
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|
@ -70,6 +88,16 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
if (MessageBox.Show(ResourceUtils.GetResourceString(this.Resources, "ConfigProfileWindow_CloseLabel"), ResourceUtils.GetResourceString(this.Resources, "ConfigProfileWindow_CloseTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
if (MessageBox.Show(ResourceUtils.GetResourceString(this.Resources, "ConfigProfileWindow_CloseLabel"), ResourceUtils.GetResourceString(this.Resources, "ConfigProfileWindow_CloseTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!e.Cancel)
|
||||||
|
PluginHelper.Instance.ResourceDictionaryChanged -= OnResourceDictionaryChanged;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ComboBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
private void ComboBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||||
|
|
@ -277,6 +305,37 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
expression?.UpdateSource();
|
expression?.UpdateSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnResourceDictionaryChanged(object sender, ResourceDictionaryChangedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceUtils.UpdateResourceDictionary(this, PluginHelper.Instance.LanguageCode);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshAlertTypeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
private void RefreshProfileList()
|
||||||
{
|
{
|
||||||
var newList = new ComboBoxItemList();
|
var newList = new ComboBoxItemList();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
using ServerManagerTool.Plugin.Common;
|
using ServerManagerTool.Plugin.Common;
|
||||||
|
using ServerManagerTool.Plugin.Common.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Resources;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
@ -20,11 +24,20 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
|
|
||||||
internal ConfigWindow(DiscordPlugin plugin, DiscordPluginConfig pluginConfig)
|
internal ConfigWindow(DiscordPlugin plugin, DiscordPluginConfig pluginConfig)
|
||||||
{
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceUtils.UpdateResourceDictionary(this, PluginHelper.Instance.LanguageCode);
|
||||||
|
PluginHelper.Instance.ResourceDictionaryChanged += OnResourceDictionaryChanged;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
|
||||||
this.Plugin = plugin ?? new DiscordPlugin();
|
this.Plugin = plugin ?? new DiscordPlugin();
|
||||||
this.PluginConfig = pluginConfig ?? new DiscordPluginConfig();
|
this.PluginConfig = pluginConfig ?? new DiscordPluginConfig();
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
if (plugin.BetaEnabled)
|
if (plugin.BetaEnabled)
|
||||||
Title = $"{Title} {ResourceUtils.GetResourceString(this.Resources, "Global_BetaModeLabel")}";
|
Title = $"{Title} {ResourceUtils.GetResourceString(this.Resources, "Global_BetaModeLabel")}";
|
||||||
|
|
||||||
|
|
@ -65,6 +78,16 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
if (MessageBox.Show(ResourceUtils.GetResourceString(this.Resources, "ConfigWindow_CloseLabel"), ResourceUtils.GetResourceString(this.Resources, "ConfigWindow_CloseTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
if (MessageBox.Show(ResourceUtils.GetResourceString(this.Resources, "ConfigWindow_CloseLabel"), ResourceUtils.GetResourceString(this.Resources, "ConfigWindow_CloseTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!e.Cancel)
|
||||||
|
PluginHelper.Instance.ResourceDictionaryChanged -= OnResourceDictionaryChanged;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfigWindow_Loaded(object sender, RoutedEventArgs e)
|
private void ConfigWindow_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
|
@ -268,6 +291,18 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
PluginConfig?.CommitChanges();
|
PluginConfig?.CommitChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnResourceDictionaryChanged(object sender, ResourceDictionaryChangedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceUtils.UpdateResourceDictionary(this, PluginHelper.Instance.LanguageCode);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Drag and Drop
|
#region Drag and Drop
|
||||||
|
|
||||||
private static readonly DependencyProperty DraggedItemProperty = DependencyProperty.Register(nameof(DraggedItem), typeof(ConfigProfile), typeof(ConfigWindow), new PropertyMetadata(null));
|
private static readonly DependencyProperty DraggedItemProperty = DependencyProperty.Register(nameof(DraggedItem), typeof(ConfigProfile), typeof(ConfigWindow), new PropertyMetadata(null));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
xmlns:local="clr-namespace:ServerManagerTool.Plugin.Discord"
|
xmlns:local="clr-namespace:ServerManagerTool.Plugin.Discord"
|
||||||
xmlns:pc="clr-namespace:ServerManagerTool.Plugin.Common;assembly=ServerManager.Plugin.Common"
|
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"
|
MinWidth="400" MinHeight="400" Width="640" Height="480" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" ResizeMode="CanResizeWithGrip"
|
||||||
Loaded="Window_Loaded"
|
Loaded="VersionFeedWindow_Loaded" Closing="VersionFeedWindow_Closing"
|
||||||
Icon="../Art/favicon.ico" Title="{DynamicResource VersionFeedWindow_Title}">
|
Icon="../Art/favicon.ico" Title="{DynamicResource VersionFeedWindow_Title}">
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using ServerManagerTool.Plugin.Common;
|
using ServerManagerTool.Plugin.Common;
|
||||||
|
using ServerManagerTool.Plugin.Common.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -18,11 +19,20 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
|
|
||||||
public VersionFeedWindow(DiscordPlugin plugin, string feedUri)
|
public VersionFeedWindow(DiscordPlugin plugin, string feedUri)
|
||||||
{
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceUtils.UpdateResourceDictionary(this, PluginHelper.Instance.LanguageCode);
|
||||||
|
PluginHelper.Instance.ResourceDictionaryChanged += OnResourceDictionaryChanged;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
|
||||||
this.Plugin = plugin ?? new DiscordPlugin();
|
this.Plugin = plugin ?? new DiscordPlugin();
|
||||||
this.feedUri = feedUri;
|
this.feedUri = feedUri;
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
this.DataContext = this;
|
this.DataContext = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +54,20 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
set { SetValue(SelectedFeedEntryProperty, value); }
|
set { SetValue(SelectedFeedEntryProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
private void VersionFeedWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!e.Cancel)
|
||||||
|
PluginHelper.Instance.ResourceDictionaryChanged -= OnResourceDictionaryChanged;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void VersionFeedWindow_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -77,5 +100,17 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
||||||
|
|
||||||
SelectedFeedEntry = FeedEntries.OrderByDescending(e => e.Updated).FirstOrDefault();
|
SelectedFeedEntry = FeedEntries.OrderByDescending(e => e.Updated).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnResourceDictionaryChanged(object sender, ResourceDictionaryChangedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResourceUtils.UpdateResourceDictionary(this, PluginHelper.Instance.LanguageCode);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// do nothing, most likely they are using an older version of a server manager
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue