diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleGoToPage.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleGoToPage.cs index 0a110305d8..258c3225a6 100644 --- a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleGoToPage.cs +++ b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleGoToPage.cs @@ -22,25 +22,19 @@ public sealed partial class SampleGoToPage : ListPage { var goBackArgs = new GoToPageArgs { - PageId = string.Empty, + PageId = "com.microsoft.SamplePages.LandingPage", NavigationMode = NavigationMode.GoBack, }; var goHomeArgs = new GoToPageArgs { - PageId = "com.microsoft.SamplePages", + PageId = "com.microsoft.SamplePages.LandingPage", NavigationMode = NavigationMode.GoHome, }; - var goToCalculatorHomeArgs = new GoToPageArgs + var pushLandingPageArgs = new GoToPageArgs { - PageId = "com.microsoft.cmdpal.calculator", - NavigationMode = NavigationMode.GoHome, - }; - - var pushArgs = new GoToPageArgs - { - PageId = "com.microsoft.SamplePages", + PageId = "com.microsoft.SamplePages.LandingPage", NavigationMode = NavigationMode.Push, }; @@ -52,7 +46,7 @@ public sealed partial class SampleGoToPage : ListPage Result = CommandResult.GoToPage(goBackArgs), }) { - Title = "Go to back page.", + Title = "Go back and then go to landing page.", Icon = new IconInfo("\uEA37"), }, new ListItem( @@ -61,27 +55,18 @@ public sealed partial class SampleGoToPage : ListPage Result = CommandResult.GoToPage(goHomeArgs), }) { - Title = "Go to Home page.", + Title = "Go back to home page and then go to landing page.", Icon = new IconInfo("\uEA37"), }, new ListItem( new AnonymousCommand(() => { }) { - Result = CommandResult.GoToPage(goToCalculatorHomeArgs), + Result = CommandResult.GoToPage(pushLandingPageArgs), }) { - Title = "Go to Calculator Home page.", + Title = "Push landing page.", Icon = new IconInfo("\uEA37"), }, - new ListItem( - new AnonymousCommand(() => { }) - { - Result = CommandResult.GoToPage(pushArgs), - }) - { - Title = "Push current page.", - Icon = new IconInfo("\uEA37"), - } ]; } } diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleLandingPage.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleLandingPage.cs new file mode 100644 index 0000000000..f379cefd5b --- /dev/null +++ b/src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleLandingPage.cs @@ -0,0 +1,34 @@ +// 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; + +public sealed partial class SampleLandingPage : ListPage +{ + public SampleLandingPage() + { + Icon = new IconInfo("\uEA37"); + Name = "This is a sample landing page to land for GotoPage call."; + Id = "com.microsoft.SamplePages.LandingPage"; + } + + public override IListItem[] GetItems() + { + return [ + new ListItem(new NoOpCommand()) + { + Title = "This is a basic item in the list", + Subtitle = "I don't do anything though", + }, + new ListItem(new NoOpCommand()) + { + Title = "This is a sample landing page to land for GotoPage call.", + Subtitle = "I don't do anything though", + }, + ]; + } +} diff --git a/src/modules/cmdpal/Exts/SamplePagesExtension/SamplePagesCommandsProvider.cs b/src/modules/cmdpal/Exts/SamplePagesExtension/SamplePagesCommandsProvider.cs index e500c25d8d..d900f9992a 100644 --- a/src/modules/cmdpal/Exts/SamplePagesExtension/SamplePagesCommandsProvider.cs +++ b/src/modules/cmdpal/Exts/SamplePagesExtension/SamplePagesCommandsProvider.cs @@ -21,6 +21,11 @@ public partial class SamplePagesCommandsProvider : CommandProvider Title = "Sample Pages", Subtitle = "View example commands", }, + new CommandItem(new SampleLandingPage()) + { + Title = "Sample Landing Pages", + Subtitle = "Sample Landing pages example for goto page", + }, ]; public override ICommandItem[] TopLevelCommands() diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs index 373fa11d66..008bd3806e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs @@ -272,53 +272,45 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page, var pageID = vm.PageId; var navigationMode = vm.NavigationMode; - if (string.IsNullOrEmpty(pageID) && navigationMode != NavigationMode.GoBack) + if (string.IsNullOrEmpty(pageID)) + { + _toast.ShowToast("Invalid page id"); + return; + } + + var tlcManager = App.Current.Services.GetService()!; + var toplevelCommand = tlcManager.LookupCommand(pageID); + + if (toplevelCommand == null) { - // TODO: Consider to show a toast? return; } switch (navigationMode) { case NavigationMode.Push: - // TODO: Implement push break; case NavigationMode.GoHome: - var tlcManager = App.Current.Services.GetService()!; - var toplevelCommand = tlcManager.LookupCommand(pageID); - - if (toplevelCommand == null) - { - break; - } - - /* Stack looks like this: - * 0: Main page - * 1: Top level command page (your extensions first page) - * 2: One of your extension pages listed in the top level command page results - * 3: ... - * ... - */ - - // So, we need to clean up existing stack frame. And push to the next top level page. while (RootFrame.CanGoBack) { GoBack(false, false); } - RootFrame.ForwardStack.Clear(); - - var msg = new PerformCommandMessage(toplevelCommand) { WithAnimation = true }; - WeakReferenceMessenger.Default.Send(msg); - break; case NavigationMode.GoBack: - GoBack(); + if (RootFrame.CanGoBack) + { + GoBack(false, false); + } + break; } + var msg = new PerformCommandMessage(toplevelCommand) { WithAnimation = true }; + WeakReferenceMessenger.Default.Send(msg); + return; }