Setting Find Changes

- added a find window to find setting in the settings control.
This commit is contained in:
Brett Hewitson 2022-06-18 15:29:22 +10:00
parent 174b5f14c9
commit 46997c6e71
18 changed files with 774 additions and 263 deletions

View file

@ -264,6 +264,9 @@
<Compile Include="Windows\DataDirectoryWindow.xaml.cs">
<DependentUpon>DataDirectoryWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\FindSettingWindow.xaml.cs">
<DependentUpon>FindSettingWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\PlayerListWindow.xaml.cs">
<DependentUpon>PlayerListWindow.xaml</DependentUpon>
</Compile>
@ -458,6 +461,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\FindSettingWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\PlayerListWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View file

@ -993,6 +993,8 @@
<!--#endregion-->
<!--#region Server Settings - General Buttons -->
<sys:String x:Key="ServerSettings_SettingFindButtonLabel">Find</sys:String>
<sys:String x:Key="ServerSettings_SettingFindButtonTooltip">Find Setting</sys:String>
<sys:String x:Key="ServerSettings_SupportZipButtonLabel">Create Support Zip</sys:String>
<sys:String x:Key="ServerSettings_SupportZipButtonTooltip">Create a zip file that contains all the files necessary for use by the server manager support team to diagnose a problem.</sys:String>
<sys:String x:Key="ServerSettings_SyncProfileButtonLabel">Sync</sys:String>
@ -5741,5 +5743,13 @@
<sys:String x:Key="DiscordBot_CountLabel">Count:</sys:String>
<sys:String x:Key="DiscordBot_MapLabel">Map:</sys:String>
<!--#endregion-->
<!--#region Find Setting Window -->
<sys:String x:Key="FindSettingWindow_Title">Find Settings</sys:String>
<sys:String x:Key="FindSettingWindow_NotFoundErrorLabel">The setting was not found: {0}</sys:String>
<sys:String x:Key="FindSettingWindow_FindButtonLabel">Find</sys:String>
<!--#endregion-->
</Globalization:GlobalizationResourceDictionary>

View file

