/ src / modules / cmdpal / ext / SamplePagesExtension / OnLoadPage.cs
OnLoadPage.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 System;
 6  using System.Collections.Generic;
 7  using System.Globalization;
 8  using Microsoft.CommandPalette.Extensions;
 9  using Microsoft.CommandPalette.Extensions.Toolkit;
10  using Windows.Foundation;
11  
12  namespace SamplePagesExtension;
13  
14  internal sealed partial class OnLoadPage : IListPage
15  {
16      private readonly List<ListItem> _items = new();
17  
18      public IIconInfo Icon => new IconInfo("\uE8AB"); // switch
19  
20      public string Title => "Load/Unload sample";
21  
22      public string PlaceholderText => "This page changes each time you load it";
23  
24      public ICommandItem EmptyContent => new CommandItem() { Icon = new IconInfo("\uE8AB"), Title = "This page starts empty", Subtitle = "but go back and open it again" };
25  
26      public IFilters Filters => null;
27  
28      public IGridProperties GridProperties => null;
29  
30      public bool HasMoreItems => false;
31  
32      public string SearchText => string.Empty;
33  
34      public bool ShowDetails => false;
35  
36      public OptionalColor AccentColor => default;
37  
38      public bool IsLoading => false;
39  
40      public string Id => string.Empty;
41  
42      public string Name => "Open";
43  
44  #pragma warning disable CS0067 // The event is never used
45      public event TypedEventHandler<object, IPropChangedEventArgs> PropChanged;
46  
47      private event TypedEventHandler<object, IItemsChangedEventArgs> InternalItemsChanged;
48  #pragma warning restore CS0067 // The event is never used
49  
50      public event TypedEventHandler<object, IItemsChangedEventArgs> ItemsChanged
51      {
52          add
53          {
54              InternalItemsChanged += value;
55              var nowString = DateTime.Now.ToString("T", CultureInfo.CurrentCulture);
56              var item = new ListItem(new NoOpCommand())
57              {
58                  Title = $"Loaded {nowString}",
59                  Icon = new IconInfo("\uECCB"), // Radio button on
60              };
61              _items.Add(item);
62          }
63  
64          remove
65          {
66              InternalItemsChanged -= value;
67              var nowString = DateTime.Now.ToString("T", CultureInfo.CurrentCulture);
68              var item = new ListItem(new NoOpCommand())
69              {
70                  Title = $"Unloaded {nowString}",
71                  Icon = new IconInfo("\uECCA"), // Radio button off
72              };
73              _items.Add(item);
74          }
75      }
76  
77      public IListItem[] GetItems() => _items.ToArray();
78  
79      public void LoadMore()
80      {
81      }
82  }