From b81bb28e254e68b1e022c0429bd8f3d56c6525b7 Mon Sep 17 00:00:00 2001 From: Enzo Batista Date: Wed, 18 Oct 2023 23:55:15 -0300 Subject: [PATCH] refactor(library): OnPasteFromClipboard function for clipboard management including comments --- .../LibraryViewController.cs | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/LibraryViewExtensionWebView2/LibraryViewController.cs b/src/LibraryViewExtensionWebView2/LibraryViewController.cs index 715821169c9..7b6c5aee20c 100644 --- a/src/LibraryViewExtensionWebView2/LibraryViewController.cs +++ b/src/LibraryViewExtensionWebView2/LibraryViewController.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -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; @@ -33,24 +31,38 @@ namespace Dynamo.LibraryViewExtensionWebView2 [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [ComVisibleAttribute(true)] + /// + /// This is for the object we're gonna host exposing the functions + /// for clipboard management to React component + /// public class ScriptObject { Action onCopyToClipboard; - Action onPasteFromClipboard; + Func onPasteFromClipboard; - internal ScriptObject(Action onCopyToClipboard, Action onPasteFromClipboard) + internal ScriptObject(Action onCopyToClipboard, Func onPasteFromClipboard) { this.onCopyToClipboard = onCopyToClipboard; this.onPasteFromClipboard = onPasteFromClipboard; } + + /// + /// 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) + /// + /// text to be added to the clipboard public void CopyToClipboard(string text) { onCopyToClipboard(text); } + + /// + /// 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(); + /// public string PasteFromClipboard() { - var text = Clipboard.GetText(); - return text; + return onPasteFromClipboard(); } } @@ -216,12 +228,21 @@ internal void RefreshLibraryView(WebView2 browser) #endregion + /// + /// This function will copy a string to clipboard + /// + /// text to be added to clipboard internal void OnCopyToClipboard(string text) { Clipboard.SetText(text); } - internal void OnPasteFromClipboard() { } + /// + /// This function will return the clipboard content + /// + internal string OnPasteFromClipboard() { + return Clipboard.GetText(); + } private string ReplaceUrlWithBase64Image(string html, string minifiedURL, bool magicreplace = true) { @@ -391,15 +412,6 @@ private void Browser_Loaded(object sender, RoutedEventArgs e) LogToDynamoConsole(msg); } - /// - /// 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 - /// - /// - /// - /// - // This enum is for matching the modifier keys between C# and javaScript enum ModifiersJS { @@ -417,10 +429,18 @@ enum EventsTracked V } + /// + /// 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 + /// + /// + /// + /// + private void Browser_KeyDown(object sender, KeyEventArgs e) { - if (!Enum.IsDefined(typeof(EventsTracked), e.Key.ToString())) return; var synteticEventData = new Dictionary