how to use js in desktop app

I am trying to use this js editor (Ace Editor) in my desktop app. This does not seem to show the editor when executed. I am not getting any error. Any ideas?

HTMLViewer1.ExecuteJavaScript(“https://github.com/ajaxorg/ace-builds/src-noconflict/ace.js” )

Have you tried to display it in a browser ? Which platform ? Mac, Windows, Linux ?

Here https://github.com/ajaxorg/ace-builds/src-noconflict/ace.js in Chrome Windows displays :

{"error":"Not Found"}

Maybe that is the issue…

Reading the doc might be a good place to start: https://ace.c9.io/#nav=embedding

I guess I don’t know what is suppose to be in the executejavascript call versus what is to be loaded in the main html file?

This code works in a browser.

[code]

HTML #editor { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
function foo(items) { var x = "All this is syntax highlighted"; return x; }
[/code]

I’ve not looked into ace but would imagine it’s similar to Quill, that I use, courtesy of Tim Parnell.

You load the HTML you have quoted above into an HTMLViewer, using the LoadPage method. That gets the editor code and equally importantly, an environment within which it can work, into the HTMLViewer.

What goes into an ExecuteJavaScript method call is then some ephemeral javascript that, to be any use, will most likely make one of the API calls that the ace editor provides to do something specific. By ephemeral, I mean that the javascript is executed, and then thrown away. You can try this for yourself in any browser by putting:

javascript:alert("Hello");

into the address bar. So doing what you showed in your OP was a bit like Kirk saying something he thought was profound, and Spock replying “Fascinating, Captain.”. IOW, your HTMLViewer1 was being ironic.

For example, to load some text into the HTMLViewer ready for editing, I have to format it up as HTML first (so, change newlines into
etc). Then, what I do in my Xojo app, is something like this:

myHTMLViewer.ExecuteJavaScript("setHTML(""" + myTextAsHTML + """);")

where setHTML is a small piece of javascript added to my equivalent of the HTML page you put in your last post. In my case it looks like this:

function setHTML (htmlstr) { quill.clipboard.dangerouslyPasteHTML (htmlstr); }

dangerouslyPasteHTML is the name of a quill API method; you’d have to look to see what functionality ace provides.

You mentioned not getting any error. When you use ExecuteJavaScript, the js you give it to execute will run and end whether it works or not - but it has no means of telling you anything. I was having this problem too until I added a window.onerror method to the HTML page:

window.onerror = function (errmess, url, linenum) { window.status = "HTMLEditEvent:Error:JavaScript error at line " + linenum + " - " + errmess; }

Using window.status means I can use the Xojo StatusChanged event to obtain the new status string and then decode it.

What it all boils down to is that ace will provide a set of API calls you can make from your HTML page. You need to decide what set of API calls your Xojo app needs, and then have those calls make ace API calls, using ExecuteJavaScript and the StatusChanged event to go back and forth between them.

[quote=343153:@Robert Kantor]I guess I don’t know what is suppose to be in the executejavascript call versus what is to be loaded in the main html file?

This code works in a browser. [/quote]

You never replied about which platform you are using. On Windows, the out of the box HTMLViewer with native renderer may not have all the bells and whistles needed to correctly run that JS program.

See https://blog.xojo.com/2016/01/04/use-newer-version-of-internet-explorer-with-webbrowser-and-htmlviewer/

If it does not work, try to use WebKit renderer.

Thanks to Tim S and Michel B both posts above helped me to move forward.

Robb

So what was it ?

Besides, my not understanding the exectutejavascript intricacies, it seems the ace editor works best using the webkit renderer.

So you are under Windows, right ?

Yes, Windows.