diff --git a/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml b/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml
index 9635708343..e3d65c72c8 100644
--- a/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml
+++ b/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml
@@ -31,5 +31,10 @@
VerticalAlignment="Stretch"
Loaded="Browser_Loaded" />
+
diff --git a/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml.cs b/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml.cs
index eeddfcb0f4..551850abbe 100644
--- a/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml.cs
+++ b/src/modules/registrypreview/RegistryPreviewUILib/MonacoEditorControl.xaml.cs
@@ -13,6 +13,8 @@ using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Web.WebView2.Core;
+using Windows.ApplicationModel.DataTransfer;
+using Windows.System;
using Windows.UI;
namespace RegistryPreviewUILib
@@ -66,6 +68,7 @@ namespace RegistryPreviewUILib
Browser.DefaultBackgroundColor = Color.FromArgb(0, 0, 0, 0);
Browser.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted;
Browser.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
+ Browser.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
Browser.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
Browser.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
Browser.CoreWebView2.Settings.AreHostObjectsAllowed = false;
@@ -89,6 +92,16 @@ namespace RegistryPreviewUILib
Browser.CoreWebView2.Navigate(index);
}
+ private async void CoreWebView2_NewWindowRequested(CoreWebView2 sender, CoreWebView2NewWindowRequestedEventArgs args)
+ {
+ // Monaco opens URI in a new window. We open the URI in the default web browser.
+ if (args.Uri != null && args.IsUserInitiated)
+ {
+ args.Handled = true;
+ await ShowOpenUriDialogAsync(new Uri(args.Uri));
+ }
+ }
+
private void CoreWebView2_PermissionRequested(CoreWebView2 sender, CoreWebView2PermissionRequestedEventArgs args)
{
if (args.PermissionKind == CoreWebView2PermissionKind.ClipboardRead)
@@ -165,5 +178,23 @@ namespace RegistryPreviewUILib
{
_textChangedThrottle?.Dispose();
}
+
+ private async Task ShowOpenUriDialogAsync(Uri uri)
+ {
+ OpenUriDialog.Content = uri.ToString();
+ var result = await OpenUriDialog.ShowAsync();
+
+ if (result == ContentDialogResult.Primary)
+ {
+ await Launcher.LaunchUriAsync(uri);
+ }
+ }
+
+ private void OpenUriDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
+ {
+ var dataPackage = new DataPackage();
+ dataPackage.SetText(sender.Content.ToString());
+ Clipboard.SetContent(dataPackage);
+ }
}
}
diff --git a/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw b/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw
index 9401908d21..73469a3b50 100644
--- a/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw
+++ b/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw
@@ -178,6 +178,22 @@
Open Registry file
+
+ Cancel
+ Dialog showed when an URI is clicked. Button to close the dialog.
+
+
+ Open
+ Dialog showed when an URI is clicked. Button to open the URI.
+
+
+ Copy
+ Dialog showed when an URI is clicked. Button to copy the URI.
+
+
+ Do you want RegistryPreview to open the external application?
+ Title of the dialog showed when an URI is clicked,"RegistryPreview" is the name of the utility.
+
Reload