From 1377dbcbf4418333634df21fdc50f67351bf12c2 Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Thu, 10 Sep 2020 20:55:36 -0400 Subject: [PATCH] Open up content dialogs for invalid URIs and unsupported schemes (#7523) If a user clicks a link that is either invalid (cannot be parsed) or has a scheme we do not support (like file or mailto (for now)), we open up a dialog box telling them the issue. References #5001 --- .../Resources/en-US/Resources.resw | 63 +++++++++++-------- src/cascadia/TerminalApp/TerminalPage.cpp | 31 ++++++++- src/cascadia/TerminalApp/TerminalPage.h | 1 + src/cascadia/TerminalApp/TerminalPage.xaml | 14 +++++ 4 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index ce6b1d0e656..15f42ebb3f6 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -1,17 +1,17 @@  - @@ -652,4 +652,13 @@ Close all tabs after the current tab + + This link is invalid: + + + This link type is currently not supported: + + + Cancel + \ No newline at end of file diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index cf06e3d0fd3..f7d377b278e 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1808,8 +1808,37 @@ namespace winrt::TerminalApp::implementation { ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } + else + { + _ShowCouldNotOpenDialog(RS_(L"UnsupportedSchemeText"), eventArgs.Uri()); + } + } + catch (...) + { + LOG_CAUGHT_EXCEPTION(); + _ShowCouldNotOpenDialog(RS_(L"InvalidUriText"), 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(); + + // Insert the reason and the URI + CouldNotOpenUriReason().Text(reason); + UnopenedUri().Text(uri); + + // Show the dialog + presenter.ShowDialog(unopenedUriDialog); } - CATCH_LOG(); } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index e47904228cd..ff394115e53 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(); diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index c872b325029..cd3858698c9 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"> + + + + + + + +