diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs index 1ab626f2aa0..15d7779d5da 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs @@ -1386,7 +1386,7 @@ private void DynamoView_Loaded(object sender, EventArgs e) } // Load the new HomePage - if (IsNewAppHomeEnabled) LoadHomePage(); + if (DynamoModel.IsTestMode || IsNewAppHomeEnabled) LoadHomePage(); loaded = true; } @@ -1394,7 +1394,7 @@ private void DynamoView_Loaded(object sender, EventArgs e) // Add the HomePage to the DynamoView once its loaded private void LoadHomePage() { - if (homePage == null && startPage != null) + if (homePage == null && (startPage != null || DynamoModel.IsTestMode)) { homePage = new UI.Views.HomePage(); homePage.DataContext = startPage; diff --git a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs index 2d3f600f191..7184cf90ae1 100644 --- a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs +++ b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs @@ -157,6 +157,7 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA this.dynWebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; this.dynWebView.CoreWebView2.Settings.IsZoomControlEnabled = false; this.dynWebView.CoreWebView2.Settings.AreDevToolsEnabled = true; + this.dynWebView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested; // Load the embeded resources var assembly = Assembly.GetExecutingAssembly(); @@ -200,6 +201,39 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA } } + private void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e) + { + e.Handled = true; + ProcessUri(e.Uri); + } + + internal bool ProcessUri(string uri) + { + if (string.IsNullOrWhiteSpace(uri)) return false; + + Uri fileUri; + try + { + fileUri = new Uri(uri); + } + catch (UriFormatException) + { + return false; + } + + if (fileUri.IsFile) + { + var filePath = fileUri.LocalPath; + if (filePath.EndsWith(".dyn") || filePath.EndsWith(".dyf")) + { + OpenFile(filePath); + return true; + } + } + + return false; + } + internal async void LoadingDone() { SendGuidesData(); @@ -443,6 +477,7 @@ public void Dispose() DataContextChanged -= OnDataContextChanged; if(startPage != null) startPage.DynamoViewModel.PropertyChanged -= DynamoViewModel_PropertyChanged; + this.dynWebView.CoreWebView2.NewWindowRequested -= CoreWebView2_NewWindowRequested; if (File.Exists(fontFilePath)) { @@ -450,6 +485,7 @@ public void Dispose() } } #endregion + } diff --git a/test/DynamoCoreWpfTests/HomePageTests.cs b/test/DynamoCoreWpfTests/HomePageTests.cs index b56d2d69abf..079f1af90b2 100644 --- a/test/DynamoCoreWpfTests/HomePageTests.cs +++ b/test/DynamoCoreWpfTests/HomePageTests.cs @@ -547,6 +547,44 @@ public void ShowSampleFilesFolderCommandFromHomePage() Assert.IsTrue(wasTestHookInvoked, "The ShowSampleFilesFolderCommand method did not invoke the test hook as expected."); Assert.IsTrue(windoClosed, "Dynamo View was not closed correctly."); } + + [Test] + [Ignore("IsNewAppHomeEnabled flag is set to false")] + public void CanOpenGraphOnDragAndDrop() + { + // Arrange + var filePath = new Uri(Path.Combine(GetTestDirectory(ExecutingDirectory), @"core\nodeLocationTest.dyn")); + var vm = View.DataContext as DynamoViewModel; + var wasTestHookInvoked = false; + + string receivedPath = null; + HomePage.TestHook = (path) => + { + receivedPath = path; + wasTestHookInvoked = true; + }; + + Assert.IsFalse(wasTestHookInvoked); + + // Create the startPage manually, as it is not created under Test environment + var startPage = new StartPageViewModel(vm, true); + var homePage = View.homePage; + homePage.DataContext = startPage; + InitializeWebView2(homePage.dynWebView); + + // Act + var result = homePage.ProcessUri(filePath.ToString()); + + Assert.IsTrue(result, "The file Uri was not processed correctly."); + + // Clean up to avoid failures testing in pipeline + var windowClosed = CloseViewAndCleanup(View); + + // Assert + Assert.IsTrue(wasTestHookInvoked, "The OpenFile method did not invoke the test hook as expected."); + Assert.AreEqual(filePath, receivedPath, "The command did not return the same filePath"); + Assert.IsTrue(windowClosed, "Dynamo View was not closed correctly."); + } #endregion #region helpers