From 18d100f978cc68de1697679fe3db0c3883aaf0f4 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 13 Jul 2013 21:03:29 +0000 Subject: [PATCH] rewrite clipboard controller --- source/Ox.UI/js/Core/Clipboard.js | 41 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/source/Ox.UI/js/Core/Clipboard.js b/source/Ox.UI/js/Core/Clipboard.js index d421f54c..02585f55 100644 --- a/source/Ox.UI/js/Core/Clipboard.js +++ b/source/Ox.UI/js/Core/Clipboard.js @@ -2,26 +2,43 @@ /*@ Ox.Clipboard Basic clipboard handler - copy Copy data to clipboard - (data) -> undefined - paste Paste data from clipboard - () -> <*> Clipboard data + add Add items to clipboard + (items[, type]) -> Number of items + clear Clear clipboard + () -> Number of items + copy Copy items to clipboard + (items[, type]) -> Number of items + paste Paste items from clipboard + () -> Items + type Get item type + () -> Item type @*/ Ox.Clipboard = (function() { - var clipboard = {}; + var clipboard = {items: [], type: void 0}; return { _print: function() { - Ox.Log('Core', JSON.stringify(clipboard)); + Ox.print(JSON.stringify(clipboard)); }, - copy: function(data) { - clipboard = data; - Ox.Log('Core', 'copy', JSON.stringify(clipboard)); + add: function(items, type) { + if (type != clipboard.type) { + Ox.Clipboard.clear(); + } + clipboard = {items: clipboard.items.concat(items), type: type}; + return clipboard.items.length; + }, + clear: function() { + clipboard = {items: [], type: void 0}; + return clipboard.items.length; + }, + copy: function(items, type) { + clipboard = {items: items, type: type}; + return clipboard.items.length; }, paste: function(type) { - return type ? clipboard.type : clipboard; + return !type || type == clipboard.type ? clipboard.items : []; }, - type: function(type) { - return type in clipboard; + type: function() { + return clipboard.type; } }; }());