Skip to content

Commit

Permalink
refactor(library): OnPasteFromClipboard function for clipboard manage…
Browse files Browse the repository at this point in the history
…ment including comments
  • Loading branch information
Enzo707 committed Oct 19, 2023
1 parent 7f12194 commit b81bb28
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/LibraryViewExtensionWebView2/LibraryViewController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -11,7 +10,6 @@
using System.Windows.Controls;
using System.Windows.Input;
using CoreNodeModels.Properties;
using Dynamo.Controls;
using Dynamo.Extensions;
using Dynamo.LibraryViewExtensionWebView2.Handlers;
using Dynamo.LibraryViewExtensionWebView2.ViewModels;
Expand All @@ -33,24 +31,38 @@ namespace Dynamo.LibraryViewExtensionWebView2
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisibleAttribute(true)]

/// <summary>
/// This is for the object we're gonna host exposing the functions
/// for clipboard management to React component
/// </summary>
public class ScriptObject
{
Action<string> onCopyToClipboard;
Action onPasteFromClipboard;
Func<string> onPasteFromClipboard;

internal ScriptObject(Action<string> onCopyToClipboard, Action onPasteFromClipboard)
internal ScriptObject(Action<string> onCopyToClipboard, Func<string> onPasteFromClipboard)
{
this.onCopyToClipboard = onCopyToClipboard;
this.onPasteFromClipboard = onPasteFromClipboard;
}

/// <summary>
/// This is the function we expose for adding a string to the clipboard
/// In React component will be accesible from chrome.webview.hostObjects.scriptObject.CopyToClipboard(text)
/// </summary>
/// <param name="text">text to be added to the clipboard</param>
public void CopyToClipboard(string text)
{
onCopyToClipboard(text);
}

/// <summary>
/// This is the function we expose for paste a string from the clipboard
/// In React component will be accesible from chrome.webview.hostObjects.scriptObject.PasteFromClipboard();
/// </summary>
public string PasteFromClipboard()
{
var text = Clipboard.GetText();
return text;
return onPasteFromClipboard();
}

}
Expand Down Expand Up @@ -216,12 +228,21 @@ internal void RefreshLibraryView(WebView2 browser)

#endregion

/// <summary>
/// This function will copy a string to clipboard
/// </summary>
/// <param name="text">text to be added to clipboard</param>
internal void OnCopyToClipboard(string text)
{
Clipboard.SetText(text);
}

internal void OnPasteFromClipboard() { }
/// <summary>
/// This function will return the clipboard content
/// </summary>
internal string OnPasteFromClipboard() {
return Clipboard.GetText();
}

private string ReplaceUrlWithBase64Image(string html, string minifiedURL, bool magicreplace = true)
{
Expand Down Expand Up @@ -391,15 +412,6 @@ private void Browser_Loaded(object sender, RoutedEventArgs e)
LogToDynamoConsole(msg);
}

/// <summary>
/// Collect the main and modifier key from KeyEventArgs in order to pass
/// that data to eventDispatcher (located in library.html) which is responsible
/// for binding KeyDown events between dynamo and webview instances
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
///

// This enum is for matching the modifier keys between C# and javaScript
enum ModifiersJS
{
Expand All @@ -417,10 +429,18 @@ enum EventsTracked
V
}

/// <summary>
/// Collect the main and modifier key from KeyEventArgs in order to pass
/// that data to eventDispatcher (located in library.html) which is responsible
/// for binding KeyDown events between dynamo and webview instances
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
///

private void Browser_KeyDown(object sender, KeyEventArgs e)

{

if (!Enum.IsDefined(typeof(EventsTracked), e.Key.ToString())) return;

var synteticEventData = new Dictionary<string, string>
Expand Down

0 comments on commit b81bb28

Please sign in to comment.