diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 3c0147ba3a9c..1d53095a2532 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -1258,13 +1258,26 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::Control::KeyChord keyChord = nullptr; if (!realArgs.KeyChord().empty()) { - keyChord = KeyChordSerialization::FromString(winrt::to_hstring(realArgs.KeyChord())); + try + { + keyChord = KeyChordSerialization::FromString(winrt::to_hstring(realArgs.KeyChord())); + _settings.GlobalSettings().ActionMap().AddSendInputAction(realArgs.Name(), realArgs.Commandline(), keyChord); + _settings.WriteSettingsToDisk(); + ActionSaved(realArgs.Commandline(), realArgs.Name(), KeyChordSerialization::ToString(keyChord)); + } + catch (const winrt::hresult_error& ex) + { + auto code = ex.code(); + auto message = ex.message(); + ActionSaveFailed(message); + return; + } } _settings.GlobalSettings().ActionMap().AddSendInputAction(realArgs.Name(), realArgs.Commandline(), keyChord); - _settings.WriteSettingsToDisk(); ActionSaved(realArgs.Commandline(), realArgs.Name(), KeyChordSerialization::ToString(keyChord)); + args.Handled(true); } } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index d41779255ba4..40202f3c9b12 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4235,6 +4235,35 @@ namespace winrt::TerminalApp::implementation } } + winrt::fire_and_forget TerminalPage::ActionSaveFailed(winrt::hstring message) + { + auto weakThis{ get_weak() }; + co_await wil::resume_foreground(Dispatcher()); + if (auto page{ weakThis.get() }) + { + // If we haven't ever loaded the TeachingTip, then do so now and + // create the toast for it. + if (page->_actionSaveFailedToast == nullptr) + { + if (auto tip{ page->FindName(L"ActionSaveFailedToast").try_as() }) + { + page->_actionSaveFailedToast = std::make_shared(tip); + // Make sure to use the weak ref when setting up this + // callback. + tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl }); + } + } + _UpdateTeachingTipTheme(ActionSaveFailedToast().try_as()); + + ActionSaveFailedMessage().Text(message); + + if (page->_actionSaveFailedToast != nullptr) + { + page->_actionSaveFailedToast->Open(); + } + } + } + // Method Description: // - Called when an attempt to rename the window has failed. This will open // the toast displaying a message to the user that the attempt to rename diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index f2491ad325ec..ddc44f1a30ba 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -150,6 +150,7 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget IdentifyWindow(); winrt::fire_and_forget ActionSaved(winrt::hstring input, winrt::hstring name, winrt::hstring keyChord); + winrt::fire_and_forget ActionSaveFailed(winrt::hstring message); winrt::fire_and_forget RenameFailed(); winrt::fire_and_forget ShowTerminalWorkingDirectory(); @@ -262,6 +263,7 @@ namespace winrt::TerminalApp::implementation std::shared_ptr _windowIdToast{ nullptr }; std::shared_ptr _actionSavedToast{ nullptr }; + std::shared_ptr _actionSaveFailedToast{ nullptr }; std::shared_ptr _windowRenameFailedToast{ nullptr }; std::shared_ptr _windowCwdToast{ nullptr }; diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index b00f35a57390..c717a578e410 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -233,5 +233,14 @@ + + + + +