From 36c726006fc756147ac2a7218da1ede04d8fc6f8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 27 Apr 2015 16:59:45 -0700 Subject: [PATCH] add more events to lists. --- lib/widget.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/widget.js b/lib/widget.js index 92dd940..ca2430d 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2990,6 +2990,7 @@ Element.prototype.setLabel = function(options) { }; Element.prototype.removeLabel = function() { + if (!this._label) return; this._label.detach(); delete this._label; }; @@ -3072,6 +3073,7 @@ Element.prototype.setHover = function(options) { }; Element.prototype.removeHover = function() { + if (!this._hover) return; this._hover.detach(); delete this._hover; }; @@ -5346,6 +5348,8 @@ List.prototype.appendItem = function(item) { self.screen.render(); }); } + + this.emit('add item'); }; List.prototype.find = @@ -5423,6 +5427,7 @@ List.prototype.removeItem = function(child) { this.select(i - 1); } } + this.emit('remove item'); }; List.prototype.clearItems = function() { @@ -5461,6 +5466,8 @@ List.prototype.setItems = function(items) { } else { this.select(Math.min(selected, items.length - 1)); } + + this.emit('set items'); }; List.prototype.select = function(index) { @@ -5492,6 +5499,9 @@ List.prototype.select = function(index) { this.value = helpers.cleanTags(this.ritems[this.selected]); if (!this.parent) return; this.scrollTo(this.selected); + + // XXX Move `action` and `select` events here. + this.emit('select item', this.items[this.selected], this.selected); }; List.prototype.move = function(offset) { @@ -6513,6 +6523,8 @@ FileManager.prototype.refresh = function(cwd, callback) { self.select(0); self.screen.render(); + self.emit('refresh'); + if (callback) callback(); }); }; @@ -7223,6 +7235,8 @@ Listbar.prototype.setItems = function(commands) { commands.forEach(function(cmd) { self.add(cmd); }); + + this.emit('set items'); }; Listbar.prototype.add = @@ -7341,6 +7355,8 @@ Listbar.prototype.appendItem = function(item, callback) { self.screen.render(); }); } + + this.emit('add item'); }; Listbar.prototype.render = function() { @@ -7417,6 +7433,9 @@ Listbar.prototype.select = function(offset) { this.leftOffset -= diff; } } + + // XXX Move `action` and `select` events here. + this.emit('select item', el, offset); }; Listbar.prototype.removeItem = function(child) { @@ -7433,6 +7452,8 @@ Listbar.prototype.removeItem = function(child) { this.select(i - 1); } } + + this.emit('remove item'); }; Listbar.prototype.move = function(offset) { @@ -7456,6 +7477,7 @@ Listbar.prototype.selectTab = function(index) { this.select(index); this.screen.render(); } + this.emit('select tab', item, index); }; /**