diff options
Diffstat (limited to 'ModerationClient/Views/MainWindow.axaml.cs')
-rw-r--r-- | ModerationClient/Views/MainWindow.axaml.cs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/ModerationClient/Views/MainWindow.axaml.cs b/ModerationClient/Views/MainWindow.axaml.cs index ccabd71..884e90c 100644 --- a/ModerationClient/Views/MainWindow.axaml.cs +++ b/ModerationClient/Views/MainWindow.axaml.cs @@ -1,10 +1,8 @@ using System; -using System.Threading; using Avalonia; using Avalonia.Controls; using Avalonia.Diagnostics; using Avalonia.Input; -using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using ModerationClient.Services; @@ -13,11 +11,10 @@ using ModerationClient.ViewModels; namespace ModerationClient.Views; public partial class MainWindow : Window { - //viewmodel - private MainWindowViewModel? _viewModel { get; set; } - public MainWindow(CommandLineConfiguration cfg, MainWindowViewModel dataContext, IHostApplicationLifetime appLifetime) { InitializeComponent(); + DataContext = dataContext; + _ = dataContext.AuthService.LoadProfileAsync(); Console.WriteLine("mainwnd"); #if DEBUG this.AttachDevTools(new DevToolsOptions() { @@ -30,19 +27,17 @@ public partial class MainWindow : Window { switch (args.Property.Name) { case nameof(Height): case nameof(Width): { - if (_viewModel is null) { + if (DataContext is not MainWindowViewModel viewModel) { Console.WriteLine("WARN: MainWindowViewModel is null, ignoring height/width change!"); return; } // Console.WriteLine("height/width changed"); - _viewModel.Scale = _viewModel.Scale; + viewModel.Scale = viewModel.Scale; break; } } }; - DataContext = _viewModel = dataContext; - _ = dataContext.AuthService.LoadProfileAsync(); dataContext.AuthService.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(MatrixAuthenticationService.IsLoggedIn)) { if (dataContext.AuthService.IsLoggedIn) { @@ -68,26 +63,32 @@ public partial class MainWindow : Window { protected override void OnKeyDown(KeyEventArgs e) => OnKeyDown(this, e); private void OnKeyDown(object? _, KeyEventArgs e) { - if (_viewModel is null) { - Console.WriteLine("WARN: MainWindowViewModel is null, ignoring key press!"); + if (DataContext is not MainWindowViewModel viewModel) { + Console.WriteLine($"WARN: DataContext is {DataContext?.GetType().Name ?? "null"}, ignoring key press!"); return; } // Console.WriteLine("MainWindow KeyDown: " + e.Key); if (e.Key == Key.Escape) { - _viewModel.Scale = 1.0f; + viewModel.Scale = 1.0f; } else if (e.Key == Key.F1) { - _viewModel.Scale -= 0.1f; - if (_viewModel.Scale < 0.1f) { - _viewModel.Scale = 0.1f; + viewModel.Scale -= 0.1f; + if (viewModel.Scale < 0.1f) { + viewModel.Scale = 0.1f; } } else if (e.Key == Key.F2) { - _viewModel.Scale += 0.1f; - if (_viewModel.Scale > 5.0f) { - _viewModel.Scale = 5.0f; + viewModel.Scale += 0.1f; + if (viewModel.Scale > 5.0f) { + viewModel.Scale = 5.0f; + } + } + else if (e.Key == Key.K && e.KeyModifiers == KeyModifiers.Control) { + if(viewModel.CurrentViewModel is ClientViewModel clientViewModel) { + Console.WriteLine("QuickSwitcher invoked"); } + else Console.WriteLine("WARN: CurrentViewModel is not ClientViewModel, ignoring Quick Switcher"); } } } \ No newline at end of file |