From f8f13c8afafd81cf3219687a044f41ad655139b7 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 3 Sep 2020 15:14:13 -0400 Subject: [PATCH 1/7] display dialog for invalid links and unsupported schemes --- .../Resources/en-US/Resources.resw | 76 +++++++++++-------- src/cascadia/TerminalApp/TerminalPage.cpp | 31 +++++++- src/cascadia/TerminalApp/TerminalPage.xaml | 14 ++++ 3 files changed, 89 insertions(+), 32 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index ce6b1d0e656..483b3b3b6b2 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -1,17 +1,17 @@  - @@ -204,12 +204,12 @@ Warnings were found while parsing your keybindings: - • Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array. - {Locked="\"keys\"","•"} This glyph is a bullet, used in a bulleted list. + • Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array. + {Locked="\"keys\"","•"} This glyph is a bullet, used in a bulleted list. - • Found a keybinding that was missing a required parameter value. This keybinding will be ignored. - {Locked="•"} This glyph is a bullet, used in a bulleted list. + • Found a keybinding that was missing a required parameter value. This keybinding will be ignored. + {Locked="•"} This glyph is a bullet, used in a bulleted list. The "globals" property is deprecated - your settings might need updating. @@ -652,4 +652,18 @@ Close all tabs after the current tab + + The URI "{0}" is invalid. + {0} will be replaced by the URI the user is attempting to open. + + + Cancel + + + The scheme "{0}" is not supported. + {0} will be replaced with the scheme the user is trying to use. + + + Cancel + \ No newline at end of file diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index ceb86a52481..5dd380eb797 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1805,8 +1805,37 @@ namespace winrt::TerminalApp::implementation { ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } + else if (auto presenter{ _dialogPresenter.get() }) + { + // FindName needs to be called first to actually load the xaml object + FindName(L"UnsupportedSchemeDialog").try_as(); + + // Set the content + const auto errorMsg = fmt::format(std::wstring_view{ RS_(L"UnsupportedSchemeContent") }, + parsed.SchemeName()); + UnsupportedSchemeDialog().Content(winrt::box_value(errorMsg)); + + // Show the dialog + presenter.ShowDialog(FindName(L"UnsupportedSchemeDialog").try_as()); + } + } + catch (...) + { + LOG_CAUGHT_EXCEPTION(); + if (auto presenter{ _dialogPresenter.get() }) + { + // FindName needs to be called first to actually load the xaml object + FindName(L"InvalidLinkDialog").try_as(); + + // Set the content + const auto errorMsg = fmt::format(std::wstring_view{ RS_(L"InvalidLinkContent") }, + eventArgs.Uri()); + InvalidLinkDialog().Content(winrt::box_value(errorMsg)); + + // Show the dialog + presenter.ShowDialog(FindName(L"InvalidLinkDialog").try_as()); + } } - CATCH_LOG(); } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index c872b325029..32a0dc771af 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -68,6 +68,20 @@ the MIT License. See LICENSE in the project root for license information. --> DefaultButton="Primary"> + + + + + + Date: Thu, 3 Sep 2020 17:13:00 -0400 Subject: [PATCH 2/7] changing resource strings --- .../TerminalApp/Resources/en-US/Resources.resw | 13 ++++++------- src/cascadia/TerminalApp/TerminalPage.cpp | 14 +++----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index 483b3b3b6b2..be673ab5455 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -204,12 +204,12 @@ Warnings were found while parsing your keybindings: - • Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array. - {Locked="\"keys\"","•"} This glyph is a bullet, used in a bulleted list. + • Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array. + {Locked="\"keys\"","•"} This glyph is a bullet, used in a bulleted list. - • Found a keybinding that was missing a required parameter value. This keybinding will be ignored. - {Locked="•"} This glyph is a bullet, used in a bulleted list. + • Found a keybinding that was missing a required parameter value. This keybinding will be ignored. + {Locked="•"} This glyph is a bullet, used in a bulleted list. The "globals" property is deprecated - your settings might need updating. @@ -652,9 +652,8 @@ Close all tabs after the current tab - - The URI "{0}" is invalid. - {0} will be replaced by the URI the user is attempting to open. + + There was an error reading this hyperlink. Cancel diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 5dd380eb797..b0e13baca96 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1808,15 +1808,15 @@ namespace winrt::TerminalApp::implementation else if (auto presenter{ _dialogPresenter.get() }) { // FindName needs to be called first to actually load the xaml object - FindName(L"UnsupportedSchemeDialog").try_as(); + auto unsupportedSchemeDialog = FindName(L"UnsupportedSchemeDialog").try_as(); // Set the content const auto errorMsg = fmt::format(std::wstring_view{ RS_(L"UnsupportedSchemeContent") }, parsed.SchemeName()); - UnsupportedSchemeDialog().Content(winrt::box_value(errorMsg)); + unsupportedSchemeDialog.Content(winrt::box_value(errorMsg)); // Show the dialog - presenter.ShowDialog(FindName(L"UnsupportedSchemeDialog").try_as()); + presenter.ShowDialog(unsupportedSchemeDialog); } } catch (...) @@ -1824,14 +1824,6 @@ namespace winrt::TerminalApp::implementation LOG_CAUGHT_EXCEPTION(); if (auto presenter{ _dialogPresenter.get() }) { - // FindName needs to be called first to actually load the xaml object - FindName(L"InvalidLinkDialog").try_as(); - - // Set the content - const auto errorMsg = fmt::format(std::wstring_view{ RS_(L"InvalidLinkContent") }, - eventArgs.Uri()); - InvalidLinkDialog().Content(winrt::box_value(errorMsg)); - // Show the dialog presenter.ShowDialog(FindName(L"InvalidLinkDialog").try_as()); } From 9240dd68f1330e1e22c1783958f37e79c92e4721 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 4 Sep 2020 11:46:44 -0400 Subject: [PATCH 3/7] dialog text/formatting --- .../TerminalApp/Resources/en-US/Resources.resw | 7 +++++++ src/cascadia/TerminalApp/TerminalPage.cpp | 13 +++++++------ src/cascadia/TerminalApp/TerminalPage.xaml | 7 +++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index be673ab5455..e5464d1f7cd 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -658,6 +658,10 @@ Cancel + + {} + {} will be replaced with the URI we could not open or parse + The scheme "{0}" is not supported. {0} will be replaced with the scheme the user is trying to use. @@ -665,4 +669,7 @@ Cancel + + This link type is currently not supported. + \ No newline at end of file diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index b0e13baca96..427d70e261a 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1807,14 +1807,15 @@ namespace winrt::TerminalApp::implementation } else if (auto presenter{ _dialogPresenter.get() }) { - // FindName needs to be called first to actually load the xaml object + // FindName needs to be called first to actually load the xaml objects auto unsupportedSchemeDialog = FindName(L"UnsupportedSchemeDialog").try_as(); + auto unopenedUri = FindName(L"UnopenedUri").try_as(); - // Set the content - const auto errorMsg = fmt::format(std::wstring_view{ RS_(L"UnsupportedSchemeContent") }, - parsed.SchemeName()); - unsupportedSchemeDialog.Content(winrt::box_value(errorMsg)); - + // Insert the URI + const auto uriMsg = fmt::format(std::wstring_view{ RS_(L"UnopenedUriText") }, + eventArgs.Uri().c_str()); + unopenedUri.Text(uriMsg); + // Show the dialog presenter.ShowDialog(unsupportedSchemeDialog); } diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index 32a0dc771af..4ff8f8e40cd 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -73,6 +73,13 @@ the MIT License. See LICENSE in the project root for license information. --> x:Name="UnsupportedSchemeDialog" x:Uid="UnsupportedSchemeDialog" DefaultButton="Primary"> + + + + + Date: Fri, 4 Sep 2020 12:25:36 -0400 Subject: [PATCH 4/7] remove unnecessary resource --- src/cascadia/TerminalApp/Resources/en-US/Resources.resw | 4 ---- src/cascadia/TerminalApp/TerminalPage.cpp | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index e5464d1f7cd..d9a241b12a2 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -658,10 +658,6 @@ Cancel - - {} - {} will be replaced with the URI we could not open or parse - The scheme "{0}" is not supported. {0} will be replaced with the scheme the user is trying to use. diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 427d70e261a..c2e4b292a65 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1812,10 +1812,8 @@ namespace winrt::TerminalApp::implementation auto unopenedUri = FindName(L"UnopenedUri").try_as(); // Insert the URI - const auto uriMsg = fmt::format(std::wstring_view{ RS_(L"UnopenedUriText") }, - eventArgs.Uri().c_str()); - unopenedUri.Text(uriMsg); - + unopenedUri.Text(eventArgs.Uri().c_str()); + // Show the dialog presenter.ShowDialog(unsupportedSchemeDialog); } From 26e80c08615adfbe6e2019a053f1609c519c8bf7 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 4 Sep 2020 14:01:42 -0400 Subject: [PATCH 5/7] resource/dialog fixes --- .../Resources/en-US/Resources.resw | 17 +++++---------- src/cascadia/TerminalApp/TerminalPage.cpp | 21 ++++++++++++------- src/cascadia/TerminalApp/TerminalPage.xaml | 13 +++--------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index d9a241b12a2..15f42ebb3f6 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -652,20 +652,13 @@ Close all tabs after the current tab - - There was an error reading this hyperlink. + + This link is invalid: - - Cancel - - - The scheme "{0}" is not supported. - {0} will be replaced with the scheme the user is trying to use. + + This link type is currently not supported: - + Cancel - - This link type is currently not supported. - \ No newline at end of file diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index c2e4b292a65..04507cc20a4 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1807,15 +1807,15 @@ namespace winrt::TerminalApp::implementation } else if (auto presenter{ _dialogPresenter.get() }) { - // FindName needs to be called first to actually load the xaml objects - auto unsupportedSchemeDialog = FindName(L"UnsupportedSchemeDialog").try_as(); - auto unopenedUri = FindName(L"UnopenedUri").try_as(); + // FindName needs to be called first to actually load the xaml object + auto unopenedUriDialog = FindName(L"CouldNotOpenUriDialog").try_as(); - // Insert the URI - unopenedUri.Text(eventArgs.Uri().c_str()); + // Insert the reason (unsupported scheme) and the URI + CouldNotOpenUriReason().Text(RS_(L"UnsupportedSchemeText")); + UnopenedUri().Text(eventArgs.Uri()); // Show the dialog - presenter.ShowDialog(unsupportedSchemeDialog); + presenter.ShowDialog(unopenedUriDialog); } } catch (...) @@ -1823,8 +1823,15 @@ namespace winrt::TerminalApp::implementation LOG_CAUGHT_EXCEPTION(); if (auto presenter{ _dialogPresenter.get() }) { + // FindName needs to be called first to actually load the xaml object + auto unopenedUriDialog = FindName(L"CouldNotOpenUriDialog").try_as(); + + // Insert the reason (invalid URI) and the URI + CouldNotOpenUriReason().Text(RS_(L"InvalidUriText")); + UnopenedUri().Text(eventArgs.Uri()); + // Show the dialog - presenter.ShowDialog(FindName(L"InvalidLinkDialog").try_as()); + presenter.ShowDialog(unopenedUriDialog); } } } diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index 4ff8f8e40cd..cd3858698c9 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -70,11 +70,11 @@ the MIT License. See LICENSE in the project root for license information. --> - + @@ -82,13 +82,6 @@ the MIT License. See LICENSE in the project root for license information. --> - - - Date: Tue, 8 Sep 2020 11:24:35 -0400 Subject: [PATCH 6/7] opening the dialog is now in a helper function --- src/cascadia/TerminalApp/TerminalPage.cpp | 42 ++++++++++++----------- src/cascadia/TerminalApp/TerminalPage.h | 1 + 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 04507cc20a4..ff4abf47c1d 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1805,34 +1805,36 @@ namespace winrt::TerminalApp::implementation { ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } - else if (auto presenter{ _dialogPresenter.get() }) + else { - // FindName needs to be called first to actually load the xaml object - auto unopenedUriDialog = FindName(L"CouldNotOpenUriDialog").try_as(); - - // Insert the reason (unsupported scheme) and the URI - CouldNotOpenUriReason().Text(RS_(L"UnsupportedSchemeText")); - UnopenedUri().Text(eventArgs.Uri()); - - // Show the dialog - presenter.ShowDialog(unopenedUriDialog); + _ShowCouldNotOpenDialog(RS_(L"UnsupportedSchemeText"), eventArgs.Uri().c_str()); } } catch (...) { LOG_CAUGHT_EXCEPTION(); - if (auto presenter{ _dialogPresenter.get() }) - { - // FindName needs to be called first to actually load the xaml object - auto unopenedUriDialog = FindName(L"CouldNotOpenUriDialog").try_as(); + _ShowCouldNotOpenDialog(RS_(L"InvalidUriText"), eventArgs.Uri().c_str()); + } + } - // Insert the reason (invalid URI) and the URI - CouldNotOpenUriReason().Text(RS_(L"InvalidUriText")); - UnopenedUri().Text(eventArgs.Uri()); + // Method Description: + // - Opens up a dialog box explaining why we could not open a URI + // Arguments: + // - The reason (unsupported scheme, invalid uri, potentially more in the future) + // - The uri + void TerminalPage::_ShowCouldNotOpenDialog(winrt::hstring reason, winrt::hstring uri) + { + if (auto presenter{ _dialogPresenter.get() }) + { + // FindName needs to be called first to actually load the xaml object + auto unopenedUriDialog = FindName(L"CouldNotOpenUriDialog").try_as(); - // Show the dialog - presenter.ShowDialog(unopenedUriDialog); - } + // Insert the reason and the URI + CouldNotOpenUriReason().Text(reason); + UnopenedUri().Text(uri); + + // Show the dialog + presenter.ShowDialog(unopenedUriDialog); } } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index ac68997afae..95fa56afce9 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -173,6 +173,7 @@ namespace winrt::TerminalApp::implementation const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs eventArgs); void _OpenHyperlinkHandler(const IInspectable sender, const Microsoft::Terminal::TerminalControl::OpenHyperlinkEventArgs eventArgs); + void _ShowCouldNotOpenDialog(winrt::hstring reason, winrt::hstring uri); bool _CopyText(const bool singleLine, const Windows::Foundation::IReference& formats); void _PasteText(); From c814eeae6cfd66da39ef5222cdcbe77ac5ef005a Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Tue, 8 Sep 2020 11:30:47 -0400 Subject: [PATCH 7/7] remove cstr call --- src/cascadia/TerminalApp/TerminalPage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index ff4abf47c1d..3383a5cded8 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1807,13 +1807,13 @@ namespace winrt::TerminalApp::implementation } else { - _ShowCouldNotOpenDialog(RS_(L"UnsupportedSchemeText"), eventArgs.Uri().c_str()); + _ShowCouldNotOpenDialog(RS_(L"UnsupportedSchemeText"), eventArgs.Uri()); } } catch (...) { LOG_CAUGHT_EXCEPTION(); - _ShowCouldNotOpenDialog(RS_(L"InvalidUriText"), eventArgs.Uri().c_str()); + _ShowCouldNotOpenDialog(RS_(L"InvalidUriText"), eventArgs.Uri()); } }