mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(edit-file) add
This commit is contained in:
parent
322b103481
commit
ce92cddf0e
7 changed files with 247 additions and 173 deletions
192
client/edit-file.js
Normal file
192
client/edit-file.js
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
||||
|
||||
(function(CloudCmd, Util, DOM) {
|
||||
'use strict';
|
||||
|
||||
CloudCmd.EditFile = function EditFileProto(callback) {
|
||||
var Info = DOM.CurrentInfo;
|
||||
var Dialog = DOM.Dialog;
|
||||
var exec = Util.exec;
|
||||
var EditFile = this;
|
||||
|
||||
var Menu,
|
||||
|
||||
TITLE = 'Edit',
|
||||
|
||||
Images = DOM.Images,
|
||||
MSG_CHANGED,
|
||||
ConfigView = {
|
||||
beforeClose: function() {
|
||||
exec.ifExist(Menu, 'hide');
|
||||
isChanged(EditFile.hide);
|
||||
}
|
||||
};
|
||||
|
||||
function init(callback) {
|
||||
var editor;
|
||||
|
||||
exec.series([
|
||||
CloudCmd.Edit,
|
||||
function(callback) {
|
||||
editor = CloudCmd.Edit.getEditor();
|
||||
callback();
|
||||
},
|
||||
function(callback) {
|
||||
authCheck(editor);
|
||||
callback();
|
||||
},
|
||||
|
||||
function(callback) {
|
||||
setListeners(editor);
|
||||
callback();
|
||||
},
|
||||
function(callback) {
|
||||
EditFile.show(callback);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
this.show = function() {
|
||||
Images.show.load();
|
||||
|
||||
Info.getData(function(error, data) {
|
||||
var path = Info.path;
|
||||
var isDir = Info.isDir;
|
||||
var name = Info.name;
|
||||
|
||||
if (isDir)
|
||||
name += '.json';
|
||||
|
||||
if (error)
|
||||
return Images.hide();
|
||||
|
||||
setMsgChanged(name);
|
||||
|
||||
CloudCmd.Edit
|
||||
.getEditor()
|
||||
.setValueFirst(path, data)
|
||||
.setModeForPath(name)
|
||||
.setOption('fontSize', 16);
|
||||
|
||||
CloudCmd.Edit.show(ConfigView);
|
||||
});
|
||||
};
|
||||
|
||||
this.hide = function() {
|
||||
CloudCmd.Edit.hide();
|
||||
};
|
||||
|
||||
function setListeners(editor) {
|
||||
var element = CloudCmd.Edit.getElement();
|
||||
|
||||
DOM.Events.addOnce('contextmenu', element, setMenu);
|
||||
|
||||
editor.on('save', function(value) {
|
||||
DOM.setCurrentSize(Format.size(value));
|
||||
});
|
||||
}
|
||||
|
||||
function authCheck(spawn) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (!config.auth)
|
||||
return;
|
||||
|
||||
spawn.emit('auth', config.username, config.password);
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setMenu(event) {
|
||||
var position = {
|
||||
x: event.clientX,
|
||||
y: event.clientY
|
||||
};
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
!Menu && DOM.loadRemote('menu', function(error) {
|
||||
var noFocus;
|
||||
var options = {
|
||||
beforeShow: function(params) {
|
||||
params.x -= 18;
|
||||
params.y -= 27;
|
||||
},
|
||||
|
||||
afterClick: function() {
|
||||
!noFocus && editor.focus();
|
||||
}
|
||||
};
|
||||
|
||||
var editor = CloudCmd.Edit.getEditor();
|
||||
|
||||
var menuData = {
|
||||
'Save Ctrl+S' : function() {
|
||||
editor.save();
|
||||
},
|
||||
'Go To Line Ctrl+G' : function() {
|
||||
noFocus = true;
|
||||
editor.goToLine();
|
||||
},
|
||||
'Cut Ctrl+X' : function() {
|
||||
editor.cutToClipboard();
|
||||
},
|
||||
'Copy Ctrl+C' : function() {
|
||||
editor.copyToClipboard();
|
||||
},
|
||||
'Paste Ctrl+V' : function() {
|
||||
editor.pasteFromClipboard();
|
||||
},
|
||||
'Delete Del' : function() {
|
||||
editor.remove('right');
|
||||
},
|
||||
'Select All Ctrl+A' : function() {
|
||||
editor.selectAll();
|
||||
},
|
||||
'Beautify Ctrl+B' : function() {
|
||||
editor.beautify();
|
||||
},
|
||||
'Minify Ctrl+M' : function() {
|
||||
editor.minify();
|
||||
},
|
||||
'Close Esc' : function() {
|
||||
EditFile.hide();
|
||||
}
|
||||
};
|
||||
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (Menu || !MenuIO)
|
||||
return;
|
||||
|
||||
var element = CloudCmd.Edit.getElement();
|
||||
|
||||
Menu = new MenuIO(element, options, menuData);
|
||||
Menu.show(position.x, position.y);
|
||||
});
|
||||
}
|
||||
|
||||
function setMsgChanged(name) {
|
||||
MSG_CHANGED = 'Do you want to save changes to ' + name + '?';
|
||||
}
|
||||
|
||||
function isChanged() {
|
||||
var editor = CloudCmd.Edit.getEditor();
|
||||
var is = editor.isChanged();
|
||||
|
||||
is && Dialog.confirm(TITLE, MSG_CHANGED, {cancel: false})
|
||||
.then(function() {
|
||||
editor.save();
|
||||
});
|
||||
}
|
||||
|
||||
init(callback);
|
||||
};
|
||||
|
||||
})(CloudCmd, Util, DOM, CloudFunc);
|
||||
|
||||
215
client/edit.js
215
client/edit.js
|
|
@ -1,4 +1,4 @@
|
|||
var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
||||
var CloudCmd, Util, DOM, CloudFunc;
|
||||
|
||||
(function(CloudCmd, Util, DOM) {
|
||||
'use strict';
|
||||
|
|
@ -6,30 +6,19 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
|||
CloudCmd.Edit = EditProto;
|
||||
|
||||
function EditProto(callback) {
|
||||
var Name = 'Edit',
|
||||
Loading = true,
|
||||
|
||||
Info = DOM.CurrentInfo,
|
||||
Dialog = DOM.Dialog,
|
||||
|
||||
var Name = 'Edit';
|
||||
var Loading = true;
|
||||
|
||||
var Dialog = DOM.Dialog,
|
||||
exec = Util.exec,
|
||||
Edit = this,
|
||||
Element,
|
||||
|
||||
Menu,
|
||||
|
||||
EditorName = 'edward',
|
||||
EditorName = 'edward',
|
||||
editor,
|
||||
|
||||
TITLE = 'Edit',
|
||||
TITLE = 'Edit',
|
||||
|
||||
Images = DOM.Images,
|
||||
MSG_CHANGED,
|
||||
Element,
|
||||
ConfigView = {
|
||||
beforeClose: function() {
|
||||
exec.ifExist(Menu, 'hide');
|
||||
isChanged(Edit.hide);
|
||||
},
|
||||
afterShow: function() {
|
||||
editor
|
||||
.moveCursorTo(0, 0)
|
||||
|
|
@ -40,24 +29,13 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
|||
function init(callback) {
|
||||
var element = createElement();
|
||||
|
||||
DOM.Events.addOnce('contextmenu', element, setMenu);
|
||||
|
||||
exec.series([
|
||||
CloudCmd.View,
|
||||
getConfig,
|
||||
function(callback) {
|
||||
loadFiles(element, callback);
|
||||
},
|
||||
function(callback) {
|
||||
authCheck(editor);
|
||||
callback();
|
||||
},
|
||||
function(callback) {
|
||||
Edit.create(element)
|
||||
.show(callback);
|
||||
},
|
||||
callback
|
||||
]);
|
||||
], callback);
|
||||
}
|
||||
|
||||
function createElement() {
|
||||
|
|
@ -71,80 +49,55 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
|||
notAppend: true
|
||||
});
|
||||
|
||||
Element = element;
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
this.show = function(callback) {
|
||||
function checkFn(name, fn) {
|
||||
if (typeof fn !== 'function')
|
||||
throw Error(name + ' should be a function!');
|
||||
}
|
||||
|
||||
function initConfig(config, options) {
|
||||
Util.copyObj(config, ConfigView);
|
||||
|
||||
if (!options)
|
||||
return config;
|
||||
|
||||
if (options.afterShow) {
|
||||
checkFn('options.afterShow', options.afterShow);
|
||||
|
||||
var afterShow = config.afterShow;
|
||||
|
||||
config.afterShow = function() {
|
||||
afterShow();
|
||||
options.afterShow();
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
this.show = function(options) {
|
||||
if (Loading)
|
||||
return;
|
||||
|
||||
Images.show.load();
|
||||
|
||||
if (callback)
|
||||
ConfigView.beforeShow = callback;
|
||||
|
||||
Info.getData(function(error, data) {
|
||||
var path = Info.path;
|
||||
var isDir = Info.isDir;
|
||||
var name = Info.name;
|
||||
|
||||
if (isDir)
|
||||
name += '.json';
|
||||
|
||||
if (error)
|
||||
return Images.hide();
|
||||
|
||||
Edit.setValue(data, {
|
||||
name: name,
|
||||
path: path
|
||||
});
|
||||
|
||||
CloudCmd.View.show(Element, ConfigView);
|
||||
});
|
||||
|
||||
CloudCmd.View.show(Element, initConfig(options));
|
||||
};
|
||||
|
||||
this.setValue = function(value, info) {
|
||||
var path = info.path;
|
||||
var name = info.name;
|
||||
|
||||
editor
|
||||
.setValueFirst(path, value)
|
||||
.setModeForPath(name)
|
||||
.setOption('fontSize', 16);
|
||||
|
||||
setMsgChanged(name);
|
||||
this.getEditor = function() {
|
||||
return editor;
|
||||
};
|
||||
|
||||
this.getElement = function() {
|
||||
return Element;
|
||||
};
|
||||
|
||||
this.hide = function() {
|
||||
CloudCmd.View.hide();
|
||||
};
|
||||
|
||||
this.create = function(element) {
|
||||
Element = element;
|
||||
|
||||
editor.on('save', function(value) {
|
||||
var size = Format.size(value);
|
||||
DOM.setCurrentSize(size);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
function authCheck(spawn) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (!config.auth)
|
||||
return;
|
||||
|
||||
spawn.emit('auth', config.username, config.password);
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getConfig(callback) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
|
|
@ -181,84 +134,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
|||
});
|
||||
}
|
||||
|
||||
function setMenu(event) {
|
||||
var position = {
|
||||
x: event.clientX,
|
||||
y: event.clientY
|
||||
};
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
!Menu && DOM.loadRemote('menu', function(error) {
|
||||
var noFocus;
|
||||
var options = {
|
||||
beforeShow: function(params) {
|
||||
params.x -= 18;
|
||||
params.y -= 27;
|
||||
},
|
||||
|
||||
afterClick: function() {
|
||||
!noFocus && editor.focus();
|
||||
}
|
||||
};
|
||||
var menuData = {
|
||||
'Save Ctrl+S' : function() {
|
||||
editor.save();
|
||||
},
|
||||
'Go To Line Ctrl+G' : function() {
|
||||
noFocus = true;
|
||||
editor.goToLine();
|
||||
},
|
||||
'Cut Ctrl+X' : function() {
|
||||
editor.cutToClipboard();
|
||||
},
|
||||
'Copy Ctrl+C' : function() {
|
||||
editor.copyToClipboard();
|
||||
},
|
||||
'Paste Ctrl+V' : function() {
|
||||
editor.pasteFromClipboard();
|
||||
},
|
||||
'Delete Del' : function() {
|
||||
editor.remove('right');
|
||||
},
|
||||
'Select All Ctrl+A' : function() {
|
||||
editor.selectAll();
|
||||
},
|
||||
'Beautify Ctrl+B' : function() {
|
||||
editor.beautify();
|
||||
},
|
||||
'Minify Ctrl+M' : function() {
|
||||
editor.minify();
|
||||
},
|
||||
'Close Esc' : function() {
|
||||
Edit.hide();
|
||||
}
|
||||
};
|
||||
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (Menu || !MenuIO)
|
||||
return;
|
||||
|
||||
Menu = new MenuIO(Element, options, menuData);
|
||||
Menu.show(position.x, position.y);
|
||||
});
|
||||
}
|
||||
|
||||
function setMsgChanged(name) {
|
||||
MSG_CHANGED = 'Do you want to save changes to ' + name + '?';
|
||||
}
|
||||
|
||||
function isChanged() {
|
||||
var is = editor.isChanged();
|
||||
|
||||
is && Dialog.confirm(TITLE, MSG_CHANGED, {cancel: false})
|
||||
.then(function() {
|
||||
editor.save();
|
||||
});
|
||||
}
|
||||
|
||||
init(callback);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ var CloudCmd, Util, DOM;
|
|||
break;
|
||||
|
||||
case Key.F4:
|
||||
CloudCmd.Edit.show();
|
||||
CloudCmd.EditFile.show();
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ var Util, DOM, CloudFunc, CloudCmd;
|
|||
'f1' : CloudCmd.Help.show,
|
||||
'f2' : DOM.renameCurrent,
|
||||
'f3' : CloudCmd.View.show,
|
||||
'f4' : CloudCmd.Edit.show,
|
||||
'f4' : CloudCmd.EditFile.show,
|
||||
'f5' : operation('copy'),
|
||||
'f6' : operation('move'),
|
||||
'f7' : DOM.promptNewDir,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[
|
||||
"edit",
|
||||
"edit-file",
|
||||
"menu",
|
||||
"view",
|
||||
"help",
|
||||
|
|
@ -8,7 +9,7 @@
|
|||
"contact",
|
||||
"upload",
|
||||
"operation",
|
||||
"konsole",
|
||||
"konsole",
|
||||
"cloud", [{
|
||||
"name": "remote",
|
||||
"data": [{
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@
|
|||
"minify": "^2.0.0",
|
||||
"minimist": "^1.2.0",
|
||||
"mollify": "^1.0.0",
|
||||
"nomine": "^1.0.1",
|
||||
"onezip": "^1.0.5",
|
||||
"opn": "^4.0.1",
|
||||
"os-homedir": "^1.0.0",
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const konsole = require('console-io/legacy');
|
|||
const edward = require('edward/legacy');
|
||||
const dword = require('dword/legacy');
|
||||
const deepword = require('deepword/legacy');
|
||||
const nomine = require('nomine/legacy');
|
||||
const spero = require('spero');
|
||||
const remedy = require('remedy');
|
||||
const ishtar = require('ishtar');
|
||||
|
|
@ -237,6 +238,10 @@ function cloudcmd(prefix, plugins) {
|
|||
prefix: prefix + '/salam',
|
||||
}),
|
||||
|
||||
nomine({
|
||||
prefix: prefix + '/rename',
|
||||
}),
|
||||
|
||||
setUrl(prefix),
|
||||
logout,
|
||||
auth(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue