diff --git a/src/cascadia/TerminalApp/ActionPaletteItem.cpp b/src/cascadia/TerminalApp/ActionPaletteItem.cpp index 2220c2d5d1a..69014dca1f8 100644 --- a/src/cascadia/TerminalApp/ActionPaletteItem.cpp +++ b/src/cascadia/TerminalApp/ActionPaletteItem.cpp @@ -23,7 +23,7 @@ namespace winrt::TerminalApp::implementation { Name(command.Name()); KeyChordText(command.KeyChordText()); - Icon(command.Icon()); + Icon(command.IconPath()); _commandChangedRevoker = command.PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& sender, auto& e) { auto item{ weakThis.get() }; @@ -40,9 +40,9 @@ namespace winrt::TerminalApp::implementation { item->KeyChordText(senderCommand.KeyChordText()); } - else if (changedProperty == L"Icon") + else if (changedProperty == L"IconPath") { - item->Icon(senderCommand.Icon()); + item->Icon(senderCommand.IconPath()); } } }); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index f1f12ad8715..348619afc69 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -93,21 +93,27 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget TerminalPage::SetSettings(CascadiaSettings settings, bool needRefreshUI) { _settings = settings; - if (needRefreshUI) - { - _RefreshUIForSettingsReload(); - } - - // Upon settings update we reload the system settings for scrolling as well. - // TODO: consider reloading this value periodically. - _systemRowsToScroll = _ReadSystemRowsToScroll(); auto weakThis{ get_weak() }; co_await winrt::resume_foreground(Dispatcher()); if (auto page{ weakThis.get() }) { + // 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().SetKeyMap(_settings.KeyMap()); + + if (needRefreshUI) + { + _RefreshUIForSettingsReload(); + } + + // Upon settings update we reload the system settings for scrolling as well. + // TODO: consider reloading this value periodically. + _systemRowsToScroll = _ReadSystemRowsToScroll(); } } diff --git a/src/cascadia/TerminalSettingsEditor/Actions.cpp b/src/cascadia/TerminalSettingsEditor/Actions.cpp new file mode 100644 index 00000000000..4d082997745 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/Actions.cpp @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "Actions.h" +#include "Actions.g.cpp" +#include "ActionsPageNavigationState.g.cpp" +#include "EnumEntry.h" + +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::System; +using namespace winrt::Windows::UI::Core; +using namespace winrt::Windows::UI::Xaml::Navigation; +using namespace winrt::Microsoft::Terminal::Settings::Model; + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + Actions::Actions() + { + InitializeComponent(); + + _filteredActions = winrt::single_threaded_observable_vector(); + } + + void Actions::OnNavigatedTo(const NavigationEventArgs& e) + { + _State = e.Parameter().as(); + + for (const auto& [k, command] : _State.Settings().GlobalSettings().Commands()) + { + // Filter out nested commands, and commands that aren't bound to a + // key. This page is currently just for displaying the actions that + // _are_ bound to keys. + if (command.HasNestedCommands() || command.KeyChordText().empty()) + { + continue; + } + _filteredActions.Append(command); + } + } + + Collections::IObservableVector Actions::FilteredActions() + { + return _filteredActions; + } + + void Actions::_OpenSettingsClick(const IInspectable& /*sender*/, + const Windows::UI::Xaml::RoutedEventArgs& /*eventArgs*/) + { + const CoreWindow window = CoreWindow::GetForCurrentThread(); + const auto rAltState = window.GetKeyState(VirtualKey::RightMenu); + const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu); + const bool altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) || + WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); + + const auto target = altPressed ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile; + + _State.RequestOpenJson(target); + } + +} diff --git a/src/cascadia/TerminalSettingsEditor/Actions.h b/src/cascadia/TerminalSettingsEditor/Actions.h new file mode 100644 index 00000000000..8eda3419842 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/Actions.h @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +#include "Actions.g.h" +#include "ActionsPageNavigationState.g.h" +#include "Utils.h" + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + struct ActionsPageNavigationState : ActionsPageNavigationStateT + { + public: + ActionsPageNavigationState(const Model::CascadiaSettings& settings) : + _Settings{ settings } {} + + void RequestOpenJson(const Model::SettingsTarget target) + { + _OpenJsonHandlers(nullptr, target); + } + + GETSET_PROPERTY(Model::CascadiaSettings, Settings, nullptr) + TYPED_EVENT(OpenJson, Windows::Foundation::IInspectable, Model::SettingsTarget); + }; + + struct Actions : ActionsT + { + public: + Actions(); + + void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e); + + Windows::Foundation::Collections::IObservableVector FilteredActions(); + + GETSET_PROPERTY(Editor::ActionsPageNavigationState, State, nullptr); + + private: + friend struct ActionsT; // for Xaml to bind events + Windows::Foundation::Collections::IObservableVector _filteredActions{ nullptr }; + + void _OpenSettingsClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs); + }; +} + +namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation +{ + BASIC_FACTORY(Actions); +} diff --git a/src/cascadia/TerminalSettingsEditor/Actions.idl b/src/cascadia/TerminalSettingsEditor/Actions.idl new file mode 100644 index 00000000000..2b1ea22aab5 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/Actions.idl @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "EnumEntry.idl"; + +namespace Microsoft.Terminal.Settings.Editor +{ + runtimeclass ActionsPageNavigationState + { + Microsoft.Terminal.Settings.Model.CascadiaSettings Settings; + void RequestOpenJson(Microsoft.Terminal.Settings.Model.SettingsTarget target); + event Windows.Foundation.TypedEventHandler OpenJson; + }; + + [default_interface] runtimeclass Actions : Windows.UI.Xaml.Controls.Page + { + Actions(); + ActionsPageNavigationState State { get; }; + + IObservableVector FilteredActions { get; }; + + } +} diff --git a/src/cascadia/TerminalSettingsEditor/Actions.xaml b/src/cascadia/TerminalSettingsEditor/Actions.xaml new file mode 100644 index 00000000000..d4157249772 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/Actions.xaml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +