/ src / modules / cmdpal / Microsoft.CmdPal.UI / Settings / ExtensionsPage.xaml.cs
ExtensionsPage.xaml.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using CommunityToolkit.Mvvm.Messaging;
 6  using CommunityToolkit.WinUI.Controls;
 7  using ManagedCommon;
 8  using Microsoft.CmdPal.UI.ViewModels;
 9  using Microsoft.CmdPal.UI.ViewModels.Services;
10  using Microsoft.Extensions.DependencyInjection;
11  using Microsoft.UI.Xaml;
12  using Microsoft.UI.Xaml.Controls;
13  using Microsoft.UI.Xaml.Input;
14  
15  namespace Microsoft.CmdPal.UI.Settings;
16  
17  public sealed partial class ExtensionsPage : Page
18  {
19      private readonly TaskScheduler _mainTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
20  
21      private readonly SettingsViewModel? viewModel;
22  
23      public ExtensionsPage()
24      {
25          this.InitializeComponent();
26  
27          var settings = App.Current.Services.GetService<SettingsModel>()!;
28          var topLevelCommandManager = App.Current.Services.GetService<TopLevelCommandManager>()!;
29          var themeService = App.Current.Services.GetService<IThemeService>()!;
30          viewModel = new SettingsViewModel(settings, topLevelCommandManager, _mainTaskScheduler, themeService);
31      }
32  
33      private void SettingsCard_Click(object sender, RoutedEventArgs e)
34      {
35          if (sender is SettingsCard card)
36          {
37              if (card.DataContext is ProviderSettingsViewModel vm)
38              {
39                  WeakReferenceMessenger.Default.Send<NavigateToExtensionSettingsMessage>(new(vm));
40              }
41          }
42      }
43  
44      private void OnFindInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
45      {
46          SearchBox?.Focus(FocusState.Keyboard);
47          args.Handled = true;
48      }
49  
50      private async void MenuFlyoutItem_OnClick(object sender, RoutedEventArgs e)
51      {
52          try
53          {
54              await FallbackRankerDialog!.ShowAsync();
55          }
56          catch (Exception ex)
57          {
58              Logger.LogError("Error when showing FallbackRankerDialog", ex);
59          }
60      }
61  }