filemanager label. do not hook remove() from List.
This commit is contained in:
parent
f8c2ebef1d
commit
1625046d9c
|
@ -1775,8 +1775,9 @@ function Element(options) {
|
|||
this.setContent(options.content || '', true);
|
||||
|
||||
if (options.label) {
|
||||
this.append(new Box({
|
||||
this._label = new Box({
|
||||
screen: this.screen,
|
||||
parent: this,
|
||||
content: options.label,
|
||||
left: 2,
|
||||
top: this.border ? 0 : -1,
|
||||
|
@ -1784,10 +1785,10 @@ function Element(options) {
|
|||
shrink: true,
|
||||
style: this.style.label,
|
||||
fixed: true
|
||||
}));
|
||||
});
|
||||
if (this.screen.autoPadding) {
|
||||
this.children[this.children.length-1].rleft = -this.ileft + 2;
|
||||
this.children[this.children.length-1].rtop = -this.itop;
|
||||
this._label.rleft = -this.ileft + 2;
|
||||
this._label.rtop = -this.itop;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4054,13 +4055,21 @@ function List(options) {
|
|||
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.type = 'list';
|
||||
|
||||
List.prototype.add = function(item) {
|
||||
List.prototype.add =
|
||||
List.prototype.addItem =
|
||||
List.prototype.appendItem = function(item) {
|
||||
var self = this;
|
||||
|
||||
// Note: Could potentially use Button here.
|
||||
|
@ -4113,19 +4122,17 @@ List.prototype.add = function(item) {
|
|||
}
|
||||
};
|
||||
|
||||
List.prototype._remove = List.prototype.remove;
|
||||
List.prototype.remove = function(child) {
|
||||
if (typeof child === 'number') {
|
||||
child = this.children[child];
|
||||
}
|
||||
var i = this.items.indexOf(child);
|
||||
if (~i) this.items.splice(i, 1);
|
||||
this._remove(child);
|
||||
};
|
||||
List.prototype.removeItem = function(child) {
|
||||
var i = typeof child !== 'number'
|
||||
? this.items.indexOf(child)
|
||||
: child;
|
||||
|
||||
List.prototype.addItem = List.prototype.add;
|
||||
List.prototype.appendItem = List.prototype.add;
|
||||
List.prototype.removeItem = List.prototype.remove;
|
||||
if (~i && this.items[i]) {
|
||||
child = this.items.splice(i, 1)[0];
|
||||
this.ritems.splice(i, 1);
|
||||
this.remove(child);
|
||||
}
|
||||
};
|
||||
|
||||
List.prototype.setItems = function(items) {
|
||||
var i = 0
|
||||
|
@ -4947,6 +4954,7 @@ function FileManager(options) {
|
|||
|
||||
options = options || {};
|
||||
options.parseTags = true;
|
||||
// options.label = ' {blue-fg}%path{/blue-fg} ';
|
||||
|
||||
List.call(this, options);
|
||||
|
||||
|
@ -4954,6 +4962,10 @@ function FileManager(options) {
|
|||
this.file = 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) {
|
||||
var value = item.content.replace(/\{[^{}]+\}/g, '').replace(/@$/, '')
|
||||
, file = path.resolve(self.cwd, value);
|
||||
|
@ -4967,6 +4979,9 @@ function FileManager(options) {
|
|||
if (stat.isDirectory()) {
|
||||
self.emit('cd', file, self.cwd);
|
||||
self.cwd = file;
|
||||
if (options.label && ~options.label.indexOf('%path')) {
|
||||
self._label.setContent(options.label.replace('%path', file));
|
||||
}
|
||||
self.refresh();
|
||||
} else {
|
||||
self.emit('file', file);
|
||||
|
|
|
@ -16,6 +16,7 @@ var fm = blessed.filemanager({
|
|||
width: 'half',
|
||||
top: 'center',
|
||||
left: 'center',
|
||||
label: ' {blue-fg}%path{/blue-fg} ',
|
||||
cwd: process.env.HOME,
|
||||
keys: true,
|
||||
vi: true,
|
||||
|
|
Loading…
Reference in New Issue