Hi
@stevel05 ,
I've tried your library, but both examples without success.
I explain here what I doing:
because I work on an old 32 bit system, and the latest B4J version that works on 32 bit machines is 7.32 (I cannot update my system now), I managed your examples in different ways.
7.32 support CustomViews, but it do not recognize b4xlibs, so I downloaded your project, dependences and all needed material, then I extracted b4xlibs in project folders of two examples you posted and imported in the IDE all classes.
It compile, but the form do not show the code editor, I''ve tried it in debug mode and seem that all initialize in the right way, but it do not show the code editor in a JFX WebView.
I've tried to write on it or put some code at runtime, but write on it is impossible, the control do not respond to keyboard events, is static, nothing change and cannot be edited.
Note that in the CodeEditor example it show all languages and themes without problems and there are no errors on both examples.
When I press on some buttons that sends to a CodeMirror some Javascript the app crashes, here the log:
State: READY
State: SCHEDULED
State: RUNNING
State: CANCELLED
webengine._executescript (java line: 155)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.webengine._executescript(webengine.java:155)
at b4j.example.codemirrorwrapper._executescript(codemirrorwrapper.java:312)
at b4j.example.codemirrorwrapper._getselectedcode(codemirrorwrapper.java:333)
at b4j.example.codeeditor._btncopy_click(codeeditor.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA$1.run(BA.java:216)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: netscape.javascript.JSException: ReferenceError: Can't find variable: editor
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:137)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(WebPage.java:1473)
at javafx.scene.web.WebEngine.executeScript(WebEngine.java:982)
... 22 more
Can't find variable: editor <<<<<<
The SUCCEDED event in the CodeMirrorWrapper LoadProgress_Event function never fires on both examples, it only show SCHEDULED, RUNNING, CANCELLED so this part of code is never called:
B4X:
Log("State: " & NewState)
If NewState = "SUCCEEDED" Then ' <<<<<< NEVER RETURN SUCCEEDED, ONLY SCHEDULED, RUNNING, CANCELLED
Log("Page LOADED")
' Setup the javascript interface
Set_Bridge
Sleep(0)
Loaded = True
Dim Su As StringUtils
ExecuteScript($"setCode("${Su.EncodeBase64(Code.GetBytes("UTF8"))}");"$)
If mByFileType <> "" Then
ExecuteScript($"changeType("${mByFileType}")"$)
Else If MimeType <> "" Then
ExecuteScript($"changeType("${MimeType}")"$)
End If
If CurrentTheme <> "" Then ExecuteScript($"editor.setOption("theme", "${CurrentTheme}");"$)
If mReadOnly <> "false" Then ExecuteScript($"editor.setOption("readOnly", ${mReadOnly});"$)
If mLineWrapping <> "false" Then ExecuteScript($"editor.setOption("lineWrapping", ${mLineWrapping});"$)
If mAutofocus <> "false" Then ExecuteScript($"editor.setOption("autofocus", ${mAutofocus});"$)
SetSize(mWidth + 10, mHeight + 10)
CallSub(mCallBack,mEventName & "_Loaded")
End If
Personally I've searched it on the Forum because I need a code editor for B4A, my purpose is to try adapt it on top of B4A WebView using WebViewExtras or UltimateWebView libraries, but if it do not work on B4J I cannot try to adapt it for this project I started, I only need HTML and Javascript integration, . If it works on B4J I think it should work on B4A too because it just work on browser right ?
I want to use it on this project, at this moment I just use a simple EditText:
https://www.b4x.com/android/forum/threads/pass-more-than-3-arguments-from-b4a-to-webview-javascript-function.139554/#post-88386
If you interested, some time ago I started to wrap RSSyntaxTextArea directly on Java using Eclipse. This control only works on top of Swing, for this I discharged a JFX Form and created a Swing Form, but now these days I tried to use the JFX SwingNode and maybe I can adapt it as control to put it on JFX Forms, I know that SwingNode only support lightweight controls, so not sure if it can work, need to try, I already tried it with Java3D Canvas without success, it is not a lightweight control.
RSyntaxTextArea worked well, I just wrapped some parts, with these I succesfully created a simple Arduino IDE with colored syntax, code completion, code folding, keyboard shortcuts for code templates, even tried the same for Java, C++ and Lua (to use with ESP8266), then I changed something wrong and now it only show a screen where all the text is red, something wrong with Theme.xls file I suppose.
This is another very good code editor, Scintilla is another one, I've managed it some ages ago, only on Win platform, but it exists for Java too so can be used as multiplatform code editor.
So.... returning to our CodeMirror project... Seem that I do something wrong on it, all seem to work apart the editor itself.
I've attached both (not working) examples as zip, note that I removed the codemirror.zip from projects Files folder because it is too big and I cannot post it. Please can you see what is wrong ?
Many thanks