44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
var TextEditor = function(terminal) {
|
|
|
|
var self = this;
|
|
|
|
this.terminal = terminal;
|
|
|
|
this.node = document.createElement('div');
|
|
|
|
this.name = document.createElement('div');
|
|
this.node.appendChild(this.name);
|
|
|
|
this.area = document.createElement('textarea');
|
|
this.node.appendChild(this.area);
|
|
this.node.appendChild(document.createElement('br'));
|
|
|
|
this.saveButton = document.createElement('button');
|
|
this.saveButton.textContent = 'Save';
|
|
|
|
this.saveCallback = function(packet, args) {
|
|
if (packet.opcode == 'Result') {
|
|
self.terminal.ui.println('Saved');
|
|
} else if (packet.opcode == 'FileException') {
|
|
self.terminal.ui.println(packet.type);
|
|
}
|
|
};
|
|
|
|
this.save = function(e) {
|
|
self.terminal.fileAPI.save(self.saveCallback, null, self.terminal.session.toAbsolutePath(self.name.textContent), Unicode.toUTF8(self.area.value));
|
|
};
|
|
|
|
this.saveButton.onclick = this.save;
|
|
this.node.appendChild(this.saveButton);
|
|
|
|
this.closeButton = document.createElement('button');
|
|
this.closeButton.textContent = 'Close';
|
|
this.close = function(e) {
|
|
self.node.parentNode.removeChild(self.node);
|
|
self.terminal.ui.input.focus();
|
|
};
|
|
this.closeButton.onclick = this.close;
|
|
this.node.appendChild(this.closeButton);
|
|
|
|
};
|