This is for JWt. The translation to C++ is left as an exercise to the
reader. And maybe if someone contributes a nice C++ widget we may add
it to Wt (and JWt)?

Anyway, it's a nice example of how you can pimp a Wt application with
JS libraries.

BR,
Wim.

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("codemirror-2.32/lib/codemirror.js"));
                
app.require(app.resolveRelativeUrl("codemirror-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 code.
                //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);
        }
}


2012/9/4 Rob Van Dyck <rob.van.d...@gmail.com>:
> Wim,,
>
> I would also be interested in seeing a small example on how this is
> supposed to be done.
>
> Thanx and regards,
> Rob.
>
> On Mon, Sep 3, 2012 at 8:53 PM, Neil D'Souza <nxd...@yahoo.com> wrote:
>> Hi Wim,
>> If you can point me to the codemirror
>> example I will be happy to morph it into what I need for my app.
>>
>>    Thanks for your help.
>>
>> Kind Regards,
>> Neil
>
> ________________________________
>> From: Wim Dumon <w...@emweb.be>
>> To: Neil D'Souza <nxd...@yahoo.com>; witty-interest@lists.sourceforge.net
>> Sent: Tuesday, September 4, 2012 12:01 AM
>> Subject: Re: [Wt-interest] [Wt Interest] Using CodeMirror with Wt
>>
>> Hello Neil,
>>
>> Is there a specific reason why you're using the widgetset mode, rather
>> than just writing a CodeMirror widget? We have recently used Code
>> Mirror in combination with Wt.
>>
>> BR,
>> Wim.
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> witty-interest mailing list
> witty-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/witty-interest

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to