Release 17 updates

This commit is contained in:
Brett Hewitson 2020-07-15 17:29:43 +10:00
parent 38dededb14
commit 4a54288072
11 changed files with 306 additions and 19 deletions

View file

@ -132,7 +132,7 @@
</StackPanel>
</GroupBox.Header>
<DataGrid ItemsSource="{Binding Profile.ProfileNames}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="true" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
<DataGrid ItemsSource="{Binding Profile.ProfileNames}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Resources>
@ -150,7 +150,7 @@
</DataGrid.VerticalGridLinesBrush>
<DataGrid.Columns>
<DataGridTemplateColumn Width="*" CanUserSort="True" SortMemberPath="DisplayName">
<DataGridTemplateColumn Width="*">
<DataGridTemplateColumn.Header>
<TextBlock Text="{DynamicResource ConfigProfileWindow_ProfileNameColumnLabel}" />
</DataGridTemplateColumn.Header>
@ -161,7 +161,7 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
<DataGridTemplateColumn Width="30" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="DeleteProfileName_Click" ToolTip="{DynamicResource ConfigProfileWindow_DeleteProfileNameTooltip}">
@ -188,7 +188,7 @@
</GroupBox.Header>
<DataGrid ItemsSource="{Binding Profile.AlertTypes}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="true" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
<DataGrid ItemsSource="{Binding Profile.AlertTypes}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Resources>
@ -206,7 +206,7 @@
</DataGrid.VerticalGridLinesBrush>
<DataGrid.Columns>
<DataGridTemplateColumn Width="*">
<DataGridTemplateColumn Width="*">
<DataGridTemplateColumn.Header>
<TextBlock Text="{DynamicResource ConfigProfileWindow_AlertTypeColumnLabel}"/>
</DataGridTemplateColumn.Header>
@ -217,7 +217,7 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
<DataGridTemplateColumn Width="30" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="DeleteAlertType_Click" ToolTip="{DynamicResource ConfigProfileWindow_DeleteAlertTypeTooltip}">

View file

@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pc="clr-namespace:ServerManagerTool.Plugin.Common;assembly=ServerManager.Plugin.Common"
Title="{DynamicResource ConfigWindow_Title}"
Name="ConfigUI" Title="{DynamicResource ConfigWindow_Title}"
Icon="/ServerManager.Plugin.Discord;component/Art/favicon.ico"
Width="640" Height="480" MinWidth="640" MinHeight="480" ResizeMode="CanResizeWithGrip" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" Closing="ConfigWindow_Closing" Loaded="ConfigWindow_Loaded">
<Window.Resources>
@ -24,8 +24,8 @@
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid Background="{StaticResource BeigeGradient}">
<Grid Background="{StaticResource BeigeGradient}" MouseLeftButtonUp="OnMouseLeftButtonUp" MouseMove="OnMouseMove">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
@ -64,7 +64,7 @@
</StackPanel>
</GroupBox.Header>
<DataGrid ItemsSource="{Binding PluginConfig.ConfigProfiles}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="true" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
<DataGrid Name="ConfigsGrid" ItemsSource="{Binding PluginConfig.ConfigProfiles}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Resources>
@ -93,7 +93,7 @@
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding Name}" IsReadOnly="True">
<DataGridTextColumn Width="*" IsReadOnly="True" Binding="{Binding Name}">
<DataGridTextColumn.Header>
<TextBlock Text="{DynamicResource ConfigWindow_NameColumnLabel}"/>
</DataGridTextColumn.Header>
@ -107,7 +107,7 @@
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
<DataGridTemplateColumn Width="30" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="EditConfigProfile_Click" ToolTip="{DynamicResource ConfigWindow_EditConfigProfileTooltip}">
@ -116,7 +116,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
<DataGridTemplateColumn Width="30" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="DeleteConfigProfile_Click" ToolTip="{DynamicResource ConfigWindow_DeleteConfigProfileTooltip}">
@ -133,5 +133,15 @@
<Button Content="{DynamicResource Global_SaveButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Right" Click="Save_Click"/>
<Button Content="{DynamicResource Global_CloseButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Left" IsCancel="True"/>
</StackPanel>
<!-- Drag and Drop Popup -->
<Popup x:Name="popup" IsHitTestVisible="False" Placement="RelativePoint" PlacementTarget="{Binding ElementName=ConfigUI}" AllowsTransparency="True">
<Border BorderBrush="LightSteelBlue" BorderThickness="2" Background="White" Opacity="0.75">
<StackPanel Orientation="Horizontal" Margin="4,3,8,3">
<Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Drag.ico,Size=32}" Width="16" Height="16"/>
<TextBlock FontSize="14" VerticalAlignment="Center" Text="{Binding DraggedItem.Name, ElementName=ConfigUI}" Margin="8,0,0,0" />
</StackPanel>
</Border>
</Popup>
</Grid>
</Window>

