mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 08:56:20 +00:00
feature(edit) add setValue, setMode, setModeForPath
This commit is contained in:
parent
523bb11605
commit
83e2ba042a
1 changed files with 63 additions and 35 deletions
|
|
@ -4,7 +4,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
|
||||
CloudCmd.Edit = EditProto;
|
||||
|
||||
function EditProto() {
|
||||
function EditProto(callback) {
|
||||
var Name = 'Edit',
|
||||
Loading = false,
|
||||
DIR = CloudCmd.LIBDIRCLIENT + 'edit/',
|
||||
|
|
@ -41,19 +41,17 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
function init(callback) {
|
||||
Loading = true;
|
||||
Util.exec.series([
|
||||
CloudCmd.View,
|
||||
load,
|
||||
Edit.show
|
||||
Edit.show.bind(null, callback)
|
||||
]);
|
||||
}
|
||||
|
||||
this.show = function() {
|
||||
var mode, htmlMode, jsMode, isHTML, isJS, modesByName,
|
||||
name = Info.name,
|
||||
isDir = Info.isDir;
|
||||
this.show = function(callback) {
|
||||
var func = Util.exec.ret(callback);
|
||||
|
||||
if (!Loading) {
|
||||
Images.showLoad();
|
||||
|
|
@ -78,40 +76,26 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
});
|
||||
}
|
||||
|
||||
modesByName = Modelist.modesByName;
|
||||
|
||||
if (isDir)
|
||||
mode = modesByName.json.mode;
|
||||
else
|
||||
mode = Modelist.getModeForPath(name).mode;
|
||||
|
||||
htmlMode = modesByName.html.mode;
|
||||
jsMode = modesByName.javascript.mode;
|
||||
|
||||
isHTML = mode === htmlMode;
|
||||
isJS = mode === jsMode;
|
||||
|
||||
Session.setMode(mode);
|
||||
setUseOfWorker(mode);
|
||||
setEmmet(isHTML);
|
||||
|
||||
Info.getData(function(error, data) {
|
||||
var UndoManager = ace.require('ace/undomanager').UndoManager;
|
||||
getData(function(error, data) {
|
||||
Edit.setValue(data);
|
||||
|
||||
Value = data;
|
||||
ConfigView.beforeShow = func;
|
||||
|
||||
if (isJS && Session.getUseWorker())
|
||||
setJsHintConfig();
|
||||
|
||||
Ace.setValue(Value);
|
||||
CloudCmd.View.show(Element, ConfigView);
|
||||
|
||||
Session.setUndoManager(new UndoManager());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.hide = function() {
|
||||
this.setValue = function(value) {
|
||||
var UndoManager = ace.require('ace/undomanager').UndoManager;
|
||||
|
||||
Value = value;
|
||||
|
||||
Ace.setValue(value);
|
||||
Session.setUndoManager(new UndoManager());
|
||||
};
|
||||
|
||||
this.hide = function() {
|
||||
CloudCmd.View.hide();
|
||||
};
|
||||
|
||||
|
|
@ -127,6 +111,50 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
Ace.gotoLine(number);
|
||||
};
|
||||
|
||||
function getData(callback) {
|
||||
var name = Info.name,
|
||||
isDir = Info.isDir;
|
||||
|
||||
Util.checkArgs(arguments, ['callback']);
|
||||
|
||||
if (isDir)
|
||||
Edit.setMode('json');
|
||||
else
|
||||
Edit.setModeForPath(name);
|
||||
|
||||
Info.getData(function(error, data) {
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
this.setModeForPath = function(name) {
|
||||
var modesByName = Modelist.modesByName,
|
||||
mode = Modelist.getModeForPath(name).mode,
|
||||
|
||||
htmlMode = modesByName.html.mode,
|
||||
jsMode = modesByName.javascript.mode,
|
||||
|
||||
isHTML = mode === htmlMode,
|
||||
isJS = mode === jsMode;
|
||||
|
||||
Session.setMode(mode);
|
||||
setUseOfWorker(mode);
|
||||
setEmmet(isHTML);
|
||||
|
||||
if (isJS && Session.getUseWorker())
|
||||
setJsHintConfig();
|
||||
};
|
||||
|
||||
this.setMode = function(mode) {
|
||||
var ext,
|
||||
modesByName = Modelist.modesByName;
|
||||
|
||||
if (modesByName[mode]) {
|
||||
ext = modesByName[mode].extensions.split('|')[0];
|
||||
Edit.setModeForPath('.' + ext);
|
||||
}
|
||||
};
|
||||
|
||||
function isChanged() {
|
||||
var is,
|
||||
value = Ace.getValue(),
|
||||
|
|
@ -489,7 +517,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
}, HIDE_TIME);
|
||||
};
|
||||
|
||||
init();
|
||||
init(callback);
|
||||
}
|
||||
|
||||
})(CloudCmd, Util, DOM, CloudFunc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue