From 397a84e5596c9a68a915ac098386652c2ce63974 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Wed, 22 Sep 2021 21:53:15 -0500 Subject: [PATCH] Make the command palette async, jump list limit 13 items --- src/cascadia/TerminalApp/CommandPalette.cpp | 20 +++++++++--- src/cascadia/TerminalApp/CommandPalette.h | 3 ++ src/cascadia/TerminalApp/CommandPalette.idl | 3 ++ src/cascadia/TerminalApp/CommandPalette.xaml | 20 +++++++++--- src/cascadia/TerminalApp/Jumplist.cpp | 8 +++++ src/cascadia/TerminalApp/TerminalPage.cpp | 32 +++++++++++++++++--- src/cascadia/TerminalApp/TerminalPage.h | 2 +- 7 files changed, 72 insertions(+), 16 deletions(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 651158122..7555aa952 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -886,17 +886,24 @@ namespace winrt::TerminalApp::implementation void CommandPalette::SetCommands(Collections::IVector const& actions) { _allCommands.Clear(); - for (const auto& action : actions) + if (actions) { - auto actionPaletteItem{ winrt::make(action) }; - auto filteredCommand{ winrt::make(actionPaletteItem) }; - _allCommands.Append(filteredCommand); + for (const auto& action : actions) + { + auto actionPaletteItem{ winrt::make(action) }; + auto filteredCommand{ winrt::make(actionPaletteItem) }; + _allCommands.Append(filteredCommand); + } } if (Visibility() == Visibility::Visible && _currentMode == CommandPaletteMode::ActionMode) { - _updateFilteredActions(); + _filterTextChanged(nullptr, nullptr); + //_updateFilteredActions(); } + + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Loading" }); + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Loaded" }); } // Method Description: @@ -1003,6 +1010,9 @@ namespace winrt::TerminalApp::implementation // clear + append when switching between modes. _filteredActions.Clear(); _updateFilteredActions(); + + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Loading" }); + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Loaded" }); } // Method Description: diff --git a/src/cascadia/TerminalApp/CommandPalette.h b/src/cascadia/TerminalApp/CommandPalette.h index af065d67d..3a50549fb 100644 --- a/src/cascadia/TerminalApp/CommandPalette.h +++ b/src/cascadia/TerminalApp/CommandPalette.h @@ -47,6 +47,9 @@ namespace winrt::TerminalApp::implementation void EnableTabSwitcherMode(const uint32_t startIdx, Microsoft::Terminal::Settings::Model::TabSwitcherMode tabSwitcherMode); void EnableTabSearchMode(); + bool Loading() const { return _currentMode == CommandPaletteMode::ActionMode && _allCommands.Size() == 0; } + bool Loaded() const { return !Loading(); } + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(winrt::hstring, NoMatchesText, _PropertyChangedHandlers); WINRT_OBSERVABLE_PROPERTY(winrt::hstring, SearchBoxPlaceholderText, _PropertyChangedHandlers); diff --git a/src/cascadia/TerminalApp/CommandPalette.idl b/src/cascadia/TerminalApp/CommandPalette.idl index 4bb72f46d..a61b1e90b 100644 --- a/src/cascadia/TerminalApp/CommandPalette.idl +++ b/src/cascadia/TerminalApp/CommandPalette.idl @@ -19,6 +19,9 @@ namespace TerminalApp String ParentCommandName { get; }; String ParsedCommandLineText { get; }; + Boolean Loading { get; }; + Boolean Loaded { get; }; + Windows.Foundation.Collections.IObservableVector FilteredActions { get; }; void SetCommands(Windows.Foundation.Collections.IVector actions); diff --git a/src/cascadia/TerminalApp/CommandPalette.xaml b/src/cascadia/TerminalApp/CommandPalette.xaml index 3fbc4490e..0b414e665 100644 --- a/src/cascadia/TerminalApp/CommandPalette.xaml +++ b/src/cascadia/TerminalApp/CommandPalette.xaml @@ -412,6 +412,7 @@ Style="{ThemeResource CommandPaletteBackground}"> + @@ -434,7 +435,7 @@ Text="{x:Bind PrefixCharacter, Mode=OneWay}" Visibility="{x:Bind PrefixCharacter, Mode=OneWay, Converter={StaticResource ParentCommandVisibilityConverter}}" /> - @@ -459,13 +460,13 @@ - + SelectionMode="Single" + Visibility="{x:Bind Loaded, Mode=OneWay}" /> + + + + diff --git a/src/cascadia/TerminalApp/Jumplist.cpp b/src/cascadia/TerminalApp/Jumplist.cpp index 3452da544..6b769d0e5 100644 --- a/src/cascadia/TerminalApp/Jumplist.cpp +++ b/src/cascadia/TerminalApp/Jumplist.cpp @@ -107,8 +107,16 @@ winrt::fire_and_forget Jumplist::UpdateJumplist(const CascadiaSettings& settings { try { + size_t i{}; for (const auto& profile : profiles) { + if (++i == 13) + { + // Only process the first 13 profiles. + // Empirically observed as the limit for tasks in Windows 10 + break; + } + // Craft the arguments following "wt.exe" auto args = fmt::format(L"-p {}", to_hstring(profile.Guid())); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index cacacb8c3..c91569a87 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1950,13 +1950,28 @@ namespace winrt::TerminalApp::implementation // - // Return Value: // - - void TerminalPage::_UpdateCommandsForPalette() + winrt::fire_and_forget TerminalPage::_UpdateCommandsForPalette() { - IMap copyOfCommands = _ExpandCommands(_settings.GlobalSettings().ActionMap().NameMap(), - _settings.ActiveProfiles().GetView(), - _settings.GlobalSettings().ColorSchemes()); + auto settings{ _settings }; + CommandPalette().SetCommands(nullptr); - _recursiveUpdateCommandKeybindingLabels(_settings, copyOfCommands.GetView()); + co_await winrt::resume_background(); + + if (settings != _settings) + { // check before each expensive operation! + co_return; + } + + IMap copyOfCommands = _ExpandCommands(settings.GlobalSettings().ActionMap().NameMap(), + settings.ActiveProfiles().GetView(), + settings.GlobalSettings().ColorSchemes()); + + if (settings != _settings) + { // check before each expensive operation! + co_return; + } + + _recursiveUpdateCommandKeybindingLabels(settings, copyOfCommands.GetView()); // Update the command palette when settings reload auto commandsCollection = winrt::single_threaded_vector(); @@ -1965,6 +1980,13 @@ namespace winrt::TerminalApp::implementation commandsCollection.Append(nameAndCommand.Value()); } + co_await winrt::resume_foreground(Dispatcher()); + + if (settings != _settings) + { + co_return; + } + CommandPalette().SetCommands(commandsCollection); } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 414c233fd..26ee229ea 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -206,7 +206,7 @@ namespace winrt::TerminalApp::implementation void _UpdateTabIcon(TerminalTab& tab); void _UpdateTabView(); void _UpdateTabWidthMode(); - void _UpdateCommandsForPalette(); + winrt::fire_and_forget _UpdateCommandsForPalette(); static winrt::Windows::Foundation::Collections::IMap _ExpandCommands(Windows::Foundation::Collections::IMapView commandsToExpand, Windows::Foundation::Collections::IVectorView profiles,