FallbackLogItem.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 ManagedCommon;
 6  using Microsoft.CmdPal.UI.ViewModels.Commands;
 7  using Microsoft.CmdPal.UI.ViewModels.Properties;
 8  using Microsoft.CommandPalette.Extensions.Toolkit;
 9  
10  namespace Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;
11  
12  internal sealed partial class FallbackLogItem : FallbackCommandItem
13  {
14      private readonly LogMessagesPage _logMessagesPage;
15  
16      private const string _id = "com.microsoft.cmdpal.log";
17  
18      public FallbackLogItem()
19          : base(new LogMessagesPage() { Id = _id }, Resources.builtin_log_subtitle, _id)
20      {
21          _logMessagesPage = (LogMessagesPage)Command!;
22          Title = string.Empty;
23          _logMessagesPage.Name = string.Empty;
24          Subtitle = Properties.Resources.builtin_log_subtitle;
25  
26          var logPath = Logger.LogDirectoryPath("\\CmdPal\\Logs\\");
27          var openLogCommand = new OpenFileCommand(logPath) { Name = Resources.builtin_log_folder_command_name };
28          MoreCommands = [new CommandContextItem(openLogCommand)];
29      }
30  
31      public override void UpdateQuery(string query)
32      {
33          _logMessagesPage.Name = query.StartsWith('l') ? Properties.Resources.builtin_log_title : string.Empty;
34          Title = _logMessagesPage.Name;
35      }
36  }