using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Threading; using ActiproSoftware.Windows.Controls.Editors; using JD.Guinness.WPF.Module.Configuration; using JD.Guinness.WPF.Module.Model.Ps4; using JD.Guinness.WPF.Module.ViewModel; using JD.Oasis.Service.API; namespace JD.Guinness.WPF.Module.View { public partial class Ps4View { public Ps4View(Ps4ViewModel viewModel) { DataContext = viewModel; InitializeComponent(); viewModel.Game.SaveAsked += OnSave; viewModel.Game.ItemFocuser.SubscribeWindow(this); viewModel.Game.ItemFocuser.Subscribe(DataGrid); viewModel.Game.ItemFocuser.Subscribe(Zones); viewModel.Game.Settings.Ps4DataGridSettings?.Apply(DataGrid); } private void OnSave(GuinnessSettings settings) => settings.Ps4DataGridSettings = new DataGridSettings(DataGrid); private void OnEditableLostFocus(object sender, RoutedEventArgs e) { if (sender is FrameworkElement element && element.Tag is FrameworkElement displayElement && element.Parent is ContentControl parent) { element.LostFocus -= OnEditableLostFocus; parent.Content = displayElement; } } private void OnAutoCompleteBoxSubmitted(object sender, AutoCompleteBoxEventArgs e) => OnEditableLostFocus(sender, e); private void OnEditablePreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (sender is ContentControl contentControl && contentControl.Content is FrameworkElement element && element.Tag is AutoCompleteBox editElement && element.Parent is ContentControl parent) { editElement.Tag = element; parent.Content = editElement; // wait for ui display so we can focus the edit element Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null); editElement.Text = (editElement.SelectedItem as LocalizedLine)?.Id.ToString() ?? string.Empty; editElement.Focus(); editElement.LostFocus += OnEditableLostFocus; } } } }