Ox.List: cleanup; trigger copy (add) and cut (add) events

This commit is contained in:
rlx 2013-07-13 23:06:01 +00:00
parent e283ff1053
commit 8383643549

View file

@ -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 itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
keyboardEvents: { keyboardEvents: {
key_control_c: copyItems, key_control_c: copyItems,
key_shift_control_c: function() {
copyItems(true);
},
key_control_e: editItems, key_control_e: editItems,
key_control_n: function() { key_control_n: function() {
addItem(''); addItem('');
@ -184,6 +187,9 @@ Ox.List = function(options, self) {
}, },
key_control_v: pasteItems, key_control_v: pasteItems,
key_control_x: cutItems, key_control_x: cutItems,
key_shift_control_x: function() {
cutItems(true);
},
key_delete: deleteItems, key_delete: deleteItems,
key_end: scrollToLast, key_end: scrollToLast,
key_enter: open, key_enter: open,
@ -374,25 +380,14 @@ Ox.List = function(options, self) {
return $page; return $page;
} }
function copyItems() { function copyItems(add) {
// fixme: both copy and paste should just deal with Ox.Clipboard, self.options.selected.length && that.triggerEvent('copy' + (add ? 'add': ''), {
// and use a "type"
self.options.selected.length && that.triggerEvent('copy', {
ids: self.options.selected 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() { function cutItems(add) {
copyItems(); copyItems(add);
deleteItems(); deleteItems();
} }
@ -1005,7 +1000,7 @@ Ox.List = function(options, self) {
} }
function pasteItems() { function pasteItems() {
that.triggerEvent('paste', Ox.Clipboard.paste()); that.triggerEvent('paste');
} }
function preview() { function preview() {
@ -1518,11 +1513,16 @@ Ox.List = function(options, self) {
/*@ /*@
addItems <f> add item to list addItems <f> add item to list
(pos, items) -> <u> add items to list at position (items) -> <u> add items at the end of the list
(pos, items) -> <u> add items at position
pos <n> position to add items pos <n> position to add items
items <a> array of items to add items <a> array of items to add
@*/ @*/
that.addItems = function(pos, items) { that.addItems = function(pos, items) {
if (arguments.length == 1) {
items = pos;
pos = self.listLength;
}
var $items = [], var $items = [],
length = items.length; length = items.length;
self.selected.forEach(function(v, i) { self.selected.forEach(function(v, i) {
@ -1586,16 +1586,6 @@ Ox.List = function(options, self) {
return that; return that;
}; };
/*@
paste <f> paste data
(data) -> <o> the list
data <o> paste object
@*/
that.paste = function(data) {
pasteItems(data);
return that;
};
/*@ /*@
reloadList <f> reload list contents reloadList <f> reload list contents
() -> <o> the list () -> <o> the list
@ -1641,7 +1631,7 @@ Ox.List = function(options, self) {
(ids) -> <u> remove items (ids) -> <u> remove items
(pos, length) -> <u> remove items (pos, length) -> <u> remove items
ids <a> array of item ids ids <a> array of item ids
pos <n> delete items starting at this position pos <n> remove items starting at this position
length <n> number of items to remove length <n> number of items to remove
@*/ @*/
that.removeItems = function(pos, length) { that.removeItems = function(pos, length) {