filemanager label. do not hook remove() from List.

This commit is contained in:
Christopher Jeffrey 2013-08-27 10:22:19 -05:00
parent f8c2ebef1d
commit 1625046d9c
2 changed files with 33 additions and 17 deletions

View File

@ -1775,8 +1775,9 @@ function Element(options) {
this.setContent(options.content || '', true); this.setContent(options.content || '', true);
if (options.label) { if (options.label) {
this.append(new Box({ this._label = new Box({
screen: this.screen, screen: this.screen,
parent: this,
content: options.label, content: options.label,
left: 2, left: 2,
top: this.border ? 0 : -1, top: this.border ? 0 : -1,
@ -1784,10 +1785,10 @@ function Element(options) {
shrink: true, shrink: true,
style: this.style.label, style: this.style.label,
fixed: true fixed: true
})); });
if (this.screen.autoPadding) { if (this.screen.autoPadding) {
this.children[this.children.length-1].rleft = -this.ileft + 2; this._label.rleft = -this.ileft + 2;
this.children[this.children.length-1].rtop = -this.itop; this._label.rtop = -this.itop;
} }
} }
@ -4054,13 +4055,21 @@ function List(options) {
el.fixed = true; el.fixed = true;
} }
}); });
// Ensure children are removed from the
// item list if they are items.
this.on('remove', function(el) {
self.removeItem(el);
});
} }
List.prototype.__proto__ = Box.prototype; List.prototype.__proto__ = Box.prototype;
List.prototype.type = 'list'; List.prototype.type = 'list';
List.prototype.add = function(item) { List.prototype.add =
List.prototype.addItem =
List.prototype.appendItem = function(item) {
var self = this; var self = this;
// Note: Could potentially use Button here. // Note: Could potentially use Button here.
@ -4113,19 +4122,17 @@ List.prototype.add = function(item) {
} }
}; };
List.prototype._remove = List.prototype.remove; List.prototype.removeItem = function(child) {
List.prototype.remove = function(child) { var i = typeof child !== 'number'
if (typeof child === 'number') { ? this.items.indexOf(child)
child = this.children[child]; : child;
}
var i = this.items.indexOf(child);
if (~i) this.items.splice(i, 1);
this._remove(child);
};
List.prototype.addItem = List.prototype.add; if (~i && this.items[i]) {
List.prototype.appendItem = List.prototype.add; child = this.items.splice(i, 1)[0];
List.prototype.removeItem = List.prototype.remove; this.ritems.splice(i, 1);
this.remove(child);
}
};
List.prototype.setItems = function(items) { List.prototype.setItems = function(items) {
var i = 0 var i = 0
@ -4947,6 +4954,7 @@ function FileManager(options) {
options = options || {}; options = options || {};
options.parseTags = true; options.parseTags = true;
// options.label = ' {blue-fg}%path{/blue-fg} ';
List.call(this, options); List.call(this, options);
@ -4954,6 +4962,10 @@ function FileManager(options) {
this.file = this.cwd; this.file = this.cwd;
this.value = this.cwd; this.value = this.cwd;
if (options.label && ~options.label.indexOf('%path')) {
this._label.setContent(options.label.replace('%path', this.cwd));
}
this.on('select', function(item) { this.on('select', function(item) {
var value = item.content.replace(/\{[^{}]+\}/g, '').replace(/@$/, '') var value = item.content.replace(/\{[^{}]+\}/g, '').replace(/@$/, '')
, file = path.resolve(self.cwd, value); , file = path.resolve(self.cwd, value);
@ -4967,6 +4979,9 @@ function FileManager(options) {
if (stat.isDirectory()) { if (stat.isDirectory()) {
self.emit('cd', file, self.cwd); self.emit('cd', file, self.cwd);
self.cwd = file; self.cwd = file;
if (options.label && ~options.label.indexOf('%path')) {
self._label.setContent(options.label.replace('%path', file));
}
self.refresh(); self.refresh();
} else { } else {
self.emit('file', file); self.emit('file', file);

View File

@ -16,6 +16,7 @@ var fm = blessed.filemanager({
width: 'half', width: 'half',
top: 'center', top: 'center',
left: 'center', left: 'center',
label: ' {blue-fg}%path{/blue-fg} ',
cwd: process.env.HOME, cwd: process.env.HOME,
keys: true, keys: true,
vi: true, vi: true,