[NUI] Enhance clipboard sample code
[platform/core/csapi/tizenfx.git] / test / NUIClipboardDataSelected / ClipboardDataSelected.cs
index f0dc005..80ff348 100644 (file)
@@ -15,6 +15,7 @@ namespace NUIClipboardDataSelected
     class Program : NUIApplication
     {
         const string TAG = "clipboard";
+        const string MIME_TYPE_PLAIN_TEXT = "text/plain;charset=utf-8";
 
         protected override void OnCreate()
         {
@@ -27,22 +28,25 @@ namespace NUIClipboardDataSelected
             Window.Instance.WindowSize = new Size(1, 1);
             Window.Instance.BackgroundColor = Color.White;
 
-
             Tizen.NUI.WindowSystem.Shell.TizenShell tzShell;
             tzShell = new Tizen.NUI.WindowSystem.Shell.TizenShell();
             Window.Instance.SetAcceptFocus(false);
 
             Tizen.NUI.WindowSystem.Shell.KVMService kvmService;
-            // window that will act as KVM Service.
+            // Window that will act as KVM Service.
             kvmService = new Tizen.NUI.WindowSystem.Shell.KVMService(tzShell, Window.Instance); 
             kvmService.SetSecondarySelction();
 
-            // Add a dummy view for easy debugging.
+            // This view has nothing to do with this test, just for easy debugging.
+            // If there is a view, it is exposed to the process monitor.
             View view = NewView();
             Window.Instance.GetDefaultLayer().Add(view);
 
             // Register event handler.
             Clipboard.Instance.DataSelected += OnClipboardDataSelected;
+
+            // Self copy test.
+            CopyTest();
         }
 
         // When copy occurs somewhere, this callback is invoked.
@@ -69,6 +73,25 @@ namespace NUIClipboardDataSelected
             Tizen.Log.Info(TAG, $"OnClipboardDataReceived type:{clipEvent.MimeType}, data:{clipEvent.Data}\n");
         }
 
+        public void CopyTest()
+        {
+            // Self copy test.
+            // * SetData() is called 5 seconds after app execution.
+            // * Observe the Log of OnClipboardDataSelected.
+            // * If the log is output, there is a problem somewhere.
+            // * DataSelected event should not be invoked
+            // * by the SetData() called within the SecondarySelection.
+            Timer timer = new Timer(5000);
+            timer.Tick += (s, e) =>
+            {
+                string data = "Lorem ipsum dolor sit amet consectetuer";
+                Tizen.Log.Info(TAG, $"SetData type:{MIME_TYPE_PLAIN_TEXT}, data:{data}\n");
+                Clipboard.Instance.SetData(MIME_TYPE_PLAIN_TEXT, data);
+                return false;
+            };
+            timer.Start();
+        }
+
         public View NewView()
         {
             var view = new View()