Skip to content

Commit

Permalink
drag and drop feature (#15059)
Browse files Browse the repository at this point in the history
- implemented drag and drop behavior for .dyn and .dyf files
- added test for the new feature. the test is passing, but ignored as webView2 initialization still causes time out on master-15
  • Loading branch information
dnenov authored Mar 26, 2024
1 parent fea0da7 commit 0c8fe05
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,15 +1386,15 @@ private void DynamoView_Loaded(object sender, EventArgs e)
}

// Load the new HomePage
if (IsNewAppHomeEnabled) LoadHomePage();
if (DynamoModel.IsTestMode || IsNewAppHomeEnabled) LoadHomePage();

loaded = true;
}

// 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;
Expand Down
36 changes: 36 additions & 0 deletions src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -443,13 +477,15 @@ public void Dispose()
DataContextChanged -= OnDataContextChanged;
if(startPage != null) startPage.DynamoViewModel.PropertyChanged -= DynamoViewModel_PropertyChanged;

this.dynWebView.CoreWebView2.NewWindowRequested -= CoreWebView2_NewWindowRequested;

if (File.Exists(fontFilePath))
{
File.Delete(fontFilePath);
}
}
#endregion

}


Expand Down
38 changes: 38 additions & 0 deletions test/DynamoCoreWpfTests/HomePageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c8fe05

Please sign in to comment.