refactor(edit) show, initAce, create

This commit is contained in:
coderaiser 2015-01-08 11:42:35 -05:00
parent be1a18bfe4
commit e3dc4b65bf

View file

@ -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,