1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 05:40:11 +00:00
msfs-popout-panel-manager/WpfApp/UserControlPanelConfiguration.xaml.cs

193 lines
8.3 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.UserDataAgent;
2022-01-27 13:40:04 +00:00
using MSFSPopoutPanelManager.WpfApp.ViewModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
namespace MSFSPopoutPanelManager.WpfApp
{
public partial class UserControlPanelConfiguration : UserControl
{
private PanelConfigurationViewModel _panelConfigurationViewModel;
public UserControlPanelConfiguration(PanelConfigurationViewModel panelConfigurationViewModel)
{
InitializeComponent();
_panelConfigurationViewModel = panelConfigurationViewModel;
this.DataContext = _panelConfigurationViewModel;
2022-07-23 19:23:32 +00:00
FocusManager.SetIsFocusScope(this, true);
2022-08-02 20:55:20 +00:00
PanelConfigGrid.PreviewKeyDown += PanelConfigGrid_KeyDown;
2022-01-27 13:40:04 +00:00
}
private void GridData_SourceUpdated(object sender, DataTransferEventArgs e)
{
2022-06-30 23:53:08 +00:00
var container = VisualTreeHelper.GetParent((Control)sender) as ContentPresenter;
2022-01-27 13:40:04 +00:00
var panelConfig = container.Content as PanelConfig;
2022-06-30 23:53:08 +00:00
var propertyName = (PanelConfigPropertyName)Enum.Parse(typeof(PanelConfigPropertyName), ((Control)sender).Name);
2022-01-27 13:40:04 +00:00
2022-09-11 13:50:04 +00:00
var panelConfigItem = new PanelConfigItem() { PanelHandle = panelConfig.PanelHandle, PanelConfigProperty = propertyName };
2022-01-27 13:40:04 +00:00
_panelConfigurationViewModel.PanelConfigUpdatedCommand.Execute(panelConfigItem);
}
private void DataGridCell_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender.GetType() == typeof(DataGridCell))
{
var cell = sender as DataGridCell;
var panelConfig = cell.DataContext as PanelConfig;
PanelConfigPropertyName selectedProperty = PanelConfigPropertyName.Invalid;
2022-06-30 23:53:08 +00:00
switch (cell.Column.Header)
2022-01-27 13:40:04 +00:00
{
case "Panel Name":
selectedProperty = PanelConfigPropertyName.PanelName;
break;
case "X-Pos":
selectedProperty = PanelConfigPropertyName.Left;
break;
case "Y-Pos":
selectedProperty = PanelConfigPropertyName.Top;
break;
case "Width":
selectedProperty = PanelConfigPropertyName.Width;
break;
case "Height":
selectedProperty = PanelConfigPropertyName.Height;
break;
case "Always on Top":
selectedProperty = PanelConfigPropertyName.AlwaysOnTop;
break;
case "Hide Titlebar":
selectedProperty = PanelConfigPropertyName.HideTitlebar;
break;
2022-04-18 19:52:39 +00:00
case "Full Screen Mode":
selectedProperty = PanelConfigPropertyName.FullScreen;
break;
2022-06-13 03:49:56 +00:00
case "Touch Enabled":
selectedProperty = PanelConfigPropertyName.TouchEnabled;
break;
2022-07-30 02:29:20 +00:00
case "Disable Game Refocus":
selectedProperty = PanelConfigPropertyName.DisableGameRefocus;
break;
2022-08-02 20:55:20 +00:00
case "":
selectedProperty = PanelConfigPropertyName.RowHeader;
break;
2022-01-27 13:40:04 +00:00
}
2022-09-11 13:50:04 +00:00
_panelConfigurationViewModel.SelectedPanelConfigItem = new PanelConfigItem() { PanelHandle = panelConfig.PanelHandle, PanelConfigProperty = selectedProperty };
2022-01-27 13:40:04 +00:00
}
}
2022-07-23 19:23:32 +00:00
private void NumericDataPoint_GotFocus(object sender, RoutedEventArgs e)
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
var textBox = e.Source as TextBox;
switch (textBox.Name)
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
case "Top":
case "Left":
case "Width":
case "Height":
_panelConfigurationViewModel.NumericDataPointTextBox = textBox;
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
var panelConfig = textBox.DataContext as PanelConfig;
2022-09-11 13:50:04 +00:00
_panelConfigurationViewModel.SelectedPanelConfigItem = new PanelConfigItem() { PanelHandle = panelConfig.PanelHandle, PanelConfigProperty = (PanelConfigPropertyName)Enum.Parse(typeof(PanelConfigPropertyName), textBox.Name) };
2022-07-23 19:23:32 +00:00
return;
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
_panelConfigurationViewModel.NumericDataPointTextBox = null;
}
private void NumericDataPoint_LostFocus(object sender, RoutedEventArgs e)
{
IInputElement focusedControl = FocusManager.GetFocusedElement(this);
if (focusedControl is Button)
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
var button = focusedControl as Button;
switch (button.Name)
{
case "MinusTenButton":
case "MinusOneButton":
case "PlusOneButton":
case "PlusTenButton":
var textBox = e.OriginalSource as TextBox;
_panelConfigurationViewModel.NumericDataPointTextBox = textBox;
return;
}
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
_panelConfigurationViewModel.NumericDataPointTextBox = null;
2022-01-27 13:40:04 +00:00
}
2022-08-02 20:55:20 +00:00
private void PanelConfigGrid_KeyDown(object sender, KeyEventArgs e)
{
2022-08-13 06:14:49 +00:00
if (_panelConfigurationViewModel.SelectedPanelConfigItem == null)
return;
2022-08-02 20:55:20 +00:00
var isControlKeyHeld = (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control;
var isShiftKeyHeld = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
switch (_panelConfigurationViewModel.SelectedPanelConfigItem.PanelConfigProperty)
{
case PanelConfigPropertyName.RowHeader:
var multiplier = isShiftKeyHeld ? 1 : 10;
switch (e.Key)
{
case Key.Left:
_panelConfigurationViewModel.ConfigurePanelCommand.Execute(new KeyAction(isControlKeyHeld ? "Control-Left" : "Left", multiplier));
break;
case Key.Right:
_panelConfigurationViewModel.ConfigurePanelCommand.Execute(new KeyAction(isControlKeyHeld ? "Control-Right" : "Right", multiplier));
break;
case Key.Up:
_panelConfigurationViewModel.ConfigurePanelCommand.Execute(new KeyAction(isControlKeyHeld ? "Control-Up" : "Up", multiplier));
break;
case Key.Down:
_panelConfigurationViewModel.ConfigurePanelCommand.Execute(new KeyAction(isControlKeyHeld ? "Control-Down" : "Down", multiplier));
break;
}
break;
case PanelConfigPropertyName.Top:
case PanelConfigPropertyName.Left:
case PanelConfigPropertyName.Height:
case PanelConfigPropertyName.Width:
switch (e.Key)
{
case Key.Up:
if (isShiftKeyHeld)
_panelConfigurationViewModel.ConfigurePanelPixelCommand.Execute(1);
else
_panelConfigurationViewModel.ConfigurePanelPixelCommand.Execute(10);
break;
case Key.Down:
if (isShiftKeyHeld)
_panelConfigurationViewModel.ConfigurePanelPixelCommand.Execute(-1);
else
_panelConfigurationViewModel.ConfigurePanelPixelCommand.Execute(-10);
break;
}
break;
}
2022-08-08 06:07:24 +00:00
}
2022-08-02 20:55:20 +00:00
2022-08-08 06:07:24 +00:00
private void Instruction_Click(object sender, RoutedEventArgs e)
{
DialogHelper.PanelConfigurationInstructionDialog();
}
private void PanelConfigGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
_panelConfigurationViewModel.SelectedPanelConfigItem = null;
this.PanelConfigGrid.Focus();
2022-08-02 20:55:20 +00:00
}
2022-01-27 13:40:04 +00:00
}
}