mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(edit) show, initAce, create
This commit is contained in:
parent
be1a18bfe4
commit
e3dc4b65bf
1 changed files with 58 additions and 54 deletions
|
|
@ -18,6 +18,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
|
||||
Menu,
|
||||
Value,
|
||||
FileName,
|
||||
Edit = this,
|
||||
Diff,
|
||||
Emmet,
|
||||
|
|
@ -46,11 +47,12 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
CloudCmd.View,
|
||||
load,
|
||||
function(callback) {
|
||||
callback();
|
||||
DOM.loadSocket(initSocket);
|
||||
callback();
|
||||
},
|
||||
Edit.show.bind(null, callback),
|
||||
]);
|
||||
function(callback) {
|
||||
Edit.show(callback);
|
||||
}, callback]);
|
||||
}
|
||||
|
||||
function getHost() {
|
||||
|
|
@ -119,40 +121,51 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
}
|
||||
}
|
||||
|
||||
this.show = function(callback) {
|
||||
var func = exec.ret(callback);
|
||||
function createElement() {
|
||||
var element = DOM.load({
|
||||
name : 'div',
|
||||
style :
|
||||
'width : 100%;' +
|
||||
'height : 100%;' +
|
||||
'font : 16px "Droid Sans Mono";' +
|
||||
'position : absolute;',
|
||||
notAppend : true
|
||||
});
|
||||
|
||||
if (!Loading) {
|
||||
Images.show.load();
|
||||
|
||||
if (!Element) {
|
||||
Element = DOM.load({
|
||||
name : 'div',
|
||||
style :
|
||||
'width : 100%;' +
|
||||
'height : 100%;' +
|
||||
'font : 16px "Droid Sans Mono";' +
|
||||
'position : absolute;',
|
||||
notAppend : true
|
||||
});
|
||||
|
||||
initAce();
|
||||
|
||||
Events.add(Element, {
|
||||
contextmenu : setMenu,
|
||||
drop : onDrop,
|
||||
dragover : Events.preventDefault
|
||||
});
|
||||
}
|
||||
|
||||
getData(function(error, data) {
|
||||
Events.add(element, {
|
||||
contextmenu : setMenu,
|
||||
drop : onDrop,
|
||||
dragover : Events.preventDefault
|
||||
});
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
this.show = function(callback) {
|
||||
var element = Edit.create(),
|
||||
name = Info.name,
|
||||
isDir = Info.isDir;
|
||||
|
||||
Images.show.load();
|
||||
|
||||
if (callback)
|
||||
ConfigView.beforeShow = callback;
|
||||
|
||||
if (isDir)
|
||||
Edit.setMode('json');
|
||||
else
|
||||
Edit.setModeForPath(name);
|
||||
|
||||
Info.getData(function(error, data) {
|
||||
if (error) {
|
||||
alert(error);
|
||||
} else {
|
||||
Edit.setValue(data);
|
||||
|
||||
ConfigView.beforeShow = func;
|
||||
|
||||
CloudCmd.View.show(Element, ConfigView);
|
||||
});
|
||||
}
|
||||
CloudCmd.View.show(element, ConfigView);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this.getValue = function() {
|
||||
|
|
@ -184,20 +197,6 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
Ace.gotoLine(number);
|
||||
};
|
||||
|
||||
function getData(callback) {
|
||||
var name = Info.name,
|
||||
isDir = Info.isDir;
|
||||
|
||||
Util.check(arguments, ['callback']);
|
||||
|
||||
if (isDir)
|
||||
Edit.setMode('json');
|
||||
else
|
||||
Edit.setModeForPath(name);
|
||||
|
||||
Info.getData(callback);
|
||||
}
|
||||
|
||||
this.setModeForPath = function(name) {
|
||||
var modesByName = Modelist.modesByName,
|
||||
mode = Modelist.getModeForPath(name).mode,
|
||||
|
|
@ -237,7 +236,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
|
||||
if (!isEqual) {
|
||||
is = Dialog.confirm(msg);
|
||||
|
||||
t
|
||||
if (is)
|
||||
Edit.save();
|
||||
}
|
||||
|
|
@ -281,9 +280,12 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
Session.setUseWorker(isMatch);
|
||||
}
|
||||
|
||||
function initAce() {
|
||||
Ace = ace.edit(Element);
|
||||
Session = Ace.getSession();
|
||||
this.create = function() {
|
||||
var element = createElement();
|
||||
|
||||
Element = element;
|
||||
Ace = ace.edit(element);
|
||||
Session = Ace.getSession();
|
||||
|
||||
Ace.commands.addCommand({
|
||||
name : 'hide',
|
||||
|
|
@ -341,7 +343,9 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, M
|
|||
|
||||
Ace.setOptions(options);
|
||||
});
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
Edit.save = function() {
|
||||
var path = Info.path,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue