sample clean up

This commit is contained in:
joadoumie
2024-09-23 11:54:38 -04:00
parent e5b1594dba
commit 94931494f3
8 changed files with 68 additions and 15 deletions

View File

@@ -3,15 +3,16 @@
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using HackerNewsExtension.Data;
using Microsoft.CmdPal.Extensions.Helpers;
namespace HackerNewsExtension;
namespace HackerNewsExtension.Commands;
internal sealed partial class CommentAction : InvokableCommand
internal sealed partial class CommentCommand : InvokableCommand
{
private readonly NewsPost _post;
internal CommentAction(NewsPost post)
internal CommentCommand(NewsPost post)
{
_post = post;
Name = "Open comments";

View File

@@ -3,19 +3,20 @@
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using HackerNewsExtension.Data;
using Microsoft.CmdPal.Extensions.Helpers;
namespace HackerNewsExtension;
namespace HackerNewsExtension.Commands;
internal sealed partial class LinkAction : InvokableCommand
internal sealed partial class LinkCommand : InvokableCommand
{
private readonly NewsPost _post;
internal LinkAction(NewsPost post)
internal LinkCommand(NewsPost post)
{
this._post = post;
this.Name = "Open link";
this.Icon = new("\uE8A7");
_post = post;
Name = "Open link";
Icon = new("\uE8A7");
}
public override CommandResult Invoke()

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace HackerNewsExtension;
namespace HackerNewsExtension.Data;
public sealed class NewsPost
{

View File

@@ -8,7 +8,7 @@ using Microsoft.CmdPal.Extensions.Helpers;
namespace HackerNewsExtension;
public partial class HackerNewsActionsProvider : ICommandProvider
public partial class HackerNewsCommandsProvider : ICommandProvider
{
public string DisplayName => $"Hacker News Commands";

View File

@@ -8,6 +8,8 @@ using System.Net.Http;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using System.Xml.Linq;
using HackerNewsExtension.Commands;
using HackerNewsExtension.Data;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.Extensions.Helpers;
@@ -57,11 +59,11 @@ internal sealed partial class HackerNewsPage : ListPage
var s = new ListSection()
{
Title = "Posts",
Items = items.Select((post) => new ListItem(new LinkAction(post))
Items = items.Select((post) => new ListItem(new LinkCommand(post))
{
Title = post.Title,
Subtitle = post.Link,
MoreCommands = [new CommandContextItem(new CommentAction(post))],
MoreCommands = [new CommandContextItem(new CommentCommand(post))],
}).ToArray(),
};
return [s];

View File

@@ -26,7 +26,7 @@ public sealed partial class SampleExtension : IExtension
switch (providerType)
{
case ProviderType.Commands:
return new HackerNewsActionsProvider();
return new HackerNewsCommandsProvider();
default:
return null;
}

View File

@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.Extensions.Helpers;
using SSHKeychainExtension.Data;
namespace SSHKeychainExtension.Commands;
internal sealed partial class OpenConfigFileCommand : InvokableCommand
{
private readonly string _configFilePath;
internal OpenConfigFileCommand(string configFilePath)
{
this._configFilePath = configFilePath;
this.Name = "Open Config File";
// TODO: Add Icon for OpenConfigFileCommand
this.Icon = new("\uE8A7");
}
public override CommandResult Invoke()
{
// Just open the config file in the default editor using shell execute
try
{
if (!string.IsNullOrEmpty(_configFilePath))
{
Process.Start(new ProcessStartInfo(_configFilePath) { UseShellExecute = true });
return CommandResult.KeepOpen();
}
}
catch
{
Debug.WriteLine("Failed to open config file");
}
return CommandResult.KeepOpen();
}
}

View File

@@ -28,7 +28,7 @@ internal sealed partial class SSHHostsListPage : ListPage
public SSHHostsListPage()
{
Icon = new(string.Empty);
Icon = new("https://cdn-icons-png.flaticon.com/512/5558/5558264.png");
Name = "SSH Keychain";
}
@@ -76,6 +76,7 @@ internal sealed partial class SSHHostsListPage : ListPage
{
Title = host.HostName,
Subtitle = host.EscapedHost,
MoreCommands = [new CommandContextItem(new OpenConfigFileCommand(_defaultConfigFile))],
}).ToArray(),
};
return [s];