From 838364354929f4c53eda0119f646c889380f7642 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 13 Jul 2013 23:06:01 +0000 Subject: [PATCH] Ox.List: cleanup; trigger copy (add) and cut (add) events --- source/Ox.UI/js/List/List.js | 46 ++++++++++++++---------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/source/Ox.UI/js/List/List.js b/source/Ox.UI/js/List/List.js index 458dcedd..e21fc46e 100644 --- a/source/Ox.UI/js/List/List.js +++ b/source/Ox.UI/js/List/List.js @@ -169,6 +169,9 @@ Ox.List = function(options, self) { itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later keyboardEvents: { key_control_c: copyItems, + key_shift_control_c: function() { + copyItems(true); + }, key_control_e: editItems, key_control_n: function() { addItem(''); @@ -184,6 +187,9 @@ Ox.List = function(options, self) { }, key_control_v: pasteItems, key_control_x: cutItems, + key_shift_control_x: function() { + cutItems(true); + }, key_delete: deleteItems, key_end: scrollToLast, key_enter: open, @@ -374,25 +380,14 @@ Ox.List = function(options, self) { return $page; } - function copyItems() { - // fixme: both copy and paste should just deal with Ox.Clipboard, - // and use a "type" - self.options.selected.length && that.triggerEvent('copy', { + function copyItems(add) { + self.options.selected.length && that.triggerEvent('copy' + (add ? 'add': ''), { ids: self.options.selected }); - /* - ids.length && self.options.copy && Ox.Clipboard.copy( - self.options.copy( - ids.map(function(id) { - return that.value(id); - }) - ) - ); - */ } - function cutItems() { - copyItems(); + function cutItems(add) { + copyItems(add); deleteItems(); } @@ -1005,7 +1000,7 @@ Ox.List = function(options, self) { } function pasteItems() { - that.triggerEvent('paste', Ox.Clipboard.paste()); + that.triggerEvent('paste'); } function preview() { @@ -1518,11 +1513,16 @@ Ox.List = function(options, self) { /*@ addItems add item to list - (pos, items) -> add items to list at position + (items) -> add items at the end of the list + (pos, items) -> add items at position pos position to add items items array of items to add @*/ that.addItems = function(pos, items) { + if (arguments.length == 1) { + items = pos; + pos = self.listLength; + } var $items = [], length = items.length; self.selected.forEach(function(v, i) { @@ -1586,16 +1586,6 @@ Ox.List = function(options, self) { return that; }; - /*@ - paste paste data - (data) -> the list - data paste object - @*/ - that.paste = function(data) { - pasteItems(data); - return that; - }; - /*@ reloadList reload list contents () -> the list @@ -1641,7 +1631,7 @@ Ox.List = function(options, self) { (ids) -> remove items (pos, length) -> remove items ids array of item ids - pos delete items starting at this position + pos remove items starting at this position length number of items to remove @*/ that.removeItems = function(pos, length) {