Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command for quickly creating a new extension #423

Merged
merged 38 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d3ac3e3
Start pulling out a template sln
zadjii-msft Jan 30, 2025
154d7db
Bunch of renames
zadjii-msft Feb 5, 2025
7e6190c
Merge remote-tracking branch 'origin/main' into dev/migrie/f/template…
zadjii-msft Feb 5, 2025
928f4c8
Yes this works. Now let's do some crazy stuff
zadjii-msft Feb 5, 2025
b4097b9
add the nuget, for `git archive`
zadjii-msft Feb 5, 2025
6e37989
some renames and missing files
zadjii-msft Feb 5, 2025
4683179
important props
zadjii-msft Feb 5, 2025
c59a508
closer
zadjii-msft Feb 5, 2025
db71a73
what about without aot
zadjii-msft Feb 5, 2025
c8c01fb
revert this
zadjii-msft Feb 5, 2025
27c28be
Revert "revert this"
zadjii-msft Feb 5, 2025
5a487d5
trimming considered harmful?
zadjii-msft Feb 5, 2025
5b4aa49
names are hard
zadjii-msft Feb 5, 2025
e582b26
This version of CsWinRT was lOaD bEaRiNg
zadjii-msft Feb 6, 2025
f10076c
Okay Trimmed works, with CsWinRT 2.2.0
zadjii-msft Feb 6, 2025
42c6376
Aot and trimming doesn't seemingly work in the PT sln
zadjii-msft Feb 6, 2025
242b35c
Don't need this project anymore
zadjii-msft Feb 6, 2025
aff9e4f
won't build without this
zadjii-msft Feb 6, 2025
c8d4300
Add a command for creating an extension
zadjii-msft Feb 6, 2025
f421405
CsWinRT 2.2.0 considered harmful
zadjii-msft Feb 6, 2025
132545f
Merge branch 'dev/migrie/f/template-project-2' into dev/migrie/f/new-…
zadjii-msft Feb 6, 2025
cdd0596
bump nuget to cswinrt 2.1.5
zadjii-msft Feb 6, 2025
65ae688
Merge remote-tracking branch 'origin/main' into dev/migrie/f/template…
zadjii-msft Feb 6, 2025
5aa0547
Merge remote-tracking branch 'origin/main' into dev/migrie/f/template…
zadjii-msft Feb 7, 2025
3bb2981
Merge branch 'dev/migrie/f/template-project-2' into dev/migrie/f/new-…
zadjii-msft Feb 7, 2025
29c3a87
Add a confirmation page
zadjii-msft Feb 7, 2025
d72f8eb
MAIN: Hey turns out that commented out `dataString` was important!
zadjii-msft Feb 7, 2025
140ede5
hook up all the form buttons
zadjii-msft Feb 7, 2025
17ebea2
Merge branch 'main' into dev/migrie/f/new-extension-command
zadjii-msft Feb 10, 2025
5be5967
the actual 0.0.5 nuget
zadjii-msft Feb 10, 2025
74dcd41
Make text selectable
zadjii-msft Feb 10, 2025
6141820
Merge remote-tracking branch 'origin/main' into dev/migrie/f/new-exte…
zadjii Feb 12, 2025
72c56a9
remove the old nupkg
zadjii Feb 12, 2025
7620bce
New template, move classes to separate files
zadjii Feb 12, 2025
c686486
Merge remote-tracking branch 'origin/main' into dev/migrie/f/new-exte…
zadjii Feb 13, 2025
89fc80b
add a settings button in the botton right
zadjii Feb 13, 2025
4216dbf
gotta do it that way for FastUpToDate
zadjii-msft Feb 13, 2025
1718d83
Actually fix the path
zadjii Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="SDKLocalSource" value=".\deps\Microsoft.CommandPalette.Extensions" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="SDKLocalSource">
<package pattern="Microsoft.CommandPalette.Extensions" />
</packageSource>
</packageSourceMapping>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// 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.

Expand All @@ -7,7 +7,7 @@
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;

namespace Microsoft.CmdPal.Ext.WinGet;
namespace Microsoft.CmdPal.Common;

