From 5e953dbd94ed680fb06fd4782aa42741c7c7f435 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 26 Feb 2025 05:25:13 -0600 Subject: [PATCH] Officially deprecate FormPage and MarkdownPage (#459) `ContentPage` is the more generic form of this. I'm deprecating this here in 0.0.8, and in 0.0.9 I'm gonna outright remove it. --- .../MastodonExtensionPage.cs | 20 ++--- .../SamplePagesExtension/Forms/SampleForm.cs | 71 ----------------- .../Pages/SampleFormPage.cs | 21 ----- .../Pages/SampleMarkdownPage.cs | 5 +- .../SamplePagesExtension/SamplesListPage.cs | 9 --- .../SpongebotExtension/SpongeSettingsForm.cs | 9 +-- .../Exts/SpongebotExtension/SpongebotPage.cs | 6 +- .../SpongebotSettingsPage.cs | 4 +- .../YouTubeExtension/Pages/YouTubeAPIForm.cs | 13 +-- .../YouTubeExtension/Pages/YouTubeAPIPage.cs | 9 +-- .../Pages/YouTubeChannelInfoMarkdownPage.cs | 7 +- .../Pages/YouTubeVideoInfoMarkdownPage.cs | 6 +- .../doc/initial-sdk-spec/initial-sdk-spec.md | 3 + .../Form.cs | 3 + .../FormPage.cs | 3 + .../MarkdownContent.cs | 9 +++ .../MarkdownPage.cs | 3 + .../Pages/SampleMarkdownDetails.cs | 79 +++++++++++++++++-- .../Pages/SampleMarkdownManyBodies.cs | 17 ++-- 19 files changed, 135 insertions(+), 162 deletions(-) delete mode 100644 src/modules/cmdpal/Exts/SamplePagesExtension/Forms/SampleForm.cs delete mode 100644 src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleFormPage.cs diff --git a/src/modules/cmdpal/Exts/MastodonExtension/MastodonExtensionPage.cs b/src/modules/cmdpal/Exts/MastodonExtension/MastodonExtensionPage.cs index 4e32ef5385..1e32ebbf73 100644 --- a/src/modules/cmdpal/Exts/MastodonExtension/MastodonExtensionPage.cs +++ b/src/modules/cmdpal/Exts/MastodonExtension/MastodonExtensionPage.cs @@ -152,18 +152,15 @@ public partial class MastodonExtensionCommandsProvider : CommandProvider } [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "This is sample code")] -public partial class MastodonPostForm : Form +public partial class MastodonPostForm : FormContent { private readonly MastodonStatus post; public MastodonPostForm(MastodonStatus post) { this.post = post; - } - public override string DataJson() - { - return $$""" + DataJson = $$""" { "author_display_name": {{JsonSerializer.Serialize(post.Account.DisplayName)}}, "author_username": {{JsonSerializer.Serialize(post.Account.Username)}}, @@ -173,12 +170,7 @@ public partial class MastodonPostForm : Form "post_url": "{{post.Url}}" } """; - } - public override ICommandResult SubmitForm(string payload) => CommandResult.Dismiss(); - - public override string TemplateJson() - { var img_block = string.Empty; if (post.MediaAttachments.Count > 0) { @@ -186,7 +178,7 @@ public partial class MastodonPostForm : Form .Select(media => $$""",{"type": "Image","url":"{{media.Url}}","size": "stretch"}""").ToArray()); } - return $$""" + TemplateJson = $$""" { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", @@ -252,10 +244,12 @@ public partial class MastodonPostForm : Form } """; } + + public override ICommandResult SubmitForm(string inputs) => CommandResult.Dismiss(); } [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "This is sample code")] -public partial class MastodonPostPage : FormPage +public partial class MastodonPostPage : ContentPage { private readonly MastodonStatus post; @@ -265,7 +259,7 @@ public partial class MastodonPostPage : FormPage this.post = post; } - public override IForm[] Forms() + public override IContent[] GetContent() { var postsAsync = GetRepliesAsync(); postsAsync.ConfigureAwait(false); diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/Forms/SampleForm.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/Forms/SampleForm.cs deleted file mode 100644 index b528c14bfb..0000000000 --- a/src/modules/cmdpal/Exts/SamplePagesExtension/Forms/SampleForm.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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.Text.Json.Nodes; -using Microsoft.CommandPalette.Extensions.Toolkit; - -namespace SamplePagesExtension; - -internal sealed partial class SampleForm : Form -{ - public SampleForm() - { - } - - public override string TemplateJson() - { - var json = $$""" -{ - "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", - "type": "AdaptiveCard", - "version": "1.5", - "body": [ - { - "type": "TextBlock", - "text": "🚧 This is a sample form 🚧", - "weight": "bolder", - "size": "extraLarge", - "spacing": "none", - "wrap": true, - "style": "heading" - }, - { - "type": "Input.Text", - "style": "text", - "id": "hotkey", - "label": "Input.Text Example", - "value": "example value", - "isRequired": false - } - ], - "actions": [ - { - "type": "Action.Submit", - "title": "Save", - "data": { - "name": "name", - "url": "url" - } - } - ] -} -"""; - return json; - } - - public override string StateJson() => "{}"; - - public override CommandResult SubmitForm(string payload) - { - var formInput = JsonNode.Parse(payload)?.AsObject(); - if (formInput == null) - { - return CommandResult.GoHome(); - } - - // Application.Current.GetService().SaveSettingAsync("GlobalHotkey", formInput["hotkey"]?.ToString() ?? string.Empty); - return CommandResult.GoHome(); - } -} diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleFormPage.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleFormPage.cs deleted file mode 100644 index f11af958c7..0000000000 --- a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleFormPage.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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 Microsoft.CommandPalette.Extensions; -using Microsoft.CommandPalette.Extensions.Toolkit; - -namespace SamplePagesExtension; - -internal sealed partial class SampleFormPage : FormPage -{ - private readonly SampleForm sampleForm = new(); - - public override IForm[] Forms() => [sampleForm]; - - public SampleFormPage() - { - Name = "Sample Form"; - Icon = new IconInfo(string.Empty); - } -} diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleMarkdownPage.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleMarkdownPage.cs index 963d8e42c7..3bfa786fb3 100644 --- a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleMarkdownPage.cs +++ b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleMarkdownPage.cs @@ -2,11 +2,12 @@ // 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.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace SamplePagesExtension; -internal sealed partial class SampleMarkdownPage : MarkdownPage +internal sealed partial class SampleMarkdownPage : ContentPage { public static readonly string SampleMarkdownText = @" # Markdown Guide @@ -167,5 +168,5 @@ Result: Name = "Sample Markdown Page"; } - public override string[] Bodies() => [SampleMarkdownText]; + public override IContent[] GetContent() => [new MarkdownContent(SampleMarkdownText)]; } diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/SamplesListPage.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/SamplesListPage.cs index 4e06ea580a..3eeed6c2c2 100644 --- a/src/modules/cmdpal/Exts/SamplePagesExtension/SamplesListPage.cs +++ b/src/modules/cmdpal/Exts/SamplePagesExtension/SamplesListPage.cs @@ -50,8 +50,6 @@ public partial class SamplesListPage : ListPage Subtitle = "Demo of using nested trees of content to create a comment thread-like experience", Icon = new IconInfo("\uE90A"), // Comment }, - - // DEPRECATED: Markdown pages new ListItem(new SampleMarkdownPage()) { Title = "Markdown Page Sample Command", @@ -68,13 +66,6 @@ public partial class SamplesListPage : ListPage Subtitle = "A page with markdown and details", }, - // DEPRECATED: Form pages - new ListItem(new SampleFormPage()) - { - Title = "Form Page Sample Command", - Subtitle = "Define inputs to retrieve input from the user", - }, - // Settings helpers new ListItem(new SampleSettingsPage()) { diff --git a/src/modules/cmdpal/Exts/SpongebotExtension/SpongeSettingsForm.cs b/src/modules/cmdpal/Exts/SpongebotExtension/SpongeSettingsForm.cs index bf01c563cc..1d31c4cb3b 100644 --- a/src/modules/cmdpal/Exts/SpongebotExtension/SpongeSettingsForm.cs +++ b/src/modules/cmdpal/Exts/SpongebotExtension/SpongeSettingsForm.cs @@ -2,19 +2,17 @@ // 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.IO; using System.Text.Json.Nodes; -using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace SpongebotExtension; -internal sealed partial class SpongeSettingsForm : Form +internal sealed partial class SpongeSettingsForm : FormContent { - public override string TemplateJson() + public SpongeSettingsForm() { - var json = $$""" + TemplateJson = $$""" { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", @@ -49,7 +47,6 @@ internal sealed partial class SpongeSettingsForm : Form ] } """; - return json; } public override CommandResult SubmitForm(string payload) diff --git a/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotPage.cs b/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotPage.cs index 4a7038e747..5b132e57cb 100644 --- a/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotPage.cs +++ b/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotPage.cs @@ -12,7 +12,7 @@ using Microsoft.CommandPalette.Extensions.Toolkit; namespace SpongebotExtension; -public partial class SpongebotPage : MarkdownPage, IFallbackHandler +public partial class SpongebotPage : ContentPage, IFallbackHandler { public CopyTextCommand CopyCommand { get; set; } = new(string.Empty); @@ -46,11 +46,11 @@ public partial class SpongebotPage : MarkdownPage, IFallbackHandler return sb.ToString(); } - public override string[] Bodies() + public override IContent[] GetContent() { var t = GenerateMeme(this.Name); t.ConfigureAwait(false); - return [t.Result]; + return [new MarkdownContent(t.Result)]; } private static async Task GenerateMeme(string text) diff --git a/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotSettingsPage.cs b/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotSettingsPage.cs index 51579fd465..76217a06f8 100644 --- a/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotSettingsPage.cs +++ b/src/modules/cmdpal/Exts/SpongebotExtension/SpongebotSettingsPage.cs @@ -7,11 +7,11 @@ using Microsoft.CommandPalette.Extensions.Toolkit; namespace SpongebotExtension; -internal sealed partial class SpongebotSettingsPage : FormPage +internal sealed partial class SpongebotSettingsPage : ContentPage { private readonly SpongeSettingsForm settingsForm = new(); - public override IForm[] Forms() => [settingsForm]; + public override IContent[] GetContent() => [settingsForm]; public SpongebotSettingsPage() { diff --git a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIForm.cs b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIForm.cs index 0e4d715802..db74bcdcc3 100644 --- a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIForm.cs +++ b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIForm.cs @@ -2,24 +2,18 @@ // 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.IO; -using System.Linq; -using System.Text; using System.Text.Json.Nodes; -using System.Threading.Tasks; using Microsoft.CommandPalette.Extensions.Toolkit; using YouTubeExtension.Helper; namespace YouTubeExtension.Pages; -internal sealed partial class YouTubeAPIForm : Form +internal sealed partial class YouTubeAPIForm : FormContent { - public override string TemplateJson() + public YouTubeAPIForm() { - var json = $$""" + TemplateJson = $$""" { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", @@ -45,7 +39,6 @@ internal sealed partial class YouTubeAPIForm : Form ] } """; - return json; } public override CommandResult SubmitForm(string payload) diff --git a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIPage.cs b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIPage.cs index d0629c6b14..bc8f5ffb9a 100644 --- a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIPage.cs +++ b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeAPIPage.cs @@ -2,21 +2,16 @@ // 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.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace YouTubeExtension.Pages; -internal sealed partial class YouTubeAPIPage : FormPage +internal sealed partial class YouTubeAPIPage : ContentPage { private readonly YouTubeAPIForm apiForm = new(); - public override IForm[] Forms() => [apiForm]; + public override IContent[] GetContent() => [apiForm]; public YouTubeAPIPage() { diff --git a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeChannelInfoMarkdownPage.cs b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeChannelInfoMarkdownPage.cs index 8c443069d1..2ba4d87aa1 100644 --- a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeChannelInfoMarkdownPage.cs +++ b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeChannelInfoMarkdownPage.cs @@ -7,12 +7,13 @@ using System.IO; using System.Net.Http; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using YouTubeExtension.Helper; namespace YouTubeExtension.Pages; -internal sealed partial class YouTubeChannelInfoMarkdownPage : MarkdownPage +internal sealed partial class YouTubeChannelInfoMarkdownPage : ContentPage { private readonly YouTubeChannel _channel; private string _markdown = string.Empty; @@ -24,7 +25,7 @@ internal sealed partial class YouTubeChannelInfoMarkdownPage : MarkdownPage _channel = channel; } - public override string[] Bodies() + public override IContent[] GetContent() { var state = File.ReadAllText(YouTubeHelper.StateJsonPath()); var jsonState = JsonNode.Parse(state); @@ -60,7 +61,7 @@ _Last updated: {DateTime.Now:MMMM dd, yyyy}_ _Data sourced via YouTube API_ "; - return new string[] { _markdown }; + return [new MarkdownContent(_markdown)]; } private async Task FillInChannelDetailsAsync(YouTubeChannel channel, string apiKey) diff --git a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeVideoInfoMarkdownPage.cs b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeVideoInfoMarkdownPage.cs index 8f209d0e30..af3f1acafa 100644 --- a/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeVideoInfoMarkdownPage.cs +++ b/src/modules/cmdpal/Exts/YouTubeExtension/Pages/YouTubeVideoInfoMarkdownPage.cs @@ -13,7 +13,7 @@ using YouTubeExtension.Helper; namespace YouTubeExtension.Pages; -internal sealed partial class YouTubeVideoInfoMarkdownPage : MarkdownPage +internal sealed partial class YouTubeVideoInfoMarkdownPage : ContentPage { private readonly YouTubeVideo _video; private string _markdown = string.Empty; @@ -25,7 +25,7 @@ internal sealed partial class YouTubeVideoInfoMarkdownPage : MarkdownPage _video = video; } - public override string[] Bodies() + public override IContent[] GetContent() { var state = File.ReadAllText(YouTubeHelper.StateJsonPath()); var jsonState = JsonNode.Parse(state); @@ -74,7 +74,7 @@ _Last updated: {DateTime.Now:MMMM dd, yyyy}_ _Data sourced via YouTube API_ "; - return new string[] { _markdown }; + return [new MarkdownContent(_markdown)]; } private async Task FillInVideoDetailsAsync(YouTubeVideo video, string apiKey) diff --git a/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md b/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md index c3f2a465df..457f1c7adb 100644 --- a/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md +++ b/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md @@ -1162,6 +1162,8 @@ on nested pages will all work exactly as expected. --> #### Markdown Pages +Deprecated. Don't use me. Use ContentPage instead. + ```csharp interface IMarkdownPage requires IPage { String[] Bodies(); // TODO! should this be an IBody, so we can make it observable? @@ -1172,6 +1174,7 @@ interface IMarkdownPage requires IPage { #### Form Pages +Deprecated. Don't use me. Use ContentPage instead. ```csharp diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Form.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Form.cs index b0716dee31..5c9e557aec 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Form.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Form.cs @@ -2,8 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Windows.Foundation.Metadata; + namespace Microsoft.CommandPalette.Extensions.Toolkit; +[Deprecated("Use FormContent instead", DeprecationType.Deprecate, 8)] public abstract partial class Form : IForm { public virtual string Data { get; set; } = string.Empty; diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormPage.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormPage.cs index 5ae21e5e5c..077ed5abc2 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormPage.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FormPage.cs @@ -2,8 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Windows.Foundation.Metadata; + namespace Microsoft.CommandPalette.Extensions.Toolkit; +[Deprecated("Use ContentPage instead", DeprecationType.Deprecate, 8)] public abstract partial class FormPage : Page, IFormPage { public abstract IForm[] Forms(); diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownContent.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownContent.cs index 31a79a7f9d..b2de535d9a 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownContent.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownContent.cs @@ -17,4 +17,13 @@ public partial class MarkdownContent : BaseObservable, IMarkdownContent } = string.Empty; + + public MarkdownContent() + { + } + + public MarkdownContent(string body) + { + Body = body; + } } diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownPage.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownPage.cs index e3a6bc8027..08b6da3e71 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownPage.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/MarkdownPage.cs @@ -2,8 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Windows.Foundation.Metadata; + namespace Microsoft.CommandPalette.Extensions.Toolkit; +[Deprecated("Use MarkdownContent & ContentPage instead", DeprecationType.Deprecate, 8)] public partial class MarkdownPage : Page, IMarkdownPage { private IDetails? _details; diff --git a/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownDetails.cs b/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownDetails.cs index d56cf81ad4..473cc5e9b4 100644 --- a/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownDetails.cs +++ b/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownDetails.cs @@ -2,31 +2,98 @@ // 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 Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace SamplePagesExtension; -internal sealed partial class SampleMarkdownDetails : MarkdownPage +internal sealed partial class SampleMarkdownDetails : ContentPage { public SampleMarkdownDetails() { Icon = new IconInfo(string.Empty); Name = "Markdown with Details"; + Details = new Details() { - Body = "... with _even more Markdown_ by it.", + Body = "... with _even more Markdown_ by it.\nEach of the sections below is some sample metadata", + Metadata = [ + new DetailsElement() + { + Key = "Plain text", + Data = new DetailsLink() { Text = "Set just the text to get text metadata" }, + }, + new DetailsElement() + { + Key = "Links", + Data = new DetailsLink() { Text = "Or metadata can be links", Link = new("https://github.com/microsoft/PowerToys") }, + }, + new DetailsElement() + { + Key = "CmdPal will display the URL if no text is given", + Data = new DetailsLink() { Link = new("https://github.com/microsoft/PowerToys") }, + }, + new DetailsElement() + { + Key = "Above a separator", + Data = new DetailsLink() { Text = "Below me is a separator" }, + }, + new DetailsElement() + { + Key = "A separator", + Data = new DetailsSeparator(), + }, + new DetailsElement() + { + Key = "Below a separator", + Data = new DetailsLink() { Text = "Above me is a separator" }, + }, + new DetailsElement() + { + Key = "Add Tags too", + Data = new DetailsTags() + { + Tags = [ + new Tag("simple text"), + new Tag("Colored text") { Foreground = ColorHelpers.FromRgb(255, 0, 0) }, + new Tag("Colored backgrounds") { Background = ColorHelpers.FromRgb(0, 0, 255) }, + new Tag("Colored everything") { Foreground = ColorHelpers.FromRgb(255, 255, 0), Background = ColorHelpers.FromRgb(0, 0, 255) }, + new Tag("Icons too") { Icon = new IconInfo("\uE735"), Foreground = ColorHelpers.FromRgb(255, 255, 0) }, + new Tag() { Icon = new IconInfo("https://i.imgur.com/t9qgDTM.png") }, + new Tag("this") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("baby") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("can") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("fit") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("so") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("many") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("tags") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("in") { Foreground = RandomColor(), Background = RandomColor() }, + new Tag("it") { Foreground = RandomColor(), Background = RandomColor() }, + ], + }, + }, + ], }; } - public override string[] Bodies() => [ + public override IContent[] GetContent() => [new MarkdownContent( """ # This page also has details So you can have markdown... -""", -""" +"""), +new MarkdownContent(""" But what this is really useful for is the tags and other things you can put into Details. Which I'd do. **IF I HAD ANY**. -""" +""") ]; + + private static OptionalColor RandomColor() + { + var r = new Random(); + var b = new byte[3]; + r.NextBytes(b); + return ColorHelpers.FromRgb(b[0], b[1], b[2]); + } } diff --git a/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownManyBodies.cs b/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownManyBodies.cs index 08a412397f..cad9cbb33c 100644 --- a/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownManyBodies.cs +++ b/src/modules/cmdpal/exts/SamplePagesExtension/Pages/SampleMarkdownManyBodies.cs @@ -2,11 +2,12 @@ // 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.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace SamplePagesExtension; -internal sealed partial class SampleMarkdownManyBodies : MarkdownPage +internal sealed partial class SampleMarkdownManyBodies : ContentPage { public SampleMarkdownManyBodies() { @@ -14,20 +15,24 @@ internal sealed partial class SampleMarkdownManyBodies : MarkdownPage Name = "Markdown with many bodies"; } - public override string[] Bodies() => [ + public override IContent[] GetContent() => [ + new MarkdownContent( """ # This page has many bodies On it you'll find multiple blocks of markdown content -""", +"""), + new MarkdownContent( """ ## Here's another block _Maybe_ you could use this pattern for implementing a post with comments page. -""", +"""), + new MarkdownContent( """ > or don't, it's your app, do whatever you want -""", +"""), + new MarkdownContent( """ You can even use it to write cryptic poems: > It's a peculiar thing, the way that I feel @@ -45,6 +50,6 @@ You can even use it to write cryptic poems: > This part of the story, I never wanted to tell > Good bye old friend, my pal, farewell. -""" +"""), ]; }