diff --git a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp index 44f1a9c2db8..63f9d1ed67a 100644 --- a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp @@ -1102,7 +1102,7 @@ namespace TerminalAppLocalTests // If you don't do this, the palette will just stay open, and the // next time we call _HandleNextTab, we'll continue traversing the // MRU list, instead of just hoping one entry. - page->CommandPalette().Visibility(Visibility::Collapsed); + page->LoadCommandPalette().Visibility(Visibility::Collapsed); }); TestOnUIThread([&page]() { @@ -1123,7 +1123,7 @@ namespace TerminalAppLocalTests // If you don't do this, the palette will just stay open, and the // next time we call _HandleNextTab, we'll continue traversing the // MRU list, instead of just hoping one entry. - page->CommandPalette().Visibility(Visibility::Collapsed); + page->LoadCommandPalette().Visibility(Visibility::Collapsed); }); TestOnUIThread([&page]() { @@ -1239,7 +1239,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"a", page->_mruTabs.GetAt(3).Title()); }); - const auto palette = winrt::get_self(page->CommandPalette()); + const auto palette = winrt::get_self(page->LoadCommandPalette()); VERIFY_ARE_EQUAL(winrt::TerminalApp::implementation::CommandPaletteMode::TabSwitchMode, palette->_currentMode, L"Verify we are in the tab switcher mode"); // At this point, the contents of the command palette's _mruTabs list is diff --git a/src/cascadia/TerminalApp/AboutDialog.cpp b/src/cascadia/TerminalApp/AboutDialog.cpp index 4d837b65b70..83a390d7042 100644 --- a/src/cascadia/TerminalApp/AboutDialog.cpp +++ b/src/cascadia/TerminalApp/AboutDialog.cpp @@ -29,6 +29,7 @@ namespace winrt::TerminalApp::implementation AboutDialog::AboutDialog() { InitializeComponent(); + QueueUpdateCheck(); } winrt::hstring AboutDialog::ApplicationDisplayName() diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index c61ab8502a4..82a2a3777a5 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -613,10 +613,10 @@ namespace winrt::TerminalApp::implementation { if (const auto& realArgs = args.ActionArgs().try_as()) { - CommandPalette().EnableCommandPaletteMode(realArgs.LaunchMode()); - CommandPalette().Visibility(CommandPalette().Visibility() == Visibility::Visible ? - Visibility::Collapsed : - Visibility::Visible); + const auto p = LoadCommandPalette(); + const auto v = p.Visibility() == Visibility::Visible ? Visibility::Collapsed : Visibility::Visible; + p.EnableCommandPaletteMode(realArgs.LaunchMode()); + p.Visibility(v); args.Handled(true); } } @@ -799,9 +799,10 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandleTabSearch(const IInspectable& /*sender*/, const ActionEventArgs& args) { - CommandPalette().SetTabs(_tabs, _mruTabs); - CommandPalette().EnableTabSearchMode(); - CommandPalette().Visibility(Visibility::Visible); + const auto p = LoadCommandPalette(); + p.SetTabs(_tabs, _mruTabs); + p.EnableTabSearchMode(); + p.Visibility(Visibility::Visible); args.Handled(true); } diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 51918082420..142dea7ccd9 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -600,13 +600,14 @@ namespace winrt::TerminalApp::implementation } else { - CommandPalette().SetTabs(_tabs, _mruTabs); + const auto p = LoadCommandPalette(); + p.SetTabs(_tabs, _mruTabs); // Otherwise, set up the tab switcher in the selected mode, with // the given ordering, and make it visible. - CommandPalette().EnableTabSwitcherMode(index, tabSwitchMode); - CommandPalette().Visibility(Visibility::Visible); - CommandPalette().SelectNextItem(bMoveRight); + p.EnableTabSwitcherMode(index, tabSwitchMode); + p.Visibility(Visibility::Visible); + p.SelectNextItem(bMoveRight); } } @@ -916,7 +917,7 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_UpdatedSelectedTab(const winrt::TerminalApp::TabBase& tab) { // Unfocus all the tabs. - for (auto tab : _tabs) + for (const auto& tab : _tabs) { tab.Focus(FocusState::Unfocused); } @@ -936,7 +937,8 @@ namespace winrt::TerminalApp::implementation // When the tab switcher is eventually dismissed, the focus will // get tossed back to the focused terminal control, so we don't // need to worry about focus getting lost. - if (CommandPalette().Visibility() != Visibility::Visible) + const auto p = CommandPaletteElement(); + if (!p || p.Visibility() != Visibility::Visible) { tab.Focus(FocusState::Programmatic); _UpdateMRUTab(tab); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index fa2612c6c24..67392e8950a 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -113,13 +113,14 @@ namespace winrt::TerminalApp::implementation _settings = settings; - // Make sure to _UpdateCommandsForPalette before - // _RefreshUIForSettingsReload. _UpdateCommandsForPalette will make - // sure the KeyChordText of Commands is updated, which needs to - // happen before the Settings UI is reloaded and tries to re-read - // those values. - _UpdateCommandsForPalette(); - CommandPalette().SetActionMap(_settings.ActionMap()); + // Make sure to call SetCommands before _RefreshUIForSettingsReload. + // SetCommands will make sure the KeyChordText of Commands is updated, which needs + // to happen before the Settings UI is reloaded and tries to re-read those values. + if (const auto p = CommandPaletteElement()) + { + p.SetCommands(_settings.GlobalSettings().ActionMap().ExpandedCommands()); + p.SetActionMap(_settings.ActionMap()); + } if (needRefreshUI) { @@ -255,20 +256,6 @@ namespace winrt::TerminalApp::implementation _UpdateTabWidthMode(); - // When the visibility of the command palette changes to "collapsed", - // the palette has been closed. Toss focus back to the currently active - // control. - CommandPalette().RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) { - if (CommandPalette().Visibility() == Visibility::Collapsed) - { - _FocusActiveControl(nullptr, nullptr); - } - }); - CommandPalette().DispatchCommandRequested({ this, &TerminalPage::_OnDispatchCommandRequested }); - CommandPalette().CommandLineExecutionRequested({ this, &TerminalPage::_OnCommandLineExecutionRequested }); - CommandPalette().SwitchToTabRequested({ this, &TerminalPage::_OnSwitchToTabRequested }); - CommandPalette().PreviewAction({ this, &TerminalPage::_PreviewActionHandler }); - // Settings AllowDependentAnimations will affect whether animations are // enabled application-wide, so we don't need to check it each time we // want to create an animation. @@ -684,7 +671,6 @@ namespace winrt::TerminalApp::implementation // Notes link, send feedback link and privacy policy link. void TerminalPage::_ShowAboutDialog() { - AboutDialog().QueueUpdateCheck(); _ShowDialogHelper(L"AboutDialog"); } @@ -1333,8 +1319,9 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_CommandPaletteButtonOnClick(const IInspectable&, const RoutedEventArgs&) { - CommandPalette().EnableCommandPaletteMode(CommandPaletteLaunchMode::Action); - CommandPalette().Visibility(Visibility::Visible); + auto p = LoadCommandPalette(); + p.EnableCommandPaletteMode(CommandPaletteLaunchMode::Action); + p.Visibility(Visibility::Visible); } // Method Description: @@ -1350,7 +1337,7 @@ namespace winrt::TerminalApp::implementation } // Method Description: - // - Called when the users pressed keyBindings while CommandPalette is open. + // - Called when the users pressed keyBindings while CommandPaletteElement is open. // - As of GH#8480, this is also bound to the TabRowControl's KeyUp event. // That should only fire when focus is in the tab row, which is hard to // do. Notably, that's possible: @@ -1421,7 +1408,7 @@ namespace winrt::TerminalApp::implementation return; } - if (const auto p = CommandPalette(); p.Visibility() == Visibility::Visible && cmd.ActionAndArgs().Action() != ShortcutAction::ToggleCommandPalette) + if (const auto p = CommandPaletteElement(); p.Visibility() == Visibility::Visible && cmd.ActionAndArgs().Action() != ShortcutAction::ToggleCommandPalette) { p.Visibility(Visibility::Collapsed); } @@ -1745,6 +1732,40 @@ namespace winrt::TerminalApp::implementation } return nullptr; } + + CommandPalette TerminalPage::LoadCommandPalette() + { + if (const auto p = CommandPaletteElement()) + { + return p; + } + + return _loadCommandPaletteSlowPath(); + } + + CommandPalette TerminalPage::_loadCommandPaletteSlowPath() + { + const auto p = FindName(L"CommandPaletteElement").as(); + + p.SetCommands(_settings.GlobalSettings().ActionMap().ExpandedCommands()); + p.SetActionMap(_settings.ActionMap()); + + // When the visibility of the command palette changes to "collapsed", + // the palette has been closed. Toss focus back to the currently active control. + p.RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) { + if (CommandPaletteElement().Visibility() == Visibility::Collapsed) + { + _FocusActiveControl(nullptr, nullptr); + } + }); + p.DispatchCommandRequested({ this, &TerminalPage::_OnDispatchCommandRequested }); + p.CommandLineExecutionRequested({ this, &TerminalPage::_OnCommandLineExecutionRequested }); + p.SwitchToTabRequested({ this, &TerminalPage::_OnSwitchToTabRequested }); + p.PreviewAction({ this, &TerminalPage::_PreviewActionHandler }); + + return p; + } + // Method Description: // - Warn the user that they are about to close all open windows, then // signal that we want to close everything. @@ -3140,21 +3161,6 @@ namespace winrt::TerminalApp::implementation } } - // Method Description: - // - Repopulates the list of commands in the command palette with the - // current commands in the settings. Also updates the keybinding labels to - // reflect any matching keybindings. - // Arguments: - // - - // Return Value: - // - - void TerminalPage::_UpdateCommandsForPalette() - { - // Update the command palette when settings reload - const auto& expanded{ _settings.GlobalSettings().ActionMap().ExpandedCommands() }; - CommandPalette().SetCommands(expanded); - } - // Method Description: // - Sets the initial actions to process on startup. We'll make a copy of // this list, and process these actions when we're loaded. @@ -4828,5 +4834,4 @@ namespace winrt::TerminalApp::implementation // _RemoveTab will make sure to null out the _stashed.draggedTab _RemoveTab(*_stashed.draggedTab); } - } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index a775902396e..1d8e616538d 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -118,6 +118,7 @@ namespace winrt::TerminalApp::implementation winrt::hstring ApplicationDisplayName(); winrt::hstring ApplicationVersion(); + CommandPalette LoadCommandPalette(); winrt::fire_and_forget RequestQuit(); winrt::fire_and_forget CloseWindow(bool bypassDialog); @@ -274,6 +275,7 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::NewConnection_revoker _newConnectionRevoker; + __declspec(noinline) CommandPalette _loadCommandPaletteSlowPath(); winrt::Windows::Foundation::IAsyncOperation _ShowDialogHelper(const std::wstring_view& name); void _ShowAboutDialog(); @@ -312,7 +314,6 @@ namespace winrt::TerminalApp::implementation void _UpdateTabIcon(TerminalTab& tab); void _UpdateTabView(); void _UpdateTabWidthMode(); - void _UpdateCommandsForPalette(); void _SetBackgroundImage(const winrt::Microsoft::Terminal::Settings::Model::IAppearanceConfig& newAppearance); void _DuplicateFocusedTab(); diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index 22daa6fedb6..ade311fcde7 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -97,7 +97,8 @@ --> + Grid.Row="2" + x:Load="False" /> -