public partial class ExtensionHostInstance
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CmdPal.UI.ViewModels.Commands;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
Expand All @@ -18,10 +17,12 @@ public partial class BuiltInsCommandProvider : CommandProvider
private readonly QuitCommand quitCommand = new();
private readonly FallbackReloadItem _fallbackReloadItem = new();
private readonly FallbackLogItem _fallbackLogItem = new();
private readonly NewExtensionPage _newExtension = new();

public override ICommandItem[] TopLevelCommands() =>
[
new CommandItem(openSettings) { Subtitle = "Open Command Palette settings" },
new CommandItem(_newExtension) { Title = _newExtension.Title, Subtitle = "Creates a project for a new Command Palette extension" },
];

public override IFallbackCommandItem[] FallbackCommands() =>
Expand All @@ -37,4 +38,6 @@ public BuiltInsCommandProvider()
DisplayName = "Built-in commands";
Icon = IconHelpers.FromRelativePath("Assets\\StoreLogo.scale-200.png");
}

public override void InitializeWithHost(IExtensionHost host) => BuiltinsExtensionHost.Instance.Initialize(host);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.Diagnostics.CodeAnalysis;
using System.IO.Compression;
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.CmdPal.Common;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Windows.Foundation;

namespace Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;

public partial class BuiltinsExtensionHost
{
internal static ExtensionHostInstance Instance { get; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// 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.Diagnostics.CodeAnalysis;
using System.IO.Compression;
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Windows.Foundation;

namespace Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;

internal sealed partial class CreatedExtensionForm : NewExtensionFormBase
{
public CreatedExtensionForm(string name, string displayName, string path)
{
TemplateJson = CardTemplate;
DataJson = $$"""
{
"name": {{JsonSerializer.Serialize(name)}},
"directory": {{JsonSerializer.Serialize(path)}},
"displayName": {{JsonSerializer.Serialize(displayName)}}
}
""";
_name = name;
_displayName = displayName;
_path = path;
}

public override ICommandResult SubmitForm(string inputs, string data)
{
var dataInput = JsonNode.Parse(data)?.AsObject();
if (dataInput == null)
{
return CommandResult.KeepOpen();
}

var verb = dataInput["x"]?.AsValue()?.ToString() ?? string.Empty;
return verb switch
{
"sln" => OpenSolution(),
"dir" => OpenDirectory(),
"new" => CreateNew(),
_ => CommandResult.KeepOpen(),
};
}

private ICommandResult OpenSolution()
{
string[] parts = [_path, _name, $"{_name}.sln"];
var pathToSolution = Path.Combine(parts);
ShellHelpers.OpenInShell(pathToSolution);
return CommandResult.GoHome();
}

private ICommandResult OpenDirectory()
{
string[] parts = [_path, _name];
var pathToDir = Path.Combine(parts);
ShellHelpers.OpenInShell(pathToDir);
return CommandResult.GoHome();
}

private ICommandResult CreateNew()
{
RaiseFormSubmit(null);
return CommandResult.KeepOpen();
}

private static readonly string CardTemplate = """
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.6",
"body": [
{
"type": "TextBlock",
"text": "Successfully created your new extension!",
"size": "large",
"weight": "bolder",
"style": "heading",
"wrap": true
},
{
"type": "TextBlock",
"text": "Your new extension \"${displayName}\" was created in:",
"wrap": true
},
{
"type": "TextBlock",
"text": "${directory}",
"fontType": "monospace"
},
{
"type": "TextBlock",
"text": "Next steps",
"style": "heading",
"wrap": true
},
{
"type": "TextBlock",
"text": "Now that your extension project has been created, open the solution up in Visual Studio to start writing your extension code.",
"wrap": true
},
{
"type": "TextBlock",
"text": "Navigate to `${name}Page.cs` to start adding items to the list, or to `${name}CommandsProvider.cs` to add new commands.",
"wrap": true
},
{
"type": "TextBlock",
"text": "Once you're ready to test deploy the package locally with Visual Studio, then run the \"Reload\" command in the Command Palette to load your new extension.",
"wrap": true
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Open Solution",
"data": {
"x": "sln"
}
},
{
"type": "Action.Submit",
"title": "Open directory",
"data": {
"x": "dir"
}
},
{
"type": "Action.Submit",
"title": "Create another",
"data": {
"x": "new"
}
}
]
}
""";

private readonly string _name;
private readonly string _displayName;
private readonly string _path;
}
Loading
Loading