UPDATE 3最终工作代码如下。您需要 src 文件夹中的 ace.js!它无法从库中运行,您需要从他们的站点获得预打包版本。
WText *editor = new WText(root());
editor->setText("function(){\n hello.abc();\n}\n");
editor->setInline(false);
上面的代码可以设置ACE窗口的内容。
MyClass::MyClass(const WEnvironment& env)
: WApplication(env)
{
wApp->require("ace-builds/src/ace.js");
// A WContainerWidget is rendered as a div
WContainerWidget *editor = new WContainerWidget(root());
editor->resize(500, 500);
std::string editor_ref = editor->jsRef(); // is a text string that will be the element when executed in JS
std::string command =
editor_ref + ".editor = ace.edit(" + editor_ref + ");" +
editor_ref + ".editor.setTheme(\"ace/theme/monokai\");" +
editor_ref + ".editor.getSession().setMode(\"ace/mode/javascript\");";
editor->doJavaScript(command);
JSignal <std::string> *jsignal = new JSignal<std::string>(editor, "textChanged");
jsignal->connect(this, &MyClass::textChanged);
WPushButton *b = new WPushButton("Save", root());
command = "function(object, event) {" +
jsignal->createCall(editor_ref + ".editor.getValue()") +
";}";
b->clicked().connect(command);
}
void MyClass::textChanged(std::string incoming)
{
}
UPDATE 2这是我的项目看起来像 atm 的样子,仍然是白色屏幕,右上角有来自 WT 的红色“正在加载...”消息。更多注释如下。
MyClass::MyClass(const WEnvironment& env)
: WApplication(env)
{
wApp->require("lib/ace/ace.js");
// A WContainerWidget is rendered as a div
WContainerWidget *editor = new WContainerWidget(root());
editor->resize(500, 500);
std::string editor_ref = editor->jsRef(); // is a text string that will be the element when executed in JS
std::string command =
editor_ref + ".editor = ace.edit(" + editor_ref + ");" +
editor_ref + ".editor.setTheme(\"ace/theme/monokai\");" +
editor_ref + ".editor.getSession().setMode(\"ace/mode/javascript\");";
editor->doJavaScript(command);
JSignal <std::string> *jsignal = new JSignal<std::string>(editor, "textChanged");
jsignal->connect(this, &MyClass::textChanged);
WPushButton *b = new WPushButton("Save", root());
command = "function(object, event) {" +
jsignal->createCall(editor_ref + ".editor.getValue()") +
";}";
b->clicked().connect(command);
}
void MyClass::textChanged(std::string incoming)
{
}
“command”变量用于 editor->doJavaScript(command) 时等于以下内容
"Wt3_3_0.$('oy4ycjy').editor = ace.edit(Wt3_3_0.$('oy4ycjy'));Wt3_3_0.$('oy4ycjy').editor.setTheme('ace/theme/monokai');Wt3_3_0.$('oy4ycjy').editor.getSession().setMode('ace/mode/javascript');"
“command”变量用于 b->clicked().connect(command); 时等于以下内容;
"function(object, event) {Wt.emit('oy4ycjy','textChanged',Wt3_3_0.$('oy4ycjy').editor.getValue());;}"
UPDATE 1
将建议的代码添加到我的构造函数中,但是页面不会从纯白色屏幕更改。我在这个 WT 项目中没有做任何其他事情,只有这段代码正在运行。
wApp->require("lib/ace/ace.js");
// A WContainerWidget is rendered as a div
WContainerWidget *editor = new WContainerWidget(root());
std::string editor_ref = editor->jsRef(); // is a text string that will be the element when executed in JS
editor->doJavaScript(
editor_ref + ".editor = ace.edit('" + editor_ref + "');" +
editor_ref + ".editor.setTheme('ace/theme/monokai');" +
editor_ref + ".editor.getSession().setMode('ace/mode/javascript');"
);
editor_ref 的值为“Wt3_3_0.$('oumvrgm')”减去引号。
还尝试添加下面的代码,但页面仍然空白。
JSignal <std::string> *jsignal = new JSignal<std::string>(editor, "textChanged");
jsignal->connect(this, &MyClass::textChanged);
WPushButton *b = new WPushButton("Save", root());
b->clicked().connect("function(object, event) {" +
jsignal->createCall(editor->jsRef() + ".editor.getValue()") +
";}");
我还发现注释掉了
editor_ref + ".editor = ace.edit('" + editor_ref + "');" +
使按钮显示,但屏幕右上角有一个红色的“正在加载...”注释,因此 WT 正在等待某些内容。
我目前将 textChanged 作为一个不执行任何操作的函数。
原帖
所以,我的问题是这样的。我怎样才能获得 ACEhttp://ace.ajax.org/#nav=about in WT http://www.webtoolkit.eu/wt。更具体地说,在 WT Wt::WTextArea 或 Wt::WTabWidget 中的 ACE,文本区域将是首选。我已经尝试这样做几天了,但没有取得太大成功。
我已经能够将 ACE 嵌入到 HTML 页面中,没有任何问题,因为他们的网站说“只需将其复制并粘贴到您的页面中”,事实就是这么简单。但是,我需要通过 WT 在本地将其加载到容器中。我将他们的存储库从 GIT 下载到我的机器上并尝试使用
require("lib/ace/ace.js");
and
doJavaScript(...);
使用各种命令都没有成功...我在 Java 和 HTML 方面的能力不如 C++ 强,所以如果这涉及大量 Java/HTML,我会要求尽可能详细的信息。先谢谢各位朋友了!