From 768dbf2c709f6ce6fce120b80a5ee0f4d64bc8ac Mon Sep 17 00:00:00 2001 From: lempere Date: Mon, 9 May 2016 14:09:02 +0200 Subject: [PATCH 1/7] add platform windows --- plugin.xml | 14 +++++++-- src/windows/Clipboard.cs | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/windows/Clipboard.cs diff --git a/plugin.xml b/plugin.xml index 4148d15..542fbc8 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,10 +2,10 @@ + version="0.2.0"> - + Clipboard @@ -56,4 +56,14 @@ + + + + + + + + + + diff --git a/src/windows/Clipboard.cs b/src/windows/Clipboard.cs new file mode 100644 index 0000000..d3a3560 --- /dev/null +++ b/src/windows/Clipboard.cs @@ -0,0 +1,62 @@ +using WPCordovaClassLib.Cordova; +using WPCordovaClassLib.Cordova.Commands; +using WPCordovaClassLib.Cordova.JSON; + +namespace Cordova.Extension.Commands +{ + public class Clipboard : BaseCommand + { + public void copy(string options) + { + string text = ""; + + try + { + text = JsonHelper.Deserialize(options)[0]; + } + catch + { + DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + + return; + } + + try + { + var dataPackage = new DataPackage(); + dataPackage.SetText(text); + Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage); + System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => + { + //System.Windows.Clipboard.SetText(text); + + }); + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); + } + catch + { + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); + } + + } + + public void paste(string options) + { + string text = ""; + + System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => + { + try + { + text = System.Windows.Clipboard.GetText(); + + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); + } + catch + { + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); + } + }); + } + } +} From 9406b94ecad8d2f43c228ded7315c1efff5ab8da Mon Sep 17 00:00:00 2001 From: Fernando Garcia Date: Mon, 9 May 2016 15:24:38 +0200 Subject: [PATCH 2/7] Update plugin.xml --- plugin.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugin.xml b/plugin.xml index 542fbc8..97c0755 100644 --- a/plugin.xml +++ b/plugin.xml @@ -58,12 +58,8 @@ - - - - - - - + + + From 73729793f95e73d2d596285ca22778b9c937c40f Mon Sep 17 00:00:00 2001 From: Fernando Garcia Date: Mon, 9 May 2016 15:29:22 +0200 Subject: [PATCH 3/7] Update plugin.xml --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 97c0755..b738ef5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -58,7 +58,7 @@ - + From 69aad19758e5a9b6df20f551c8bdbb7704164ff4 Mon Sep 17 00:00:00 2001 From: Fernando Garcia Date: Mon, 9 May 2016 16:16:38 +0200 Subject: [PATCH 4/7] Create ClipboardProxy.js --- src/windows/ClipboardProxy.js | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/windows/ClipboardProxy.js diff --git a/src/windows/ClipboardProxy.js b/src/windows/ClipboardProxy.js new file mode 100644 index 0000000..ccb324e --- /dev/null +++ b/src/windows/ClipboardProxy.js @@ -0,0 +1,50 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +/*jslint sloppy:true */ +/*global Windows:true, require, document, window, module */ + +var cordova = require('cordova'); + +module.exports = { + + copy:function(options) { + var text = ""; + + var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage(); + dataPackage.setText(text); + Windows.ApplicationModel.DataTransfer.Clipboard.setContent(dataPackage); + + }, + paste:function(options) { + var text = ""; + + var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); + if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { + dataPackageView.getTextAsync().then(function (value) { + text = value; + }); + } + + } +}; // exports + +require("cordova/exec/proxy").add("Clipboard", module.exports); From b5ba1b33a2313cf2626435049d40749307fa1072 Mon Sep 17 00:00:00 2001 From: Fernando Garcia Date: Mon, 9 May 2016 16:21:43 +0200 Subject: [PATCH 5/7] Delete Clipboard.cs --- src/windows/Clipboard.cs | 62 ---------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/windows/Clipboard.cs diff --git a/src/windows/Clipboard.cs b/src/windows/Clipboard.cs deleted file mode 100644 index d3a3560..0000000 --- a/src/windows/Clipboard.cs +++ /dev/null @@ -1,62 +0,0 @@ -using WPCordovaClassLib.Cordova; -using WPCordovaClassLib.Cordova.Commands; -using WPCordovaClassLib.Cordova.JSON; - -namespace Cordova.Extension.Commands -{ - public class Clipboard : BaseCommand - { - public void copy(string options) - { - string text = ""; - - try - { - text = JsonHelper.Deserialize(options)[0]; - } - catch - { - DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); - - return; - } - - try - { - var dataPackage = new DataPackage(); - dataPackage.SetText(text); - Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage); - System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => - { - //System.Windows.Clipboard.SetText(text); - - }); - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); - } - catch - { - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); - } - - } - - public void paste(string options) - { - string text = ""; - - System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => - { - try - { - text = System.Windows.Clipboard.GetText(); - - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); - } - catch - { - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); - } - }); - } - } -} From fbf9427cac1527d521470ad6d9d66b7ddb2767ff Mon Sep 17 00:00:00 2001 From: Fernando Garcia Date: Mon, 9 May 2016 16:29:03 +0200 Subject: [PATCH 6/7] Update ClipboardProxy.js --- src/windows/ClipboardProxy.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/windows/ClipboardProxy.js b/src/windows/ClipboardProxy.js index ccb324e..c9e541a 100644 --- a/src/windows/ClipboardProxy.js +++ b/src/windows/ClipboardProxy.js @@ -27,23 +27,40 @@ var cordova = require('cordova'); module.exports = { copy:function(options) { - var text = ""; - - var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage(); - dataPackage.setText(text); - Windows.ApplicationModel.DataTransfer.Clipboard.setContent(dataPackage); + var text = ""; + try { + text = JSON.parse(options)[0]; + } + catch (e) { + //DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + return; + } + try { + var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage(); + dataPackage.setText(text); + Windows.ApplicationModel.DataTransfer.Clipboard.setContent(dataPackage); + //DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); + } + catch (e) { + //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); + } }, paste:function(options) { var text = ""; - var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); - if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { - dataPackageView.getTextAsync().then(function (value) { + try { + var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); + if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { + dataPackageView.getTextAsync().then(function (value) { text = value; + //DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); }); + } } - + catch (e) { + //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); + } } }; // exports From 11bc48b485374098dec6b84ae57e15c19e9f72b8 Mon Sep 17 00:00:00 2001 From: Fernando Garcia Date: Mon, 9 May 2016 17:04:42 +0200 Subject: [PATCH 7/7] Update ClipboardProxy.js --- src/windows/ClipboardProxy.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/windows/ClipboardProxy.js b/src/windows/ClipboardProxy.js index c9e541a..130693f 100644 --- a/src/windows/ClipboardProxy.js +++ b/src/windows/ClipboardProxy.js @@ -26,13 +26,13 @@ var cordova = require('cordova'); module.exports = { - copy:function(options) { + copy:function(successCallback, errorCallback, args) { var text = ""; try { - text = JSON.parse(options)[0]; + text = args[0]; } catch (e) { - //DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + errorCallback(e); return; } @@ -40,13 +40,13 @@ module.exports = { var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage(); dataPackage.setText(text); Windows.ApplicationModel.DataTransfer.Clipboard.setContent(dataPackage); - //DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); + successCallback(text); } catch (e) { - //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); + errorCallback(e);; } }, - paste:function(options) { + paste:function(successCallback, errorCallback, args) { var text = ""; try { @@ -54,12 +54,12 @@ module.exports = { if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { dataPackageView.getTextAsync().then(function (value) { text = value; - //DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text)); + successCallback(text); }); } } catch (e) { - //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); + errorCallback(e);; } } }; // exports