NewExtensionPage.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 Microsoft.CommandPalette.Extensions;
 6  using Microsoft.CommandPalette.Extensions.Toolkit;
 7  
 8  namespace Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;
 9  
10  public partial class NewExtensionPage : ContentPage
11  {
12      private NewExtensionForm _inputForm = new();
13      private NewExtensionFormBase? _resultForm;
14  
15      public override IContent[] GetContent()
16      {
17          return _resultForm is not null ? [_resultForm] : [_inputForm];
18      }
19  
20      public NewExtensionPage()
21      {
22          Name = Properties.Resources.builtin_create_extension_name;
23          Title = Properties.Resources.builtin_create_extension_title;
24          Icon = IconHelpers.FromRelativePath("Assets\\CreateExtension.svg");
25  
26          _inputForm.FormSubmitted += FormSubmitted;
27      }
28  
29      private void FormSubmitted(NewExtensionFormBase sender, NewExtensionFormBase? args)
30      {
31          if (_resultForm is not null)
32          {
33              _resultForm.FormSubmitted -= FormSubmitted;
34          }
35  
36          _resultForm = args;
37          if (_resultForm is not null)
38          {
39              _resultForm.FormSubmitted += FormSubmitted;
40          }
41          else
42          {
43              _inputForm = new();
44              _inputForm.FormSubmitted += FormSubmitted;
45          }
46  
47          RaiseItemsChanged(1);
48      }
49  }