diff --git a/DomainModel/DomainModel.csproj b/DomainModel/DomainModel.csproj index c03a46f..0fb178f 100644 --- a/DomainModel/DomainModel.csproj +++ b/DomainModel/DomainModel.csproj @@ -11,9 +11,9 @@ https://github.com/hawkeye-stan/msfs-popout-panel-manager MSFSPopoutPanelManager.DomainModel x64 - 4.1.0.2 - 4.1.0.2 - 4.1.0.2 + 4.1.0.3 + 4.1.0.3 + 4.1.0.3 win-x64 Embedded Debug;Release;Local diff --git a/DomainModel/Profile/FloatingPanel.cs b/DomainModel/Profile/FloatingPanel.cs index 13c57b5..80ec241 100644 --- a/DomainModel/Profile/FloatingPanel.cs +++ b/DomainModel/Profile/FloatingPanel.cs @@ -7,7 +7,7 @@ namespace MSFSPopoutPanelManager.DomainModel.Profile { public bool IsEnabled { get; set; } - public string Binding { get; set; } + public string KeyboardBinding { get; set; } [JsonIgnore] public bool IsDetectingKeystroke { get; set; } diff --git a/DomainModel/Profile/PanelConfig.cs b/DomainModel/Profile/PanelConfig.cs index 7a315e6..681a7c3 100644 --- a/DomainModel/Profile/PanelConfig.cs +++ b/DomainModel/Profile/PanelConfig.cs @@ -33,7 +33,7 @@ namespace MSFSPopoutPanelManager.DomainModel.Profile arg.PropertyName == nameof(FloatingPanel.IsEnabled)) { if (!FloatingPanel.IsEnabled) - FloatingPanel.Binding = null; + FloatingPanel.KeyboardBinding = null; } } diff --git a/DomainModel/Setting/KeyboardShortcutSetting.cs b/DomainModel/Setting/KeyboardShortcutSetting.cs index af74335..60e6e14 100644 --- a/DomainModel/Setting/KeyboardShortcutSetting.cs +++ b/DomainModel/Setting/KeyboardShortcutSetting.cs @@ -1,11 +1,37 @@ -using MSFSPopoutPanelManager.Shared; +using System.Collections.Generic; +using System.Linq; +using MSFSPopoutPanelManager.Shared; +using Newtonsoft.Json; namespace MSFSPopoutPanelManager.DomainModel.Setting { public class KeyboardShortcutSetting : ObservableObject { + private string _startPopOutKeyBindingLegacyConversion; + public bool IsEnabled { get; set; } = true; - public string StartPopOutKeyBinding { get; set; } = "O"; + public string StartPopOutKeyBinding + { + get => _startPopOutKeyBindingLegacyConversion; + set + { + // Convert legacy start pop out keyboard binding to new keyboard bindings (v4.0.3 and earlier) + + if (string.IsNullOrEmpty(value)) + return; + + var keys = new List() { "LeftCtrl", "LeftShift", value.ToUpper() }; + keys = keys.OrderBy(x => x).ToList(); + PopOutKeyboardBinding = string.Join("|", keys); + + _startPopOutKeyBindingLegacyConversion = null; + } + } + + public string PopOutKeyboardBinding { get; set; } + + [JsonIgnore] + public bool IsDetectingKeystroke { get; set; } } } diff --git a/MainApp/App.xaml.cs b/MainApp/App.xaml.cs index 576e45b..532f358 100644 --- a/MainApp/App.xaml.cs +++ b/MainApp/App.xaml.cs @@ -54,7 +54,7 @@ namespace MSFSPopoutPanelManager.MainApp services.AddSingleton(s => new AppOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new ProfileOrchestrator(SharedStorage)); services.AddSingleton(s => new PanelSourceOrchestrator(SharedStorage, s.GetRequiredService())); - services.AddSingleton(s => new PanelPopOutOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); + services.AddSingleton(s => new PanelPopOutOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new PanelConfigurationOrchestrator(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new FlightSimOrchestrator(SharedStorage)); services.AddSingleton(s => new KeyboardOrchestrator(SharedStorage)); @@ -66,10 +66,11 @@ namespace MSFSPopoutPanelManager.MainApp services.AddSingleton(s => new ProfileCardListViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new ProfileCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); services.AddSingleton(s => new TrayIconViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); + services.AddSingleton(s => new PreferenceDrawerViewModel(SharedStorage, s.GetRequiredService())); services.AddTransient(s => new AddProfileViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PopOutPanelListViewModel(SharedStorage)); - services.AddTransient(s => new PopOutPanelConfigCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); + services.AddTransient(s => new PopOutPanelConfigCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PopOutPanelSourceCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PopOutPanelSourceLegacyCardViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new PanelConfigFieldViewModel(SharedStorage, s.GetRequiredService())); diff --git a/MainApp/AppUserControl/PopOutPanelConfigCard.xaml b/MainApp/AppUserControl/PopOutPanelConfigCard.xaml index f797150..5992aff 100644 --- a/MainApp/AppUserControl/PopOutPanelConfigCard.xaml +++ b/MainApp/AppUserControl/PopOutPanelConfigCard.xaml @@ -327,7 +327,7 @@ - Floating Window + Floating Panel Toggle - + Text="Keyboard Binding:" /> - diff --git a/MainApp/AppUserControl/PopOutPanelConfigCard.xaml.cs b/MainApp/AppUserControl/PopOutPanelConfigCard.xaml.cs index b7552d1..3e63b01 100644 --- a/MainApp/AppUserControl/PopOutPanelConfigCard.xaml.cs +++ b/MainApp/AppUserControl/PopOutPanelConfigCard.xaml.cs @@ -2,12 +2,8 @@ using MSFSPopoutPanelManager.DomainModel.Profile; using MSFSPopoutPanelManager.MainApp.AppUserControl.PopOutPanelCard; using MSFSPopoutPanelManager.MainApp.ViewModel; -using MSFSPopoutPanelManager.Orchestration; using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; -using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -36,7 +32,6 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl InitializeComponent(); }; } - public PanelConfig DataItem { get => (PanelConfig)GetValue(DataItemProperty2); @@ -70,168 +65,7 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl if (!string.IsNullOrEmpty(param)) _viewModel.PanelAttributeUpdatedCommand.Execute(param); - - //if (sender is ToggleButton { Name: "TglBtnAllowFloatPanel" }) - // ComboBoxFloatPanelKeyBinding.SelectedIndex = 0; } - - //private void ComboBoxFloatPanelKeyBinding_OnSelectionChanged(object sender, SelectionChangedEventArgs e) - //{ - // var comboBox = (ComboBox)sender; - - // if (comboBox.SelectedIndex is 0 or -1) - // { - // _viewModel.DataItem.FloatingPanel.Binding = null; - // return; - // } - - // var selectedValue = comboBox.SelectedValue.ToString(); - - // if (_viewModel.ActiveProfile.PanelConfigs.Any(x => x.FloatingPanel.Binding == selectedValue && x.Id != _viewModel.DataItem.Id)) - // comboBox.SelectedIndex = 0; - - - // _viewModel.DataItem.FloatingPanel.Binding = selectedValue; - //} - - //private readonly List _floatKeyBindings = new() - //{ - // "", - // "Ctrl-1", - // "Ctrl-2", - // "Ctrl-3", - // "Ctrl-4", - // "Ctrl-5", - // "Ctrl-6", - // "Ctrl-7", - // "Ctrl-8", - // "Ctrl-9", - // "Ctrl-0" - //}; - - //private void ComboBoxFloatPanelKeyBinding_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - //{ - // BindFloatPanelKeyBinding(); - //} - - //private void ComboBoxFloatPanelKeyBinding_OnLoaded(object sender, RoutedEventArgs e) - //{ - // BindFloatPanelKeyBinding(); - //} - - //private void BindFloatPanelKeyBinding() - //{ - // var items = new List(); - // items.AddRange(_floatKeyBindings); - - // foreach (var panelConfig in _viewModel.ActiveProfile.PanelConfigs) - // { - // if (panelConfig.FloatingPanel.Binding != null && panelConfig.Id != _viewModel.DataItem.Id) - // items.Remove(panelConfig.FloatingPanel.Binding); - // } - - // ComboBoxFloatPanelKeyBinding.ItemsSource = items; - - // var index = items.ToList().FindIndex(x => string.Equals(x, _viewModel.DataItem.FloatingPanel.Binding, StringComparison.CurrentCultureIgnoreCase)); - - // if (index == -1) - // return; - - // this.ComboBoxFloatPanelKeyBinding.SelectedIndex = index; - //} - - private void BtnDetectFloatPanelKeyBinding_OnClick(object sender, RoutedEventArgs e) - { - this.KeyDown -= OnDetectKeyDown; - this.KeyDown += OnDetectKeyDown; - this.KeyUp -= OnDetectKeyUp; - this.KeyUp += OnDetectKeyUp; - - _viewModel.DataItem.FloatingPanel.IsDetectingKeystroke = true; - } - - private bool _isDetectingKeys; - - private void OnDetectKeyDown(object sender, KeyEventArgs e) - { - //if (!_isDetectingKeys) - //{ - // _isDetectingKeys = true; - // _viewModel.DataItem.FloatingPanel.Binding.Clear(); - //} - - //_viewModel.DataItem.FloatingPanel.Binding.Add(e.Key == Key.System ? e.SystemKey.ToString() : e.Key.ToString()); - } - - private void OnDetectKeyUp(object sender, KeyEventArgs e) - { - //_isDetectingKeys = false; - //Debug.WriteLine(string.Join(" + ", _viewModel.DataItem.FloatingPanel.Binding.ToArray())); - - //this.KeyDown -= OnDetectKeyDown; - //this.KeyUp -= OnDetectKeyUp; - - //_viewModel.DataItem.FloatingPanel.IsDetectingKeystroke = false; - } - - - //private List _capturesList = new(); - //private bool _isCapturing; - - //private GlobalKeyboardHook _globalKeyboardHook; - - //private void BtnTest_OnClick(object sender, RoutedEventArgs e) - //{ - // if (_globalKeyboardHook != null) - // { - // _globalKeyboardHook.KeyboardPressed -= GlobalKeyboardHookOnKeyboardPressed; - // _globalKeyboardHook?.Dispose(); - // _globalKeyboardHook = null; - // } - // else - // { - // _globalKeyboardHook = new GlobalKeyboardHook(); - // _globalKeyboardHook.KeyboardPressed += GlobalKeyboardHookOnKeyboardPressed; - // } - //} - - //private void GlobalKeyboardHookOnKeyboardPressed(object sender, GlobalKeyboardHookEventArgs e) - //{ - // if (e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp) - // { - // _isCapturing = false; - // } - - // if (e.KeyboardState is GlobalKeyboardHook.KeyboardState.KeyDown or GlobalKeyboardHook.KeyboardState.SysKeyDown && !_isCapturing) - // { - // _capturesList.Add(new KeyPressState { Key = e.KeyboardData.Key.ToString()}); - // return; - // } - - // if (e.KeyboardState is GlobalKeyboardHook.KeyboardState.KeyUp or GlobalKeyboardHook.KeyboardState.SysKeyUp && !_isCapturing) - // { - // var matched = _capturesList.FirstOrDefault(x => x.Key == e.KeyboardData.Key.ToString()); - - // if (matched == null) - // { - // // Error since there is keydown but no keyup - // _isCapturing = true; - // _capturesList.Clear(); - // } - // else - // { - // matched.IsPressed = true; - - // // Check if all keydown matches keyup - // if (_capturesList.All(x => x.IsPressed)) - // { - // Debug.WriteLine(string.Join(" + ", _capturesList.ToArray().Select(x => x.Key))); - // _capturesList.Clear(); - // } - // } - // } - //} } - } diff --git a/MainApp/AppUserControl/PreferenceDrawer.xaml b/MainApp/AppUserControl/PreferenceDrawer.xaml index dfe6883..b9dd135 100644 --- a/MainApp/AppUserControl/PreferenceDrawer.xaml +++ b/MainApp/AppUserControl/PreferenceDrawer.xaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:appUserControl="clr-namespace:MSFSPopoutPanelManager.MainApp.AppUserControl" xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding" + xmlns:converter="clr-namespace:MSFSPopoutPanelManager.MainApp.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:localcontrol="clr-namespace:MSFSPopoutPanelManager.MainApp.CustomControl" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" @@ -12,6 +13,7 @@ Width="1024" mc:Ignorable="d"> +