View file

@ -267,5 +267,111 @@ namespace ServerManagerTool.Plugin.Discord.Windows
JsonUtils.SerializeToFile(PluginConfig, configFile);
PluginConfig?.CommitChanges();
}
#region Drag and Drop
private static readonly DependencyProperty DraggedItemProperty = DependencyProperty.Register(nameof(DraggedItem), typeof(ConfigProfile), typeof(ConfigWindow), new PropertyMetadata(null));
private ConfigProfile DraggedItem
{
get { return GetValue(DraggedItemProperty) as ConfigProfile; }
set { SetValue(DraggedItemProperty, value); }
}
private bool IsDragging { get; set; }
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ResetDragDrop();
// check fi the column is a template column (no drag-n-drop for those column types)
var cell = WindowUtils.TryFindFromPoint<DataGridCell>((UIElement)sender, e.GetPosition(ConfigsGrid));
if (cell != null) return;
// check if we have a valid row
var row = WindowUtils.TryFindFromPoint<DataGridRow>((UIElement)sender, e.GetPosition(ConfigsGrid));
if (row == null) return;
// set flag that indicates we're capturing mouse movements
IsDragging = true;
DraggedItem = (ConfigProfile)row.Item;
}
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (!IsDragging)
{
if (popup.IsOpen)
popup.IsOpen = false;
return;
}
//get the target item
var targetItem = (ConfigProfile)ConfigsGrid.SelectedItem;
if (targetItem == null || !ReferenceEquals(DraggedItem, targetItem))
{
//get target index
var targetIndex = PluginConfig.ConfigProfiles.IndexOf(targetItem);
//move source at the target's location
Move(DraggedItem, targetIndex);
//select the dropped item
ConfigsGrid.SelectedItem = DraggedItem;
}
//reset
ResetDragDrop();
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (!IsDragging || e.LeftButton != MouseButtonState.Pressed)
{
if (popup.IsOpen)
popup.IsOpen = false;
return;
}
// display the popup if it hasn't been opened yet
if (!popup.IsOpen)
{
// switch to read-only mode
ConfigsGrid.IsReadOnly = true;
// make sure the popup is visible
popup.IsOpen = true;
}
var popupSize = new Size(popup.ActualWidth, popup.ActualHeight);
popup.PlacementRectangle = new Rect(e.GetPosition(this), popupSize);
// make sure the row under the grid is being selected
var position = e.GetPosition(ConfigsGrid);
var row = WindowUtils.TryFindFromPoint<DataGridRow>(ConfigsGrid, position);
if (row != null) ConfigsGrid.SelectedItem = row.Item;
}
private void Move(ConfigProfile draggedItem, int newIndex)
{
if (draggedItem == null)
return;
var index = PluginConfig.ConfigProfiles.IndexOf(draggedItem);
if (index < 0)
return;
PluginConfig.ConfigProfiles.Move(index, newIndex);
}
private void ResetDragDrop()
{
IsDragging = false;
popup.IsOpen = false;
ConfigsGrid.IsReadOnly = false;
}
#endregion
}
}