60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
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.Ps5;
|
|
using JD.Guinness.WPF.Module.ViewModel;
|
|
using JD.Oasis.Service.API;
|
|
|
|
namespace JD.Guinness.WPF.Module.View
|
|
{
|
|
public partial class Ps5View
|
|
{
|
|
public Ps5View(Ps5ViewModel viewModel)
|
|
{
|
|
DataContext = viewModel;
|
|
|
|
InitializeComponent();
|
|
|
|
viewModel.Game.SaveAsked += OnSave;
|
|
viewModel.Game.ItemFocuser.SubscribeWindow<Ps5Configuration>(this);
|
|
viewModel.Game.ItemFocuser.Subscribe<Ps5Trophy>(DataGrid);
|
|
viewModel.Game.Settings.Ps5DataGridSettings?.Apply(DataGrid);
|
|
}
|
|
|
|
private void OnSave(GuinnessSettings settings) => settings.Ps5DataGridSettings = 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;
|
|
}
|
|
}
|
|
}
|
|
}
|