mirror of
https://github.com/slap-editor/slap.git
synced 2024-09-11 04:45:47 +03:00
fix(save): move slap code from EditorWidget
This commit is contained in:
parent
a30ab82592
commit
35f0fcb7e2
@ -86,12 +86,28 @@ Pane.prototype.requestClose = function () {
|
||||
}
|
||||
};
|
||||
|
||||
Pane.prototype.save = function (path) {
|
||||
var self = this;
|
||||
var header = self.screen.slap.header;
|
||||
var editor = self.editor;
|
||||
return editor.save(path)
|
||||
.tap(function () { header.message("saved to " + editor.textBuf.getPath(), 'success'); })
|
||||
.catch(function (err) {
|
||||
switch ((err.cause || err).code) {
|
||||
case 'EACCES': case 'EISDIR':
|
||||
header.message(err.message, 'error');
|
||||
break;
|
||||
default: throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Pane.prototype._initHandlers = function () {
|
||||
var self = this;
|
||||
var editor = self.editor;
|
||||
self.on('element keypress', function (el, ch, key) {
|
||||
switch (self.resolveBinding(key)) {
|
||||
case 'save': if (!editor.readOnly()) editor.textBuf.getPath() ? editor.save().done() : self.saveAsForm.show(); return false;
|
||||
case 'save': if (!editor.readOnly()) editor.textBuf.getPath() ? self.save().done() : self.saveAsForm.show(); return false;
|
||||
case 'saveAs': if (!editor.readOnly()) self.saveAsForm.show(); return false;
|
||||
case 'close': self.requestClose(); return false;
|
||||
case 'find': self.findForm.show(); return false;
|
||||
|
@ -48,7 +48,7 @@ SaveAsForm.prototype._initHandlers = function () {
|
||||
self.screen.slap.header.message("couldn't save, no filename passed", 'error');
|
||||
return;
|
||||
}
|
||||
self.pane.editor.save(path).done(function (newPath) {
|
||||
self.pane.save(path).done(function (newPath) {
|
||||
if (newPath) {
|
||||
self.hide();
|
||||
self.emit('save', newPath);
|
||||
|
Loading…
Reference in New Issue
Block a user