@ -576,6 +576,12 @@
<Label Content="{DynamicResource ServerMonitor_Title}" VerticalAlignment="Center" Padding="0"/>
</StackPanel>
</ContentControl>
<ContentControl x:Key="SettingFindButtonContent">
<StackPanel Orientation="Horizontal" Height="27">
<Image Margin="5,0,5,0" Source="{com:Icon Path=/Ark Server Manager;component/Art/Find.ico,Size=32}" Width="16" VerticalAlignment="Center"/>
<Label Content="{DynamicResource ServerSettings_SettingFindButtonLabel}" VerticalAlignment="Center"/>
</StackPanel>
</ContentControl>
<ContentControl x:Key="SupportZipButtonContent">
<StackPanel Orientation="Horizontal" Height="27">
<Image Margin="5,0,5,0" Source="{com:Icon Path=/Ark Server Manager;component/Art/Zip.ico,Size=32}" Width="16" VerticalAlignment="Center"/>

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,16 @@
using System;
using Microsoft.WindowsAPICodePack.Dialogs;
using ServerManagerTool.Common;
using ServerManagerTool.Common.Controls;
using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Serialization;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using ServerManagerTool.Lib.ViewModel;
using ServerManagerTool.Plugin.Common;
using ServerManagerTool.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@ -13,17 +25,7 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using Microsoft.WindowsAPICodePack.Dialogs;
using ServerManagerTool.Common;
using ServerManagerTool.Common.Lib;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Serialization;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using ServerManagerTool.Lib.ViewModel;
using ServerManagerTool.Plugin.Common;
using ServerManagerTool.Utils;
using System.Windows.Media;
using WPFSharp.Globalizer;
namespace ServerManagerTool
@ -32,6 +34,8 @@ namespace ServerManagerTool
{
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
private CancellationTokenSource _upgradeCancellationSource = null;
private FindSettingWindow _findSettingWindow = null;
private Control _lastFoundControl = null;
// Using a DependencyProperty as the backing store for ServerManager. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BaseDinoModListProperty = DependencyProperty.Register(nameof(BaseDinoModList), typeof(ComboBoxItemList), typeof(ServerSettingsControl), new PropertyMetadata(null));
@ -427,6 +431,12 @@ namespace ServerManagerTool
RefreshBaseGameMapsList();
RefreshBaseTotalConversionsList();
}
if (sender is FindSettingWindow)
{
_findSettingWindow = null;
UnselectControl();
}
}
private void ModDetailsWindow_SavePerformed(object sender, ProfileEventArgs e)
@ -1149,6 +1159,18 @@ namespace ServerManagerTool
window.ShowDialog();
}
private void SettingFind_Click(object sender, RoutedEventArgs e)
{
if (_findSettingWindow is null)
{
_findSettingWindow = new FindSettingWindow(this);
_findSettingWindow.Owner = Window.GetWindow(this);
_findSettingWindow.Closed += Window_Closed;
}
_findSettingWindow.Show();
_findSettingWindow.Focus();
}
private void HiddenField_GotFocus(object sender, RoutedEventArgs e)
{
var hideTextBox = sender as TextBox;
@ -1282,7 +1304,7 @@ namespace ServerManagerTool
private void EnableSOTFCheckbox_SourceUpdated(object sender, DataTransferEventArgs e)
{
var checkBox = sender as CheckBox;
var checkBox = sender as CheckBoxAndTextBlock;
if (checkBox == null || checkBox != EnableSOTFCheckbox)
return;
@ -4333,6 +4355,65 @@ namespace ServerManagerTool
}
}
public void SelectControl(Control control)
{
if (control is null)
return;
bool focused = false;
Application.Current.Dispatcher.Invoke(() =>
{
Window.GetWindow(this)?.Activate();
UnselectControl();
var parent = WindowUtils.TryFindParent<Expander>(control);
if (parent != null)
{
parent.IsExpanded = true;
}
control.Background = Brushes.AliceBlue;
control.BringIntoView();
if (control is AnnotatedSlider)
{
focused = ((AnnotatedSlider)control).Focus();
}
else if (control is AnnotatedCheckBoxAndFloatSlider)
{
focused = ((AnnotatedCheckBoxAndFloatSlider)control).Focus();
}
else if (control is AnnotatedCheckBoxAndIntegerSlider)
{
focused = ((AnnotatedCheckBoxAndIntegerSlider)control).Focus();
}
else if (control is AnnotatedCheckBoxAndLongSlider)
{
focused = ((AnnotatedCheckBoxAndLongSlider)control).Focus();
}
else if (control is CheckBoxAndTextBlock)
{
focused = ((CheckBoxAndTextBlock)control).Focus();
}
else
{
focused = control.Focus();
}
_lastFoundControl = control;
});
}
public void UnselectControl()
{
if (_lastFoundControl is null)
return;
_lastFoundControl.Background = null;
_lastFoundControl = null;
}
private async Task<bool> UpdateServer(bool establishLock, bool updateServer, bool updateMods, bool closeProgressWindow)
{
if (_upgradeCancellationSource != null)

View file

@ -5,17 +5,22 @@
<title>Ark Server Manager Version Feed</title>
<subtitle>This is the Ark Server Manager release version feed.</subtitle>
<link href="http://arkservermanager.freeforums.net/" />
<updated>2022-06-17T00:00:00Z</updated>
<updated>2022-06-18T00:00:00Z</updated>
<entry>
<id>urn:uuid:1AE0925B-64EB-4177-B834-7A75FA46E807</id>
<title>1.1.433 (1.1.433.2)</title>
<summary>1.1.433.2</summary>
<title>1.1.433 (1.1.433.3)</title>
<summary>1.1.433.3</summary>
<link href="" />
<updated>2022-06-17T00:00:00Z</updated>
<updated>2022-06-18T00: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;">NEW</u>
<br/>
<ul>
<li>Server Settings - added new find button to find settings by name.</li>
</ul>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>

View file

@ -5,7 +5,30 @@
<title>Ark Server Manager Version Feed</title>
<subtitle>This is the Ark Server Manager beta version feed.</subtitle>
<link href="http://arkservermanager.freeforums.net/" />
<updated>2022-06-17T00:00:00Z</updated>
<updated>2022-06-18T00:00:00Z</updated>
<entry>
<id>urn:uuid:1AE0925B-64EB-4177-B834-7A75FA46E807</id>
<title>1.1.433 (1.1.433.3)</title>
<summary>1.1.433.3</summary>
<link href="" />
<updated>2022-06-18T00: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;">NEW</u>
<br/>
<ul>
<li>Server Settings - added new find button to find settings by name.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:1AE0925B-64EB-4177-B834-7A75FA46E807</id>

View file

@ -0,0 +1,36 @@
<Window x:Class="ServerManagerTool.FindSettingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="300" Height="80" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" ResizeMode="NoResize" SizeToContent="Height"
Icon="../Art/favicon.ico" Title="{DynamicResource FindSettingWindow_Title}"
x:Name="FindSetting">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Globalization\en-US\en-US.xaml"/>
<ResourceDictionary Source="..\Styles\Default.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid Background="{StaticResource GradientBackground}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="5,3,5,3" Text="{Binding FindSettingString, ElementName=FindSetting, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" SourceUpdated="FindSettingString_SourceUpdated" VerticalContentAlignment="Center" MaxLength="50" />
<Button Grid.Row="3" Grid.Column="2" Content="{DynamicResource FindSettingWindow_FindButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Right" Click="Find_Click"/>
</Grid>
</Window>

View file

@ -0,0 +1,164 @@
using ServerManagerTool.Common.Attibutes;
using ServerManagerTool.Common.Extensions;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Lib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFSharp.Globalizer;
namespace ServerManagerTool
{
/// <summary>
/// Interaction logic for FindSettingWindow.xaml
/// </summary>
public partial class FindSettingWindow : Window
{
private static List<(string setting, string profileProperty)> _profileSettings = null;
private static List<(string setting, Control control)> _settingControls = null;
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
private int _controlIndex = -1;
private ServerSettingsControl _serverSettingsControl;
public static readonly DependencyProperty FindSettingStringProperty = DependencyProperty.Register(nameof(FindSettingString), typeof(string), typeof(FindSettingWindow), new PropertyMetadata(""));
public FindSettingWindow(ServerSettingsControl control)
{
InitializeComponent();
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
_serverSettingsControl = control;
LoadSettings(control.Settings);
LoadControls(control);
this.DataContext = this;
}
public string FindSettingString
{
get { return (string)GetValue(FindSettingStringProperty); }
set { SetValue(FindSettingStringProperty, value); }
}
private async void Find_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(FindSettingString))
return;
var cursor = this.Cursor;
try
{
Application.Current.Dispatcher.Invoke(() => this.Cursor = Cursors.Wait);
await Task.Delay(100);
_serverSettingsControl.UnselectControl();
var foundControls = _settingControls
.Where(s => s.setting.Contains(FindSettingString, StringComparison.OrdinalIgnoreCase))
.Select(s => s.control)
.ToArray();
if (foundControls.Length == 0)
{
MessageBox.Show(string.Format(_globalizer.GetResourceString("FindSettingWindow_NotFoundErrorLabel"), FindSettingString), _globalizer.GetResourceString("FindSettingWindow_Title"), MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
var oldIndex = _controlIndex;
var newIndex = oldIndex + 1;
if (newIndex >= foundControls.Length)
{
_controlIndex = -1;
MessageBox.Show(string.Format(_globalizer.GetResourceString("FindSettingWindow_NotFoundErrorLabel"), FindSettingString), _globalizer.GetResourceString("FindSettingWindow_Title"), MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
_serverSettingsControl.SelectControl(foundControls[newIndex]);
_controlIndex = newIndex;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, _globalizer.GetResourceString("FindSettingWindow_Title"), MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor);
}
}
private void LoadControls(DependencyObject parent)
{
if (_settingControls != null)
return;
try
{
_settingControls = WindowUtils.GetLogicalTreeControls(parent);
for (int i = 0; i < _settingControls.Count; i++)
{
var item = _settingControls[i];
var setting = _profileSettings
.FirstOrDefault(x => x.profileProperty.Equals(item.setting, StringComparison.OrdinalIgnoreCase))
.setting;
if (setting != null && !setting.Equals(item.setting, StringComparison.OrdinalIgnoreCase))
{
_settingControls[i] = (setting, item.control);
}
#if DEBUG
Debug.WriteLine($"{_settingControls[i].setting}; {_settingControls[i].control.GetType().FullName}");
#endif
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, _globalizer.GetResourceString("FindSettingWindow_Title"), MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void LoadSettings(ServerProfile profile)
{
if (_profileSettings != null)
return;
try
{
_profileSettings = new List<(string setting, string profileProperty)>();
var fields = profile?.GetType()
.GetProperties()
.Where(f => f.IsDefined(typeof(BaseIniFileEntryAttribute), false));
foreach (var field in fields)
{
var attributes = field
.GetCustomAttributes(typeof(BaseIniFileEntryAttribute), false)
.OfType<BaseIniFileEntryAttribute>();
foreach (var attr in attributes)
{
_profileSettings.Add((string.IsNullOrWhiteSpace(attr.Key) ? field.Name : attr.Key, field.Name));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, _globalizer.GetResourceString("FindSettingWindow_Title"), MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void FindSettingString_SourceUpdated(object sender, System.Windows.Data.DataTransferEventArgs e)
{
_serverSettingsControl.UnselectControl();
_controlIndex = -1;
}
}
}