mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
Discord Plugin Profile Name Column Changes
1. Profile name has been converted to a droplist and is now populated with the Server Manager Profile Names for selection.
This commit is contained in:
parent
eaa7876ab4
commit
fce9a3e65f
10 changed files with 212 additions and 24 deletions
|
|
@ -3,7 +3,7 @@
|
|||
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"
|
||||
Title="{DynamicResource ConfigProfileWindow_Title}"
|
||||
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">
|
||||
<Window.Resources>
|
||||
|
|
@ -150,11 +150,17 @@
|
|||
</DataGrid.VerticalGridLinesBrush>
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="*" Binding="{Binding Value}">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{DynamicResource ConfigProfileWindow_ProfileNameColumnLabel}"/>
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTemplateColumn Width="*" CanUserSort="True" SortMemberPath="DisplayName">
|
||||
<DataGridTemplateColumn.Header>
|
||||
<TextBlock Text="{DynamicResource ConfigProfileWindow_ProfileNameColumnLabel}" />
|
||||
</DataGridTemplateColumn.Header>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox IsEditable="True" ItemsSource="{Binding ProfileList, ElementName=ConfigProfileUI}" SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=Explicit}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" GotFocus="ComboBox_GotFocus" LostFocus="ComboBox_LostFocus" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
|
|
@ -210,6 +216,7 @@
|
|||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ServerManagerTool.Plugin.Discord.Windows
|
||||
|
|
@ -15,6 +17,7 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
|||
public partial class ConfigProfileWindow : Window
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
@ -23,6 +26,8 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
|||
this.Profile = profile.Clone();
|
||||
this.Profile.CommitChanges();
|
||||
|
||||
RefreshProfileList();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
if (plugin.BetaEnabled)
|
||||
|
|
@ -49,6 +54,12 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
|||
set;
|
||||
}
|
||||
|
||||
private ComboBoxItemList ProfileList
|
||||
{
|
||||
get { return GetValue(ProfileListProperty) as ComboBoxItemList; }
|
||||
set { SetValue(ProfileListProperty, value); }
|
||||
}
|
||||
|
||||
private void ConfigProfileWindow_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (DialogResult.HasValue && DialogResult.Value)
|
||||
|
|
@ -219,5 +230,91 @@ namespace ServerManagerTool.Plugin.Discord.Windows
|
|||
MessageBox.Show(ResourceUtils.GetResourceString(this.Resources, "ConfigProfileWindow_DeleteProfileNameErrorLabel"), ResourceUtils.GetResourceString(this.Resources, "ConfigProfileWindow_DeleteErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBox_GotFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var comboBox = sender as ComboBox;
|
||||
if (comboBox == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
comboBox.BeginInit();
|
||||
}
|
||||
finally
|
||||
{
|
||||
comboBox.EndInit();
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var comboBox = sender as ComboBox;
|
||||
if (comboBox == null)
|
||||
return;
|
||||
|
||||
if (comboBox.SelectedItem == null)
|
||||
{
|
||||
var text = comboBox.Text;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
var source = comboBox.ItemsSource as ComboBoxItemList;
|
||||
source?.Add(new ComboBoxItem
|
||||
{
|
||||
ValueMember = text,
|
||||
DisplayMember = text,
|
||||
});
|
||||
}
|
||||
|
||||
comboBox.SelectedValue = text;
|
||||
}
|
||||
|
||||
var expression = comboBox.GetBindingExpression(Selector.SelectedValueProperty);
|
||||
expression?.UpdateSource();
|
||||
|
||||
expression = comboBox.GetBindingExpression(ComboBox.TextProperty);
|
||||
expression?.UpdateSource();
|
||||
}
|
||||
|
||||
private void RefreshProfileList()
|
||||
{
|
||||
var newList = new ComboBoxItemList();
|
||||
newList.Add(new ComboBoxItem
|
||||
{
|
||||
ValueMember = string.Empty,
|
||||
DisplayMember = string.Empty,
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var profile in PluginHelper.Instance.FetchProfileList())
|
||||
{
|
||||
newList.Add(new ComboBoxItem
|
||||
{
|
||||
ValueMember = profile.ProfileName,
|
||||
DisplayMember = $"* {profile.ProfileName}",
|
||||
});
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// do nothing, most likely they are using an older version of a server manager
|
||||
}
|
||||
|
||||
foreach (var profile in Profile.ProfileNames)
|
||||
{
|
||||
if (!newList.Any(p => p.ValueMember.Equals(profile.Value, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
newList.Add(new ComboBoxItem
|
||||
{
|
||||
ValueMember = profile.Value,
|
||||
DisplayMember = profile.Value,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.ProfileList = newList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue