提交 6cddaa67 编写于 作者: NoSubject's avatar NoSubject

新政脚本编辑器monaco

上级 8c5a9442
o2.widget = o2.widget || {};
o2.require("o2.widget.ScriptArea", null, false);
o2.require("o2.widget.CssEditor", null, false);
//o2.require("o2.widget.CssEditor", null, false);
o2.widget.CssArea = new Class({
Implements: [Options, Events],
Extends: o2.widget.ScriptArea,
......@@ -52,22 +53,31 @@ o2.widget.CssArea = new Class({
loadEditor: function(content){
var value=(content) ? content.code : "";
value = (value) ? value : "";
this.jsEditor = new o2.widget.CssEditor(this.contentNode,{
this.jsEditor = new o2.widget.JavascriptEditor(this.contentNode,{
"option": {
"mode": "css",
"value": value,
"lineNumbers": false
},
"onPostLoad": function(){
this.editor = this.jsEditor.editor;
this.editor.id = "2";
this.editor.on("change", function() {
this.jsEditor.addEditorEvent("change", function() {
this.fireEvent("change");
}.bind(this));
this.editor.on("blur", function() {
this.jsEditor.addEditorEvent("blur", function() {
this.fireEvent("blur");
}.bind(this));
this.editor.resize();
// this.editor.on("change", function() {
// this.fireEvent("change");
// }.bind(this));
// this.editor.on("blur", function() {
// this.fireEvent("blur");
// }.bind(this));
this.jsEditor.resize();
this.fireEvent("postLoad");
}.bind(this),
"onSave": function(){
......
o2.widget = o2.widget || {};
o2.require("o2.widget.HtmlEditor", null, false);
//o2.require("o2.widget.HtmlEditor", null, false);
o2.require("o2.widget.ScriptArea", null, false);
o2.widget.HtmlEditorArea = new Class({
Implements: [Options, Events],
Extends: o2.widget.ScriptArea,
......@@ -7,16 +8,26 @@ o2.widget.HtmlEditorArea = new Class({
loadEditor: function(content){
var value=(content) ? content.code : "";
value = (value) ? value : "";
this.jsEditor = new o2.widget.HtmlEditor(this.contentNode,{
this.jsEditor = new o2.widget.JavascriptEditor(this.contentNode,{
"option": {
"mode": "html",
"value": value,
"lineNumbers": false
},
"onPostLoad": function(){
this.editor = this.jsEditor.editor;
this.editor.on("change", function() {
this.jsEditor.addEditorEvent("change", function() {
this.fireEvent("change");
}.bind(this));
this.jsEditor.addEditorEvent("blur", function() {
this.fireEvent("blur");
}.bind(this));
// this.editor.on("change", function() {
// this.fireEvent("change");
// }.bind(this));
this.jsEditor.resize();
this.fireEvent("postLoad");
}.bind(this),
"onSave": function(){
......
......@@ -89,28 +89,38 @@ o2.widget.JavascriptEditor = new Class({
this.editorClass.load(function(){
this.editor = monaco.editor.create(this.node, {
value: this.options.option.value,
language: "javascript",
language: this.options.option.mode,
theme: this.theme,
fontSize: this.fontSize,
lineNumbersMinChars: 3,
lineNumbers: (this.options.option.lineNumbers) ? "on" : "off",
mouseWheelZoom: true,
automaticLayout: true
});
this.focus();
o2.require("o2.xScript.Macro", function(){
o2.require("o2.xScript.Macro", function() {
var json = null;
o2.getJSON("/o2_core/o2/widget/$JavascriptEditor/environment.json", function(data){ json = data; }, false);
o2.getJSON("/o2_core/o2/widget/$JavascriptEditor/environment.json", function (data) {
json = data;
}, false);
this.Macro = new o2.Macro.FormContext(json);
//registerReferenceProvider
//monaco.languages.registerReferenceProvider('javascript', {
monaco.languages.registerCompletionItemProvider('javascript', {
provideCompletionItems: function(model, position, context, token) {
"triggerCharacters": ["."],
provideCompletionItems: function (model, position, context, token) {
debugger;
var textUntilPosition = model.getValueInRange({startLineNumber: position.lineNumber, startColumn: 1, endLineNumber: position.lineNumber, endColumn: position.column});
var textUntilPosition = model.getValueInRange({
startLineNumber: position.lineNumber,
startColumn: 1,
endLineNumber: position.lineNumber,
endColumn: position.column
});
var textPrefix = textUntilPosition.substr(0, textUntilPosition.lastIndexOf("."));
code = "try {return "+textPrefix+";}catch(e){return null;}";
//code = "try {return this;}catch(e){return null;}";
var o = this.Macro.exec(code);
var word = model.getWordUntilPosition(position);
......@@ -121,43 +131,40 @@ o2.widget.JavascriptEditor = new Class({
endColumn: word.endColumn
};
if (o){
if (o) {
var arr = [];
Object.keys(o).each(function(key){
Object.keys(o).each(function (key) {
var type = typeOf(o[key]);
if (type==="function") {
if (type === "function") {
var count = o[key].length;
var v = key+"(";
for (var i=1; i<=count; i++) v+= (i==count) ? "par"+i : "par"+i+", ";
v+=");";
var v = key + "(";
for (var i = 1; i <= count; i++) v += (i == count) ? "par" + i : "par" + i + ", ";
v += ")";
arr.push({
label: key,
kind: monaco.languages.CompletionItemKind.Function,
//documentation: "Fast, unopinionated, minimalist web framework",
insertText: v,
range: range
range: range,
detail: type
});
}else{
} else {
arr.push({
label: key,
kind: monaco.languages.CompletionItemKind.Interface,
//documentation: "Fast, unopinionated, minimalist web framework",
insertText: key,
range: range
range: range,
detail: type
});
}
});
}
return {suggestions: arr}
}.bind(this),
resolveCompletionItem: this.provideCompletionItems
}.bind(this)
});
}.bind(this));
});
this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function(e){
this.fireEvent("save");
......@@ -238,14 +245,14 @@ o2.widget.JavascriptEditor = new Class({
caption: key,
value: v,
score: 3,
meta: "function O2"
meta: type
});
}else{
arr2.push({
caption: key,
value: x+"."+key,
score: 3,
meta: (type!="null") ? typeOf(o[key])+" O2" : "O2"
meta: type
});
}
});
......@@ -319,6 +326,8 @@ o2.widget.JavascriptEditor = new Class({
var ev = name;
switch (ev) {
case "change": ev = "onDidChangeModelContent"; break;
case "blue": ev = "onDidBlurEditorText"; break;
}
if (this.editor[ev]) this.editor[ev](fun);
break;
......
......@@ -4,7 +4,7 @@ o2.widget.MWFRaphael = MWFRaphael = {
if (window.Raphael){
if (callback) callback();
}else{
COMMON.AjaxModule.loadDom("raphael", function(){
COMMON.AjaxModule.load("raphael", function(){
this.expandRaphael();
if (callback) callback();
}.bind(this), true, true);
......
......@@ -120,7 +120,7 @@ o2.widget.ScriptArea = new Class({
var th = this.titleNode.getStyle("height").toInt();
var height = (size.y || h)-(titleSize.y || th)-2-6;
this.contentNode.setStyle("height", ""+height+"px");
if (this.editor) this.editor.resize();
if (this.jsEditor) this.jsEditor.resize();
},
toJson: function(){
return (this.editor) ? {"code": this.editor.getValue(), "html": this.editor.getValue()} : this.contentCode;
......@@ -190,10 +190,18 @@ o2.widget.ScriptArea = new Class({
},
"onPostLoad": function(){
this.editor = this.jsEditor.editor;
this.editor.id = "2";
this.editor.on("change", function() {
//this.editor.id = "2";
this.jsEditor.addEditorEvent("change", function() {
this.fireEvent("change");
}.bind(this));
this.jsEditor.addEditorEvent("blur", function() {
this.fireEvent("blur");
}.bind(this));
// this.editor.on("change", function() {
// this.fireEvent("change");
// }.bind(this));
// this.editor.on("paste", function() {
// o2.load("JSBeautifier", function(){
// this.editor.setValue(js_beautify(this.editor.getValue()));
......@@ -201,7 +209,7 @@ o2.widget.ScriptArea = new Class({
// this.fireEvent("paste");
// }.bind(this));
this.editor.resize();
this.jsEditor.resize();
this.fireEvent("postLoad");
}.bind(this),
"onSave": function(){
......
......@@ -104,12 +104,20 @@ MWF.xApplication.cms.ScriptDesigner.Script = new Class({
if (this.data.text) {
this.editor.editor.setValue(this.data.text);
}
this.editor.editor.on("change", function (e) {
if (!this.isChanged) {
this.editor.addEditorEvent("change", function(){
if (!this.isChanged){
this.isChanged = true;
this.page.textNode.set("text", " * " + this.page.textNode.get("text"));
this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
}
}.bind(this));
// this.editor.editor.on("change", function (e) {
// if (!this.isChanged) {
// this.isChanged = true;
// this.page.textNode.set("text", " * " + this.page.textNode.get("text"));
// }
// }.bind(this));
this.editor.addEvent("save", function () {
this.save();
}.bind(this));
......
......@@ -545,10 +545,18 @@ MWF.xApplication.portal.PageDesigner.Script = new Class({
},
"onPostLoad": function(){
this.editor = this.jsEditor.editor;
this.editor.on("change", function() {
this.jsEditor.addEditorEvent("change", function() {
this.fireEvent("change");
}.bind(this));
this.editor.resize();
this.jsEditor.addEditorEvent("blur", function() {
this.fireEvent("blur");
}.bind(this));
// this.editor.on("change", function() {
// this.fireEvent("change");
// }.bind(this));
this.jsEditor.resize();
if (callback) callback();
this.fireEvent("postLoad");
}.bind(this),
......@@ -842,12 +850,22 @@ MWF.xApplication.portal.PageDesigner.Script.Item = new Class({
"onPostLoad": function(){
this.editor = this.jsEditor.editor;
this.editor.id = "1";
this.editor.on("change", function() {
this.jsEditor.addEditorEvent("change", function() {
var text = this.scriptPage.textNode.get("text");
if (text.substr(0,1)!=="*") this.scriptPage.textNode.set("text","*"+ text);
this.change();
}.bind(this));
this.editor.resize();
this.jsEditor.addEditorEvent("blur", function() {
this.fireEvent("blur");
}.bind(this));
// this.editor.on("change", function() {
// var text = this.scriptPage.textNode.get("text");
// if (text.substr(0,1)!=="*") this.scriptPage.textNode.set("text","*"+ text);
// this.change();
// }.bind(this));
this.jsEditor.resize();
}.bind(this),
"onSave": function(){
this.save();
......
......@@ -102,12 +102,18 @@ MWF.xApplication.portal.ScriptDesigner.Script = new Class({
if (this.data.text){
this.editor.editor.setValue(this.data.text);
}
this.editor.editor.on("change", function(e){
this.editor.addEditorEvent("change", function(){
if (!this.isChanged){
this.isChanged = true;
this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
}
}.bind(this));
// this.editor.editor.on("change", function(e){
// if (!this.isChanged){
// this.isChanged = true;
// this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
// }
// }.bind(this));
this.editor.addEvent("save", function(){
this.save();
}.bind(this));
......
......@@ -56,17 +56,23 @@ MWF.xApplication.process.ProcessDesigner.widget.ScriptText = new Class({
this.editor = new MWF.widget.JavascriptEditor(this.editorNode, {
"option": {"value": this.code},
"onSave": function(){
var value = this.editor.editor.getValue();
var value = this.editor.getValue();
this.fireEvent("change", [value]);
this.app.saveProcess();
}.bind(this)
});
this.editor.load(function(){
this.editor.editor.on("blur", function(){
var value = this.editor.editor.getValue();
this.editor.addEditorEvent("blur", function(){
var value = this.editor.getValue();
this.fireEvent("change", [value]);
}.bind(this));
// this.editor.editor.on("blur", function(){
// var value = this.editor.editor.getValue();
// this.fireEvent("change", [value]);
// }.bind(this));
this.createScriptReferenceMenu();
this.editor.addEvent("reference", function(editor, e, e1){
......
......@@ -208,10 +208,15 @@ MWF.xApplication.query.StatementDesigner.Statement = new Class({
}
this.json.data = this.editor.editor.getValue();
this.editor.editor.on("change", function(){
this.data.data = this.editor.editor.getValue();
this.editor.addEditorEvent("change", function(){
this.data.data = this.editor.getValue();
this.checkJpqlType();
}.bind(this));
// this.editor.editor.on("change", function(){
// this.data.data = this.editor.getValue();
// this.checkJpqlType();
// }.bind(this));
}.bind(this));
}.bind(this), false);
}
......
......@@ -1099,9 +1099,13 @@ MWF.xApplication.query.TableDesigner.Table.JPQLRunner = new Class({
o2.require("o2.widget.JavascriptEditor", function(){
this.editor = new o2.widget.JavascriptEditor(this.contentWhereArea, {"title": "JPQL", "option": {"mode": "sql"}});
this.editor.load(function(){
this.editor.editor.on("change", function(){
this.editor.addEditorEvent("change", function(){
this.checkJpqlType();
}.bind(this));
// this.editor.editor.on("change", function(){
// this.checkJpqlType();
// }.bind(this));
if (callback) callback();
}.bind(this));
}.bind(this), false);
......
......@@ -117,12 +117,19 @@ MWF.xApplication.service.AgentDesigner.Agent = new Class({
defaultText += "********************/\n";
this.editor.editor.setValue(defaultText);
}
this.editor.editor.on("change", function(e){
this.editor.addEditorEvent("change", function(){
if (!this.isChanged){
this.isChanged = true;
this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
}
}.bind(this));
// this.editor.editor.on("change", function(e){
// if (!this.isChanged){
// this.isChanged = true;
// this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
// }
// }.bind(this));
this.editor.addEvent("save", function(){
this.save();
}.bind(this));
......
......@@ -124,12 +124,19 @@ MWF.xApplication.service.InvokeDesigner.Invoke = new Class({
defaultText += "********************/\n";
this.editor.editor.setValue(defaultText);
}
this.editor.editor.on("change", function(e){
this.editor.addEditorEvent("change", function(){
if (!this.isChanged){
this.isChanged = true;
this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
}
}.bind(this));
// this.editor.editor.on("change", function(e){
// if (!this.isChanged){
// this.isChanged = true;
// this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
// }
// }.bind(this));
this.editor.addEvent("save", function(){
this.save();
}.bind(this));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册