栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

与WT一起使用ACE

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

与WT一起使用ACE

也许这使您朝着正确的方向前进:

wApp->require("lib/ace/ace.js")// A WContainerWidget is rendered as a divWContainerWidget *editor = new WContainerWidget(parent);// editor->jsRef() is a text string that will be the element when executed in JSeditor->doJavascript(    editor->jsRef() + ".editor = ace.edit(" + editor->jsRef() + ");" +    editor->jsRef() + ".editor.setTheme('ace/theme/monokai');" +    editor->jsRef() + ".editor.getSession().setMode('ace/mode/javascript');"  );

那应该装饰编辑器。Wt不会自动将对div的修改发送到服务器,因此您可以通过JSignal手动执行此操作(发出从JS到C ++的信号):

JSignal <std::string> *jsignal = new JSignal<std::string>(editor, "textChanged");jsignal->connect(this, MyClass::textChanged);WPushButton *b = new WPushButton("Save", parent);b->clicked().connect("function(object, event) {" +    jsignal->createCall(editor->jsRef() + ".editor.getValue()") +  ";}");

(上面的代码未经测试,因此您可能需要稍作调整)

我已经将CodeMirror集成在早期的JWt(java)项目中,如下所示:

import eu.webtoolkit.jwt.WApplication;import eu.webtoolkit.jwt.WContainerWidget;import eu.webtoolkit.jwt.Wtextarea;public class CodeMirrortextarea extends WContainerWidget {        private Wtextarea textarea;        public CodeMirrortextarea(WContainerWidget parent) {     super(parent);     textarea = new Wtextarea(this);     WApplication app = WApplication.getInstance();     app.require(app.resolveRelativeUrl("premirror-2.32/lib/premirror.js"));     app.require(app.resolveRelativeUrl("premirror-2.32/mode/groovy/groovy.js"));     //TODO:     //We save the editor state to the text area on each key stroke,     //it appears to be not a performance issue,     //however it might very well become one when editing larger fragments of pre.     //A better solution would be to save this state to the text area only when     //the form is submitted, currently this is not yet possible in Wt???.     String js =  "var e = " + textarea.getJsRef() + ";" +  "var cm = CodeMirror.fromtextarea(e, {" +  "       onKeyEvent : function (editor, event) {" +         "editor.save();" +         "   }," +  "       lineNumbers: true" +  "       });" +  "var self = " + getJsRef() + ";" +  "self.cm = cm;";     this.doJavascript(js);        }        public CodeMirrortextarea() {     this(null);        }        public void setText(String text) {     textarea.setText(text);        }        public String getText() {     return textarea.getText();        }        public void setMarker(int line, String htmlMarker) {     String js =  "var self = " + getJsRef() + ";" +  "self.cm.setMarker(" + line + ", " + jsStringLiteral(htmlMarker +"%N%") + ");";     this.doJavascript(js);        }        public void clearMarker(int line) {     String js =  "var self = " + getJsRef() + ";" +  "self.cm.clearMarker(" + line + ");";     this.doJavascript(js);        }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/449048.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号